|
| 1 | +import { Command } from 'commander'; |
| 2 | +import { config, NodeLicenseAbi } from "@sentry/core"; |
| 3 | +import fs from 'fs'; |
| 4 | +import { parse } from "csv/sync"; |
| 5 | +import inquirer from 'inquirer'; |
| 6 | +import {ethers} from "ethers"; |
| 7 | + |
| 8 | +/** |
| 9 | + * Function to check SNL balances of a provided list of accounts. |
| 10 | + * @param cli - Commander instance |
| 11 | + */ |
| 12 | +export function checkFlaggedAccounts(cli: Command): void { |
| 13 | + cli |
| 14 | + .command('check-flagged-accounts') |
| 15 | + .description('Checks accounts for non-zero SNL balance from provided csv.') |
| 16 | + .action(async () => { |
| 17 | + //prompt user for the path to the list |
| 18 | + const { pathToList } = await inquirer.prompt({ |
| 19 | + type: 'input', |
| 20 | + name: 'pathToList', |
| 21 | + message: 'Enter the absolute path to the csv containing addresses to check:', |
| 22 | + }); |
| 23 | + |
| 24 | + //validate csv path |
| 25 | + if (!fs.existsSync(pathToList)) { |
| 26 | + console.log("Invalid file path, file does not exists", pathToList); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + //read addresses from csv |
| 31 | + const addressesToCheck = parse(fs.readFileSync(pathToList), { columns: true }); |
| 32 | + |
| 33 | + //connect to arbitrum one |
| 34 | + const provider = new ethers.JsonRpcProvider(config.arbitrumOneJsonRpcUrl); |
| 35 | + |
| 36 | + //load contract with provider |
| 37 | + const nodeLicense = new ethers.Contract(config.nodeLicenseAddress, NodeLicenseAbi, provider); |
| 38 | + |
| 39 | + console.log("Checking balances of flagged wallets..."); |
| 40 | + let flaggedCount = 0 |
| 41 | + try { |
| 42 | + for (let i = 0; i < addressesToCheck.length; i++) { |
| 43 | + //validate |
| 44 | + if (!addressesToCheck[i].address) { |
| 45 | + console.error(`ERROR: Invalid address in line ${i}`, addressesToCheck[i]); |
| 46 | + continue; |
| 47 | + } |
| 48 | + |
| 49 | + //trim address |
| 50 | + let validAddress = ""; |
| 51 | + const trimmedAddress = addressesToCheck[i].address.trim(); |
| 52 | + try { |
| 53 | + validAddress = ethers.getAddress(trimmedAddress); |
| 54 | + } catch (error) { |
| 55 | + console.error(`ERROR: Invalid trimmed address ${trimmedAddress}`); |
| 56 | + console.error((error as Error).message); |
| 57 | + continue; |
| 58 | + } |
| 59 | + |
| 60 | + //query balance |
| 61 | + const bal = await nodeLicense.balanceOf(validAddress); |
| 62 | + if (bal > 0) { |
| 63 | + console.log(`Address: ${validAddress} Balance: ${bal}`); |
| 64 | + flaggedCount++; |
| 65 | + } |
| 66 | + } |
| 67 | + console.log(`Found ${flaggedCount} addresses from list with a non-zero balance.`); |
| 68 | + } catch (error) { |
| 69 | + console.log("Failed to get balances:", error); |
| 70 | + } |
| 71 | + }); |
| 72 | +} |
0 commit comments