From 132de1f5825feea6d2ea857fce87490b10728fde Mon Sep 17 00:00:00 2001 From: Taha Abbasi Date: Mon, 8 Jan 2024 18:58:23 -0800 Subject: [PATCH] updated depositAndStake Fetch event --- src/openStaking.ts | 36 +++++++----------------------------- src/utils/helpers.ts | 12 ++++++------ 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/openStaking.ts b/src/openStaking.ts index 1efb133..094f2a2 100644 --- a/src/openStaking.ts +++ b/src/openStaking.ts @@ -37,13 +37,11 @@ export async function getUniqueStakersFromOpenStaking( existingSnapshot ? existingSnapshot.uniqueStakers : [] ); - // Convert block identifiers to actual block numbers const currentBlockNumber = await web3Instance.eth.getBlockNumber(); const resolvedFromBlock = fromBlock === "latest" ? currentBlockNumber : fromBlock; const resolvedToBlock = toBlock === "latest" ? currentBlockNumber : toBlock; const step = blockIterationSize; - let startBlock = resolvedFromBlock; if (existingSnapshot && existingSnapshot.latestBlockCaptured >= resolvedFromBlock) { startBlock = existingSnapshot.latestBlockCaptured + 1; @@ -62,37 +60,16 @@ export async function getUniqueStakersFromOpenStaking( topics: [transferEventSignature, null, web3Instance.eth.abi.encodeParameter("address", stakingContractAddress)], }; - try { const logs = await web3Instance.eth.getPastLogs(transferEventFilter); - console.log("Fetched logs:", logs); - - logs.forEach((log) => { - console.log("Log:", log); - - const eventInterface = tokenContract.options.jsonInterface.find( - (i: any) => i.signature === log.topics[0] - ); - if (!eventInterface) { - console.error("Event interface not found for signature:", log.topics[0]); - return; - } + for (const log of logs) { + const transactionReceipt = await web3Instance.eth.getTransactionReceipt(log.transactionHash); + const transactionSender = transactionReceipt.from.toLowerCase(); - const inputs = eventInterface.inputs as AbiInput[]; - - const event = web3Instance.eth.abi.decodeLog( - inputs, - log.data, - log.topics.slice(1) - ); - console.log("Decoded event:", event); - - // Check if the destination address matches the staking contract address - if (event.dst.toLowerCase() === stakingContractAddress.toLowerCase()) { - uniqueStakers.add(event.src.toLowerCase()); - } - }); + // Add the transaction sender to the set of unique stakers + uniqueStakers.add(transactionSender); + } console.log("Unique stakers fetched for blocks", currentBlock, "to", endBlock); await saveStakingSnapshot( @@ -115,6 +92,7 @@ export async function getUniqueStakersFromOpenStaking( return uniqueStakers; } + export async function getOpenStakingStakedBalances( stakingPoolName: string, stakingContractAddress: string, diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 09498ef..a10ec2e 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -73,14 +73,14 @@ export const processStakingContractDataItem = async ( DB_COLLECTION_STAKING_SNAPSHOT!, DB_CONNECTION_STRING! ); - console.log("Staked balances:", stakedBalances); + // console.log("Staked balances:", stakedBalances); const result = { stakingPoolName: stakingPoolName, stakedBalances: stakedBalances, }; - console.log("Result:", JSON.stringify(result, null, 2)); + // console.log("Result:", JSON.stringify(result, null, 2)); // Update the totalStakedBalances object updateTotalStakedBalances(stakedBalances, totalStakedBalances); @@ -102,7 +102,7 @@ export const processStakingContractDataItem = async ( DB_COLLECTION_STAKING_SNAPSHOT!, DB_CONNECTION_STRING! ); - console.log("Unique staker addresses from open staking:", uniqueStakers); + // console.log("Unique staker addresses from open staking:", uniqueStakers); const stakedBalances = await getOpenStakingStakedBalances( stakingPoolName, @@ -116,14 +116,14 @@ export const processStakingContractDataItem = async ( DB_COLLECTION_STAKING_SNAPSHOT!, DB_CONNECTION_STRING! ); - console.log("Staked balances from open staking:", stakedBalances); + // console.log("Staked balances from open staking:", stakedBalances); const result = { stakingPoolName: stakingPoolName, stakedBalances: stakedBalances, }; - console.log("Result:", JSON.stringify(result, null, 2)); + // console.log("Result:", JSON.stringify(result, null, 2)); // Update the totalStakedBalances object updateTotalStakedBalances(stakedBalances, totalStakedBalances); @@ -141,7 +141,7 @@ export const processStakingContractDataItem = async ( // Add the total staked balances to the finalResults array finalResults.push({ stakingPoolName: "totalStakedBalances", stakedBalances: totalStakedBalances }); - console.log("Final Results:", JSON.stringify(finalResults, null, 2)); + // console.log("Final Results:", JSON.stringify(finalResults, null, 2)); return finalResults; };