From 330a452b1c83c3d1269c019de984aba02d5f4c6a Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Thu, 30 Nov 2023 12:02:40 -0300 Subject: [PATCH] Removing fetchChunk and putting limit on the debouncer; changing the console time label; --- .../modules/data/token-prices/coingecko.ts | 34 +++---------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/balancer-js/src/modules/data/token-prices/coingecko.ts b/balancer-js/src/modules/data/token-prices/coingecko.ts index 8e6d3c635..865b649c5 100644 --- a/balancer-js/src/modules/data/token-prices/coingecko.ts +++ b/balancer-js/src/modules/data/token-prices/coingecko.ts @@ -21,7 +21,8 @@ export class CoingeckoPriceRepository implements Findable { )}?vs_currencies=usd,eth`; this.debouncer = new Debouncer( this.fetch.bind(this), - 200 + 200, + 10 ); } @@ -29,38 +30,11 @@ export class CoingeckoPriceRepository implements Findable { addresses: string[], { signal }: { signal?: AbortSignal } = {} ): Promise { - const promises = []; - const maxAddressesAllowedByCoingecko = 10; // Coingecko is only allowing 10 tokens per time - - const fetchChunk = async (chunk: string[]): Promise => { - const { data } = await axios.get(this.url(chunk), { + try { + const { data } = await axios.get(this.url(addresses), { signal, }); return data; - }; - - for ( - let i = 0; - i < addresses.length / maxAddressesAllowedByCoingecko; - i += 1 - ) { - promises.push( - fetchChunk( - addresses.slice( - i * maxAddressesAllowedByCoingecko, - (i + 1) * maxAddressesAllowedByCoingecko - ) - ) - ); - } - let tokenPrices: TokenPrices = {}; - try { - console.time(`fetching coingecko for ${addresses.length} tokens`); - tokenPrices = (await Promise.all(promises)).reduce((acc, cur) => { - return { ...acc, ...cur }; - }, {}); - console.timeEnd(`fetching coingecko for ${addresses.length} tokens`); - return tokenPrices; } catch (error) { const message = ['Error fetching token prices from coingecko']; if ((error as AxiosError).isAxiosError) {