refactored forwarder to utilize utils

This commit is contained in:
David Sun 2019-06-21 10:17:36 -07:00
parent ac771e2865
commit 2afb06de13

View File

@ -19,6 +19,7 @@ import {
import { affiliateFeeUtils } from '../utils/affiliate_fee_utils'; import { affiliateFeeUtils } from '../utils/affiliate_fee_utils';
import { assert } from '../utils/assert'; import { assert } from '../utils/assert';
import { assetDataUtils } from '../utils/asset_data_utils'; import { assetDataUtils } from '../utils/asset_data_utils';
import { SwapQuoteConsumerUtils } from '../utils/swap_quote_consumer_utils';
import { utils } from '../utils/utils'; import { utils } from '../utils/utils';
export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumer<ForwarderMarketBuySmartContractParams> { export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumer<ForwarderMarketBuySmartContractParams> {
@ -164,7 +165,7 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumer<ForwarderMa
const { orders, feeOrders, makerAssetFillAmount, worstCaseQuoteInfo } = swapQuoteWithAffiliateFee; const { orders, feeOrders, makerAssetFillAmount, worstCaseQuoteInfo } = swapQuoteWithAffiliateFee;
const finalTakerAddress = await this._getTakerAddressOrThrowAsync(opts); const finalTakerAddress = await SwapQuoteConsumerUtils.getTakerAddressOrThrowAsync(this.provider, opts);
try { try {
const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEthAsync( const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEthAsync(
@ -193,25 +194,6 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumer<ForwarderMa
} }
} }
private async _getTakerAddressOrThrowAsync(opts: Partial<ForwarderSwapQuoteExecutionOpts>): Promise<string> {
if (opts.takerAddress !== undefined) {
return opts.takerAddress;
} else {
const web3Wrapper = new Web3Wrapper(this.provider);
const availableAddresses = await web3Wrapper.getAvailableAddressesAsync();
const firstAvailableAddress = _.head(availableAddresses);
if (firstAvailableAddress !== undefined) {
return firstAvailableAddress;
} else {
throw new Error(SwapQuoteConsumerError.NoAddressAvailable);
}
}
}
/**
* Get the assetData that represents the WETH token.
* Will throw if WETH does not exist for the current network.
*/
private _getEtherTokenAssetDataOrThrow(): string { private _getEtherTokenAssetDataOrThrow(): string {
return assetDataUtils.getEtherTokenAssetData(this._contractWrappers); return assetDataUtils.getEtherTokenAssetData(this._contractWrappers);
} }