Skip to content

Commit

Permalink
fix: Secta - v2 decimals -18
Browse files Browse the repository at this point in the history
  • Loading branch information
jac0x committed May 3, 2024
1 parent b02b2f3 commit 47f01d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion adapters/secta/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions adapters/secta/src/sdk/poolDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,32 @@ 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<string>();

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);

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]) {
Expand Down

0 comments on commit 47f01d4

Please sign in to comment.