aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2017-11-13 00:28:01 +0800
committerJacob Evans <jacob@dekz.net>2017-11-13 00:28:01 +0800
commit3e2a614eb9a4f1219e2f11ea29c8a7cd59dd74dd (patch)
tree37f4c3dc2344607737e5da3d79ed5cf0c3bb5ffd
parentabb23631df4fd775d2f9c96332e16c0732b2955e (diff)
downloaddexon-sol-tools-3e2a614eb9a4f1219e2f11ea29c8a7cd59dd74dd.tar
dexon-sol-tools-3e2a614eb9a4f1219e2f11ea29c8a7cd59dd74dd.tar.gz
dexon-sol-tools-3e2a614eb9a4f1219e2f11ea29c8a7cd59dd74dd.tar.bz2
dexon-sol-tools-3e2a614eb9a4f1219e2f11ea29c8a7cd59dd74dd.tar.lz
dexon-sol-tools-3e2a614eb9a4f1219e2f11ea29c8a7cd59dd74dd.tar.xz
dexon-sol-tools-3e2a614eb9a4f1219e2f11ea29c8a7cd59dd74dd.tar.zst
dexon-sol-tools-3e2a614eb9a4f1219e2f11ea29c8a7cd59dd74dd.zip
Calculate the remaining order amount in maker units
-rw-r--r--src/types.ts1
-rw-r--r--src/utils/order_state_utils.ts16
-rw-r--r--test/order_state_watcher_test.ts2
3 files changed, 19 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..ff5c1880d 100644
--- a/src/utils/order_state_utils.ts
+++ b/src/utils/order_state_utils.ts
@@ -60,6 +60,21 @@ 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);
+ // 200 in order, 100 unavailable = 100 remaning, 0.5 remaning proportion
+ const remainingTakerProportion = remainingTakerTokenAmount.dividedBy(totalTakerTokenAmount);
+ const remainingMakerTokenAmount = remainingTakerProportion.times(totalMakerTokenAmount);
+ // min allowance, balance in account of maker
+ const fillableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]);
+ // min ^, remaining order maker token amount
+ const remainingFillableMakerTokenAmount = BigNumber.min(fillableMakerTokenAmount, remainingMakerTokenAmount);
+ // TODO
+ // edge case when maker token is ZRX
+ // rounding issues, check if its fillabae
const orderRelevantState = {
makerBalance,
makerProxyAllowance,
@@ -67,6 +82,7 @@ export class OrderStateUtils {
makerFeeProxyAllowance,
filledTakerTokenAmount,
canceledTakerTokenAmount,
+ remainingFillableMakerTokenAmount,
};
return orderRelevantState;
}
diff --git a/test/order_state_watcher_test.ts b/test/order_state_watcher_test.ts
index 3421353e3..039bcef18 100644
--- a/test/order_state_watcher_test.ts
+++ b/test/order_state_watcher_test.ts
@@ -189,6 +189,8 @@ describe('OrderStateWatcher', () => {
expect(validOrderState.orderHash).to.be.equal(orderHash);
const orderRelevantState = validOrderState.orderRelevantState;
const remainingMakerBalance = makerBalance.sub(fillAmountInBaseUnits);
+ const remainingFillable = fillableAmount.minus(fillAmountInBaseUnits);
+ expect(remainingFillable).to.be.bignumber.equal(fillableAmount.minus(fillAmountInBaseUnits));
expect(orderRelevantState.makerBalance).to.be.bignumber.equal(remainingMakerBalance);
if (eventCount === 2) {
done();