-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatus.ts
More file actions
45 lines (36 loc) · 1.73 KB
/
Copy pathstatus.ts
File metadata and controls
45 lines (36 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Connection, Keypair, PublicKey, } from "@solana/web3.js"
import { getAssociatedTokenAddressSync, getMint } from "@solana/spl-token";
import { BN } from "bn.js";
import base58 from "bs58"
import { readJson, retrieveEnvVariable, sleep } from "./utils"
import { RPC_ENDPOINT, RPC_WEBSOCKET_ENDPOINT } from "./constants";
const connection = new Connection(RPC_ENDPOINT, { wsEndpoint: RPC_WEBSOCKET_ENDPOINT, commitment: "confirmed" });
export const displayStatus = async () => {
console.log("displayStatus start");
try {
const walletsData = readJson()
console.log("walletsData: ", walletsData);
const mintStr = readJson("mint.json")[0]
console.log("mintStr: ", mintStr);
const restoredKeypair = Keypair.fromSecretKey(base58.decode(mintStr));
console.log("restoredKeypair", restoredKeypair);
const mint = restoredKeypair.publicKey;
console.log("mint: ", mint.toString());
const wallets = walletsData.map((kp) => Keypair.fromSecretKey(base58.decode(kp)))
const mintInfo = await getMint(connection, mint)
wallets.map(async (kp, i) => {
const ata = getAssociatedTokenAddressSync(mint, kp.publicKey)
const tokenBalance = (await connection.getTokenAccountBalance(ata)).value.uiAmount
if (!tokenBalance) {
console.log("Token balance not retrieved, Error...")
return
}
const percent = new BN(tokenBalance).div(new BN((mintInfo.supply).toString()).div(new BN(10 ** mintInfo.decimals))).mul(new BN(100)).toString()
console.log("Wallet ", i, " : ", kp.publicKey.toBase58(), ", Holding Percent -> ", percent, "%, Token Balance -> ", tokenBalance.toFixed(2))
})
} catch (error) {
console.log("Error in displaying wallets status")
return
}
}
displayStatus()