Add changes for the feature flag
This commit is contained in:
parent
4b508d255d
commit
a03d0800b0
@ -122,3 +122,5 @@ export const constants = {
|
|||||||
DEFAULT_INFO_LOGGER,
|
DEFAULT_INFO_LOGGER,
|
||||||
DEFAULT_WARNING_LOGGER,
|
DEFAULT_WARNING_LOGGER,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ENABLE_PRICE_AWARE_RFQ: boolean = false;
|
||||||
|
@ -8,7 +8,7 @@ import { BlockParamLiteral, SupportedProvider, ZeroExProvider } from 'ethereum-t
|
|||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
import { artifacts } from './artifacts';
|
||||||
import { constants } from './constants';
|
import { constants, ENABLE_PRICE_AWARE_RFQ } from './constants';
|
||||||
import {
|
import {
|
||||||
CalculateSwapQuoteOpts,
|
CalculateSwapQuoteOpts,
|
||||||
LiquidityForTakerMakerAssetDataPair,
|
LiquidityForTakerMakerAssetDataPair,
|
||||||
@ -696,6 +696,31 @@ export class SwapQuoter {
|
|||||||
opts.rfqt = undefined;
|
opts.rfqt = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!ENABLE_PRICE_AWARE_RFQ && // Price-aware RFQ is disabled.
|
||||||
|
opts.rfqt && // This is an RFQT-enabled API request
|
||||||
|
opts.rfqt.intentOnFilling && // The requestor is asking for a firm quote
|
||||||
|
opts.rfqt.apiKey &&
|
||||||
|
this._isApiKeyWhitelisted(opts.rfqt.apiKey) && // A valid API key was provided
|
||||||
|
sourceFilters.isAllowed(ERC20BridgeSource.Native) // Native liquidity is not excluded
|
||||||
|
) {
|
||||||
|
if (!opts.rfqt.takerAddress || opts.rfqt.takerAddress === constants.NULL_ADDRESS) {
|
||||||
|
throw new Error('RFQ-T requests must specify a taker address');
|
||||||
|
}
|
||||||
|
orderBatchPromises.push(
|
||||||
|
quoteRequestor
|
||||||
|
.requestRfqtFirmQuotesAsync(
|
||||||
|
makerAssetData,
|
||||||
|
takerAssetData,
|
||||||
|
assetFillAmount,
|
||||||
|
marketOperation,
|
||||||
|
undefined,
|
||||||
|
opts.rfqt,
|
||||||
|
)
|
||||||
|
.then(firmQuotes => firmQuotes.map(quote => quote.signedOrder)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const orderBatches: SignedOrder[][] = await Promise.all(orderBatchPromises);
|
const orderBatches: SignedOrder[][] = await Promise.all(orderBatchPromises);
|
||||||
const unsortedOrders: SignedOrder[] = orderBatches.reduce((_orders, batch) => _orders.concat(...batch), []);
|
const unsortedOrders: SignedOrder[] = orderBatches.reduce((_orders, batch) => _orders.concat(...batch), []);
|
||||||
const orders = sortingUtils.sortOrders(unsortedOrders);
|
const orders = sortingUtils.sortOrders(unsortedOrders);
|
||||||
|
@ -4,6 +4,7 @@ import { RFQTIndicativeQuote } from '@0x/quote-server';
|
|||||||
import { SignedOrder } from '@0x/types';
|
import { SignedOrder } from '@0x/types';
|
||||||
import { BigNumber, NULL_ADDRESS } from '@0x/utils';
|
import { BigNumber, NULL_ADDRESS } from '@0x/utils';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
import { ENABLE_PRICE_AWARE_RFQ } from '../../constants';
|
||||||
|
|
||||||
import { MarketOperation, Omit } from '../../types';
|
import { MarketOperation, Omit } from '../../types';
|
||||||
import { QuoteRequestor } from '../quote_requestor';
|
import { QuoteRequestor } from '../quote_requestor';
|
||||||
@ -216,6 +217,17 @@ export class MarketOperationUtils {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const rfqtPromise = !ENABLE_PRICE_AWARE_RFQ && quoteSourceFilters.isAllowed(ERC20BridgeSource.Native)
|
||||||
|
? getRfqtIndicativeQuotesAsync(
|
||||||
|
nativeOrders[0].makerAssetData,
|
||||||
|
nativeOrders[0].takerAssetData,
|
||||||
|
MarketOperation.Sell,
|
||||||
|
takerAmount,
|
||||||
|
undefined,
|
||||||
|
_opts,
|
||||||
|
)
|
||||||
|
: Promise.resolve([]);
|
||||||
|
|
||||||
const offChainBalancerPromise = sampleBalancerOffChain
|
const offChainBalancerPromise = sampleBalancerOffChain
|
||||||
? this._sampler.getBalancerSellQuotesOffChainAsync(makerToken, takerToken, sampleAmounts)
|
? this._sampler.getBalancerSellQuotesOffChainAsync(makerToken, takerToken, sampleAmounts)
|
||||||
: Promise.resolve([]);
|
: Promise.resolve([]);
|
||||||
@ -230,11 +242,13 @@ export class MarketOperationUtils {
|
|||||||
|
|
||||||
const [
|
const [
|
||||||
[tokenDecimals, orderFillableAmounts, ethToMakerAssetRate, ethToTakerAssetRate, dexQuotes, twoHopQuotes],
|
[tokenDecimals, orderFillableAmounts, ethToMakerAssetRate, ethToTakerAssetRate, dexQuotes, twoHopQuotes],
|
||||||
|
rfqtIndicativeQuotes,
|
||||||
offChainBalancerQuotes,
|
offChainBalancerQuotes,
|
||||||
offChainCreamQuotes,
|
offChainCreamQuotes,
|
||||||
offChainBancorQuotes,
|
offChainBancorQuotes,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
samplerPromise,
|
samplerPromise,
|
||||||
|
rfqtPromise,
|
||||||
offChainBalancerPromise,
|
offChainBalancerPromise,
|
||||||
offChainCreamPromise,
|
offChainCreamPromise,
|
||||||
offChainBancorPromise,
|
offChainBancorPromise,
|
||||||
@ -251,7 +265,7 @@ export class MarketOperationUtils {
|
|||||||
orderFillableAmounts,
|
orderFillableAmounts,
|
||||||
ethToOutputRate: ethToMakerAssetRate,
|
ethToOutputRate: ethToMakerAssetRate,
|
||||||
ethToInputRate: ethToTakerAssetRate,
|
ethToInputRate: ethToTakerAssetRate,
|
||||||
rfqtIndicativeQuotes: [],
|
rfqtIndicativeQuotes,
|
||||||
twoHopQuotes,
|
twoHopQuotes,
|
||||||
quoteSourceFilters,
|
quoteSourceFilters,
|
||||||
makerTokenDecimals: makerTokenDecimals.toNumber(),
|
makerTokenDecimals: makerTokenDecimals.toNumber(),
|
||||||
@ -350,7 +364,16 @@ export class MarketOperationUtils {
|
|||||||
this._liquidityProviderRegistry,
|
this._liquidityProviderRegistry,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
const rfqtPromise = !ENABLE_PRICE_AWARE_RFQ && quoteSourceFilters.isAllowed(ERC20BridgeSource.Native)
|
||||||
|
? getRfqtIndicativeQuotesAsync(
|
||||||
|
nativeOrders[0].makerAssetData,
|
||||||
|
nativeOrders[0].takerAssetData,
|
||||||
|
MarketOperation.Buy,
|
||||||
|
makerAmount,
|
||||||
|
undefined,
|
||||||
|
_opts,
|
||||||
|
)
|
||||||
|
: Promise.resolve([]);
|
||||||
const offChainBalancerPromise = sampleBalancerOffChain
|
const offChainBalancerPromise = sampleBalancerOffChain
|
||||||
? this._sampler.getBalancerBuyQuotesOffChainAsync(makerToken, takerToken, sampleAmounts)
|
? this._sampler.getBalancerBuyQuotesOffChainAsync(makerToken, takerToken, sampleAmounts)
|
||||||
: Promise.resolve([]);
|
: Promise.resolve([]);
|
||||||
@ -361,9 +384,10 @@ export class MarketOperationUtils {
|
|||||||
|
|
||||||
const [
|
const [
|
||||||
[tokenDecimals, orderFillableAmounts, ethToMakerAssetRate, ethToTakerAssetRate, dexQuotes, twoHopQuotes],
|
[tokenDecimals, orderFillableAmounts, ethToMakerAssetRate, ethToTakerAssetRate, dexQuotes, twoHopQuotes],
|
||||||
|
rfqtIndicativeQuotes,
|
||||||
offChainBalancerQuotes,
|
offChainBalancerQuotes,
|
||||||
offChainCreamQuotes,
|
offChainCreamQuotes,
|
||||||
] = await Promise.all([samplerPromise, offChainBalancerPromise, offChainCreamPromise]);
|
] = await Promise.all([samplerPromise, rfqtPromise, offChainBalancerPromise, offChainCreamPromise]);
|
||||||
// Attach the MultiBridge address to the sample fillData
|
// Attach the MultiBridge address to the sample fillData
|
||||||
(dexQuotes.find(quotes => quotes[0] && quotes[0].source === ERC20BridgeSource.MultiBridge) || []).forEach(
|
(dexQuotes.find(quotes => quotes[0] && quotes[0].source === ERC20BridgeSource.MultiBridge) || []).forEach(
|
||||||
q => (q.fillData = { poolAddress: this._multiBridge }),
|
q => (q.fillData = { poolAddress: this._multiBridge }),
|
||||||
@ -379,7 +403,7 @@ export class MarketOperationUtils {
|
|||||||
orderFillableAmounts,
|
orderFillableAmounts,
|
||||||
ethToOutputRate: ethToTakerAssetRate,
|
ethToOutputRate: ethToTakerAssetRate,
|
||||||
ethToInputRate: ethToMakerAssetRate,
|
ethToInputRate: ethToMakerAssetRate,
|
||||||
rfqtIndicativeQuotes: [],
|
rfqtIndicativeQuotes,
|
||||||
twoHopQuotes,
|
twoHopQuotes,
|
||||||
quoteSourceFilters,
|
quoteSourceFilters,
|
||||||
makerTokenDecimals: makerTokenDecimals.toNumber(),
|
makerTokenDecimals: makerTokenDecimals.toNumber(),
|
||||||
@ -651,7 +675,7 @@ export class MarketOperationUtils {
|
|||||||
|
|
||||||
// If RFQ liquidity is enabled, make a request to check RFQ liquidity
|
// If RFQ liquidity is enabled, make a request to check RFQ liquidity
|
||||||
const { rfqt } = _opts;
|
const { rfqt } = _opts;
|
||||||
if (rfqt && rfqt.quoteRequestor && marketSideLiquidity.quoteSourceFilters.isAllowed(ERC20BridgeSource.Native)) {
|
if (ENABLE_PRICE_AWARE_RFQ && rfqt && rfqt.quoteRequestor && marketSideLiquidity.quoteSourceFilters.isAllowed(ERC20BridgeSource.Native)) {
|
||||||
// Calculate a suggested price. For now, this is simply the overall price of the aggregation.
|
// Calculate a suggested price. For now, this is simply the overall price of the aggregation.
|
||||||
let comparisonPrice: BigNumber | undefined;
|
let comparisonPrice: BigNumber | undefined;
|
||||||
if (optimizerResult) {
|
if (optimizerResult) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user