diff options
author | Fabio Berger <me@fabioberger.com> | 2018-05-30 07:58:30 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-05-30 07:58:30 +0800 |
commit | 4874d55d03918b47967024777194d88a5f2bc1fc (patch) | |
tree | 4a53834e9424a8b33aa7d0edaf13de11f2e807a3 /packages/order-utils/src/order_state_utils.ts | |
parent | 10faa474950a902af943b3c51f3703491afa6520 (diff) | |
download | dexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.tar dexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.tar.gz dexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.tar.bz2 dexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.tar.lz dexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.tar.xz dexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.tar.zst dexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.zip |
Initial refactor of order-utils. Move many utils from contracts into this package.
Diffstat (limited to 'packages/order-utils/src/order_state_utils.ts')
-rw-r--r-- | packages/order-utils/src/order_state_utils.ts | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/packages/order-utils/src/order_state_utils.ts b/packages/order-utils/src/order_state_utils.ts index 36171f526..61050c9d6 100644 --- a/packages/order-utils/src/order_state_utils.ts +++ b/packages/order-utils/src/order_state_utils.ts @@ -11,7 +11,8 @@ import * as _ from 'lodash'; import { AbstractBalanceAndProxyAllowanceFetcher } from './abstract/abstract_balance_and_proxy_allowance_fetcher'; import { AbstractOrderFilledCancelledFetcher } from './abstract/abstract_order_filled_cancelled_fetcher'; -import { getOrderHashHex } from './order_hash'; +import { assetProxyUtils } from './asset_proxy_utils'; +import { orderHashUtils } from './order_hash'; import { RemainingFillableCalculator } from './remaining_fillable_calculator'; const ACCEPTABLE_RELATIVE_ROUNDING_ERROR = 0.0001; @@ -23,7 +24,7 @@ export class OrderStateUtils { const unavailableTakerTokenAmount = orderRelevantState.cancelledTakerTokenAmount.add( orderRelevantState.filledTakerTokenAmount, ); - const availableTakerTokenAmount = signedOrder.takerTokenAmount.minus(unavailableTakerTokenAmount); + const availableTakerTokenAmount = signedOrder.takerAssetAmount.minus(unavailableTakerTokenAmount); if (availableTakerTokenAmount.eq(0)) { throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero); } @@ -42,9 +43,9 @@ export class OrderStateUtils { throw new Error(ExchangeContractErrs.InsufficientMakerFeeAllowance); } } - const minFillableTakerTokenAmountWithinNoRoundingErrorRange = signedOrder.takerTokenAmount + const minFillableTakerTokenAmountWithinNoRoundingErrorRange = signedOrder.takerAssetAmount .dividedBy(ACCEPTABLE_RELATIVE_ROUNDING_ERROR) - .dividedBy(signedOrder.makerTokenAmount); + .dividedBy(signedOrder.makerAssetAmount); if ( orderRelevantState.remainingFillableTakerTokenAmount.lessThan( minFillableTakerTokenAmountWithinNoRoundingErrorRange, @@ -62,7 +63,7 @@ export class OrderStateUtils { } public async getOrderStateAsync(signedOrder: SignedOrder): Promise<OrderState> { const orderRelevantState = await this.getOrderRelevantStateAsync(signedOrder); - const orderHash = getOrderHashHex(signedOrder); + const orderHash = orderHashUtils.getOrderHashHex(signedOrder); try { OrderStateUtils._validateIfOrderIsValid(signedOrder, orderRelevantState); const orderState: OrderStateValid = { @@ -82,22 +83,22 @@ export class OrderStateUtils { } public async getOrderRelevantStateAsync(signedOrder: SignedOrder): Promise<OrderRelevantState> { const zrxTokenAddress = this._orderFilledCancelledFetcher.getZRXTokenAddress(); - const orderHash = getOrderHashHex(signedOrder); + const orderHash = orderHashUtils.getOrderHashHex(signedOrder); const makerBalance = await this._balanceAndProxyAllowanceFetcher.getBalanceAsync( - signedOrder.makerTokenAddress, - signedOrder.maker, + signedOrder.makerAssetData, + signedOrder.makerAddress, ); const makerProxyAllowance = await this._balanceAndProxyAllowanceFetcher.getProxyAllowanceAsync( - signedOrder.makerTokenAddress, - signedOrder.maker, + signedOrder.makerAssetData, + signedOrder.makerAddress, ); const makerFeeBalance = await this._balanceAndProxyAllowanceFetcher.getBalanceAsync( zrxTokenAddress, - signedOrder.maker, + signedOrder.makerAddress, ); const makerFeeProxyAllowance = await this._balanceAndProxyAllowanceFetcher.getProxyAllowanceAsync( zrxTokenAddress, - signedOrder.maker, + signedOrder.makerAddress, ); const filledTakerTokenAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash); const cancelledTakerTokenAmount = await this._orderFilledCancelledFetcher.getCancelledTakerAmountAsync( @@ -106,8 +107,8 @@ export class OrderStateUtils { const unavailableTakerTokenAmount = await this._orderFilledCancelledFetcher.getUnavailableTakerAmountAsync( orderHash, ); - const totalMakerTokenAmount = signedOrder.makerTokenAmount; - const totalTakerTokenAmount = signedOrder.takerTokenAmount; + const totalMakerTokenAmount = signedOrder.makerAssetAmount; + const totalTakerTokenAmount = signedOrder.takerAssetAmount; const remainingTakerTokenAmount = totalTakerTokenAmount.minus(unavailableTakerTokenAmount); const remainingMakerTokenAmount = remainingTakerTokenAmount .times(totalMakerTokenAmount) @@ -115,7 +116,8 @@ export class OrderStateUtils { const transferrableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]); const transferrableFeeTokenAmount = BigNumber.min([makerFeeProxyAllowance, makerFeeBalance]); - const isMakerTokenZRX = signedOrder.makerTokenAddress === zrxTokenAddress; + const zrxAssetData = assetProxyUtils.encodeERC20ProxyData(zrxTokenAddress); + const isMakerTokenZRX = signedOrder.makerAssetData === zrxAssetData; const remainingFillableCalculator = new RemainingFillableCalculator( signedOrder, isMakerTokenZRX, |