From 5c42d06f8984a5f4e0668880f492076336d6aa2e Mon Sep 17 00:00:00 2001 From: Valentino Conti Date: Thu, 13 Feb 2025 01:02:06 -0300 Subject: [PATCH 1/2] Add custom coingecko url --- wormhole-connect/src/config/index.ts | 1 + wormhole-connect/src/config/types.ts | 2 ++ wormhole-connect/src/utils/coingecko.ts | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/wormhole-connect/src/config/index.ts b/wormhole-connect/src/config/index.ts index b8e1f162b..7dbd710db 100644 --- a/wormhole-connect/src/config/index.ts +++ b/wormhole-connect/src/config/index.ts @@ -120,6 +120,7 @@ export function buildConfig( Devnet: ['http://localhost:7071'], }[network], coinGeckoApiKey: customConfig.coinGeckoApiKey, + coinGeckoCustomUrl: customConfig.coinGeckoCustomUrl, // Callbacks triggerEvent: wrapEventHandler(customConfig.eventHandler), diff --git a/wormhole-connect/src/config/types.ts b/wormhole-connect/src/config/types.ts index 41667e686..0f9aa61d4 100644 --- a/wormhole-connect/src/config/types.ts +++ b/wormhole-connect/src/config/types.ts @@ -95,6 +95,7 @@ export interface WormholeConnectConfig { // External resources rpcs?: ChainResourceMap; coinGeckoApiKey?: string; + coinGeckoCustomUrl?: string; // White lists chains?: Chain[]; @@ -138,6 +139,7 @@ export interface InternalConfig { wormholeApi: string; wormholeRpcHosts: string[]; coinGeckoApiKey?: string; + coinGeckoCustomUrl?: string; tokens: TokenCache; tokenWhitelist?: (string | TokenTuple)[]; diff --git a/wormhole-connect/src/utils/coingecko.ts b/wormhole-connect/src/utils/coingecko.ts index 145870034..b5c83f6e3 100644 --- a/wormhole-connect/src/utils/coingecko.ts +++ b/wormhole-connect/src/utils/coingecko.ts @@ -50,7 +50,11 @@ const coingeckoRequest = async ( : {}), }); - const hostname = config.coinGeckoApiKey ? COINGECKO_URL_PRO : COINGECKO_URL; + const hostname = config.coinGeckoCustomUrl + ? config.coinGeckoCustomUrl + : config.coinGeckoApiKey + ? COINGECKO_URL_PRO + : COINGECKO_URL; return fetch(`${hostname}${path}`, { signal: params?.abort?.signal, From 9b946bddab9f973c2a4a19e01f0971d8e5b02473 Mon Sep 17 00:00:00 2001 From: Valentino Conti Date: Thu, 13 Feb 2025 15:44:07 -0300 Subject: [PATCH 2/2] object for coingecko config --- wormhole-connect/src/config/index.ts | 3 +-- wormhole-connect/src/config/types.ts | 12 ++++++++---- wormhole-connect/src/utils/coingecko.ts | 14 +++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/wormhole-connect/src/config/index.ts b/wormhole-connect/src/config/index.ts index 7dbd710db..e7cbed0c4 100644 --- a/wormhole-connect/src/config/index.ts +++ b/wormhole-connect/src/config/index.ts @@ -119,8 +119,7 @@ export function buildConfig( ], Devnet: ['http://localhost:7071'], }[network], - coinGeckoApiKey: customConfig.coinGeckoApiKey, - coinGeckoCustomUrl: customConfig.coinGeckoCustomUrl, + coingecko: customConfig.coingecko, // Callbacks triggerEvent: wrapEventHandler(customConfig.eventHandler), diff --git a/wormhole-connect/src/config/types.ts b/wormhole-connect/src/config/types.ts index 0f9aa61d4..00afe4f26 100644 --- a/wormhole-connect/src/config/types.ts +++ b/wormhole-connect/src/config/types.ts @@ -94,8 +94,10 @@ export interface WormholeConnectConfig { // External resources rpcs?: ChainResourceMap; - coinGeckoApiKey?: string; - coinGeckoCustomUrl?: string; + coingecko?: { + apiKey?: string; + customUrl?: string; + }; // White lists chains?: Chain[]; @@ -138,8 +140,10 @@ export interface InternalConfig { mayanApi: string; wormholeApi: string; wormholeRpcHosts: string[]; - coinGeckoApiKey?: string; - coinGeckoCustomUrl?: string; + coingecko?: { + apiKey?: string; + customUrl?: string; + }; tokens: TokenCache; tokenWhitelist?: (string | TokenTuple)[]; diff --git a/wormhole-connect/src/utils/coingecko.ts b/wormhole-connect/src/utils/coingecko.ts index b5c83f6e3..96eddff4f 100644 --- a/wormhole-connect/src/utils/coingecko.ts +++ b/wormhole-connect/src/utils/coingecko.ts @@ -45,16 +45,16 @@ const coingeckoRequest = async ( ): Promise => { const headers = new Headers({ 'Content-Type': 'application/json', - ...(config.coinGeckoApiKey - ? { 'x-cg-pro-api-key': config.coinGeckoApiKey } + ...(config.coingecko?.apiKey + ? { 'x-cg-pro-api-key': config.coingecko.apiKey } : {}), }); - const hostname = config.coinGeckoCustomUrl - ? config.coinGeckoCustomUrl - : config.coinGeckoApiKey - ? COINGECKO_URL_PRO - : COINGECKO_URL; + const hostname = config.coingecko?.customUrl + ? config.coingecko.customUrl + : config.coingecko?.apiKey + ? COINGECKO_URL_PRO + : COINGECKO_URL; return fetch(`${hostname}${path}`, { signal: params?.abort?.signal,