Refactor orderValidationUtils to use the generated contract wrapper instead of the higher-level one

This commit is contained in:
Fabio Berger
2018-06-11 14:34:00 +02:00
parent ce6078ed94
commit afa27a3c2a

View File

@@ -3,7 +3,7 @@ import { ExchangeContractErrs, Order, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
import { ExchangeContract } from '../contract_wrappers/generated/exchange';
import { TradeSide, TransferType } from '../types';
import { constants } from '../utils/constants';
import { utils } from '../utils/utils';
@@ -11,7 +11,7 @@ import { utils } from '../utils/utils';
import { ExchangeTransferSimulator } from './exchange_transfer_simulator';
export class OrderValidationUtils {
private _exchangeWrapper: ExchangeWrapper;
private _exchangeContract: ExchangeContract;
public static validateCancelOrderThrowIfInvalid(
order: Order,
cancelTakerTokenAmount: BigNumber,
@@ -104,8 +104,8 @@ export class OrderValidationUtils {
.round(0);
return fillMakerTokenAmount;
}
constructor(exchangeWrapper: ExchangeWrapper) {
this._exchangeWrapper = exchangeWrapper;
constructor(exchangeContract: ExchangeContract) {
this._exchangeContract = exchangeContract;
}
public async validateOrderFillableOrThrowAsync(
exchangeTradeEmulator: ExchangeTransferSimulator,
@@ -114,7 +114,9 @@ export class OrderValidationUtils {
expectedFillTakerTokenAmount?: BigNumber,
): Promise<void> {
const orderHash = getOrderHashHex(signedOrder);
const unavailableTakerTokenAmount = await this._exchangeWrapper.getUnavailableTakerAmountAsync(orderHash);
const unavailableTakerTokenAmount = await this._exchangeContract.getUnavailableTakerTokenAmount.callAsync(
orderHash,
);
OrderValidationUtils._validateRemainingFillAmountNotZeroOrThrow(
signedOrder.takerTokenAmount,
unavailableTakerTokenAmount,
@@ -146,7 +148,9 @@ export class OrderValidationUtils {
if (!isValidSignature(orderHash, signedOrder.ecSignature, signedOrder.maker)) {
throw new Error(OrderError.InvalidSignature);
}
const unavailableTakerTokenAmount = await this._exchangeWrapper.getUnavailableTakerAmountAsync(orderHash);
const unavailableTakerTokenAmount = await this._exchangeContract.getUnavailableTakerTokenAmount.callAsync(
orderHash,
);
OrderValidationUtils._validateRemainingFillAmountNotZeroOrThrow(
signedOrder.takerTokenAmount,
unavailableTakerTokenAmount,
@@ -167,7 +171,7 @@ export class OrderValidationUtils {
zrxTokenAddress,
);
const wouldRoundingErrorOccur = await this._exchangeWrapper.isRoundingErrorAsync(
const wouldRoundingErrorOccur = await this._exchangeContract.isRoundingError.callAsync(
filledTakerTokenAmount,
signedOrder.takerTokenAmount,
signedOrder.makerTokenAmount,