diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-10-05 14:47:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-05 14:47:55 +0800 |
commit | 0eb7b81636a9efa8decbf9068d78ffe670e20426 (patch) | |
tree | 4c4761c9df6fc42f8aa86a9cdee0c707710e54fb /src | |
parent | 5bc7d716e03f8786b93fbe506096abe0fb7d08a9 (diff) | |
parent | 0594667d36e1551f17ff8b409c47df196f9b1072 (diff) | |
download | dexon-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')
-rw-r--r-- | src/utils/order_validation_utils.ts | 15 |
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)) { |