added new parameter nativeExclusivelyRFQT
This commit is contained in:
@@ -47,7 +47,6 @@ const DEFAULT_SWAP_QUOTER_OPTS: SwapQuoterOpts = {
|
||||
rfqt: {
|
||||
takerApiKeyWhitelist: [],
|
||||
makerAssetOfferings: {},
|
||||
skipBuyRequests: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ export class SwapQuoter {
|
||||
private readonly _orderStateUtils: OrderStateUtils;
|
||||
private readonly _quoteRequestor: QuoteRequestor;
|
||||
private readonly _rfqtTakerApiKeyWhitelist: string[];
|
||||
private readonly _rfqtSkipBuyRequests: boolean;
|
||||
|
||||
/**
|
||||
* Instantiates a new SwapQuoter instance given existing liquidity in the form of orders and feeOrders.
|
||||
@@ -170,10 +169,6 @@ export class SwapQuoter {
|
||||
this.expiryBufferMs = expiryBufferMs;
|
||||
this.permittedOrderFeeTypes = permittedOrderFeeTypes;
|
||||
this._rfqtTakerApiKeyWhitelist = rfqt ? rfqt.takerApiKeyWhitelist || [] : [];
|
||||
this._rfqtSkipBuyRequests =
|
||||
rfqt && rfqt.skipBuyRequests !== undefined
|
||||
? rfqt.skipBuyRequests
|
||||
: (r => r !== undefined && r.skipBuyRequests === true)(constants.DEFAULT_SWAP_QUOTER_OPTS.rfqt);
|
||||
this._contractAddresses = options.contractAddresses || getContractAddressesForChainOrThrow(chainId);
|
||||
this._devUtilsContract = new DevUtilsContract(this._contractAddresses.devUtils, provider);
|
||||
this._protocolFeeUtils = ProtocolFeeUtils.getInstance(
|
||||
@@ -561,20 +556,26 @@ export class SwapQuoter {
|
||||
} else {
|
||||
gasPrice = await this.getGasPriceEstimationOrThrowAsync();
|
||||
}
|
||||
|
||||
// If RFQT is enabled and `nativeExclusivelyRFQT` is set, then `ERC20BridgeSource.Native` should
|
||||
// never be excluded.
|
||||
if ((opts.rfqt && opts.rfqt.nativeExclusivelyRFQT === true) && opts.excludedSources.includes(ERC20BridgeSource.Native)) {
|
||||
throw new Error('Native liquidity cannot be excluded if "rfqt.nativeExclusivelyRFQT" is set');
|
||||
}
|
||||
|
||||
// get batches of orders from different sources, awaiting sources in parallel
|
||||
const orderBatchPromises: Array<Promise<SignedOrder[]>> = [];
|
||||
orderBatchPromises.push(
|
||||
// Don't fetch from the DB if Native has been excluded
|
||||
opts.excludedSources.includes(ERC20BridgeSource.Native)
|
||||
// Don't fetch Open Orderbook orders from the DB if Native has been excluded, or if `nativeExclusivelyRFQT` has been set.
|
||||
opts.excludedSources.includes(ERC20BridgeSource.Native) || (opts.rfqt && opts.rfqt.nativeExclusivelyRFQT === true)
|
||||
? Promise.resolve([])
|
||||
: this._getSignedOrdersAsync(makerAssetData, takerAssetData),
|
||||
);
|
||||
if (
|
||||
opts.rfqt &&
|
||||
opts.rfqt.intentOnFilling &&
|
||||
opts.rfqt.apiKey &&
|
||||
this._rfqtTakerApiKeyWhitelist.includes(opts.rfqt.apiKey) &&
|
||||
!(marketOperation === MarketOperation.Buy && this._rfqtSkipBuyRequests)
|
||||
opts.rfqt && // This is an RFQT-enabled API request
|
||||
opts.rfqt.intentOnFilling && // The requestor is asking for a firm quote
|
||||
!opts.excludedSources.includes(ERC20BridgeSource.Native) && // Native liquidity is not excluded
|
||||
this._rfqtTakerApiKeyWhitelist.includes(opts.rfqt.apiKey) // A valid API key was provided
|
||||
) {
|
||||
if (!opts.rfqt.takerAddress || opts.rfqt.takerAddress === constants.NULL_ADDRESS) {
|
||||
throw new Error('RFQ-T requests must specify a taker address');
|
||||
@@ -636,8 +637,7 @@ export class SwapQuoter {
|
||||
opts !== undefined &&
|
||||
opts.isIndicative !== undefined &&
|
||||
opts.isIndicative &&
|
||||
this._rfqtTakerApiKeyWhitelist.includes(opts.apiKey) &&
|
||||
!(op === MarketOperation.Buy && this._rfqtSkipBuyRequests)
|
||||
this._rfqtTakerApiKeyWhitelist.includes(opts.apiKey)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,12 +199,18 @@ export interface SwapQuoteOrdersBreakdown {
|
||||
[source: string]: BigNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* nativeExclusivelyRFQT: if set to `true`, Swap quote will exclude Open Orderbook liquidity.
|
||||
* If set to `true` and `ERC20BridgeSource.Native` is part of the `excludedSources`
|
||||
* array in `SwapQuoteRequestOpts`, an Error will be raised.
|
||||
*/
|
||||
export interface RfqtRequestOpts {
|
||||
takerAddress: string;
|
||||
apiKey: string;
|
||||
intentOnFilling: boolean;
|
||||
isIndicative?: boolean;
|
||||
makerEndpointMaxResponseTimeMs?: number;
|
||||
nativeExclusivelyRFQT?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,7 +255,6 @@ export interface SwapQuoterOpts extends OrderPrunerOpts {
|
||||
rfqt?: {
|
||||
takerApiKeyWhitelist: string[];
|
||||
makerAssetOfferings: RfqtMakerAssetOfferings;
|
||||
skipBuyRequests?: boolean;
|
||||
warningLogger?: LogFunction;
|
||||
infoLogger?: LogFunction;
|
||||
};
|
||||
|
||||
@@ -335,7 +335,7 @@ describe('MarketOperationUtils tests', () => {
|
||||
},
|
||||
} as any) as DexOrderSampler;
|
||||
|
||||
describe.only('getRfqtIndicativeQuotesAsync', () => {
|
||||
describe('getRfqtIndicativeQuotesAsync', () => {
|
||||
const partialRfqt: RfqtRequestOpts = {
|
||||
apiKey: 'foo',
|
||||
takerAddress: NULL_ADDRESS,
|
||||
|
||||
Reference in New Issue
Block a user