From c1dae2d1541070e1ac78c1860ee288c1dd6ffb33 Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Wed, 20 Dec 2023 20:15:24 +0100 Subject: [PATCH 1/2] removing coingecko --- src/modules/prices/beets-price-fetcher.ts | 38 +++++++++++++++++++++++ src/modules/tokens/tokens.ts | 15 ++++----- src/modules/worker/worker.ts | 2 +- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/modules/prices/beets-price-fetcher.ts b/src/modules/prices/beets-price-fetcher.ts index df41d52c..022d5cbe 100644 --- a/src/modules/prices/beets-price-fetcher.ts +++ b/src/modules/prices/beets-price-fetcher.ts @@ -9,6 +9,41 @@ import axios from 'axios'; const BEETS_API_URL = process.env.BEETS_API_URL || 'https://api-v3.balancer.fi/graphql'; +export const nativeAssetMap = { + 1: { + symbol: 'eth', + address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', + }, + 10: { + symbol: 'eth', + address: '0x4200000000000000000000000000000000000006', + }, + 100: { + symbol: 'xdai', + address: '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d', + }, + 137: { + symbol: 'matic', + address: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', + }, + 1101: { + symbol: 'eth', + address: '0x4f9a0e7fd2bf6067db6994cf12e4495df938e6e9', + }, + 8453: { + symbol: 'eth', + address: '0x4200000000000000000000000000000000000006', + }, + 42161: { + symbol: 'eth', + address: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', + }, + 43114: { + symbol: 'avax', + address: '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7', + }, +} + class BeetsPriceFetcher { async fetch(tokens: Token[]): Promise { const tokenPricesByChain: Record> = {}; @@ -26,6 +61,9 @@ class BeetsPriceFetcher { token.price = token.price || {}; token.price.usd = tokenPricesByChain[token.chainId][token.address].toString(); + token.price[nativeAssetMap[token.chainId].symbol] = + (tokenPricesByChain[token.chainId][token.address] / + tokenPricesByChain[token.chainId][nativeAssetMap[token.chainId].address]).toString(); } return token; }); diff --git a/src/modules/tokens/tokens.ts b/src/modules/tokens/tokens.ts index fd2840dd..b90e36c6 100644 --- a/src/modules/tokens/tokens.ts +++ b/src/modules/tokens/tokens.ts @@ -1,7 +1,6 @@ import { BigNumber, ethers } from 'ethers'; import { Token } from './types'; import { Contract } from '@ethersproject/contracts'; -import PriceFetcher from '@/modules/prices/price-fetcher'; import BeetsPriceFetcher from '@/modules/prices/beets-price-fetcher'; import { getToken, updateTokens } from '@/modules/dynamodb'; import { TokenPrices } from '@balancer-labs/sdk'; @@ -10,18 +9,20 @@ const log = console.log; export async function updateTokenPrices( tokens: Token[], - abortOnRateLimit = false ) { const beetsPriceFetcher = new BeetsPriceFetcher(); log(`fetching prices for ${tokens.length} tokens from beets API`); const beetsTokensWithPrices = await beetsPriceFetcher.fetch(tokens); log(`Saving ${beetsTokensWithPrices.length} updated tokens to DB`); await updateTokens(beetsTokensWithPrices); - const priceFetcher = new PriceFetcher(abortOnRateLimit); - log(`fetching prices for ${tokens.length} tokens from coingecko`); - const tokensWithPrices = await priceFetcher.fetch(tokens); - log(`Saving ${tokensWithPrices.length} updated tokens to DB`); - await updateTokens(tokensWithPrices); + + // Commenting out coingecko price fetcher, as it is not working because of rate limiting + // const priceFetcher = new PriceFetcher(abortOnRateLimit); + // log(`fetching prices for ${tokens.length} tokens from coingecko`); + // const tokensWithPrices = await priceFetcher.fetch(tokens); + // log(`Saving ${tokensWithPrices.length} updated tokens to DB`); + // await updateTokens(tokensWithPrices); + log('finished updating token prices'); } diff --git a/src/modules/worker/worker.ts b/src/modules/worker/worker.ts index 1c0aeb95..f0207481 100644 --- a/src/modules/worker/worker.ts +++ b/src/modules/worker/worker.ts @@ -109,7 +109,7 @@ async function decorateAndSavePools(chainId: number) { async function updatePrices() { const tokens = await getTokens(); log('Updating token prices'); - await updateTokenPrices(tokens, false); + await updateTokenPrices(tokens); log('Updated token prices'); setTimeout(updatePrices, UPDATE_PRICES_INTERVAL); } From 674ebfcf817335dc7688b55fe0b4ecb206a518eb Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Wed, 20 Dec 2023 20:19:35 +0100 Subject: [PATCH 2/2] fix --- src/lambdas/update-prices.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lambdas/update-prices.ts b/src/lambdas/update-prices.ts index 1e84d822..e72932f4 100644 --- a/src/lambdas/update-prices.ts +++ b/src/lambdas/update-prices.ts @@ -9,7 +9,7 @@ export const handler = wrapHandler(async (): Promise => { log('Fetching all tokens.'); const tokens = await getTokens(); log(`Fetched ${tokens.length} tokens. Updating token prices`); - await updateTokenPrices(tokens, true); + await updateTokenPrices(tokens); log(`Updated prices`); return { statusCode: 201, body: '' }; } catch (e) {