aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/util
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-01-25 23:42:58 +0800
committerFabio Berger <me@fabioberger.com>2018-01-25 23:42:58 +0800
commit71d68f975cd7bc089f0cbef4e5888a73eab4ee42 (patch)
tree9482602fc23d2baec3fff1fb97750ad45adc6eca /packages/contracts/util
parentec3d8a034fe763d8255935985b1fb97aff6c177b (diff)
parentf58f0ddb67555c3f0c7252ea3e003824984c48ad (diff)
downloaddexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.gz
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.bz2
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.lz
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.xz
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.zst
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.zip
Merge branch 'development' into feature/portal-ledger-support
* development: (437 commits) Publish Update yarn.lock Update the CHANGELOG Fix the bug making it impossible to specify the custom ZRX address Fix fill/cancel order by looking for NoError instead of empty blockchainErr given the BlockchainErrs type refactor Add a comment about a yarn bug Add our mainnet and kovan nodes as backups for Portal requests Fix bug hiding the user info from topBar Add dev-utils package to top level README Prettier newline Prettier Allow Token symbols to be alphanumeric Update CHANGELOG, rebase on development Should not -> cannot Reject negative amounts in isValidBaseUnitAmount Re-add changelog for 0x.js Fix prettier Update yarn.lock Move tests to a separate folder Change file layout ... # Conflicts: # packages/website/README.md
Diffstat (limited to 'packages/contracts/util')
-rw-r--r--packages/contracts/util/artifacts.ts7
-rw-r--r--packages/contracts/util/balances.ts19
-rw-r--r--packages/contracts/util/bignumber_config.ts11
-rw-r--r--packages/contracts/util/constants.ts5
-rw-r--r--packages/contracts/util/crypto.ts5
-rw-r--r--packages/contracts/util/exchange_wrapper.ts134
-rw-r--r--packages/contracts/util/formatters.ts82
-rw-r--r--packages/contracts/util/multi_sig_wrapper.ts23
-rw-r--r--packages/contracts/util/order.ts17
-rw-r--r--packages/contracts/util/order_factory.ts29
-rw-r--r--packages/contracts/util/rpc.ts43
-rw-r--r--packages/contracts/util/token_registry_wrapper.ts16
-rw-r--r--packages/contracts/util/types.ts20
13 files changed, 214 insertions, 197 deletions
diff --git a/packages/contracts/util/artifacts.ts b/packages/contracts/util/artifacts.ts
index b15c9216f..ecb18cbce 100644
--- a/packages/contracts/util/artifacts.ts
+++ b/packages/contracts/util/artifacts.ts
@@ -6,6 +6,7 @@ export class Artifacts {
public Exchange: any;
public ZRXToken: any;
public DummyToken: any;
+ public DummyTokenV2: any;
public EtherToken: any;
public MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: any;
public MaliciousToken: any;
@@ -17,9 +18,11 @@ export class Artifacts {
this.Exchange = artifacts.require('Exchange');
this.ZRXToken = artifacts.require('ZRXToken');
this.DummyToken = artifacts.require('DummyToken');
- this.EtherToken = artifacts.require('EtherToken');
+ this.DummyTokenV2 = artifacts.require('DummyToken_v2');
+ this.EtherToken = artifacts.require('WETH9');
this.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress = artifacts.require(
- 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress');
+ 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress',
+ );
this.MaliciousToken = artifacts.require('MaliciousToken');
}
}
diff --git a/packages/contracts/util/balances.ts b/packages/contracts/util/balances.ts
index fce15db6d..6a1659ab1 100644
--- a/packages/contracts/util/balances.ts
+++ b/packages/contracts/util/balances.ts
@@ -1,22 +1,19 @@
-import {BigNumber} from 'bignumber.js';
+import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
-import {bigNumberConfigs} from './bignumber_config';
-import {BalancesByOwner, ContractInstance} from './types';
-
-bigNumberConfigs.configure();
+import { BalancesByOwner, ContractInstance } from './types';
export class Balances {
- private tokenContractInstances: ContractInstance[];
- private ownerAddresses: string[];
+ private _tokenContractInstances: ContractInstance[];
+ private _ownerAddresses: string[];
constructor(tokenContractInstances: ContractInstance[], ownerAddresses: string[]) {
- this.tokenContractInstances = tokenContractInstances;
- this.ownerAddresses = ownerAddresses;
+ this._tokenContractInstances = tokenContractInstances;
+ this._ownerAddresses = ownerAddresses;
}
public async getAsync(): Promise<BalancesByOwner> {
const balancesByOwner: BalancesByOwner = {};
- for (const tokenContractInstance of this.tokenContractInstances) {
- for (const ownerAddress of this.ownerAddresses) {
+ for (const tokenContractInstance of this._tokenContractInstances) {
+ for (const ownerAddress of this._ownerAddresses) {
let balance = await tokenContractInstance.balanceOf(ownerAddress);
balance = new BigNumber(balance);
if (_.isUndefined(balancesByOwner[ownerAddress])) {
diff --git a/packages/contracts/util/bignumber_config.ts b/packages/contracts/util/bignumber_config.ts
deleted file mode 100644
index 38f59d341..000000000
--- a/packages/contracts/util/bignumber_config.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import {BigNumber} from 'bignumber.js';
-
-export const bigNumberConfigs = {
- configure() {
- // By default BigNumber's `toString` method converts to exponential notation if the value has
- // more then 20 digits. We want to avoid this behavior, so we set EXPONENTIAL_AT to a high number
- BigNumber.config({
- EXPONENTIAL_AT: 1000,
- });
- },
-};
diff --git a/packages/contracts/util/constants.ts b/packages/contracts/util/constants.ts
index 5beebc68c..e61b2f802 100644
--- a/packages/contracts/util/constants.ts
+++ b/packages/contracts/util/constants.ts
@@ -1,4 +1,9 @@
export const constants = {
NULL_BYTES: '0x',
INVALID_OPCODE: 'invalid opcode',
+ REVERT: 'revert',
+ TESTRPC_NETWORK_ID: 50,
+ MAX_ETHERTOKEN_WITHDRAW_GAS: 43000,
+ MAX_TOKEN_TRANSFERFROM_GAS: 80000,
+ MAX_TOKEN_APPROVE_GAS: 60000,
};
diff --git a/packages/contracts/util/crypto.ts b/packages/contracts/util/crypto.ts
index 5253b8c15..9173df643 100644
--- a/packages/contracts/util/crypto.ts
+++ b/packages/contracts/util/crypto.ts
@@ -1,4 +1,3 @@
-import {BigNumber} from 'bignumber.js';
import BN = require('bn.js');
import ABI = require('ethereumjs-abi');
import ethUtil = require('ethereumjs-util');
@@ -19,14 +18,14 @@ export const crypto = {
const isNumber = _.isFinite(arg);
if (isNumber) {
argTypes.push('uint8');
- } else if ((arg).isBigNumber) {
+ } else if (arg.isBigNumber) {
argTypes.push('uint256');
args[i] = new BN(arg.toString(10), 10);
} else if (ethUtil.isValidAddress(arg)) {
argTypes.push('address');
} else if (_.isString(arg)) {
argTypes.push('string');
- } else if (_.isBoolean(arg)) {
+ } else if (_.isBoolean(arg)) {
argTypes.push('bool');
} else {
throw new Error(`Unable to guess arg type: ${arg}`);
diff --git a/packages/contracts/util/exchange_wrapper.ts b/packages/contracts/util/exchange_wrapper.ts
index 304dcdacf..ca79f92c4 100644
--- a/packages/contracts/util/exchange_wrapper.ts
+++ b/packages/contracts/util/exchange_wrapper.ts
@@ -1,23 +1,26 @@
-import {BigNumber} from 'bignumber.js';
+import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
-import {formatters} from './formatters';
-import {Order} from './order';
-import {ContractInstance} from './types';
+import { formatters } from './formatters';
+import { Order } from './order';
+import { ContractInstance } from './types';
export class ExchangeWrapper {
- private exchange: ContractInstance;
+ private _exchange: ContractInstance;
constructor(exchangeContractInstance: ContractInstance) {
- this.exchange = exchangeContractInstance;
+ this._exchange = exchangeContractInstance;
}
- public async fillOrderAsync(order: Order, from: string,
- opts: {
- fillTakerTokenAmount?: BigNumber;
- shouldThrowOnInsufficientBalanceOrAllowance?: boolean;
- } = {}) {
+ public async fillOrderAsync(
+ order: Order,
+ from: string,
+ opts: {
+ fillTakerTokenAmount?: BigNumber;
+ shouldThrowOnInsufficientBalanceOrAllowance?: boolean;
+ } = {},
+ ) {
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
- const tx = await this.exchange.fillOrder(
+ const tx = await this._exchange.fillOrder(
params.orderAddresses,
params.orderValues,
params.fillTakerTokenAmount,
@@ -25,48 +28,52 @@ export class ExchangeWrapper {
params.v,
params.r,
params.s,
- {from},
+ { from },
);
_.each(tx.logs, log => wrapLogBigNumbers(log));
return tx;
}
- public async cancelOrderAsync(order: Order, from: string,
- opts: {cancelTakerTokenAmount?: BigNumber} = {}) {
+ public async cancelOrderAsync(order: Order, from: string, opts: { cancelTakerTokenAmount?: BigNumber } = {}) {
const params = order.createCancel(opts.cancelTakerTokenAmount);
- const tx = await this.exchange.cancelOrder(
+ const tx = await this._exchange.cancelOrder(
params.orderAddresses,
params.orderValues,
params.cancelTakerTokenAmount,
- {from},
+ { from },
);
_.each(tx.logs, log => wrapLogBigNumbers(log));
return tx;
}
- public async fillOrKillOrderAsync(order: Order, from: string,
- opts: {fillTakerTokenAmount?: BigNumber} = {}) {
+ public async fillOrKillOrderAsync(order: Order, from: string, opts: { fillTakerTokenAmount?: BigNumber } = {}) {
const shouldThrowOnInsufficientBalanceOrAllowance = true;
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
- const tx = await this.exchange.fillOrKillOrder(
+ const tx = await this._exchange.fillOrKillOrder(
params.orderAddresses,
params.orderValues,
params.fillTakerTokenAmount,
params.v,
params.r,
params.s,
- {from},
+ { from },
);
_.each(tx.logs, log => wrapLogBigNumbers(log));
return tx;
}
- public async batchFillOrdersAsync(orders: Order[], from: string,
- opts: {
- fillTakerTokenAmounts?: BigNumber[];
- shouldThrowOnInsufficientBalanceOrAllowance?: boolean;
- } = {}) {
+ public async batchFillOrdersAsync(
+ orders: Order[],
+ from: string,
+ opts: {
+ fillTakerTokenAmounts?: BigNumber[];
+ shouldThrowOnInsufficientBalanceOrAllowance?: boolean;
+ } = {},
+ ) {
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
const params = formatters.createBatchFill(
- orders, shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmounts);
- const tx = await this.exchange.batchFillOrders(
+ orders,
+ shouldThrowOnInsufficientBalanceOrAllowance,
+ opts.fillTakerTokenAmounts,
+ );
+ const tx = await this._exchange.batchFillOrders(
params.orderAddresses,
params.orderValues,
params.fillTakerTokenAmounts,
@@ -74,36 +81,44 @@ export class ExchangeWrapper {
params.v,
params.r,
params.s,
- {from},
+ { from },
);
_.each(tx.logs, log => wrapLogBigNumbers(log));
return tx;
}
- public async batchFillOrKillOrdersAsync(orders: Order[], from: string,
- opts: {fillTakerTokenAmounts?: BigNumber[]} = {}) {
+ public async batchFillOrKillOrdersAsync(
+ orders: Order[],
+ from: string,
+ opts: { fillTakerTokenAmounts?: BigNumber[] } = {},
+ ) {
const params = formatters.createBatchFill(orders, undefined, opts.fillTakerTokenAmounts);
- const tx = await this.exchange.batchFillOrKillOrders(
+ const tx = await this._exchange.batchFillOrKillOrders(
params.orderAddresses,
params.orderValues,
params.fillTakerTokenAmounts,
params.v,
params.r,
params.s,
- {from},
+ { from },
);
_.each(tx.logs, log => wrapLogBigNumbers(log));
return tx;
}
- public async fillOrdersUpToAsync(orders: Order[], from: string,
- opts: {
- fillTakerTokenAmount?: BigNumber;
- shouldThrowOnInsufficientBalanceOrAllowance?: boolean;
- } = {}) {
+ public async fillOrdersUpToAsync(
+ orders: Order[],
+ from: string,
+ opts: {
+ fillTakerTokenAmount?: BigNumber;
+ shouldThrowOnInsufficientBalanceOrAllowance?: boolean;
+ } = {},
+ ) {
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
- const params = formatters.createFillUpTo(orders,
- shouldThrowOnInsufficientBalanceOrAllowance,
- opts.fillTakerTokenAmount);
- const tx = await this.exchange.fillOrdersUpTo(
+ const params = formatters.createFillUpTo(
+ orders,
+ shouldThrowOnInsufficientBalanceOrAllowance,
+ opts.fillTakerTokenAmount,
+ );
+ const tx = await this._exchange.fillOrdersUpTo(
params.orderAddresses,
params.orderValues,
params.fillTakerTokenAmount,
@@ -111,19 +126,22 @@ export class ExchangeWrapper {
params.v,
params.r,
params.s,
- {from},
+ { from },
);
_.each(tx.logs, log => wrapLogBigNumbers(log));
return tx;
}
- public async batchCancelOrdersAsync(orders: Order[], from: string,
- opts: {cancelTakerTokenAmounts?: BigNumber[]} = {}) {
+ public async batchCancelOrdersAsync(
+ orders: Order[],
+ from: string,
+ opts: { cancelTakerTokenAmounts?: BigNumber[] } = {},
+ ) {
const params = formatters.createBatchCancel(orders, opts.cancelTakerTokenAmounts);
- const tx = await this.exchange.batchCancelOrders(
+ const tx = await this._exchange.batchCancelOrders(
params.orderAddresses,
params.orderValues,
params.cancelTakerTokenAmounts,
- {from},
+ { from },
);
_.each(tx.logs, log => wrapLogBigNumbers(log));
return tx;
@@ -131,11 +149,11 @@ export class ExchangeWrapper {
public async getOrderHashAsync(order: Order): Promise<string> {
const shouldThrowOnInsufficientBalanceOrAllowance = false;
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance);
- const orderHash = await this.exchange.getOrderHash(params.orderAddresses, params.orderValues);
+ const orderHash = await this._exchange.getOrderHash(params.orderAddresses, params.orderValues);
return orderHash;
}
public async isValidSignatureAsync(order: Order): Promise<boolean> {
- const isValidSignature = await this.exchange.isValidSignature(
+ const isValidSignature = await this._exchange.isValidSignature(
order.params.maker,
order.params.orderHashHex,
order.params.v,
@@ -144,14 +162,20 @@ export class ExchangeWrapper {
);
return isValidSignature;
}
- public async isRoundingErrorAsync(numerator: BigNumber, denominator: BigNumber,
- target: BigNumber): Promise<boolean> {
- const isRoundingError = await this.exchange.isRoundingError(numerator, denominator, target);
+ public async isRoundingErrorAsync(
+ numerator: BigNumber,
+ denominator: BigNumber,
+ target: BigNumber,
+ ): Promise<boolean> {
+ const isRoundingError = await this._exchange.isRoundingError(numerator, denominator, target);
return isRoundingError;
}
- public async getPartialAmountAsync(numerator: BigNumber, denominator: BigNumber,
- target: BigNumber): Promise<BigNumber> {
- const partialAmount = new BigNumber(await this.exchange.getPartialAmount(numerator, denominator, target));
+ public async getPartialAmountAsync(
+ numerator: BigNumber,
+ denominator: BigNumber,
+ target: BigNumber,
+ ): Promise<BigNumber> {
+ const partialAmount = new BigNumber(await this._exchange.getPartialAmount(numerator, denominator, target));
return partialAmount;
}
}
diff --git a/packages/contracts/util/formatters.ts b/packages/contracts/util/formatters.ts
index 0ad44481a..0d0ef6df4 100644
--- a/packages/contracts/util/formatters.ts
+++ b/packages/contracts/util/formatters.ts
@@ -1,13 +1,15 @@
-import {BigNumber} from 'bignumber.js';
+import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
-import {Order} from './order';
-import {BatchCancelOrders, BatchFillOrders, FillOrdersUpTo} from './types';
+import { Order } from './order';
+import { BatchCancelOrders, BatchFillOrders, FillOrdersUpTo } from './types';
export const formatters = {
- createBatchFill(orders: Order[],
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- fillTakerTokenAmounts: BigNumber[] = []) {
+ createBatchFill(
+ orders: Order[],
+ shouldThrowOnInsufficientBalanceOrAllowance: boolean,
+ fillTakerTokenAmounts: BigNumber[] = [],
+ ) {
const batchFill: BatchFillOrders = {
orderAddresses: [],
orderValues: [],
@@ -18,11 +20,21 @@ export const formatters = {
s: [],
};
_.forEach(orders, order => {
- batchFill.orderAddresses.push([order.params.maker, order.params.taker, order.params.makerToken,
- order.params.takerToken, order.params.feeRecipient]);
- batchFill.orderValues.push([order.params.makerTokenAmount, order.params.takerTokenAmount,
- order.params.makerFee, order.params.takerFee,
- order.params.expirationTimestampInSec, order.params.salt]);
+ batchFill.orderAddresses.push([
+ order.params.maker,
+ order.params.taker,
+ order.params.makerToken,
+ order.params.takerToken,
+ order.params.feeRecipient,
+ ]);
+ batchFill.orderValues.push([
+ order.params.makerTokenAmount,
+ order.params.takerTokenAmount,
+ order.params.makerFee,
+ order.params.takerFee,
+ order.params.expirationTimestampInSec,
+ order.params.salt,
+ ]);
batchFill.v.push(order.params.v);
batchFill.r.push(order.params.r);
batchFill.s.push(order.params.s);
@@ -32,9 +44,11 @@ export const formatters = {
});
return batchFill;
},
- createFillUpTo(orders: Order[],
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- fillTakerTokenAmount: BigNumber) {
+ createFillUpTo(
+ orders: Order[],
+ shouldThrowOnInsufficientBalanceOrAllowance: boolean,
+ fillTakerTokenAmount: BigNumber,
+ ) {
const fillUpTo: FillOrdersUpTo = {
orderAddresses: [],
orderValues: [],
@@ -45,11 +59,21 @@ export const formatters = {
s: [],
};
orders.forEach(order => {
- fillUpTo.orderAddresses.push([order.params.maker, order.params.taker, order.params.makerToken,
- order.params.takerToken, order.params.feeRecipient]);
- fillUpTo.orderValues.push([order.params.makerTokenAmount, order.params.takerTokenAmount,
- order.params.makerFee, order.params.takerFee,
- order.params.expirationTimestampInSec, order.params.salt]);
+ fillUpTo.orderAddresses.push([
+ order.params.maker,
+ order.params.taker,
+ order.params.makerToken,
+ order.params.takerToken,
+ order.params.feeRecipient,
+ ]);
+ fillUpTo.orderValues.push([
+ order.params.makerTokenAmount,
+ order.params.takerTokenAmount,
+ order.params.makerFee,
+ order.params.takerFee,
+ order.params.expirationTimestampInSec,
+ order.params.salt,
+ ]);
fillUpTo.v.push(order.params.v);
fillUpTo.r.push(order.params.r);
fillUpTo.s.push(order.params.s);
@@ -63,11 +87,21 @@ export const formatters = {
cancelTakerTokenAmounts,
};
orders.forEach(order => {
- batchCancel.orderAddresses.push([order.params.maker, order.params.taker, order.params.makerToken,
- order.params.takerToken, order.params.feeRecipient]);
- batchCancel.orderValues.push([order.params.makerTokenAmount, order.params.takerTokenAmount,
- order.params.makerFee, order.params.takerFee,
- order.params.expirationTimestampInSec, order.params.salt]);
+ batchCancel.orderAddresses.push([
+ order.params.maker,
+ order.params.taker,
+ order.params.makerToken,
+ order.params.takerToken,
+ order.params.feeRecipient,
+ ]);
+ batchCancel.orderValues.push([
+ order.params.makerTokenAmount,
+ order.params.takerTokenAmount,
+ order.params.makerFee,
+ order.params.takerFee,
+ order.params.expirationTimestampInSec,
+ order.params.salt,
+ ]);
if (cancelTakerTokenAmounts.length < orders.length) {
batchCancel.cancelTakerTokenAmounts.push(order.params.takerTokenAmount);
}
diff --git a/packages/contracts/util/multi_sig_wrapper.ts b/packages/contracts/util/multi_sig_wrapper.ts
index 4ad970ac9..0e2e671ec 100644
--- a/packages/contracts/util/multi_sig_wrapper.ts
+++ b/packages/contracts/util/multi_sig_wrapper.ts
@@ -3,12 +3,12 @@ import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
import * as Web3 from 'web3';
-import {ContractInstance, TransactionDataParams} from './types';
+import { ContractInstance, TransactionDataParams } from './types';
export class MultiSigWrapper {
- private multiSig: ContractInstance;
+ private _multiSig: ContractInstance;
public static encodeFnArgs(name: string, abi: Web3.AbiDefinition[], args: any[]) {
- const abiEntity = _.find(abi, {name}) as Web3.MethodAbi;
+ const abiEntity = _.find(abi, { name }) as Web3.MethodAbi;
if (_.isUndefined(abiEntity)) {
throw new Error(`Did not find abi entry for name: ${name}`);
}
@@ -22,13 +22,18 @@ export class MultiSigWrapper {
return funcSig + argsData.join('');
}
constructor(multiSigContractInstance: ContractInstance) {
- this.multiSig = multiSigContractInstance;
+ this._multiSig = multiSigContractInstance;
}
- public async submitTransactionAsync(destination: string, from: string,
- dataParams: TransactionDataParams,
- value: number = 0) {
- const {name, abi, args = []} = dataParams;
+ public async submitTransactionAsync(
+ destination: string,
+ from: string,
+ dataParams: TransactionDataParams,
+ value: number = 0,
+ ) {
+ const { name, abi, args = [] } = dataParams;
const encoded = MultiSigWrapper.encodeFnArgs(name, abi, args);
- return this.multiSig.submitTransaction(destination, value, encoded, {from});
+ return this._multiSig.submitTransaction(destination, value, encoded, {
+ from,
+ });
}
}
diff --git a/packages/contracts/util/order.ts b/packages/contracts/util/order.ts
index ec5362b66..e202d485b 100644
--- a/packages/contracts/util/order.ts
+++ b/packages/contracts/util/order.ts
@@ -1,11 +1,10 @@
-import {promisify} from '@0xproject/utils';
-import {BigNumber} from 'bignumber.js';
+import { BigNumber, promisify } from '@0xproject/utils';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
import Web3 = require('web3');
-import {crypto} from './crypto';
-import {OrderParams} from './types';
+import { crypto } from './crypto';
+import { OrderParams } from './types';
// In order to benefit from type-safety, we re-assign the global web3 instance injected by Truffle
// with type `any` to a variable of type `Web3`.
@@ -17,11 +16,11 @@ export class Order {
this.params = params;
}
public isValidSignature() {
- const {v, r, s} = this.params;
+ const { v, r, s } = this.params;
if (_.isUndefined(v) || _.isUndefined(r) || _.isUndefined(s)) {
throw new Error('Cannot call isValidSignature on unsigned order');
}
- const orderHash = this.getOrderHash();
+ const orderHash = this._getOrderHash();
const msgHash = ethUtil.hashPersonalMessage(ethUtil.toBuffer(orderHash));
try {
const pubKey = ethUtil.ecrecover(msgHash, v, ethUtil.toBuffer(r), ethUtil.toBuffer(s));
@@ -32,9 +31,9 @@ export class Order {
}
}
public async signAsync() {
- const orderHash = this.getOrderHash();
+ const orderHash = this._getOrderHash();
const signature = await promisify<string>(web3.eth.sign)(this.params.maker, orderHash);
- const {v, r, s} = ethUtil.fromRpcSig(signature);
+ const { v, r, s } = ethUtil.fromRpcSig(signature);
this.params = _.assign(this.params, {
orderHashHex: orderHash,
v,
@@ -88,7 +87,7 @@ export class Order {
};
return cancel;
}
- private getOrderHash(): string {
+ private _getOrderHash(): string {
const orderHash = crypto.solSHA3([
this.params.exchangeContractAddress,
this.params.maker,
diff --git a/packages/contracts/util/order_factory.ts b/packages/contracts/util/order_factory.ts
index 526e229a4..a45877de0 100644
--- a/packages/contracts/util/order_factory.ts
+++ b/packages/contracts/util/order_factory.ts
@@ -1,22 +1,27 @@
-import {ZeroEx} from '0x.js';
-import {BigNumber} from 'bignumber.js';
+import { ZeroEx } from '0x.js';
+import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
-import {Order} from './order';
-import {DefaultOrderParams, OptionalOrderParams, OrderParams} from './types';
+import { Order } from './order';
+import { DefaultOrderParams, OptionalOrderParams, OrderParams } from './types';
export class OrderFactory {
- private defaultOrderParams: DefaultOrderParams;
+ private _defaultOrderParams: DefaultOrderParams;
constructor(defaultOrderParams: DefaultOrderParams) {
- this.defaultOrderParams = defaultOrderParams;
+ this._defaultOrderParams = defaultOrderParams;
}
public async newSignedOrderAsync(customOrderParams: OptionalOrderParams = {}) {
- const randomExpiration = new BigNumber(Math.floor((Date.now() + (Math.random() * 100000000000)) / 1000));
- const orderParams: OrderParams = _.assign({}, {
- expirationTimestampInSec: randomExpiration,
- salt: ZeroEx.generatePseudoRandomSalt(),
- taker: ZeroEx.NULL_ADDRESS,
- }, this.defaultOrderParams, customOrderParams);
+ const randomExpiration = new BigNumber(Math.floor((Date.now() + Math.random() * 100000000000) / 1000));
+ const orderParams: OrderParams = _.assign(
+ {},
+ {
+ expirationTimestampInSec: randomExpiration,
+ salt: ZeroEx.generatePseudoRandomSalt(),
+ taker: ZeroEx.NULL_ADDRESS,
+ },
+ this._defaultOrderParams,
+ customOrderParams,
+ );
const order = new Order(orderParams);
await order.signAsync();
return order;
diff --git a/packages/contracts/util/rpc.ts b/packages/contracts/util/rpc.ts
deleted file mode 100644
index 023602bd6..000000000
--- a/packages/contracts/util/rpc.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import 'isomorphic-fetch';
-
-import * as truffleConf from '../truffle.js';
-
-export class RPC {
- private host: string;
- private port: number;
- private id: number;
- constructor() {
- this.host = truffleConf.networks.development.host;
- this.port = truffleConf.networks.development.port;
- this.id = 0;
- }
- public async increaseTimeAsync(time: number) {
- const method = 'evm_increaseTime';
- const params = [time];
- const payload = this.toPayload(method, params);
- return this.sendAsync(payload);
- }
- public async mineBlockAsync() {
- const method = 'evm_mine';
- const payload = this.toPayload(method);
- return this.sendAsync(payload);
- }
- private toPayload(method: string, params: any[] = []) {
- const payload = JSON.stringify({
- id: this.id,
- method,
- params,
- });
- this.id++;
- return payload;
- }
- private async sendAsync(payload: string): Promise<any> {
- const opts = {
- method: 'POST',
- body: payload,
- };
- const response = await fetch(`http://${this.host}:${this.port}`, opts);
- const responsePayload = await response.json();
- return responsePayload;
- }
-}
diff --git a/packages/contracts/util/token_registry_wrapper.ts b/packages/contracts/util/token_registry_wrapper.ts
index 5e1c627cc..07a577dea 100644
--- a/packages/contracts/util/token_registry_wrapper.ts
+++ b/packages/contracts/util/token_registry_wrapper.ts
@@ -1,24 +1,24 @@
-import {ContractInstance, Token} from './types';
+import { ContractInstance, Token } from './types';
export class TokenRegWrapper {
- private tokenReg: ContractInstance;
+ private _tokenReg: ContractInstance;
constructor(tokenRegContractInstance: ContractInstance) {
- this.tokenReg = tokenRegContractInstance;
+ this._tokenReg = tokenRegContractInstance;
}
public addTokenAsync(token: Token, from: string) {
- const tx = this.tokenReg.addToken(
+ const tx = this._tokenReg.addToken(
token.address,
token.name,
token.symbol,
token.decimals,
token.ipfsHash,
token.swarmHash,
- {from},
+ { from },
);
return tx;
}
public async getTokenMetaDataAsync(tokenAddress: string) {
- const data = await this.tokenReg.getTokenMetaData(tokenAddress);
+ const data = await this._tokenReg.getTokenMetaData(tokenAddress);
const token: Token = {
address: data[0],
name: data[1],
@@ -30,7 +30,7 @@ export class TokenRegWrapper {
return token;
}
public async getTokenByNameAsync(tokenName: string) {
- const data = await this.tokenReg.getTokenByName(tokenName);
+ const data = await this._tokenReg.getTokenByName(tokenName);
const token: Token = {
address: data[0],
name: data[1],
@@ -42,7 +42,7 @@ export class TokenRegWrapper {
return token;
}
public async getTokenBySymbolAsync(tokenSymbol: string) {
- const data = await this.tokenReg.getTokenBySymbol(tokenSymbol);
+ const data = await this._tokenReg.getTokenBySymbol(tokenSymbol);
const token: Token = {
address: data[0],
name: data[1],
diff --git a/packages/contracts/util/types.ts b/packages/contracts/util/types.ts
index b2cf786df..e511ca9f4 100644
--- a/packages/contracts/util/types.ts
+++ b/packages/contracts/util/types.ts
@@ -1,4 +1,4 @@
-import {BigNumber} from 'bignumber.js';
+import { BigNumber } from '@0xproject/utils';
import * as Web3 from 'web3';
export interface BalancesByOwner {
@@ -84,15 +84,6 @@ export interface TransactionDataParams {
args: any[];
}
-export interface Token {
- address?: string;
- name: string;
- symbol: string;
- decimals: number;
- ipfsHash: string;
- swarmHash: string;
-}
-
export interface MultiSigConfig {
owners: string[];
confirmationsRequired: number;
@@ -103,6 +94,15 @@ export interface MultiSigConfigByNetwork {
[networkName: string]: MultiSigConfig;
}
+export interface Token {
+ address?: string;
+ name: string;
+ symbol: string;
+ decimals: number;
+ ipfsHash: string;
+ swarmHash: string;
+}
+
export interface TokenInfoByNetwork {
development: Token[];
live: Token[];