Allow injection of an RfqtFirmQuoteValidator and an RfqtQuoteObserver (#11)
* Allow injection of RFQT quote hooks * Remove QuoteObserver * Remove unnecessary `async` * modernized the code based on latest spec * prettify Co-authored-by: Daniel Pyrathon <daniel@0x.org>
This commit is contained in:
parent
ab698cec14
commit
85f5d32de2
@ -103,6 +103,7 @@ export {
|
||||
MockedRfqtFirmQuoteResponse,
|
||||
OrderPrunerPermittedFeeTypes,
|
||||
RfqtMakerAssetOfferings,
|
||||
RfqtFirmQuoteValidator,
|
||||
RfqtRequestOpts,
|
||||
SamplerOverrides,
|
||||
SignedOrderWithFillableAmounts,
|
||||
|
@ -295,6 +295,10 @@ export interface RfqtMakerAssetOfferings {
|
||||
|
||||
export type LogFunction = (obj: object, msg?: string, ...args: any[]) => void;
|
||||
|
||||
export interface RfqtFirmQuoteValidator {
|
||||
getRFQTTakerFillableAmounts(quotes: SignedOrder[]): Promise<BigNumber[]>;
|
||||
}
|
||||
|
||||
export interface SwapQuoterRfqtOpts {
|
||||
takerApiKeyWhitelist: string[];
|
||||
makerAssetOfferings: RfqtMakerAssetOfferings;
|
||||
|
@ -683,20 +683,24 @@ export class MarketOperationUtils {
|
||||
rfqt,
|
||||
);
|
||||
if (firmQuotes.length > 0) {
|
||||
// Compute the RFQ order fillable amounts. This is done by performing a "soft" order
|
||||
// validation and by checking order balances that are monitored by our worker.
|
||||
// If a firm quote validator does not exist, then we assume that all orders are valid.
|
||||
const firmQuoteSignedOrders = firmQuotes.map(quote => quote.signedOrder);
|
||||
const rfqOrderFillableAmounts =
|
||||
rfqt.firmQuoteValidator === undefined
|
||||
? firmQuoteSignedOrders.map(signedOrder => signedOrder.takerAssetAmount)
|
||||
: await rfqt.firmQuoteValidator.getRFQTTakerFillableAmounts(firmQuoteSignedOrders);
|
||||
|
||||
// Re-run optimizer with the new firm quote. This is the second and last time
|
||||
// we run the optimized in a block of code. In this case, we don't catch a potential `NoOptimalPath` exception
|
||||
// and we let it bubble up if it happens.
|
||||
//
|
||||
// NOTE: as of now, we assume that RFQ orders are 100% fillable because these are trusted market makers, therefore
|
||||
// we do not perform an extra check to get fillable taker amounts.
|
||||
optimizerResult = await this._generateOptimizedOrdersAsync(
|
||||
{
|
||||
...marketSideLiquidity,
|
||||
nativeOrders: marketSideLiquidity.nativeOrders.concat(
|
||||
firmQuotes.map(quote => quote.signedOrder),
|
||||
),
|
||||
nativeOrders: marketSideLiquidity.nativeOrders.concat(firmQuoteSignedOrders),
|
||||
orderFillableAmounts: marketSideLiquidity.orderFillableAmounts.concat(
|
||||
firmQuotes.map(quote => quote.signedOrder.takerAssetAmount),
|
||||
rfqOrderFillableAmounts,
|
||||
),
|
||||
},
|
||||
optimizerOpts,
|
||||
|
@ -2,7 +2,7 @@ import { RFQTIndicativeQuote } from '@0x/quote-server';
|
||||
import { MarketOperation, SignedOrder } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { RfqtRequestOpts, SignedOrderWithFillableAmounts } from '../../types';
|
||||
import { RfqtFirmQuoteValidator, RfqtRequestOpts, SignedOrderWithFillableAmounts } from '../../types';
|
||||
import { QuoteRequestor } from '../../utils/quote_requestor';
|
||||
import { QuoteReport } from '../quote_report_generator';
|
||||
|
||||
@ -239,6 +239,7 @@ export interface OptimizedMarketOrder extends SignedOrderWithFillableAmounts {
|
||||
|
||||
export interface GetMarketOrdersRfqtOpts extends RfqtRequestOpts {
|
||||
quoteRequestor?: QuoteRequestor;
|
||||
firmQuoteValidator?: RfqtFirmQuoteValidator;
|
||||
}
|
||||
|
||||
export type FeeEstimate = (fillData?: FillData) => number | BigNumber;
|
||||
|
Loading…
x
Reference in New Issue
Block a user