aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src/utils')
-rw-r--r--packages/contracts/src/utils/artifacts.ts2
-rw-r--r--packages/contracts/src/utils/constants.ts1
-rw-r--r--packages/contracts/src/utils/exchange_wrapper.ts42
-rw-r--r--packages/contracts/src/utils/log_decoder.ts52
-rw-r--r--packages/contracts/src/utils/multi_sig_wrapper.ts18
-rw-r--r--packages/contracts/src/utils/signing_utils.ts4
-rw-r--r--packages/contracts/src/utils/transaction_factory.ts9
-rw-r--r--packages/contracts/src/utils/types.ts1
-rw-r--r--packages/contracts/src/utils/web3_wrapper.ts2
9 files changed, 73 insertions, 58 deletions
diff --git a/packages/contracts/src/utils/artifacts.ts b/packages/contracts/src/utils/artifacts.ts
index fe74ea072..357c66a0a 100644
--- a/packages/contracts/src/utils/artifacts.ts
+++ b/packages/contracts/src/utils/artifacts.ts
@@ -15,6 +15,7 @@ import * as TestLibs from '../artifacts/TestLibs.json';
import * as TestSignatureValidator from '../artifacts/TestSignatureValidator.json';
import * as TokenRegistry from '../artifacts/TokenRegistry.json';
import * as EtherToken from '../artifacts/WETH9.json';
+import * as Whitelist from '../artifacts/Whitelist.json';
import * as ZRX from '../artifacts/ZRXToken.json';
export const artifacts = {
@@ -33,5 +34,6 @@ export const artifacts = {
TestLibs: (TestLibs as any) as ContractArtifact,
TestSignatureValidator: (TestSignatureValidator as any) as ContractArtifact,
TokenRegistry: (TokenRegistry as any) as ContractArtifact,
+ Whitelist: (Whitelist as any) as ContractArtifact,
ZRX: (ZRX as any) as ContractArtifact,
};
diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts
index 7a0e26a48..9b0b92545 100644
--- a/packages/contracts/src/utils/constants.ts
+++ b/packages/contracts/src/utils/constants.ts
@@ -28,6 +28,7 @@ export const constants = {
DUMMY_TOKEN_SYMBOL: '',
DUMMY_TOKEN_DECIMALS: new BigNumber(18),
DUMMY_TOKEN_TOTAL_SUPPLY: new BigNumber(0),
+ NULL_BYTES: '0x',
NUM_DUMMY_ERC20_TO_DEPLOY: 3,
NUM_DUMMY_ERC721_TO_DEPLOY: 1,
NUM_ERC721_TOKENS_TO_MINT: 2,
diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts
index f7bd207a4..8f5915d97 100644
--- a/packages/contracts/src/utils/exchange_wrapper.ts
+++ b/packages/contracts/src/utils/exchange_wrapper.ts
@@ -7,16 +7,18 @@ import { ExchangeContract } from '../contract_wrappers/generated/exchange';
import { constants } from './constants';
import { formatters } from './formatters';
-import { logDecoder } from './log_decoder';
+import { LogDecoder } from './log_decoder';
import { orderUtils } from './order_utils';
import { OrderInfo, SignedTransaction } from './types';
export class ExchangeWrapper {
private _exchange: ExchangeContract;
private _web3Wrapper: Web3Wrapper;
+ private _logDecoder: LogDecoder;
constructor(exchangeContract: ExchangeContract, provider: Provider) {
this._exchange = exchangeContract;
this._web3Wrapper = new Web3Wrapper(provider);
+ this._logDecoder = new LogDecoder(this._web3Wrapper, this._exchange.address);
}
public async fillOrderAsync(
signedOrder: SignedOrder,
@@ -30,13 +32,13 @@ export class ExchangeWrapper {
params.signature,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async cancelOrderAsync(signedOrder: SignedOrder, from: string): Promise<TransactionReceiptWithDecodedLogs> {
const params = orderUtils.createCancel(signedOrder);
const txHash = await this._exchange.cancelOrder.sendTransactionAsync(params.order, { from });
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async fillOrKillOrderAsync(
@@ -51,7 +53,7 @@ export class ExchangeWrapper {
params.signature,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async fillOrderNoThrowAsync(
@@ -66,7 +68,7 @@ export class ExchangeWrapper {
params.signature,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async batchFillOrdersAsync(
@@ -81,7 +83,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async batchFillOrKillOrdersAsync(
@@ -96,7 +98,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async batchFillOrdersNoThrowAsync(
@@ -111,7 +113,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async marketSellOrdersAsync(
@@ -126,7 +128,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async marketSellOrdersNoThrowAsync(
@@ -141,7 +143,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async marketBuyOrdersAsync(
@@ -156,7 +158,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async marketBuyOrdersNoThrowAsync(
@@ -171,7 +173,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async batchCancelOrdersAsync(
@@ -180,12 +182,12 @@ export class ExchangeWrapper {
): Promise<TransactionReceiptWithDecodedLogs> {
const params = formatters.createBatchCancel(orders);
const txHash = await this._exchange.batchCancelOrders.sendTransactionAsync(params.orders, { from });
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async cancelOrdersUpToAsync(salt: BigNumber, from: string): Promise<TransactionReceiptWithDecodedLogs> {
const txHash = await this._exchange.cancelOrdersUpTo.sendTransactionAsync(salt, { from });
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async registerAssetProxyAsync(
@@ -203,7 +205,7 @@ export class ExchangeWrapper {
oldAssetProxyAddress,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async executeTransactionAsync(
@@ -217,7 +219,7 @@ export class ExchangeWrapper {
signedTx.signature,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async getTakerAssetFilledAmountAsync(orderHashHex: string): Promise<BigNumber> {
@@ -241,13 +243,7 @@ export class ExchangeWrapper {
params.rightSignature,
{ from },
);
- const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
- return tx;
- }
- private async _getTxWithDecodedExchangeLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
- const tx = await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => logDecoder.decodeLogOrThrow(log));
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
}
diff --git a/packages/contracts/src/utils/log_decoder.ts b/packages/contracts/src/utils/log_decoder.ts
index d2e65d176..32819b657 100644
--- a/packages/contracts/src/utils/log_decoder.ts
+++ b/packages/contracts/src/utils/log_decoder.ts
@@ -1,19 +1,23 @@
import { ContractArtifact } from '@0xproject/sol-compiler';
-import { AbiDefinition, LogEntry, LogWithDecodedArgs, RawLog } from '@0xproject/types';
+import {
+ AbiDefinition,
+ LogEntry,
+ LogWithDecodedArgs,
+ RawLog,
+ TransactionReceiptWithDecodedLogs,
+} from '@0xproject/types';
import { AbiDecoder, BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { artifacts } from './artifacts';
+import { constants } from './constants';
-const abiArrays: AbiDefinition[][] = [];
-_.forEach(artifacts, (artifact: ContractArtifact) => {
- const compilerOutput = artifact.compilerOutput;
- abiArrays.push(compilerOutput.abi);
-});
-const abiDecoder = new AbiDecoder(abiArrays);
-
-export const logDecoder = {
- wrapLogBigNumbers(log: any): any {
+export class LogDecoder {
+ private _web3Wrapper: Web3Wrapper;
+ private _contractAddress: string;
+ private _abiDecoder: AbiDecoder;
+ public static wrapLogBigNumbers(log: any): any {
const argNames = _.keys(log.args);
for (const argName of argNames) {
const isWeb3BigNumber = _.startsWith(log.args[argName].constructor.toString(), 'function BigNumber(');
@@ -21,13 +25,29 @@ export const logDecoder = {
log.args[argName] = new BigNumber(log.args[argName]);
}
}
- },
- decodeLogOrThrow<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
- const logWithDecodedArgsOrLog = abiDecoder.tryToDecodeLogOrNoop(log);
+ }
+ constructor(web3Wrapper: Web3Wrapper, contractAddress: string) {
+ this._web3Wrapper = web3Wrapper;
+ this._contractAddress = contractAddress;
+ const abiArrays: AbiDefinition[][] = [];
+ _.forEach(artifacts, (artifact: ContractArtifact) => {
+ const compilerOutput = artifact.compilerOutput;
+ abiArrays.push(compilerOutput.abi);
+ });
+ this._abiDecoder = new AbiDecoder(abiArrays);
+ }
+ public decodeLogOrThrow<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
+ const logWithDecodedArgsOrLog = this._abiDecoder.tryToDecodeLogOrNoop(log);
if (_.isUndefined((logWithDecodedArgsOrLog as LogWithDecodedArgs<ArgsType>).args)) {
throw new Error(`Unable to decode log: ${JSON.stringify(log)}`);
}
- logDecoder.wrapLogBigNumbers(logWithDecodedArgsOrLog);
+ LogDecoder.wrapLogBigNumbers(logWithDecodedArgsOrLog);
return logWithDecodedArgsOrLog;
- },
-};
+ }
+ public async getTxWithDecodedLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
+ const tx = await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
+ tx.logs = _.filter(tx.logs, log => log.address === this._contractAddress);
+ tx.logs = _.map(tx.logs, log => this.decodeLogOrThrow(log));
+ return tx;
+ }
+}
diff --git a/packages/contracts/src/utils/multi_sig_wrapper.ts b/packages/contracts/src/utils/multi_sig_wrapper.ts
index 5c73cdf5a..d67692194 100644
--- a/packages/contracts/src/utils/multi_sig_wrapper.ts
+++ b/packages/contracts/src/utils/multi_sig_wrapper.ts
@@ -7,14 +7,16 @@ import { AssetProxyOwnerContract } from '../contract_wrappers/generated/asset_pr
import { MultiSigWalletContract } from '../contract_wrappers/generated/multi_sig_wallet';
import { constants } from './constants';
-import { logDecoder } from './log_decoder';
+import { LogDecoder } from './log_decoder';
export class MultiSigWrapper {
private _multiSig: MultiSigWalletContract;
private _web3Wrapper: Web3Wrapper;
+ private _logDecoder: LogDecoder;
constructor(multiSigContract: MultiSigWalletContract, provider: Provider) {
this._multiSig = multiSigContract;
this._web3Wrapper = new Web3Wrapper(provider);
+ this._logDecoder = new LogDecoder(this._web3Wrapper, this._multiSig.address);
}
public async submitTransactionAsync(
destination: string,
@@ -26,17 +28,17 @@ export class MultiSigWrapper {
const txHash = await this._multiSig.submitTransaction.sendTransactionAsync(destination, value, data, {
from,
});
- const tx = await this._getTxWithDecodedMultiSigLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async confirmTransactionAsync(txId: BigNumber, from: string): Promise<TransactionReceiptWithDecodedLogs> {
const txHash = await this._multiSig.confirmTransaction.sendTransactionAsync(txId, { from });
- const tx = await this._getTxWithDecodedMultiSigLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async executeTransactionAsync(txId: BigNumber, from: string): Promise<TransactionReceiptWithDecodedLogs> {
const txHash = await this._multiSig.executeTransaction.sendTransactionAsync(txId, { from });
- const tx = await this._getTxWithDecodedMultiSigLogsAsync(txHash);
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
public async executeRemoveAuthorizedAddressAsync(
@@ -45,13 +47,7 @@ export class MultiSigWrapper {
): Promise<TransactionReceiptWithDecodedLogs> {
const txHash = await (this
._multiSig as AssetProxyOwnerContract).executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from });
- const tx = await this._getTxWithDecodedMultiSigLogsAsync(txHash);
- return tx;
- }
- private async _getTxWithDecodedMultiSigLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
- const tx = await this._web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
- tx.logs = _.filter(tx.logs, log => log.address === this._multiSig.address);
- tx.logs = _.map(tx.logs, log => logDecoder.decodeLogOrThrow(log));
+ const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
return tx;
}
}
diff --git a/packages/contracts/src/utils/signing_utils.ts b/packages/contracts/src/utils/signing_utils.ts
index 41d63832e..d56d2cd44 100644
--- a/packages/contracts/src/utils/signing_utils.ts
+++ b/packages/contracts/src/utils/signing_utils.ts
@@ -7,19 +7,19 @@ export const signingUtils = {
const prefixedMessage = ethUtil.hashPersonalMessage(message);
const ecSignature = ethUtil.ecsign(prefixedMessage, privateKey);
const signature = Buffer.concat([
- ethUtil.toBuffer(signatureType),
ethUtil.toBuffer(ecSignature.v),
ecSignature.r,
ecSignature.s,
+ ethUtil.toBuffer(signatureType),
]);
return signature;
} else if (signatureType === SignatureType.EIP712) {
const ecSignature = ethUtil.ecsign(message, privateKey);
const signature = Buffer.concat([
- ethUtil.toBuffer(signatureType),
ethUtil.toBuffer(ecSignature.v),
ecSignature.r,
ecSignature.s,
+ ethUtil.toBuffer(signatureType),
]);
return signature;
} else {
diff --git a/packages/contracts/src/utils/transaction_factory.ts b/packages/contracts/src/utils/transaction_factory.ts
index 41907132a..f66d55f9b 100644
--- a/packages/contracts/src/utils/transaction_factory.ts
+++ b/packages/contracts/src/utils/transaction_factory.ts
@@ -7,26 +7,25 @@ import { signingUtils } from './signing_utils';
import { SignedTransaction } from './types';
export class TransactionFactory {
- private _signer: string;
+ private _signerBuff: Buffer;
private _exchangeAddress: string;
private _privateKey: Buffer;
constructor(privateKey: Buffer, exchangeAddress: string) {
this._privateKey = privateKey;
this._exchangeAddress = exchangeAddress;
- const signerBuff = ethUtil.privateToAddress(this._privateKey);
- this._signer = `0x${signerBuff.toString('hex')}`;
+ this._signerBuff = ethUtil.privateToAddress(this._privateKey);
}
public newSignedTransaction(
data: string,
signatureType: SignatureType = SignatureType.Ecrecover,
): SignedTransaction {
const salt = generatePseudoRandomSalt();
- const txHash = crypto.solSHA3([this._exchangeAddress, salt, ethUtil.toBuffer(data)]);
+ const txHash = crypto.solSHA3([this._exchangeAddress, this._signerBuff, salt, ethUtil.toBuffer(data)]);
const signature = signingUtils.signMessage(txHash, this._privateKey, signatureType);
const signedTx = {
exchangeAddress: this._exchangeAddress,
salt,
- signer: this._signer,
+ signer: `0x${this._signerBuff.toString('hex')}`,
data,
signature: `0x${signature.toString('hex')}`,
};
diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts
index 9a0c95504..a6c90dae0 100644
--- a/packages/contracts/src/utils/types.ts
+++ b/packages/contracts/src/utils/types.ts
@@ -105,6 +105,7 @@ export enum ContractName {
DummyERC721Token = 'DummyERC721Token',
TestLibBytes = 'TestLibBytes',
Authorizable = 'Authorizable',
+ Whitelist = 'Whitelist',
}
export interface SignedTransaction {
diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts
index 02595506b..4b8512222 100644
--- a/packages/contracts/src/utils/web3_wrapper.ts
+++ b/packages/contracts/src/utils/web3_wrapper.ts
@@ -7,7 +7,7 @@ import { coverage } from './coverage';
export const txDefaults = {
from: devConstants.TESTRPC_FIRST_ADDRESS,
- gas: devConstants.GAS_ESTIMATE,
+ gas: devConstants.GAS_LIMIT,
};
const providerConfigs = { shouldUseInProcessGanache: true };
export const provider = web3Factory.getRpcProvider(providerConfigs);