Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
asset-swapper: extract method
Browse files Browse the repository at this point in the history
Addresses review comment #2555 (comment)
  • Loading branch information
feuGeneA committed Apr 21, 2020
1 parent 4cc9cea commit 5effc6e
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions packages/asset-swapper/src/utils/market_operation_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ import {
OrderDomain,
} from './types';

async function getRfqtIndicativeQuotesAsync(
makerAssetData: string,
takerAssetData: string,
marketOperation: MarketOperation,
assetFillAmount: BigNumber,
opts: Partial<GetMarketOrdersOpts>,
): Promise<RfqtIndicativeQuoteResponse[]> {
if (opts.rfqt && opts.rfqt.quoteRequestor) {
return opts.rfqt.quoteRequestor.requestRfqtIndicativeQuotesAsync(
makerAssetData,
takerAssetData,
assetFillAmount,
marketOperation,
opts.rfqt,
);
} else {
return Promise.resolve<RfqtIndicativeQuoteResponse[]>([]);
}
}

export class MarketOperationUtils {
private readonly _wethAddress: string;

Expand Down Expand Up @@ -93,16 +113,13 @@ export class MarketOperationUtils {
this._liquidityProviderRegistry,
),
);
const rfqtPromise =
_opts !== undefined && _opts.rfqt !== undefined && _opts.rfqt.quoteRequestor !== undefined
? _opts.rfqt.quoteRequestor.requestRfqtIndicativeQuotesAsync(
nativeOrders[0].makerAssetData,
nativeOrders[0].takerAssetData,
takerAmount,
MarketOperation.Sell,
_opts.rfqt,
)
: Promise.resolve<RfqtIndicativeQuoteResponse[]>([]);
const rfqtPromise = getRfqtIndicativeQuotesAsync(
makerToken,
takerToken,
MarketOperation.Sell,
takerAmount,
_opts,
);
const [
[orderFillableAmounts, liquidityProviderAddress, ethToMakerAssetRate, dexQuotes],
rfqtIndicativeQuotes,
Expand Down Expand Up @@ -176,16 +193,13 @@ export class MarketOperationUtils {
this._liquidityProviderRegistry,
),
);
const rfqtPromise =
opts !== undefined && _opts.rfqt !== undefined && _opts.rfqt.quoteRequestor !== undefined
? _opts.rfqt.quoteRequestor.requestRfqtIndicativeQuotesAsync(
nativeOrders[0].makerAssetData,
nativeOrders[0].takerAssetData,
makerAmount,
MarketOperation.Buy,
_opts.rfqt,
)
: [];
const rfqtPromise = getRfqtIndicativeQuotesAsync(
makerToken,
takerToken,
MarketOperation.Buy,
makerAmount,
_opts,
);
const [
[orderFillableAmounts, liquidityProviderAddress, ethToTakerAssetRate, dexQuotes],
rfqtIndicativeQuotes,
Expand Down

0 comments on commit 5effc6e

Please sign in to comment.