Skip to content

Instantly share code, notes, and snippets.

@zobront
Last active August 24, 2022 20:32
Show Gist options
  • Save zobront/a08cd3c17f02e30f0b9ffcdb5d5617b9 to your computer and use it in GitHub Desktop.
Save zobront/a08cd3c17f02e30f0b9ffcdb5d5617b9 to your computer and use it in GitHub Desktop.
script to grab a sorted list of the largest holders of rfDAI
const ethers = require('ethers');
const STARTING_BLOCK = 41918655;
const FINAL_BLOCK = 44000000;
async function main() {
const provider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/fantom/");
let balances = {};
for (let i = STARTING_BLOCK; i < FINAL_BLOCK;) {
console.log(`Block ${i}: (${Math.floor((i - STARTING_BLOCK) / (FINAL_BLOCK - STARTING_BLOCK) * 100)}%)`)
filter = {
address: "0x77dc33dC0278d21398cb9b16CbFf99c1B712a87A",
topics: [ "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" ],
fromBlock: i,
toBlock: i + 2500
};
try {
const logs = await provider.getLogs(filter);
for (log of logs) {
let from = "0x" + log.topics[1].slice(-40);
let to = "0x" + log.topics[2].slice(-40);
let amt = parseFloat(ethers.utils.formatEther(ethers.BigNumber.from(log.data)));
balances[from] = balances[from] ? balances[from] - amt : -amt;
balances[to] = balances[to] ? balances[to] + amt : amt;
}
i += 2500;
} catch (err) {
console.log(err)
}
}
console.log("-----------------------")
sorted = Object.keys(balances).sort((a,b) => balances[a] - balances[b])
for (addr of sorted) {
console.log(`${ethers.utils.getAddress(addr)}: ${balances[addr]}`)
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment