diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-13 08:39:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 08:39:24 +0800 |
commit | 6becf22a2f752ef7c34ce1b423efd51773cc5fde (patch) | |
tree | 809556ebee179b3f4012870ae7353e3b4abcd520 /src | |
parent | 6daf70b745b561f9a767886e2b40891da7ebc184 (diff) | |
parent | 32246fd26bc71b09818491d513a380a8bd85fdec (diff) | |
download | dexon-sol-tools-6becf22a2f752ef7c34ce1b423efd51773cc5fde.tar dexon-sol-tools-6becf22a2f752ef7c34ce1b423efd51773cc5fde.tar.gz dexon-sol-tools-6becf22a2f752ef7c34ce1b423efd51773cc5fde.tar.bz2 dexon-sol-tools-6becf22a2f752ef7c34ce1b423efd51773cc5fde.tar.lz dexon-sol-tools-6becf22a2f752ef7c34ce1b423efd51773cc5fde.tar.xz dexon-sol-tools-6becf22a2f752ef7c34ce1b423efd51773cc5fde.tar.zst dexon-sol-tools-6becf22a2f752ef7c34ce1b423efd51773cc5fde.zip |
Merge pull request #210 from dekz/orderWatcherRemaining
Calculate the remaining order amount in maker units
Diffstat (limited to 'src')
-rw-r--r-- | src/types.ts | 1 | ||||
-rw-r--r-- | src/utils/order_state_utils.ts | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/types.ts b/src/types.ts index 160b71fda..a366fc31e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -493,6 +493,7 @@ export interface OrderRelevantState { makerFeeProxyAllowance: BigNumber; filledTakerTokenAmount: BigNumber; canceledTakerTokenAmount: BigNumber; + remainingFillableMakerTokenAmount: BigNumber; } export interface OrderStateValid { diff --git a/src/utils/order_state_utils.ts b/src/utils/order_state_utils.ts index 2a5becf9a..36a4b68d6 100644 --- a/src/utils/order_state_utils.ts +++ b/src/utils/order_state_utils.ts @@ -60,6 +60,16 @@ export class OrderStateUtils { ); const filledTakerTokenAmount = await this.exchangeWrapper.getFilledTakerAmountAsync(orderHash, methodOpts); const canceledTakerTokenAmount = await this.exchangeWrapper.getCanceledTakerAmountAsync(orderHash, methodOpts); + const unavailableTakerTokenAmount = + await this.exchangeWrapper.getUnavailableTakerAmountAsync(orderHash, methodOpts); + const totalMakerTokenAmount = signedOrder.makerTokenAmount; + const totalTakerTokenAmount = signedOrder.takerTokenAmount; + const remainingTakerTokenAmount = totalTakerTokenAmount.minus(unavailableTakerTokenAmount); + const remainingMakerTokenAmount = remainingTakerTokenAmount.times(totalMakerTokenAmount) + .dividedToIntegerBy(totalTakerTokenAmount); + const fillableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]); + const remainingFillableMakerTokenAmount = BigNumber.min(fillableMakerTokenAmount, remainingMakerTokenAmount); + // TODO: Handle edge case where maker token is ZRX with fee const orderRelevantState = { makerBalance, makerProxyAllowance, @@ -67,6 +77,7 @@ export class OrderStateUtils { makerFeeProxyAllowance, filledTakerTokenAmount, canceledTakerTokenAmount, + remainingFillableMakerTokenAmount, }; return orderRelevantState; } |