Skip to content

Commit 7f086fc

Browse files
Merge pull request #575 from xai-foundation/feat/sc-6819
Check Flagged Accounts CLI
2 parents a0097ba + 3abfdb2 commit 7f086fc

File tree

6 files changed

+88
-66
lines changed

6 files changed

+88
-66
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

apps/cli/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { removePromoCode } from './commands/licenses/remove-promo-code.js';
5454
import { displayNodeAgreement } from './commands/display-node-agreement.js';
5555
import { exportChallengeInfo } from './commands/export-challenge-info.js';
5656
import { startKycProcess } from './commands/kyc/start-kyc-process.js';
57+
import { checkFlaggedAccounts } from './commands/flagged/checkFlaggedAccounts.js';
5758

5859
const cli = new Command();
5960

@@ -115,6 +116,7 @@ syncStakingPools(cli);
115116
monitorNodeCreated(cli);
116117
processUnclaimedChallenges(cli);
117118
startKycProcess(cli);
119+
checkFlaggedAccounts(cli);
118120

119121
// Default action if no command is specified
120122
cli.action(async () => {

infrastructure/smart-contracts/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"deploy-sepolia": "hardhat run scripts/sepolia-deploy/deployAndPopulateSepolia.mjs",
4141
"deploy-tiny-keys": "hardhat run scripts/tiny-keys/deployTinyKeys.mjs",
4242
"start-tiny-keys-drop": "hardhat run scripts/tiny-keys/startAirdrop.mjs",
43-
"process-tiny-keys-drop": "hardhat run scripts/tiny-keys/processAirdrop.mjs",
44-
"check-flagged-accounts": "hardhat run scripts/flagged/flaggedNodeLicenses.mjs"
43+
"process-tiny-keys-drop": "hardhat run scripts/tiny-keys/processAirdrop.mjs"
4544
},
4645
"dependencies": {
4746
"@sentry/core": "workspace:*",
@@ -53,7 +52,6 @@
5352
"ganache-cli": "^6.12.2",
5453
"hardhat": "^2.2.0",
5554
"hardhat-contract-sizer": "^2.10.0",
56-
"inquirer": "^9.2.12",
5755
"web3": "^4.3.0"
5856
},
5957
"devDependencies": {

infrastructure/smart-contracts/scripts/flagged/flaggedNodeLicenses.mjs

-50
This file was deleted.

pnpm-lock.yaml

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)