diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-20 01:25:40 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-26 04:25:56 +0800 |
commit | 1690aae1cfcd19be23db9f77bd0da0c86141e679 (patch) | |
tree | e2163ddce5be205419ab5a92f57e1ce006a5dac8 /src | |
parent | 4d27b89fe38e0bb617aa05c86735025de9799fe9 (diff) | |
download | dexon-0x-contracts-1690aae1cfcd19be23db9f77bd0da0c86141e679.tar.gz dexon-0x-contracts-1690aae1cfcd19be23db9f77bd0da0c86141e679.tar.zst dexon-0x-contracts-1690aae1cfcd19be23db9f77bd0da0c86141e679.zip |
Simplify order checks
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/order_validation_utils.ts | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts index 12b7f27fd..8a737040c 100644 --- a/src/utils/order_validation_utils.ts +++ b/src/utils/order_validation_utils.ts @@ -28,25 +28,19 @@ export class OrderValidationUtils { const exchangeRate = signedOrder.takerTokenAmount.div(signedOrder.makerTokenAmount); const fillMakerAmount = fillTakerAmount.div(exchangeRate); - if (isMakerTokenZRX) { - const requiredMakerAmount = fillMakerAmount.plus(signedOrder.makerFee); - if (requiredMakerAmount.greaterThan(makerBalance)) { - throw new Error(ExchangeContractErrs.InsufficientMakerBalance); - } - if (requiredMakerAmount.greaterThan(makerAllowance)) { - throw new Error(ExchangeContractErrs.InsufficientMakerAllowance); - } - } else { + const requiredMakerAmount = isMakerTokenZRX ? fillMakerAmount.plus(signedOrder.makerFee) : fillMakerAmount; + if (requiredMakerAmount.greaterThan(makerBalance)) { + throw new Error(ExchangeContractErrs.InsufficientMakerBalance); + } + if (requiredMakerAmount.greaterThan(makerAllowance)) { + throw new Error(ExchangeContractErrs.InsufficientMakerAllowance); + } + + if (!isMakerTokenZRX) { const makerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker); const makerZRXAllowance = await this.tokenWrapper.getProxyAllowanceAsync( zrxTokenAddress, signedOrder.maker); - if (fillMakerAmount.greaterThan(makerBalance)) { - throw new Error(ExchangeContractErrs.InsufficientMakerBalance); - } - if (fillMakerAmount.greaterThan(makerAllowance)) { - throw new Error(ExchangeContractErrs.InsufficientMakerAllowance); - } if (signedOrder.makerFee.greaterThan(makerZRXBalance)) { throw new Error(ExchangeContractErrs.InsufficientMakerFeeBalance); } @@ -64,24 +58,18 @@ export class OrderValidationUtils { const isTakerTokenZRX = signedOrder.takerTokenAddress === zrxTokenAddress; - if (isTakerTokenZRX) { - const requiredTakerAmount = fillTakerAmount.plus(signedOrder.takerFee); - if (requiredTakerAmount.greaterThan(takerBalance)) { - throw new Error(ExchangeContractErrs.InsufficientTakerBalance); - } - if (requiredTakerAmount.greaterThan(takerAllowance)) { - throw new Error(ExchangeContractErrs.InsufficientTakerAllowance); - } - } else { + const requiredTakerAmount = isTakerTokenZRX ? fillTakerAmount.plus(signedOrder.takerFee) : fillTakerAmount; + if (requiredTakerAmount.greaterThan(takerBalance)) { + throw new Error(ExchangeContractErrs.InsufficientTakerBalance); + } + if (requiredTakerAmount.greaterThan(takerAllowance)) { + throw new Error(ExchangeContractErrs.InsufficientTakerAllowance); + } + + if (!isTakerTokenZRX) { const takerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress); const takerZRXAllowance = await this.tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, senderAddress); - if (fillTakerAmount.greaterThan(takerBalance)) { - throw new Error(ExchangeContractErrs.InsufficientTakerBalance); - } - if (fillTakerAmount.greaterThan(takerAllowance)) { - throw new Error(ExchangeContractErrs.InsufficientTakerAllowance); - } if (signedOrder.takerFee.greaterThan(takerZRXBalance)) { throw new Error(ExchangeContractErrs.InsufficientTakerFeeBalance); } |