fix: Remove API key whitelist field (#323)

* Refactor integrator ID and add Prometheus metrics

* Update packages/asset-swapper/src/swap_quoter.ts

Co-authored-by: David Walsh <5778036+rhinodavid@users.noreply.github.com>

* Update packages/asset-swapper/src/swap_quoter.ts

Co-authored-by: David Walsh <5778036+rhinodavid@users.noreply.github.com>

* Update packages/asset-swapper/src/swap_quoter.ts

Co-authored-by: David Walsh <5778036+rhinodavid@users.noreply.github.com>

* Added documentation and fixed some minor requests

* Added more metrics

* more docs

* lint fix

* added new Integrator ID addition

* refactor tests

* Refactor new types

Co-authored-by: David Walsh <5778036+rhinodavid@users.noreply.github.com>
This commit is contained in:
Daniel Pyrathon 2021-09-14 14:43:02 -04:00 committed by GitHub
parent 6ce4458a5d
commit 79f36cf6fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -244,7 +244,6 @@ export interface RfqRequestOpts {
takerAddress: string; takerAddress: string;
txOrigin: string; txOrigin: string;
integrator: Integrator; integrator: Integrator;
apiKeyWhitelist?: string[];
intentOnFilling: boolean; intentOnFilling: boolean;
isIndicative?: boolean; isIndicative?: boolean;
makerEndpointMaxResponseTimeMs?: number; makerEndpointMaxResponseTimeMs?: number;
@ -297,6 +296,7 @@ export interface RfqFirmQuoteValidator {
export interface Integrator { export interface Integrator {
integratorId: string; integratorId: string;
label: string; label: string;
whitelistIntegratorUrls?: string[];
} }
export interface SwapQuoterRfqOpts { export interface SwapQuoterRfqOpts {

View File

@ -214,7 +214,7 @@ export class QuoteRequestor {
* @returns a list of TypedMakerUrl instances * @returns a list of TypedMakerUrl instances
*/ */
public static getTypedMakerUrlsAndWhitelist( public static getTypedMakerUrlsAndWhitelist(
options: Pick<RfqmRequestOptions, 'apiKeyWhitelist' | 'altRfqAssetOfferings'>, options: Pick<RfqmRequestOptions, 'integrator' | 'altRfqAssetOfferings'>,
assetOfferings: RfqMakerAssetOfferings, assetOfferings: RfqMakerAssetOfferings,
): TypedMakerUrl[] { ): TypedMakerUrl[] {
const standardUrls = Object.keys(assetOfferings).map( const standardUrls = Object.keys(assetOfferings).map(
@ -233,8 +233,8 @@ export class QuoteRequestor {
let typedMakerUrls = standardUrls.concat(altUrls); let typedMakerUrls = standardUrls.concat(altUrls);
// If there is a whitelist, only allow approved maker URLs // If there is a whitelist, only allow approved maker URLs
if (options.apiKeyWhitelist !== undefined) { if (options.integrator.whitelistIntegratorUrls !== undefined) {
const whitelist = new Set(options.apiKeyWhitelist.map(key => key.toLowerCase())); const whitelist = new Set(options.integrator.whitelistIntegratorUrls.map(key => key.toLowerCase()));
typedMakerUrls = typedMakerUrls.filter(makerUrl => whitelist.has(makerUrl.url.toLowerCase())); typedMakerUrls = typedMakerUrls.filter(makerUrl => whitelist.has(makerUrl.url.toLowerCase()));
} }
return typedMakerUrls; return typedMakerUrls;

View File

@ -862,7 +862,11 @@ describe('QuoteRequestor', async () => {
const [apiKeyWhitelist, results] = test; const [apiKeyWhitelist, results] = test;
const response = QuoteRequestor.getTypedMakerUrlsAndWhitelist( const response = QuoteRequestor.getTypedMakerUrlsAndWhitelist(
{ {
apiKeyWhitelist, integrator: {
integratorId: 'foo',
label: 'bar',
whitelistIntegratorUrls: apiKeyWhitelist,
},
altRfqAssetOfferings: {}, altRfqAssetOfferings: {},
}, },
{ {