From 8b7caef0db337a5f1b9bf41ee5f8a9157eda4d1d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 4 Oct 2017 14:21:39 +0300 Subject: Fix an issue when validation failed, but contract call will succeed --- src/utils/order_validation_utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/utils/order_validation_utils.ts') diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts index 6f7522c41..de20cf06d 100644 --- a/src/utils/order_validation_utils.ts +++ b/src/utils/order_validation_utils.ts @@ -121,7 +121,11 @@ export class OrderValidationUtils { } if (!isMakerTokenZRX) { - const makerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker); + const isTakerTokenZRX = signedOrder.takerTokenAddress === zrxTokenAddress; + let makerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker); + if (isTakerTokenZRX) { + makerZRXBalance = makerZRXBalance.plus(fillTakerAmount); + } const makerZRXAllowance = await this.tokenWrapper.getProxyAllowanceAsync( zrxTokenAddress, signedOrder.maker); -- cgit v1.2.3 From 0caab98399544d93891d11a2f25309f92433f3c1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 4 Oct 2017 14:58:08 +0300 Subject: Fi fees validation is one of the tokens transfered is 0x --- src/utils/order_validation_utils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/utils/order_validation_utils.ts') diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts index de20cf06d..160afc43e 100644 --- a/src/utils/order_validation_utils.ts +++ b/src/utils/order_validation_utils.ts @@ -145,6 +145,9 @@ export class OrderValidationUtils { signedOrder.takerTokenAddress, senderAddress); const isTakerTokenZRX = signedOrder.takerTokenAddress === zrxTokenAddress; + // exchangeRate is the price of one maker token denominated in taker tokens + const exchangeRate = signedOrder.takerTokenAmount.div(signedOrder.makerTokenAmount); + const fillMakerAmount = fillTakerAmount.div(exchangeRate); const requiredTakerAmount = isTakerTokenZRX ? fillTakerAmount.plus(signedOrder.takerFee) : fillTakerAmount; if (requiredTakerAmount.greaterThan(takerBalance)) { @@ -155,7 +158,11 @@ export class OrderValidationUtils { } if (!isTakerTokenZRX) { - const takerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress); + const isMakerTokenZRX = signedOrder.makerTokenAddress === zrxTokenAddress; + let takerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress); + if (isMakerTokenZRX) { + takerZRXBalance = takerZRXBalance.plus(fillMakerAmount); + } const takerZRXAllowance = await this.tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, senderAddress); if (signedOrder.takerFee.greaterThan(takerZRXBalance)) { -- cgit v1.2.3 From 0594667d36e1551f17ff8b409c47df196f9b1072 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 5 Oct 2017 09:46:54 +0300 Subject: Small reordering --- src/utils/order_validation_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/order_validation_utils.ts') diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts index 160afc43e..0450d26a6 100644 --- a/src/utils/order_validation_utils.ts +++ b/src/utils/order_validation_utils.ts @@ -121,8 +121,8 @@ export class OrderValidationUtils { } if (!isMakerTokenZRX) { - const isTakerTokenZRX = signedOrder.takerTokenAddress === zrxTokenAddress; let makerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker); + const isTakerTokenZRX = signedOrder.takerTokenAddress === zrxTokenAddress; if (isTakerTokenZRX) { makerZRXBalance = makerZRXBalance.plus(fillTakerAmount); } -- cgit v1.2.3