Skip to content

Instantly share code, notes, and snippets.

@nozim
Last active September 19, 2025 23:23
Show Gist options
  • Select an option

  • Save nozim/4d4044e00da9cae3fc7d637367e2d4d3 to your computer and use it in GitHub Desktop.

Select an option

Save nozim/4d4044e00da9cae3fc7d637367e2d4d3 to your computer and use it in GitHub Desktop.
Log aggregated token transfers across chains
// tevent format is following
/*
{
timestamp: Date.now(), // e.g. 1694567890123
fromAddress: "0x1234567890abcdef1234567890abcdef12345678",
fromOwner: { value: "Alice" }, // optional
toAddress: "0xabcdef1234567890abcdef1234567890abcdef12",
toOwner: { value: "Bob" }, // optional
amount: "1000000000000000000", // string for big.Int
tokenAddress: "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
symbol: "USDT",
chain: "Ethereum",
network: "mainnet",
txHash: "0xa1b2c3d4e5f67890123456789abcdef0123456789abcdef0123456789abcdef",
decimals: 18,
position: 42n
}
*/
function getMinute(ts) {
return Math.floor(ts / 60000) * 60000;
}
var stablecoins = ['USDC','USDT', 'DAI']
var volumes = {};
async function onTransfer(tevent) {
var amt = BigInt(tevent.amount)/BigInt(1e6) // ignore fractional
if (!volumes[tevent.chain]) {
volumes[tevent.chain]={}
}
if (!volumes[tevent.chain][tevent.symbol]) {
volumes[tevent.chain][tevent.symbol]=0
}
volumes[tevent.chain][tevent.symbol]+=amt;
}
setInterval(() => {
const minuteKey = getMinute(Date.now());
console.log(`=== Snapshot for ${new Date(minuteKey).toISOString()} ===`);
if (Object.keys(volumes).length === 0) {
console.log("No stablecoin transfers");
} else {
for (const [chain, symbols] of Object.entries(volumes)) {
for (const [symbol, vol] of Object.entries(symbols)) {
console.log(chain, "|", symbol, ":", vol.toString());
}
}
}
console.log("========================================\n");
// reset after logging
volumes = {};
}, 30_000); // 60 sec
module.exports = onTransfer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment