aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-04-30 16:05:45 +0800
committerJacob Evans <jacob@dekz.net>2018-05-01 12:43:47 +0800
commitb36587fac833f4fa35aaed49e4ee05f6ce347a02 (patch)
tree1f902e97de4b33c885ca2ae5d6bd01119944e539 /packages/0x.js/src
parent47604384d4042c3c61f29a635491f8165236e763 (diff)
downloaddexon-sol-tools-b36587fac833f4fa35aaed49e4ee05f6ce347a02.tar
dexon-sol-tools-b36587fac833f4fa35aaed49e4ee05f6ce347a02.tar.gz
dexon-sol-tools-b36587fac833f4fa35aaed49e4ee05f6ce347a02.tar.bz2
dexon-sol-tools-b36587fac833f4fa35aaed49e4ee05f6ce347a02.tar.lz
dexon-sol-tools-b36587fac833f4fa35aaed49e4ee05f6ce347a02.tar.xz
dexon-sol-tools-b36587fac833f4fa35aaed49e4ee05f6ce347a02.tar.zst
dexon-sol-tools-b36587fac833f4fa35aaed49e4ee05f6ce347a02.zip
Execute taker side in trade simulation
Fill if the taker address is open
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/utils/exchange_transfer_simulator.ts6
-rw-r--r--packages/0x.js/src/utils/order_validation_utils.ts25
2 files changed, 9 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..ccefea930 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,11 @@ export class ExchangeTransferSimulator {
tradeSide: TradeSide,
transferType: TransferType,
): Promise<void> {
+ // If we are simulating an open order then 0x0 will have no balance or allowance
+ 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(