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,
|
MockedRfqtFirmQuoteResponse,
|
||||||
OrderPrunerPermittedFeeTypes,
|
OrderPrunerPermittedFeeTypes,
|
||||||
RfqtMakerAssetOfferings,
|
RfqtMakerAssetOfferings,
|
||||||
|
RfqtFirmQuoteValidator,
|
||||||
RfqtRequestOpts,
|
RfqtRequestOpts,
|
||||||
SamplerOverrides,
|
SamplerOverrides,
|
||||||
SignedOrderWithFillableAmounts,
|
SignedOrderWithFillableAmounts,
|
||||||
|
@ -295,6 +295,10 @@ export interface RfqtMakerAssetOfferings {
|
|||||||
|
|
||||||
export type LogFunction = (obj: object, msg?: string, ...args: any[]) => void;
|
export type LogFunction = (obj: object, msg?: string, ...args: any[]) => void;
|
||||||
|
|
||||||
|
export interface RfqtFirmQuoteValidator {
|
||||||
|
getRFQTTakerFillableAmounts(quotes: SignedOrder[]): Promise<BigNumber[]>;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SwapQuoterRfqtOpts {
|
export interface SwapQuoterRfqtOpts {
|
||||||
takerApiKeyWhitelist: string[];
|
takerApiKeyWhitelist: string[];
|
||||||
makerAssetOfferings: RfqtMakerAssetOfferings;
|
makerAssetOfferings: RfqtMakerAssetOfferings;
|
||||||
|
@ -683,20 +683,24 @@ export class MarketOperationUtils {
|
|||||||
rfqt,
|
rfqt,
|
||||||
);
|
);
|
||||||
if (firmQuotes.length > 0) {
|
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
|
// 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
|
// 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.
|
// 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(
|
optimizerResult = await this._generateOptimizedOrdersAsync(
|
||||||
{
|
{
|
||||||
...marketSideLiquidity,
|
...marketSideLiquidity,
|
||||||
nativeOrders: marketSideLiquidity.nativeOrders.concat(
|
nativeOrders: marketSideLiquidity.nativeOrders.concat(firmQuoteSignedOrders),
|
||||||
firmQuotes.map(quote => quote.signedOrder),
|
|
||||||
),
|
|
||||||
orderFillableAmounts: marketSideLiquidity.orderFillableAmounts.concat(
|
orderFillableAmounts: marketSideLiquidity.orderFillableAmounts.concat(
|
||||||
firmQuotes.map(quote => quote.signedOrder.takerAssetAmount),
|
rfqOrderFillableAmounts,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
optimizerOpts,
|
optimizerOpts,
|
||||||
|
@ -2,7 +2,7 @@ import { RFQTIndicativeQuote } from '@0x/quote-server';
|
|||||||
import { MarketOperation, SignedOrder } from '@0x/types';
|
import { MarketOperation, SignedOrder } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
|
|
||||||
import { RfqtRequestOpts, SignedOrderWithFillableAmounts } from '../../types';
|
import { RfqtFirmQuoteValidator, RfqtRequestOpts, SignedOrderWithFillableAmounts } from '../../types';
|
||||||
import { QuoteRequestor } from '../../utils/quote_requestor';
|
import { QuoteRequestor } from '../../utils/quote_requestor';
|
||||||
import { QuoteReport } from '../quote_report_generator';
|
import { QuoteReport } from '../quote_report_generator';
|
||||||
|
|
||||||
@ -239,6 +239,7 @@ export interface OptimizedMarketOrder extends SignedOrderWithFillableAmounts {
|
|||||||
|
|
||||||
export interface GetMarketOrdersRfqtOpts extends RfqtRequestOpts {
|
export interface GetMarketOrdersRfqtOpts extends RfqtRequestOpts {
|
||||||
quoteRequestor?: QuoteRequestor;
|
quoteRequestor?: QuoteRequestor;
|
||||||
|
firmQuoteValidator?: RfqtFirmQuoteValidator;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FeeEstimate = (fillData?: FillData) => number | BigNumber;
|
export type FeeEstimate = (fillData?: FillData) => number | BigNumber;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user