From 47f01d44cc4c58b5e019b84f0dbf972bb9f8f7c0 Mon Sep 17 00:00:00 2001 From: Jac <39693487+lijac@users.noreply.github.com> Date: Fri, 3 May 2024 17:09:49 -0400 Subject: [PATCH] fix: Secta - v2 decimals -18 --- adapters/secta/src/index.ts | 2 +- adapters/secta/src/sdk/poolDetails.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/adapters/secta/src/index.ts b/adapters/secta/src/index.ts index ca98518e..d1144770 100644 --- a/adapters/secta/src/index.ts +++ b/adapters/secta/src/index.ts @@ -152,7 +152,7 @@ export const getUserTVLByBlock = async (blocks: BlockData) => { return csvRows; }; -readBlocksFromCSV(path.resolve(__dirname, "../hourly_blocks.csv")) +readBlocksFromCSV(path.resolve(__dirname, "../block_numbers_secta.tsv")) .then(async (blocks) => { console.log(blocks); const allCsvRows: any[] = []; // Array to accumulate CSV rows for all blocks diff --git a/adapters/secta/src/sdk/poolDetails.ts b/adapters/secta/src/sdk/poolDetails.ts index 2a1d04de..b8496343 100644 --- a/adapters/secta/src/sdk/poolDetails.ts +++ b/adapters/secta/src/sdk/poolDetails.ts @@ -21,12 +21,19 @@ export const getV2LpValue = async (rpc: string, pairs: V2Pair[], mintedAddresses const liquidityInfo: LiquidityInfo = {}; + const WAD = new BigNumber("1000000000000000000"); + for (const pair of pairs) { const userAddresses = mintedAddresses[pair.id] || new Set(); for (const userAddress of userAddresses) { // Get the user's balance of the LP token as a BigNumber - const userLpBalanceBigInt = await getERC20TokenBalanceAtBlock(rpc, pair.id, userAddress, blockNumber); + const userLpBalanceBigInt = await getERC20TokenBalanceAtBlock( + rpc, + pair.id, + userAddress, + blockNumber + ); const userLpBalance = new BigNumber(userLpBalanceBigInt.toString()); const totalSupply = new BigNumber(pair.totalSupply); @@ -34,8 +41,12 @@ export const getV2LpValue = async (rpc: string, pairs: V2Pair[], mintedAddresses const userShare = userLpBalance.dividedBy(totalSupply); // Calculate user's share of token0 and token1 - const token0Amount = userShare.multipliedBy(new BigNumber(pair.reserve0)); - const token1Amount = userShare.multipliedBy(new BigNumber(pair.reserve1)); + const token0Amount = userShare + .multipliedBy(new BigNumber(pair.reserve0)) + .dividedBy(WAD); + const token1Amount = userShare + .multipliedBy(new BigNumber(pair.reserve1)) + .dividedBy(WAD); // Ensure user's entry exists in the liquidity info if (!liquidityInfo[userAddress]) {