From 3e2a614eb9a4f1219e2f11ea29c8a7cd59dd74dd Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Sun, 12 Nov 2017 11:28:01 -0500 Subject: Calculate the remaining order amount in maker units --- src/utils/order_state_utils.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/utils') 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; } -- cgit v1.2.3 From fdb3fa6801e07972f53a05c312c2ee933809f823 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Sun, 12 Nov 2017 17:24:31 -0500 Subject: Added specs for allowance and balance changes --- src/utils/order_state_utils.ts | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/utils') diff --git a/src/utils/order_state_utils.ts b/src/utils/order_state_utils.ts index ff5c1880d..fde7a7e02 100644 --- a/src/utils/order_state_utils.ts +++ b/src/utils/order_state_utils.ts @@ -72,9 +72,7 @@ export class OrderStateUtils { 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, -- cgit v1.2.3 From 5e77e8809abd96136fb11ebdc84a2aefa32d4cea Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Sun, 12 Nov 2017 17:30:57 -0500 Subject: Update comment --- src/utils/order_state_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/utils/order_state_utils.ts b/src/utils/order_state_utils.ts index fde7a7e02..4f57de9fe 100644 --- a/src/utils/order_state_utils.ts +++ b/src/utils/order_state_utils.ts @@ -65,7 +65,7 @@ export class OrderStateUtils { const totalMakerTokenAmount = signedOrder.makerTokenAmount; const totalTakerTokenAmount = signedOrder.takerTokenAmount; const remainingTakerTokenAmount = totalTakerTokenAmount.minus(unavailableTakerTokenAmount); - // 200 in order, 100 unavailable = 100 remaning, 0.5 remaning proportion + // 200 in order, 100 unavailable = 100 remaning, 0.5 remaining in taker proportion const remainingTakerProportion = remainingTakerTokenAmount.dividedBy(totalTakerTokenAmount); const remainingMakerTokenAmount = remainingTakerProportion.times(totalMakerTokenAmount); // min allowance, balance in account of maker -- cgit v1.2.3 From 42e3ab91a794f61d65008d969b3d48080b5035d7 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Sun, 12 Nov 2017 19:17:27 -0500 Subject: Perform the division after multiplication to reduce compounding the rounding errors --- src/utils/order_state_utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/utils') diff --git a/src/utils/order_state_utils.ts b/src/utils/order_state_utils.ts index 4f57de9fe..7c10a5480 100644 --- a/src/utils/order_state_utils.ts +++ b/src/utils/order_state_utils.ts @@ -66,13 +66,13 @@ export class OrderStateUtils { const totalTakerTokenAmount = signedOrder.takerTokenAmount; const remainingTakerTokenAmount = totalTakerTokenAmount.minus(unavailableTakerTokenAmount); // 200 in order, 100 unavailable = 100 remaning, 0.5 remaining in taker proportion - const remainingTakerProportion = remainingTakerTokenAmount.dividedBy(totalTakerTokenAmount); - const remainingMakerTokenAmount = remainingTakerProportion.times(totalMakerTokenAmount); + const remainingMakerTokenAmount = remainingTakerTokenAmount.times(totalMakerTokenAmount) + .dividedToIntegerBy(totalTakerTokenAmount); // 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); - // edge case when maker token is ZRX + // TODO: Handle edge case where maker token is ZRX with fee const orderRelevantState = { makerBalance, makerProxyAllowance, -- cgit v1.2.3 From 32246fd26bc71b09818491d513a380a8bd85fdec Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Sun, 12 Nov 2017 19:37:03 -0500 Subject: remove comments --- src/utils/order_state_utils.ts | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/utils') diff --git a/src/utils/order_state_utils.ts b/src/utils/order_state_utils.ts index 7c10a5480..36a4b68d6 100644 --- a/src/utils/order_state_utils.ts +++ b/src/utils/order_state_utils.ts @@ -65,12 +65,9 @@ export class OrderStateUtils { const totalMakerTokenAmount = signedOrder.makerTokenAmount; const totalTakerTokenAmount = signedOrder.takerTokenAmount; const remainingTakerTokenAmount = totalTakerTokenAmount.minus(unavailableTakerTokenAmount); - // 200 in order, 100 unavailable = 100 remaning, 0.5 remaining in taker proportion const remainingMakerTokenAmount = remainingTakerTokenAmount.times(totalMakerTokenAmount) .dividedToIntegerBy(totalTakerTokenAmount); - // 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: Handle edge case where maker token is ZRX with fee const orderRelevantState = { -- cgit v1.2.3