aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/utils/exchange_wrapper.ts10
-rw-r--r--packages/contracts/src/utils/formatters.ts10
-rw-r--r--packages/contracts/src/utils/log_decoder.ts29
-rw-r--r--packages/contracts/src/utils/signed_order_utils.ts44
4 files changed, 77 insertions, 16 deletions
diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts
index 75b452b04..daab002b3 100644
--- a/packages/contracts/src/utils/exchange_wrapper.ts
+++ b/packages/contracts/src/utils/exchange_wrapper.ts
@@ -20,10 +20,7 @@ export class ExchangeWrapper {
from: string,
opts: { takerTokenFillAmount?: BigNumber } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = signedOrderUtils.createFill(
- signedOrder,
- opts.takerTokenFillAmount,
- );
+ const params = signedOrderUtils.createFill(signedOrder, opts.takerTokenFillAmount);
const txHash = await this._exchange.fillOrder.sendTransactionAsync(
params.orderAddresses,
params.orderValues,
@@ -60,10 +57,7 @@ export class ExchangeWrapper {
from: string,
opts: { takerTokenFillAmount?: BigNumber } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = signedOrderUtils.createFill(
- signedOrder,
- opts.takerTokenFillAmount,
- );
+ const params = signedOrderUtils.createFill(signedOrder, opts.takerTokenFillAmount);
const txHash = await this._exchange.fillOrKillOrder.sendTransactionAsync(
params.orderAddresses,
params.orderValues,
diff --git a/packages/contracts/src/utils/formatters.ts b/packages/contracts/src/utils/formatters.ts
index 88e12a6b4..48c77fea1 100644
--- a/packages/contracts/src/utils/formatters.ts
+++ b/packages/contracts/src/utils/formatters.ts
@@ -5,10 +5,7 @@ import * as _ from 'lodash';
import { BatchCancelOrders, BatchFillOrders, MarketFillOrders } from './types';
export const formatters = {
- createBatchFill(
- signedOrders: SignedOrder[],
- takerTokenFillAmounts: BigNumber[] = [],
- ) {
+ createBatchFill(signedOrders: SignedOrder[], takerTokenFillAmounts: BigNumber[] = []) {
const batchFill: BatchFillOrders = {
orderAddresses: [],
orderValues: [],
@@ -42,10 +39,7 @@ export const formatters = {
});
return batchFill;
},
- createMarketFillOrders(
- signedOrders: SignedOrder[],
- takerTokenFillAmount: BigNumber,
- ) {
+ createMarketFillOrders(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber) {
const marketFillOrders: MarketFillOrders = {
orderAddresses: [],
orderValues: [],
diff --git a/packages/contracts/src/utils/log_decoder.ts b/packages/contracts/src/utils/log_decoder.ts
new file mode 100644
index 000000000..98dd8eab6
--- /dev/null
+++ b/packages/contracts/src/utils/log_decoder.ts
@@ -0,0 +1,29 @@
+import { LogWithDecodedArgs, RawLog } from '@0xproject/types';
+import { AbiDecoder } from '@0xproject/utils';
+import * as _ from 'lodash';
+import * as Web3 from 'web3';
+
+import { artifacts } from './artifacts';
+import { Artifact } from './types';
+
+export class LogDecoder {
+ private _abiDecoder: AbiDecoder;
+ constructor(networkId: number) {
+ if (_.isUndefined(networkId)) {
+ throw new Error('networkId not specified');
+ }
+ const abiArrays: Web3.AbiDefinition[][] = [];
+ _.forEach(artifacts, (artifact: Artifact) => {
+ const network = artifact.networks[networkId];
+ if (_.isUndefined(network)) {
+ throw new Error(`Artifact does not exist on network ${networkId}`);
+ }
+ abiArrays.push(network.abi);
+ });
+ this._abiDecoder = new AbiDecoder(abiArrays);
+ }
+ public tryToDecodeLogOrNoop<ArgsType>(log: Web3.LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
+ const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log);
+ return logWithDecodedArgs;
+ }
+}
diff --git a/packages/contracts/src/utils/signed_order_utils.ts b/packages/contracts/src/utils/signed_order_utils.ts
new file mode 100644
index 000000000..6122748b4
--- /dev/null
+++ b/packages/contracts/src/utils/signed_order_utils.ts
@@ -0,0 +1,44 @@
+import { SignedOrder } from '0x.js';
+import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import ethUtil = require('ethereumjs-util');
+import * as _ from 'lodash';
+
+import { crypto } from './crypto';
+
+export const signedOrderUtils = {
+ createFill: (signedOrder: SignedOrder, takerTokenFillAmount?: BigNumber) => {
+ const fill = {
+ ...signedOrderUtils.getOrderAddressesAndValues(signedOrder),
+ takerTokenFillAmount: takerTokenFillAmount || signedOrder.takerTokenAmount,
+ ...signedOrder.ecSignature,
+ };
+ return fill;
+ },
+ createCancel(signedOrder: SignedOrder, takerTokenCancelAmount?: BigNumber) {
+ const cancel = {
+ ...signedOrderUtils.getOrderAddressesAndValues(signedOrder),
+ takerTokenCancelAmount: takerTokenCancelAmount || signedOrder.takerTokenAmount,
+ };
+ return cancel;
+ },
+ getOrderAddressesAndValues(signedOrder: SignedOrder) {
+ return {
+ orderAddresses: [
+ signedOrder.maker,
+ signedOrder.taker,
+ signedOrder.makerTokenAddress,
+ signedOrder.takerTokenAddress,
+ signedOrder.feeRecipient,
+ ],
+ orderValues: [
+ signedOrder.makerTokenAmount,
+ signedOrder.takerTokenAmount,
+ signedOrder.makerFee,
+ signedOrder.takerFee,
+ signedOrder.expirationUnixTimestampSec,
+ signedOrder.salt,
+ ],
+ };
+ },
+};