Skip to content

Commit aee8733

Browse files
author
James Bartnik
committed
Merge branch 'master' into ui
2 parents bb495c5 + 6c0982f commit aee8733

File tree

11 files changed

+265
-11
lines changed

11 files changed

+265
-11
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as Vorpal from "vorpal";
2+
import { changeWhitelistStatus as coreChangeWhitelistStatus, getSignerFromPrivateKey } from "@xai-vanguard-node/core";
3+
4+
/**
5+
* Function to change the whitelist status of a list of wallets in the esXai contract.
6+
* @param cli - Vorpal instance
7+
*/
8+
export function changeWhitelistStatus(cli: Vorpal) {
9+
cli
10+
.command('change-whitelist-status', 'Changes the whitelist status of a list of wallets in the esXai contract.')
11+
.action(async function (this: Vorpal.CommandInstance) {
12+
const walletsPrompt: Vorpal.PromptObject = {
13+
type: 'input',
14+
name: 'wallets',
15+
message: 'Enter the wallets (comma-separated):'
16+
};
17+
const statusPrompt: Vorpal.PromptObject = {
18+
type: 'confirm',
19+
name: 'status',
20+
message: 'Enter the whitelist status for all wallets (true or false):'
21+
};
22+
const privateKeyPrompt: Vorpal.PromptObject = {
23+
type: 'password',
24+
name: 'privateKey',
25+
message: 'Enter the private key of an admin:'
26+
};
27+
const {wallets} = await this.prompt(walletsPrompt);
28+
const {status} = await this.prompt(statusPrompt);
29+
const {privateKey} = await this.prompt(privateKeyPrompt);
30+
const walletsArray = wallets.split(',').map((wallet: string) => wallet.trim());
31+
const walletsStatuses = walletsArray.reduce((acc: {[key: string]: typeof status}, wallet: string) => ({...acc, [wallet]: status}), {});
32+
this.log(`Changing whitelist status for wallets: ${wallets}...`);
33+
const { signer } = getSignerFromPrivateKey(privateKey);
34+
await coreChangeWhitelistStatus(signer, walletsStatuses, (wallet: string, isWhitelisted: boolean) => {
35+
this.log(`Wallet: ${wallet}, Whitelisted: ${isWhitelisted}`);
36+
});
37+
this.log(`Whitelist statuses changed.`);
38+
});
39+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as Vorpal from "vorpal";
2+
import { checkWhitelist as coreCheckWhitelist } from "@xai-vanguard-node/core";
3+
4+
/**
5+
* Function to check the whitelist status of a list of wallets in the esXai contract.
6+
* @param cli - Vorpal instance
7+
*/
8+
export function checkWhitelist(cli: Vorpal) {
9+
cli
10+
.command('check-whitelist', 'Checks the whitelist status of a list of wallets in the esXai contract. Wallets should be provided as a comma-separated list.')
11+
.action(async function (this: Vorpal.CommandInstance) {
12+
const walletsPrompt: Vorpal.PromptObject = {
13+
type: 'input',
14+
name: 'wallets',
15+
message: 'Enter the wallets (comma-separated):'
16+
};
17+
const {wallets} = await this.prompt(walletsPrompt);
18+
const walletsArray = wallets.split(',').map((wallet: string) => wallet.trim());
19+
this.log(`Checking whitelist status for wallets: ${wallets}...`);
20+
await coreCheckWhitelist(walletsArray, (wallet: string, isWhitelisted: boolean) => {
21+
this.log(`Wallet: ${wallet}, Whitelisted: ${isWhitelisted}`);
22+
});
23+
this.log(`Whitelist statuses retrieved.`);
24+
});
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as Vorpal from "vorpal";
2+
import { listWhitelistAddresses as coreListWhitelistAddresses } from "@xai-vanguard-node/core";
3+
4+
/**
5+
* Function to list all whitelisted addresses in the esXai contract.
6+
* @param cli - Vorpal instance
7+
*/
8+
export function listWhitelistAddresses(cli: Vorpal) {
9+
cli
10+
.command('list-whitelist-addresses', 'Lists all whitelisted addresses in the esXai contract.')
11+
.action(async function (this: Vorpal.CommandInstance) {
12+
this.log(`Fetching all whitelisted addresses...`);
13+
const whitelistAddresses = await coreListWhitelistAddresses((address: string) => {
14+
this.log(`Address: ${address}`);
15+
});
16+
this.log(`Whitelisted addresses retrieved.`);
17+
});
18+
}

apps/cli/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { setKycStatus } from './commands/kyc/set-kyc-status';
2929
import { totalSupply } from './commands/xai-token/total-supply';
3030
import { getBalancesForAddresses } from './commands/xai-token/get-balances';
3131
import { getAllContractAddresses } from './commands/get-contract-addresses';
32+
import { checkWhitelist } from './commands/xai-token/check-whitelist';
33+
import { changeWhitelistStatus } from './commands/xai-token/change-whitelist-status';
3234

3335
const cli = new Vorpal();
3436

@@ -63,6 +65,8 @@ setRollupAddress(cli);
6365
toggleAssertionChecking(cli);
6466
totalSupply(cli);
6567
getAllContractAddresses(cli);
68+
checkWhitelist(cli);
69+
changeWhitelistStatus(cli);
6670

6771
cli
6872
.delimiter('vanguard-node$')

packages/core/src/abis/esXaiAbi.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,39 @@ export const esXaiAbi = [
353353
}
354354
]
355355
},
356+
{
357+
"type": "function",
358+
"name": "getWhitelistCount",
359+
"constant": true,
360+
"stateMutability": "view",
361+
"payable": false,
362+
"inputs": [],
363+
"outputs": [
364+
{
365+
"type": "uint256",
366+
"name": ""
367+
}
368+
]
369+
},
370+
{
371+
"type": "function",
372+
"name": "getWhitelistedAddressAtIndex",
373+
"constant": true,
374+
"stateMutability": "view",
375+
"payable": false,
376+
"inputs": [
377+
{
378+
"type": "uint256",
379+
"name": "index"
380+
}
381+
],
382+
"outputs": [
383+
{
384+
"type": "address",
385+
"name": ""
386+
}
387+
]
388+
},
356389
{
357390
"type": "function",
358391
"name": "grantRole",

packages/core/src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ export const config = {
22
"arbitrumBlockExplorer": "https://arbiscan.io",
33
"arbitrumGoerliBlockExplorer": "https://goerli.arbiscan.io",
44
"defaultRpcUrl": "https://goerli-rollup.arbitrum.io/rpc",
5-
"esXaiAddress": "0x79Bf74A93D86dce235471751a7d359c65bF67862",
6-
"nodeLicenseAddress": "0x465EEF81240A8620e645660678a9E0304C606c6f",
7-
"refereeAddress": "0xB934633A8A082c1c9b6172eF2888b8A5fD10E556",
5+
"esXaiAddress": "0x022D5be65285Df414Ea40AA41b1e85b63f5466F6",
6+
"nodeLicenseAddress": "0x8e56484b39293fd74B43F11DB815eED9d1Ba0062",
7+
"refereeAddress": "0xf927CD82CE6a488f78AA63f2a8dcdd96aE9FAb40",
88
"rollupAddress": "0x082742561295f6e1b43c4f5d1e2d52d7FfE082f1",
9-
"xaiAddress": "0xEF8BcCC86E4864ccEc6EBdA0f14279f2C5535B5d"
9+
"xaiAddress": "0x4B5591e65307b09AeabDEE680AD7b6bb90D513f8"
1010
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ethers } from "ethers";
2+
import { esXaiAbi } from "../abis";
3+
import { config } from "../config";
4+
5+
/**
6+
* Changes the whitelist status of an object of wallets in the esXai contract.
7+
*
8+
* @param signer - The signer with DEFAULT_ADMIN_ROLE.
9+
* @param walletsStatuses - Object with wallet addresses as keys and their whitelist status as values.
10+
* @param callback - Optional callback function to handle wallets and their whitelist status as they are processed.
11+
* @returns An array of objects, each containing a wallet address and its new whitelist status.
12+
*/
13+
export async function changeWhitelistStatus(
14+
signer: ethers.Signer,
15+
walletsStatuses: { [wallet: string]: boolean },
16+
callback?: (wallet: string, isWhitelisted: boolean) => void
17+
): Promise<{wallet: string, isWhitelisted: boolean}[]> {
18+
19+
// Create a contract instance
20+
const contract = new ethers.Contract(config.esXaiAddress, esXaiAbi, signer);
21+
22+
// Change the whitelist status of each wallet
23+
const whitelistStatuses = [];
24+
for (const wallet in walletsStatuses) {
25+
const status = walletsStatuses[wallet];
26+
const currentStatus = await contract.isWhitelisted(wallet);
27+
if (status !== currentStatus) {
28+
if (status) {
29+
await contract.addToWhitelist(wallet);
30+
} else {
31+
await contract.removeFromWhitelist(wallet);
32+
}
33+
whitelistStatuses.push({wallet, isWhitelisted: status});
34+
if (callback) {
35+
callback(wallet, status);
36+
}
37+
}
38+
}
39+
40+
return whitelistStatuses;
41+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ethers } from 'ethers';
2+
import { esXaiAbi } from '../abis';
3+
import { config } from '../config';
4+
import { getProvider } from '../utils/getProvider';
5+
6+
/**
7+
* Checks if the provided addresses are in the whitelist.
8+
* @param addresses - The addresses to check.
9+
* @param callback - Optional callback function to handle addresses and their whitelist status as they are retrieved.
10+
* @returns An array of objects, each containing an address and its whitelist status.
11+
*/
12+
export async function checkWhitelist(
13+
addresses: string[],
14+
callback?: (address: string, isWhitelisted: boolean) => void
15+
): Promise<{address: string, isWhitelisted: boolean}[]> {
16+
17+
// Get the provider
18+
const provider = getProvider();
19+
20+
// Create an instance of the esXai contract
21+
const esXaiContract = new ethers.Contract(config.esXaiAddress, esXaiAbi, provider);
22+
23+
// Check the whitelist status of all addresses
24+
const whitelistStatuses = [];
25+
for (let i = 0; i < addresses.length; i++) {
26+
const address = addresses[i];
27+
const isWhitelisted = await esXaiContract.isWhitelisted(address);
28+
whitelistStatuses.push({address, isWhitelisted});
29+
if (callback) {
30+
callback(address, isWhitelisted);
31+
}
32+
}
33+
34+
return whitelistStatuses;
35+
}

packages/core/src/xai-token/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
export * from "./totalSupply";
2-
export * from "./balance";
2+
export * from "./balance";
3+
export * from "./checkWhitelist";
4+
export * from "./changeWhitelistStatus";
5+
export * from "./listWhitelistAddresses";
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { ethers } from "ethers";
2+
import { getProvider } from "../utils/getProvider";
3+
import { config } from "../config";
4+
import { esXaiAbi } from "../abis";
5+
6+
/**
7+
* Lists all whitelisted addresses in the esXai contract.
8+
*
9+
* @param callback - Optional callback function to handle whitelisted addresses as they are retrieved.
10+
* @returns An array of whitelisted addresses.
11+
*/
12+
export async function listWhitelistAddresses(
13+
callback?: (address: string) => void
14+
): Promise<string[]> {
15+
16+
// Get the provider
17+
const provider = getProvider();
18+
19+
// Create a contract instance
20+
const contract = new ethers.Contract(config.esXaiAddress, esXaiAbi, provider);
21+
22+
// Get the number of whitelisted addresses
23+
const whitelistCount = await contract.getWhitelistCount();
24+
25+
// Get all whitelisted addresses
26+
const whitelistAddresses = [];
27+
for (let i = 0; i < whitelistCount; i++) {
28+
const address = await contract.getWhitelistedAddressAtIndex(i);
29+
whitelistAddresses.push(address);
30+
if (callback) {
31+
callback(address);
32+
}
33+
}
34+
35+
return whitelistAddresses;
36+
}

0 commit comments

Comments
 (0)