add tx origin blacklist to RFQ options (#169)

* add tx origin blacklist to RFQ options

* Fix typo

* use set instead of array

* make sure tx origin is lower case

* changed default blacklist value from array to set
This commit is contained in:
Alex Kroeger 2021-03-11 18:05:16 -08:00 committed by GitHub
parent 3cc639c8d0
commit dabe6fd793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -52,6 +52,7 @@ const DEFAULT_SWAP_QUOTER_OPTS: SwapQuoterOpts = {
rfqt: { rfqt: {
takerApiKeyWhitelist: [], takerApiKeyWhitelist: [],
makerAssetOfferings: {}, makerAssetOfferings: {},
txOriginBlacklist: new Set(),
}, },
tokenAdjacencyGraph: DEFAULT_TOKEN_ADJACENCY_GRAPH, tokenAdjacencyGraph: DEFAULT_TOKEN_ADJACENCY_GRAPH,
}; };

View File

@ -410,6 +410,14 @@ export class SwapQuoter {
return whitelistedApiKeys.includes(apiKey); return whitelistedApiKeys.includes(apiKey);
} }
private _isTxOriginBlacklisted(txOrigin: string | undefined): boolean {
if (!txOrigin) {
return false;
}
const blacklistedTxOrigins = this._rfqtOptions ? this._rfqtOptions.txOriginBlacklist : new Set();
return blacklistedTxOrigins.has(txOrigin.toLowerCase());
}
private _validateRfqtOpts( private _validateRfqtOpts(
sourceFilters: SourceFilters, sourceFilters: SourceFilters,
rfqt: RfqtRequestOpts | undefined, rfqt: RfqtRequestOpts | undefined,
@ -438,6 +446,19 @@ export class SwapQuoter {
return undefined; return undefined;
} }
// If the requested tx origin is blacklisted, raise a warning and disable RFQ
if (this._isTxOriginBlacklisted(txOrigin)) {
if (this._rfqtOptions && this._rfqtOptions.warningLogger) {
this._rfqtOptions.warningLogger(
{
txOrigin,
},
'Attempt at using a tx Origin that is blacklisted. Disabling RFQ for the request lifetime.',
);
}
return undefined;
}
// Otherwise check other RFQ options // Otherwise check other RFQ options
if ( if (
intentOnFilling && // The requestor is asking for a firm quote intentOnFilling && // The requestor is asking for a firm quote

View File

@ -286,6 +286,7 @@ export interface RfqtFirmQuoteValidator {
export interface SwapQuoterRfqtOpts { export interface SwapQuoterRfqtOpts {
takerApiKeyWhitelist: string[]; takerApiKeyWhitelist: string[];
makerAssetOfferings: RfqtMakerAssetOfferings; makerAssetOfferings: RfqtMakerAssetOfferings;
txOriginBlacklist: Set<string>;
altRfqCreds?: { altRfqCreds?: {
altRfqApiKey: string; altRfqApiKey: string;
altRfqProfile: string; altRfqProfile: string;