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:
parent
3cc639c8d0
commit
dabe6fd793
@ -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,
|
||||||
};
|
};
|
||||||
|
@ -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
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user