Last active
October 10, 2025 16:34
-
-
Save nozim/23b37dac9889fad0e3a79358d3818c75 to your computer and use it in GitHub Desktop.
Source code for @LiveStablecoinBot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 | |
| } | |
| */ | |
| const TelegramBot = require('node-telegram-bot-api'); | |
| const botToken = '// put tour own here' ; | |
| const bot = new TelegramBot(botToken, {polling: true}); | |
| var subscribers = []; | |
| // Anyone who messages the bot gets added | |
| bot.on('message', (msg) => { | |
| const chatId = msg.chat.id; | |
| if (!subscribers.includes(chatId)) { | |
| subscribers.push(chatId); | |
| bot.sendMessage(chatId, 'Added! You will get updates every 1 min'); | |
| } | |
| }); | |
| var stablecoins = ['USDC', 'USDT', 'DAI'] | |
| var senders = {} | |
| var grouped = {}; | |
| var chains = {}; | |
| async function onTransfer(tevent) { | |
| if (!stablecoins.includes(tevent.symbol)) { | |
| return; | |
| } | |
| var key = tevent.chain + " " + tevent.fromAddress + " " + tevent.symbol; | |
| var amt = BigInt(tevent.amount) / BigInt(1e6) // ignore fractional | |
| if (senders[key] === undefined) { | |
| senders[key] = { | |
| volume: BigInt(0), | |
| chain: tevent.chain, | |
| address: tevent.fromAddress, | |
| symbol: tevent.symbol, | |
| lastTx: tevent.txHash | |
| } | |
| } | |
| senders[key].volume += amt; | |
| senders[key].lastTx = tevent.txHash; | |
| } | |
| setInterval(() => { | |
| if (subscribers.length === 0) return; | |
| const sorted = Object.entries(senders) | |
| .sort((a, b) => b[1].volume > a[1].volume ? 1 : -1) | |
| .slice(0, 10); | |
| let msg = '<b>π Top 10 Senders (1 min)</b>\n\n'; | |
| sorted.forEach(([key, data], i) => { | |
| msg += `${i + 1}. <b>${data.chain.toUpperCase()} ${data.symbol}</b>\n`; | |
| msg += ` π° Volume: $${data.volume.toLocaleString()}\n`; | |
| msg += ` π€ Address:\n <code>${data.address}</code>\n`; | |
| msg += ` π Last Tx:\n <code>${data.lastTx}</code>\n\n`; | |
| }); | |
| subscribers.forEach(chatId => { | |
| bot.sendMessage(chatId, msg, {parse_mode: 'HTML'}); | |
| }); | |
| }, 60 * 1000); | |
| module.exports = onTransfer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment