aboutsummaryrefslogtreecommitdiffstats
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
parent31d068b83ff8d8e9117e410693c3afbc6f8a82ab (diff)
downloaddexon-sol-tools-4d27b89fe38e0bb617aa05c86735025de9799fe9.tar
dexon-sol-tools-4d27b89fe38e0bb617aa05c86735025de9799fe9.tar.gz
dexon-sol-tools-4d27b89fe38e0bb617aa05c86735025de9799fe9.tar.bz2
dexon-sol-tools-4d27b89fe38e0bb617aa05c86735025de9799fe9.tar.lz
dexon-sol-tools-4d27b89fe38e0bb617aa05c86735025de9799fe9.tar.xz
dexon-sol-tools-4d27b89fe38e0bb617aa05c86735025de9799fe9.tar.zst
dexon-sol-tools-4d27b89fe38e0bb617aa05c86735025de9799fe9.zip
Store tokenWrapper inside of OrdervalidationUtils
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts6
-rw-r--r--src/utils/order_validation_utils.ts46
2 files changed, 29 insertions, 23 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 88dca82b2..2ddd63422 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -61,6 +61,7 @@ export class ExchangeWrapper extends ContractWrapper {
};
private _exchangeContractIfExists?: ExchangeContract;
private _exchangeLogEventEmitters: ContractEventEmitter[];
+ private _orderValidationUtils: OrderValidationUtils;
private _tokenWrapper: TokenWrapper;
private static _getOrderAddressesAndValues(order: Order): [OrderAddresses, OrderValues] {
const orderAddresses: OrderAddresses = [
@@ -83,6 +84,7 @@ export class ExchangeWrapper extends ContractWrapper {
constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) {
super(web3Wrapper);
this._tokenWrapper = tokenWrapper;
+ this._orderValidationUtils = new OrderValidationUtils(tokenWrapper);
this._exchangeLogEventEmitters = [];
}
/**
@@ -662,8 +664,8 @@ export class ExchangeWrapper extends ContractWrapper {
throw new Error(ExchangeContractErrs.OrderFillExpired);
}
const zrxTokenAddress = await this._getZRXTokenAddressAsync(signedOrder.exchangeContractAddress);
- await OrderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
- this._tokenWrapper, signedOrder, fillTakerAmount, senderAddress, zrxTokenAddress,
+ await this._orderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ signedOrder, fillTakerAmount, senderAddress, zrxTokenAddress,
);
const wouldRoundingErrorOccur = await this._isRoundingErrorAsync(
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);