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

Commit

Permalink
Merge pull request #2562 from 0xProject/feature/rfqt-warning-logger
Browse files Browse the repository at this point in the history
asset-swapper: support RFQ-T logger callback
  • Loading branch information
feuGeneA authored Apr 23, 2020
2 parents be2db50 + 980246d commit 456f8a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion packages/asset-swapper/src/swap_quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ export class SwapQuoter {
this._devUtilsContract = new DevUtilsContract(this._contractAddresses.devUtils, provider);
this._protocolFeeUtils = new ProtocolFeeUtils(constants.PROTOCOL_FEE_UTILS_POLLING_INTERVAL_IN_MS);
this._orderStateUtils = new OrderStateUtils(this._devUtilsContract);
this._quoteRequestor = new QuoteRequestor(options.rfqt ? options.rfqt.makerEndpoints || [] : []);
this._quoteRequestor = new QuoteRequestor(
options.rfqt ? options.rfqt.makerEndpoints || [] : [],
options.rfqt ? options.rfqt.warningLogger : undefined,
);
const sampler = new DexOrderSampler(
new IERC20BridgeSamplerContract(this._contractAddresses.erc20BridgeSampler, this.provider, {
gas: samplerGasLimit,
Expand Down
1 change: 1 addition & 0 deletions packages/asset-swapper/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export interface SwapQuoterOpts extends OrderPrunerOpts {
rfqt?: {
takerApiKeyWhitelist: string[];
makerEndpoints: string[];
warningLogger?: (s: string) => void;
};
}

Expand Down
22 changes: 13 additions & 9 deletions packages/asset-swapper/src/utils/quote_requestor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ function hasExpectedAssetData(
export class QuoteRequestor {
private readonly _rfqtMakerEndpoints: string[];
private readonly _schemaValidator: SchemaValidator = new SchemaValidator();
private readonly _warningLogger: (s: string) => void;

constructor(rfqtMakerEndpoints: string[]) {
constructor(rfqtMakerEndpoints: string[], logger: (s: string) => void = s => logUtils.warn(s)) {
this._rfqtMakerEndpoints = rfqtMakerEndpoints;
this._warningLogger = logger;
}

public async requestRfqtFirmQuotesAsync(
Expand All @@ -112,12 +114,12 @@ export class QuoteRequestor {
timeout: _opts.makerEndpointMaxResponseTimeMs,
});
} catch (err) {
logUtils.warn(
this._warningLogger(
`Failed to get RFQ-T firm quote from market maker endpoint ${rfqtMakerEndpoint} for API key ${
_opts.apiKey
} for taker address ${_opts.takerAddress}`,
);
logUtils.warn(err);
this._warningLogger(err);
return undefined;
}
}),
Expand All @@ -132,7 +134,7 @@ export class QuoteRequestor {
const validatedOrdersWithStringInts = ordersWithStringInts.filter(order => {
const hasValidSchema = this._schemaValidator.isValid(order, schemas.signedOrderSchema);
if (!hasValidSchema) {
logUtils.warn(`Invalid RFQ-t order received, filtering out: ${JSON.stringify(order)}`);
this._warningLogger(`Invalid RFQ-t order received, filtering out: ${JSON.stringify(order)}`);
return false;
}

Expand All @@ -144,7 +146,7 @@ export class QuoteRequestor {
order.takerAssetData.toLowerCase(),
)
) {
logUtils.warn(`Unexpected asset data in RFQ-T order, filtering out: ${JSON.stringify(order)}`);
this._warningLogger(`Unexpected asset data in RFQ-T order, filtering out: ${JSON.stringify(order)}`);
return false;
}

Expand Down Expand Up @@ -190,12 +192,12 @@ export class QuoteRequestor {
timeout: options.makerEndpointMaxResponseTimeMs,
});
} catch (err) {
logUtils.warn(
this._warningLogger(
`Failed to get RFQ-T indicative quote from market maker endpoint ${rfqtMakerEndpoint} for API key ${
options.apiKey
} for taker address ${options.takerAddress}`,
);
logUtils.warn(err);
this._warningLogger(err);
return undefined;
}
}),
Expand All @@ -209,13 +211,15 @@ export class QuoteRequestor {

const validResponsesWithStringInts = responsesWithStringInts.filter(response => {
if (!this._isValidRfqtIndicativeQuoteResponse(response)) {
logUtils.warn(`Invalid RFQ-T indicative quote received, filtering out: ${JSON.stringify(response)}`);
this._warningLogger(
`Invalid RFQ-T indicative quote received, filtering out: ${JSON.stringify(response)}`,
);
return false;
}
if (
!hasExpectedAssetData(makerAssetData, takerAssetData, response.makerAssetData, response.takerAssetData)
) {
logUtils.warn(
this._warningLogger(
`Unexpected asset data in RFQ-T indicative quote, filtering out: ${JSON.stringify(response)}`,
);
return false;
Expand Down

0 comments on commit 456f8a9

Please sign in to comment.