aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-09-26 18:39:05 +0800
committerFabio Berger <me@fabioberger.com>2017-09-26 18:39:05 +0800
commit25116940c0f3df4431e16d050da9b5d4f301b9d8 (patch)
tree859639a9e5233f75f19241af8c413c4e4b0fb506
parent2148eb6d9901bbc34210df2e96542f71eef215f9 (diff)
downloaddexon-0x-contracts-25116940c0f3df4431e16d050da9b5d4f301b9d8.tar
dexon-0x-contracts-25116940c0f3df4431e16d050da9b5d4f301b9d8.tar.gz
dexon-0x-contracts-25116940c0f3df4431e16d050da9b5d4f301b9d8.tar.bz2
dexon-0x-contracts-25116940c0f3df4431e16d050da9b5d4f301b9d8.tar.lz
dexon-0x-contracts-25116940c0f3df4431e16d050da9b5d4f301b9d8.tar.xz
dexon-0x-contracts-25116940c0f3df4431e16d050da9b5d4f301b9d8.tar.zst
dexon-0x-contracts-25116940c0f3df4431e16d050da9b5d4f301b9d8.zip
Refactor our logic checking fillAmountNotZero and expiry
-rw-r--r--src/utils/order_validation_utils.ts35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts
index ba02390d5..6f7522c41 100644
--- a/src/utils/order_validation_utils.ts
+++ b/src/utils/order_validation_utils.ts
@@ -18,13 +18,10 @@ export class OrderValidationUtils {
): Promise<void> {
const orderHash = utils.getOrderHashHex(signedOrder);
const unavailableTakerTokenAmount = await this.exchangeWrapper.getUnavailableTakerAmountAsync(orderHash);
- if (signedOrder.takerTokenAmount.eq(unavailableTakerTokenAmount)) {
- throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero);
- }
- const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
- if (signedOrder.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
- throw new Error(ExchangeContractErrs.OrderFillExpired);
- }
+ this.validateRemainingFillAmountNotZeroOrThrow(
+ signedOrder.takerTokenAmount, unavailableTakerTokenAmount,
+ );
+ this.validateOrderNotExpiredOrThrow(signedOrder.expirationUnixTimestampSec);
let fillTakerTokenAmount = signedOrder.takerTokenAmount.minus(unavailableTakerTokenAmount);
if (!_.isUndefined(expectedFillTakerTokenAmount)) {
fillTakerTokenAmount = expectedFillTakerTokenAmount;
@@ -45,16 +42,13 @@ export class OrderValidationUtils {
throw new Error(ZeroExError.InvalidSignature);
}
const unavailableTakerTokenAmount = await this.exchangeWrapper.getUnavailableTakerAmountAsync(orderHash);
- if (signedOrder.takerTokenAmount.eq(unavailableTakerTokenAmount)) {
- throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero);
- }
+ this.validateRemainingFillAmountNotZeroOrThrow(
+ signedOrder.takerTokenAmount, unavailableTakerTokenAmount,
+ );
if (signedOrder.taker !== constants.NULL_ADDRESS && signedOrder.taker !== takerAddress) {
throw new Error(ExchangeContractErrs.TransactionSenderIsNotFillOrderTaker);
}
- const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
- if (signedOrder.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
- throw new Error(ExchangeContractErrs.OrderFillExpired);
- }
+ this.validateOrderNotExpiredOrThrow(signedOrder.expirationUnixTimestampSec);
await this.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress,
);
@@ -168,4 +162,17 @@ export class OrderValidationUtils {
}
}
}
+ private validateRemainingFillAmountNotZeroOrThrow(
+ takerTokenAmount: BigNumber.BigNumber, unavailableTakerTokenAmount: BigNumber.BigNumber,
+ ) {
+ if (takerTokenAmount.eq(unavailableTakerTokenAmount)) {
+ throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero);
+ }
+ }
+ private validateOrderNotExpiredOrThrow(expirationUnixTimestampSec: BigNumber.BigNumber) {
+ const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
+ if (expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
+ throw new Error(ExchangeContractErrs.OrderFillExpired);
+ }
+ }
}