aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-20 01:22:09 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-26 04:25:56 +0800
commit4d27b89fe38e0bb617aa05c86735025de9799fe9 (patch)
treee9443eade896cdd58cc7611118c43004f7921cb3 /src/utils
parent31d068b83ff8d8e9117e410693c3afbc6f8a82ab (diff)
downloaddexon-0x-contracts-4d27b89fe38e0bb617aa05c86735025de9799fe9.tar.gz
dexon-0x-contracts-4d27b89fe38e0bb617aa05c86735025de9799fe9.tar.zst
dexon-0x-contracts-4d27b89fe38e0bb617aa05c86735025de9799fe9.zip
Store tokenWrapper inside of OrdervalidationUtils
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/order_validation_utils.ts46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts
index f85b8dd23..12b7f27fd 100644
--- a/src/utils/order_validation_utils.ts
+++ b/src/utils/order_validation_utils.ts
@@ -2,22 +2,25 @@ import {ExchangeContractErrs, SignedOrder} from '../types';
import {TokenWrapper} from '../contract_wrappers/token_wrapper';
export class OrderValidationUtils {
- public static async validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
- tokenWrapper: TokenWrapper, signedOrder: SignedOrder, fillTakerAmount: BigNumber.BigNumber,
- senderAddress: string, zrxTokenAddress: string): Promise<void> {
- await OrderValidationUtils.validateFillOrderMakerBalancesAllowancesThrowIfInvalidAsync(
- tokenWrapper, signedOrder, fillTakerAmount, zrxTokenAddress,
+ private tokenWrapper: TokenWrapper;
+ constructor(tokenWrapper: TokenWrapper) {
+ this.tokenWrapper = tokenWrapper;
+ }
+ public async validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ signedOrder: SignedOrder, fillTakerAmount: BigNumber.BigNumber, senderAddress: string, zrxTokenAddress: string,
+ ): Promise<void> {
+ await this.validateFillOrderMakerBalancesAllowancesThrowIfInvalidAsync(
+ signedOrder, fillTakerAmount, zrxTokenAddress,
);
- await OrderValidationUtils.validateFillOrderTakerBalancesAllowancesThrowIfInvalidAsync(
- tokenWrapper, signedOrder, fillTakerAmount, senderAddress, zrxTokenAddress,
+ await this.validateFillOrderTakerBalancesAllowancesThrowIfInvalidAsync(
+ signedOrder, fillTakerAmount, senderAddress, zrxTokenAddress,
);
}
- private static async validateFillOrderMakerBalancesAllowancesThrowIfInvalidAsync(
- tokenWrapper: TokenWrapper, signedOrder: SignedOrder, fillTakerAmount: BigNumber.BigNumber,
- zrxTokenAddress: string,
+ private async validateFillOrderMakerBalancesAllowancesThrowIfInvalidAsync(
+ signedOrder: SignedOrder, fillTakerAmount: BigNumber.BigNumber, zrxTokenAddress: string,
): Promise<void> {
- const makerBalance = await tokenWrapper.getBalanceAsync(signedOrder.makerTokenAddress, signedOrder.maker);
- const makerAllowance = await tokenWrapper.getProxyAllowanceAsync(
+ const makerBalance = await this.tokenWrapper.getBalanceAsync(signedOrder.makerTokenAddress, signedOrder.maker);
+ const makerAllowance = await this.tokenWrapper.getProxyAllowanceAsync(
signedOrder.makerTokenAddress, signedOrder.maker);
const isMakerTokenZRX = signedOrder.makerTokenAddress === zrxTokenAddress;
@@ -34,8 +37,9 @@ export class OrderValidationUtils {
throw new Error(ExchangeContractErrs.InsufficientMakerAllowance);
}
} else {
- const makerZRXBalance = await tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker);
- const makerZRXAllowance = await tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, signedOrder.maker);
+ 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);
@@ -51,12 +55,12 @@ export class OrderValidationUtils {
}
}
}
- private static async validateFillOrderTakerBalancesAllowancesThrowIfInvalidAsync(
- tokenWrapper: TokenWrapper, signedOrder: SignedOrder, fillTakerAmount: BigNumber.BigNumber,
- senderAddress: string, zrxTokenAddress: string,
+ private async validateFillOrderTakerBalancesAllowancesThrowIfInvalidAsync(
+ signedOrder: SignedOrder, fillTakerAmount: BigNumber.BigNumber, senderAddress: string, zrxTokenAddress: string,
): Promise<void> {
- const takerBalance = await tokenWrapper.getBalanceAsync(signedOrder.takerTokenAddress, senderAddress);
- const takerAllowance = await tokenWrapper.getProxyAllowanceAsync(signedOrder.takerTokenAddress, senderAddress);
+ const takerBalance = await this.tokenWrapper.getBalanceAsync(signedOrder.takerTokenAddress, senderAddress);
+ const takerAllowance = await this.tokenWrapper.getProxyAllowanceAsync(
+ signedOrder.takerTokenAddress, senderAddress);
const isTakerTokenZRX = signedOrder.takerTokenAddress === zrxTokenAddress;
@@ -69,8 +73,8 @@ export class OrderValidationUtils {
throw new Error(ExchangeContractErrs.InsufficientTakerAllowance);
}
} else {
- const takerZRXBalance = await tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress);
- const takerZRXAllowance = await tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, senderAddress);
+ 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);