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;
txOrigin: string;
integrator: Integrator;
apiKeyWhitelist?: string[];
intentOnFilling: boolean;
isIndicative?: boolean;
makerEndpointMaxResponseTimeMs?: number;
@ -297,6 +296,7 @@ export interface RfqFirmQuoteValidator {
export interface Integrator {
integratorId: string;
label: string;
whitelistIntegratorUrls?: string[];
}
export interface SwapQuoterRfqOpts {

View File

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

View File

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