aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/order_validation_utils.ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-10-05 14:47:55 +0800
committerGitHub <noreply@github.com>2017-10-05 14:47:55 +0800
commit0eb7b81636a9efa8decbf9068d78ffe670e20426 (patch)
tree4c4761c9df6fc42f8aa86a9cdee0c707710e54fb /src/utils/order_validation_utils.ts
parent5bc7d716e03f8786b93fbe506096abe0fb7d08a9 (diff)
parent0594667d36e1551f17ff8b409c47df196f9b1072 (diff)
downloaddexon-sol-tools-0eb7b81636a9efa8decbf9068d78ffe670e20426.tar
dexon-sol-tools-0eb7b81636a9efa8decbf9068d78ffe670e20426.tar.gz
dexon-sol-tools-0eb7b81636a9efa8decbf9068d78ffe670e20426.tar.bz2
dexon-sol-tools-0eb7b81636a9efa8decbf9068d78ffe670e20426.tar.lz
dexon-sol-tools-0eb7b81636a9efa8decbf9068d78ffe670e20426.tar.xz
dexon-sol-tools-0eb7b81636a9efa8decbf9068d78ffe670e20426.tar.zst
dexon-sol-tools-0eb7b81636a9efa8decbf9068d78ffe670e20426.zip
Merge pull request #181 from 0xProject/feature/order-validation-zrx
Fees validations when one of the tokens is ZRX
Diffstat (limited to 'src/utils/order_validation_utils.ts')
-rw-r--r--src/utils/order_validation_utils.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts
index 6f7522c41..0450d26a6 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);
+ let makerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker);
+ const isTakerTokenZRX = signedOrder.takerTokenAddress === zrxTokenAddress;
+ if (isTakerTokenZRX) {
+ makerZRXBalance = makerZRXBalance.plus(fillTakerAmount);
+ }
const makerZRXAllowance = await this.tokenWrapper.getProxyAllowanceAsync(
zrxTokenAddress, signedOrder.maker);
@@ -141,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)) {
@@ -151,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)) {