aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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)) {