From e744e4cd989bd3ae1070c59f7baa8097f18b8b06 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 22 Dec 2017 15:05:32 +0100 Subject: Apply prettier config --- packages/contracts/util/artifacts.ts | 3 +- packages/contracts/util/balances.ts | 6 +- packages/contracts/util/crypto.ts | 4 +- packages/contracts/util/exchange_wrapper.ts | 108 +++++++++++++--------- packages/contracts/util/formatters.ts | 82 +++++++++++----- packages/contracts/util/multi_sig_wrapper.ts | 19 ++-- packages/contracts/util/order.ts | 12 +-- packages/contracts/util/order_factory.ts | 25 +++-- packages/contracts/util/token_registry_wrapper.ts | 4 +- packages/contracts/util/types.ts | 2 +- 10 files changed, 167 insertions(+), 98 deletions(-) (limited to 'packages/contracts/util') diff --git a/packages/contracts/util/artifacts.ts b/packages/contracts/util/artifacts.ts index 14acd32a1..ecb18cbce 100644 --- a/packages/contracts/util/artifacts.ts +++ b/packages/contracts/util/artifacts.ts @@ -21,7 +21,8 @@ export class Artifacts { 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 5800a2008..eaeecf1c4 100644 --- a/packages/contracts/util/balances.ts +++ b/packages/contracts/util/balances.ts @@ -1,8 +1,8 @@ -import {bigNumberConfigs} from '@0xproject/utils'; -import {BigNumber} from 'bignumber.js'; +import { bigNumberConfigs } from '@0xproject/utils'; +import { BigNumber } from 'bignumber.js'; import * as _ from 'lodash'; -import {BalancesByOwner, ContractInstance} from './types'; +import { BalancesByOwner, ContractInstance } from './types'; bigNumberConfigs.configure(); diff --git a/packages/contracts/util/crypto.ts b/packages/contracts/util/crypto.ts index 2e43ae816..9173df643 100644 --- a/packages/contracts/util/crypto.ts +++ b/packages/contracts/util/crypto.ts @@ -18,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 9545710cd..200b0fb1e 100644 --- a/packages/contracts/util/exchange_wrapper.ts +++ b/packages/contracts/util/exchange_wrapper.ts @@ -1,20 +1,23 @@ -import {BigNumber} from 'bignumber.js'; +import { BigNumber } from 'bignumber.js'; 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; constructor(exchangeContractInstance: ContractInstance) { 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( @@ -25,25 +28,23 @@ 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( 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( @@ -53,19 +54,25 @@ export class ExchangeWrapper { 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); + orders, + shouldThrowOnInsufficientBalanceOrAllowance, + opts.fillTakerTokenAmounts, + ); const tx = await this._exchange.batchFillOrders( params.orderAddresses, params.orderValues, @@ -74,13 +81,16 @@ 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( params.orderAddresses, @@ -89,20 +99,25 @@ export class ExchangeWrapper { 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 params = formatters.createFillUpTo( + orders, + shouldThrowOnInsufficientBalanceOrAllowance, + opts.fillTakerTokenAmount, + ); const tx = await this._exchange.fillOrdersUpTo( params.orderAddresses, params.orderValues, @@ -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( params.orderAddresses, params.orderValues, params.cancelTakerTokenAmounts, - {from}, + { from }, ); _.each(tx.logs, log => wrapLogBigNumbers(log)); return tx; @@ -144,13 +162,19 @@ export class ExchangeWrapper { ); return isValidSignature; } - public async isRoundingErrorAsync(numerator: BigNumber, denominator: BigNumber, - target: BigNumber): Promise { + public async isRoundingErrorAsync( + numerator: BigNumber, + denominator: BigNumber, + target: BigNumber, + ): Promise { const isRoundingError = await this._exchange.isRoundingError(numerator, denominator, target); return isRoundingError; } - public async getPartialAmountAsync(numerator: BigNumber, denominator: BigNumber, - target: BigNumber): Promise { + public async getPartialAmountAsync( + numerator: BigNumber, + denominator: BigNumber, + target: BigNumber, + ): Promise { 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..ab3558ee7 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 'bignumber.js'; 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 2e4174436..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; 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}`); } @@ -24,11 +24,16 @@ export class MultiSigWrapper { constructor(multiSigContractInstance: ContractInstance) { 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 52d611ade..2427ffb87 100644 --- a/packages/contracts/util/order.ts +++ b/packages/contracts/util/order.ts @@ -1,11 +1,11 @@ -import {promisify} from '@0xproject/utils'; -import {BigNumber} from 'bignumber.js'; +import { promisify } from '@0xproject/utils'; +import { BigNumber } from 'bignumber.js'; 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,7 +17,7 @@ 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'); } @@ -34,7 +34,7 @@ export class Order { public async signAsync() { const orderHash = this._getOrderHash(); const signature = await promisify(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, diff --git a/packages/contracts/util/order_factory.ts b/packages/contracts/util/order_factory.ts index 9d96a8394..3ae06a335 100644 --- a/packages/contracts/util/order_factory.ts +++ b/packages/contracts/util/order_factory.ts @@ -1,9 +1,9 @@ -import {ZeroEx} from '0x.js'; -import {BigNumber} from 'bignumber.js'; +import { ZeroEx } from '0x.js'; +import { BigNumber } from 'bignumber.js'; 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; @@ -11,12 +11,17 @@ export class OrderFactory { 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/token_registry_wrapper.ts b/packages/contracts/util/token_registry_wrapper.ts index c10cf4f5f..07a577dea 100644 --- a/packages/contracts/util/token_registry_wrapper.ts +++ b/packages/contracts/util/token_registry_wrapper.ts @@ -1,4 +1,4 @@ -import {ContractInstance, Token} from './types'; +import { ContractInstance, Token } from './types'; export class TokenRegWrapper { private _tokenReg: ContractInstance; @@ -13,7 +13,7 @@ export class TokenRegWrapper { token.decimals, token.ipfsHash, token.swarmHash, - {from}, + { from }, ); return tx; } diff --git a/packages/contracts/util/types.ts b/packages/contracts/util/types.ts index b2cf786df..9b225cb0b 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 'bignumber.js'; import * as Web3 from 'web3'; export interface BalancesByOwner { -- cgit v1.2.3