From cdf0cb6884db79d3d3c6fe70c0891e175110f3ff Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:46:18 +0100 Subject: [PATCH] fix: aave pricing (#1260) --- .changeset/calm-panthers-exercise.md | 5 ++++ .../aave-price-handler.service.ts | 29 ++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 .changeset/calm-panthers-exercise.md diff --git a/.changeset/calm-panthers-exercise.md b/.changeset/calm-panthers-exercise.md new file mode 100644 index 000000000..8fb5a82c0 --- /dev/null +++ b/.changeset/calm-panthers-exercise.md @@ -0,0 +1,5 @@ +--- +'backend': patch +--- + +aave pricing diff --git a/modules/token/lib/token-price-handlers/aave-price-handler.service.ts b/modules/token/lib/token-price-handlers/aave-price-handler.service.ts index d0f213457..3d5de278a 100644 --- a/modules/token/lib/token-price-handlers/aave-price-handler.service.ts +++ b/modules/token/lib/token-price-handlers/aave-price-handler.service.ts @@ -32,18 +32,17 @@ export class AavePriceHandlerService implements TokenPriceHandler { } public async updatePricesForTokens(tokens: PrismaTokenWithTypes[]): Promise { - const acceptedTokens = this.getAcceptedTokens(tokens); - const acceptedAddresses = acceptedTokens.map((token) => token.address); - const acceptedAaveTokens = this.aaveTokens.filter((token) => acceptedAddresses.includes(token.wrappedToken)); + const addresses = tokens.map((token) => token.address); + const aaveTokens = this.aaveTokens.filter((token) => addresses.includes(token.wrappedToken)); const tokenAndPrices: tokenAndPrice[] = []; const timestamp = timestampRoundedUpToNearestHour(); // Group tokens by chain - const tokensByChain = _.groupBy(acceptedTokens, 'chain'); + const tokensByChain = _.groupBy(aaveTokens, 'chain'); const updatedTokens: PrismaTokenWithTypes[] = []; for (const chain in tokensByChain) { - const aaveTokensForChain = acceptedAaveTokens.filter((token) => token.chain === (chain as Chain)); + const aaveTokensForChain = tokensByChain[chain]; if (!aaveTokensForChain.length) { continue; } @@ -73,22 +72,26 @@ export class AavePriceHandlerService implements TokenPriceHandler { underlyingPrices, ); - for (const token of tokensByChain[chain]) { - const underlying = aaveTokensForChain.find((t) => t.wrappedToken === token.address)?.underlying; - if (!underlying) { - throw new Error(`AavePriceHandlerService: Underlying token for ${token.address} not found`); + for (const token of aaveTokensForChain) { + const dbToken = tokens.find((t) => t.address === token.wrappedToken); + const underlying = token.underlying; + if (!dbToken || !underlyingMap[underlying]) { + console.error( + `AavePriceHandlerService: Underlying price for ${token.wrappedToken} on ${chain} not found`, + ); + continue; } try { - const price = Number((rateMap[token.address] * underlyingMap[underlying].price).toFixed(2)); + const price = Number((rateMap[token.wrappedToken] * underlyingMap[underlying].price).toFixed(2)); - updatedTokens.push(token); + updatedTokens.push(dbToken); tokenAndPrices.push({ - address: token.address, + address: token.wrappedToken, chain: token.chain, price, }); } catch (e: any) { - console.error('Aave price failed for', token.address, chain, e.message); + console.error('Aave price failed for', token.wrappedToken, chain, e.message); } } }