Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
taha-abbasi committed Jan 9, 2024
2 parents d9bb9bd + 1c57c59 commit 6ba3df4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
36 changes: 7 additions & 29 deletions src/openStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -115,6 +92,7 @@ export async function getUniqueStakersFromOpenStaking(
return uniqueStakers;
}


export async function getOpenStakingStakedBalances(
stakingPoolName: string,
stakingContractAddress: string,
Expand Down
12 changes: 6 additions & 6 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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;
};
Expand Down

0 comments on commit 6ba3df4

Please sign in to comment.