diff options
author | Jacob Evans <dekz@dekz.net> | 2018-05-01 19:55:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-01 19:55:49 +0800 |
commit | 3e683162e9e894dc5c309d26feb866eb6d98b154 (patch) | |
tree | 61230314cf99cba43bd43fff477196481e90719a /packages/0x.js/src | |
parent | 7104ae4752e83bb6d19599893b2e5a2b2d44b008 (diff) | |
parent | 8e7937bdb61887ea3df66a602a275f5643e6585c (diff) | |
download | dexon-sol-tools-3e683162e9e894dc5c309d26feb866eb6d98b154.tar dexon-sol-tools-3e683162e9e894dc5c309d26feb866eb6d98b154.tar.gz dexon-sol-tools-3e683162e9e894dc5c309d26feb866eb6d98b154.tar.bz2 dexon-sol-tools-3e683162e9e894dc5c309d26feb866eb6d98b154.tar.lz dexon-sol-tools-3e683162e9e894dc5c309d26feb866eb6d98b154.tar.xz dexon-sol-tools-3e683162e9e894dc5c309d26feb866eb6d98b154.tar.zst dexon-sol-tools-3e683162e9e894dc5c309d26feb866eb6d98b154.zip |
Merge pull request #568 from 0xProject/bug/0x.js/trade-simulator-trading-zrx
Execute Taker side in trade simulation
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/utils/exchange_transfer_simulator.ts | 8 | ||||
-rw-r--r-- | packages/0x.js/src/utils/order_validation_utils.ts | 25 |
2 files changed, 11 insertions, 22 deletions
diff --git a/packages/0x.js/src/utils/exchange_transfer_simulator.ts b/packages/0x.js/src/utils/exchange_transfer_simulator.ts index 9a920c643..f8301f5c2 100644 --- a/packages/0x.js/src/utils/exchange_transfer_simulator.ts +++ b/packages/0x.js/src/utils/exchange_transfer_simulator.ts @@ -5,6 +5,7 @@ import * as _ from 'lodash'; import { TokenWrapper } from '../contract_wrappers/token_wrapper'; import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store'; import { ExchangeContractErrs, TradeSide, TransferType } from '../types'; +import { constants } from '../utils/constants'; enum FailureReason { Balance = 'balance', @@ -66,6 +67,13 @@ export class ExchangeTransferSimulator { tradeSide: TradeSide, transferType: TransferType, ): Promise<void> { + // HACK: When simulating an open order (e.g taker is NULL_ADDRESS), we don't want to adjust balances/ + // allowances for the taker. We do however, want to increase the balance of the maker since the maker + // might be relying on those funds to fill subsequent orders or pay the order's fees. + if (from === constants.NULL_ADDRESS && tradeSide === TradeSide.Taker) { + await this._increaseBalanceAsync(tokenAddress, to, amountInBaseUnits); + return; + } const balance = await this._store.getBalanceAsync(tokenAddress, from); const proxyAllowance = await this._store.getProxyAllowanceAsync(tokenAddress, from); if (proxyAllowance.lessThan(amountInBaseUnits)) { diff --git a/packages/0x.js/src/utils/order_validation_utils.ts b/packages/0x.js/src/utils/order_validation_utils.ts index f32bf43d0..b320a3e92 100644 --- a/packages/0x.js/src/utils/order_validation_utils.ts +++ b/packages/0x.js/src/utils/order_validation_utils.ts @@ -124,31 +124,12 @@ export class OrderValidationUtils { if (!_.isUndefined(expectedFillTakerTokenAmount)) { fillTakerTokenAmount = expectedFillTakerTokenAmount; } - const fillMakerTokenAmount = OrderValidationUtils._getPartialAmount( + await OrderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync( + exchangeTradeEmulator, + signedOrder, fillTakerTokenAmount, - signedOrder.takerTokenAmount, - signedOrder.makerTokenAmount, - ); - await exchangeTradeEmulator.transferFromAsync( - signedOrder.makerTokenAddress, - signedOrder.maker, signedOrder.taker, - fillMakerTokenAmount, - TradeSide.Maker, - TransferType.Trade, - ); - const makerFeeAmount = OrderValidationUtils._getPartialAmount( - fillTakerTokenAmount, - signedOrder.takerTokenAmount, - signedOrder.makerFee, - ); - await exchangeTradeEmulator.transferFromAsync( zrxTokenAddress, - signedOrder.maker, - signedOrder.feeRecipient, - makerFeeAmount, - TradeSide.Maker, - TransferType.Fee, ); } public async validateFillOrderThrowIfInvalidAsync( |