diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-22 22:05:32 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-03 18:37:38 +0800 |
commit | e744e4cd989bd3ae1070c59f7baa8097f18b8b06 (patch) | |
tree | a7fde03873f3c1b8689d3991edbb362f8022e5f0 /packages/0x.js/test/utils/fill_scenarios.ts | |
parent | 9a96e8c704b6f84e00bbe848159a4819844cf09d (diff) | |
download | dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.gz dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.zst dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.zip |
Apply prettier config
Diffstat (limited to 'packages/0x.js/test/utils/fill_scenarios.ts')
-rw-r--r-- | packages/0x.js/test/utils/fill_scenarios.ts | 166 |
1 files changed, 115 insertions, 51 deletions
diff --git a/packages/0x.js/test/utils/fill_scenarios.ts b/packages/0x.js/test/utils/fill_scenarios.ts index 8f28ee503..734db8ee6 100644 --- a/packages/0x.js/test/utils/fill_scenarios.ts +++ b/packages/0x.js/test/utils/fill_scenarios.ts @@ -1,12 +1,12 @@ -import {Web3Wrapper} from '@0xproject/web3-wrapper'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import BigNumber from 'bignumber.js'; -import {SignedOrder, Token, ZeroEx} from '../../src'; -import {artifacts} from '../../src/artifacts'; -import {DummyTokenContract} from '../../src/contract_wrappers/generated/dummy_token'; -import {orderFactory} from '../utils/order_factory'; +import { SignedOrder, Token, ZeroEx } from '../../src'; +import { artifacts } from '../../src/artifacts'; +import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token'; +import { orderFactory } from '../utils/order_factory'; -import {constants} from './constants'; +import { constants } from './constants'; const INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS = new BigNumber(100); @@ -17,8 +17,13 @@ export class FillScenarios { private _coinbase: string; private _zrxTokenAddress: string; private _exchangeContractAddress: string; - constructor(zeroEx: ZeroEx, userAddresses: string[], - tokens: Token[], zrxTokenAddress: string, exchangeContractAddress: string) { + constructor( + zeroEx: ZeroEx, + userAddresses: string[], + tokens: Token[], + zrxTokenAddress: string, + exchangeContractAddress: string, + ) { this._zeroEx = zeroEx; this._userAddresses = userAddresses; this._tokens = tokens; @@ -31,7 +36,8 @@ export class FillScenarios { for (const token of this._tokens) { if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') { const contractInstance = web3Wrapper.getContractInstance( - artifacts.DummyTokenArtifact.abi, token.address, + artifacts.DummyTokenArtifact.abi, + token.address, ); const defaults = {}; const dummyToken = new DummyTokenContract(contractInstance, defaults); @@ -43,61 +49,110 @@ export class FillScenarios { } } } - public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, - makerAddress: string, takerAddress: string, - fillableAmount: BigNumber, - expirationUnixTimestampSec?: BigNumber): - Promise<SignedOrder> { + public async createFillableSignedOrderAsync( + makerTokenAddress: string, + takerTokenAddress: string, + makerAddress: string, + takerAddress: string, + fillableAmount: BigNumber, + expirationUnixTimestampSec?: BigNumber, + ): Promise<SignedOrder> { return this.createAsymmetricFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, - fillableAmount, fillableAmount, expirationUnixTimestampSec, + makerTokenAddress, + takerTokenAddress, + makerAddress, + takerAddress, + fillableAmount, + fillableAmount, + expirationUnixTimestampSec, ); } public async createFillableSignedOrderWithFeesAsync( - makerTokenAddress: string, takerTokenAddress: string, - makerFee: BigNumber, takerFee: BigNumber, - makerAddress: string, takerAddress: string, + makerTokenAddress: string, + takerTokenAddress: string, + makerFee: BigNumber, + takerFee: BigNumber, + makerAddress: string, + takerAddress: string, fillableAmount: BigNumber, - feeRecepient: string, expirationUnixTimestampSec?: BigNumber, + feeRecepient: string, + expirationUnixTimestampSec?: BigNumber, ): Promise<SignedOrder> { return this._createAsymmetricFillableSignedOrderWithFeesAsync( - makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress, - fillableAmount, fillableAmount, feeRecepient, expirationUnixTimestampSec, + makerTokenAddress, + takerTokenAddress, + makerFee, + takerFee, + makerAddress, + takerAddress, + fillableAmount, + fillableAmount, + feeRecepient, + expirationUnixTimestampSec, ); } public async createAsymmetricFillableSignedOrderAsync( - makerTokenAddress: string, takerTokenAddress: string, makerAddress: string, takerAddress: string, - makerFillableAmount: BigNumber, takerFillableAmount: BigNumber, - expirationUnixTimestampSec?: BigNumber): Promise<SignedOrder> { + makerTokenAddress: string, + takerTokenAddress: string, + makerAddress: string, + takerAddress: string, + makerFillableAmount: BigNumber, + takerFillableAmount: BigNumber, + expirationUnixTimestampSec?: BigNumber, + ): Promise<SignedOrder> { const makerFee = new BigNumber(0); const takerFee = new BigNumber(0); const feeRecepient = constants.NULL_ADDRESS; return this._createAsymmetricFillableSignedOrderWithFeesAsync( - makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress, - makerFillableAmount, takerFillableAmount, feeRecepient, expirationUnixTimestampSec, + makerTokenAddress, + takerTokenAddress, + makerFee, + takerFee, + makerAddress, + takerAddress, + makerFillableAmount, + takerFillableAmount, + feeRecepient, + expirationUnixTimestampSec, ); } - public async createPartiallyFilledSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, - takerAddress: string, fillableAmount: BigNumber, - partialFillAmount: BigNumber) { + public async createPartiallyFilledSignedOrderAsync( + makerTokenAddress: string, + takerTokenAddress: string, + takerAddress: string, + fillableAmount: BigNumber, + partialFillAmount: BigNumber, + ) { const [makerAddress] = this._userAddresses; const signedOrder = await this.createAsymmetricFillableSignedOrderAsync( - makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, - fillableAmount, fillableAmount, + makerTokenAddress, + takerTokenAddress, + makerAddress, + takerAddress, + fillableAmount, + fillableAmount, ); const shouldThrowOnInsufficientBalanceOrAllowance = false; await this._zeroEx.exchange.fillOrderAsync( - signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, + signedOrder, + partialFillAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + takerAddress, ); return signedOrder; } private async _createAsymmetricFillableSignedOrderWithFeesAsync( - makerTokenAddress: string, takerTokenAddress: string, - makerFee: BigNumber, takerFee: BigNumber, - makerAddress: string, takerAddress: string, - makerFillableAmount: BigNumber, takerFillableAmount: BigNumber, - feeRecepient: string, expirationUnixTimestampSec?: BigNumber): Promise<SignedOrder> { - + makerTokenAddress: string, + takerTokenAddress: string, + makerFee: BigNumber, + takerFee: BigNumber, + makerAddress: string, + takerAddress: string, + makerFillableAmount: BigNumber, + takerFillableAmount: BigNumber, + feeRecepient: string, + expirationUnixTimestampSec?: BigNumber, + ): Promise<SignedOrder> { await Promise.all([ this._increaseBalanceAndAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount), this._increaseBalanceAndAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount), @@ -107,14 +162,27 @@ export class FillScenarios { this._increaseBalanceAndAllowanceAsync(this._zrxTokenAddress, takerAddress, takerFee), ]); - const signedOrder = await orderFactory.createSignedOrderAsync(this._zeroEx, - makerAddress, takerAddress, makerFee, takerFee, - makerFillableAmount, makerTokenAddress, takerFillableAmount, takerTokenAddress, - this._exchangeContractAddress, feeRecepient, expirationUnixTimestampSec); + const signedOrder = await orderFactory.createSignedOrderAsync( + this._zeroEx, + makerAddress, + takerAddress, + makerFee, + takerFee, + makerFillableAmount, + makerTokenAddress, + takerFillableAmount, + takerTokenAddress, + this._exchangeContractAddress, + feeRecepient, + expirationUnixTimestampSec, + ); return signedOrder; } private async _increaseBalanceAndAllowanceAsync( - tokenAddress: string, address: string, amount: BigNumber): Promise<void> { + tokenAddress: string, + address: string, + amount: BigNumber, + ): Promise<void> { if (amount.isZero() || address === ZeroEx.NULL_ADDRESS) { return; // noop } @@ -123,16 +191,12 @@ export class FillScenarios { this._increaseAllowanceAsync(tokenAddress, address, amount), ]); } - private async _increaseBalanceAsync( - tokenAddress: string, address: string, amount: BigNumber): Promise<void> { + private async _increaseBalanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise<void> { await this._zeroEx.token.transferAsync(tokenAddress, this._coinbase, address, amount); } - private async _increaseAllowanceAsync( - tokenAddress: string, address: string, amount: BigNumber): Promise<void> { + private async _increaseAllowanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise<void> { const oldMakerAllowance = await this._zeroEx.token.getProxyAllowanceAsync(tokenAddress, address); const newMakerAllowance = oldMakerAllowance.plus(amount); - await this._zeroEx.token.setProxyAllowanceAsync( - tokenAddress, address, newMakerAllowance, - ); + await this._zeroEx.token.setProxyAllowanceAsync(tokenAddress, address, newMakerAllowance); } } |