diff --git a/packages/asset-swapper/src/utils/quote_requestor.ts b/packages/asset-swapper/src/utils/quote_requestor.ts index e453ef1844..e38c60f2a8 100644 --- a/packages/asset-swapper/src/utils/quote_requestor.ts +++ b/packages/asset-swapper/src/utils/quote_requestor.ts @@ -8,6 +8,25 @@ import { MarketOperation } from '../types'; /** * Request quotes from RFQ-T providers */ + +function getTokenAddressOrThrow(assetData: string): string { + const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData); + if (decodedAssetData.hasOwnProperty('tokenAddress')) { + // type cast necessary here as decodeAssetDataOrThrow returns + // an AssetData object, which doesn't necessarily contain a + // token address. (it could possibly be a StaticCallAssetData, + // which lacks an address.) so we'll just assume it's a token + // here. should be safe, with the enclosing guard condition + // and subsequent error. + // tslint:disable-next-line:no-unnecessary-type-assertion + return (decodedAssetData as ERC20AssetData).tokenAddress; + } else { + throw new Error( + `Decoded asset data (${JSON.stringify(decodedAssetData)}) does not contain a token address`, + ); + } +} + export class QuoteRequestor { private readonly _rfqtMakerEndpoints: string[]; @@ -26,24 +45,6 @@ export class QuoteRequestor { ): Promise { const makerEndpointMaxResponseTimeMs = 1000; - const getTokenAddressOrThrow = (assetData: string): string => { - const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData); - if (decodedAssetData.hasOwnProperty('tokenAddress')) { - // type cast necessary here as decodeAssetDataOrThrow returns - // an AssetData object, which doesn't necessarily contain a - // token address. (it could possibly be a StaticCallAssetData, - // which lacks an address.) so we'll just assume it's a token - // here. should be safe, with the enclosing guard condition - // and subsequent error. - // tslint:disable-next-line:no-unnecessary-type-assertion - return (decodedAssetData as ERC20AssetData).tokenAddress; - } else { - throw new Error( - `Decoded asset data (${JSON.stringify(decodedAssetData)}) does not contain a token address`, - ); - } - }; - const buyToken = getTokenAddressOrThrow(makerAssetData); const sellToken = getTokenAddressOrThrow(takerAssetData);