2023-11-21 03:30:01 -08:00
|
|
|
import yargs from "yargs";
|
|
|
|
import { hideBin } from "yargs/helpers";
|
|
|
|
import { DefaultStore, PrivateKey, toPrivateKey } from "../src";
|
|
|
|
|
|
|
|
const parser = yargs(hideBin(process.argv))
|
|
|
|
.usage("Usage: $0 --private-key <private-key> [--chain <chain>]")
|
|
|
|
.options({
|
|
|
|
"private-key": {
|
|
|
|
type: "string",
|
|
|
|
demandOption: true,
|
|
|
|
desc: "Private key to use to sign transaction",
|
|
|
|
},
|
|
|
|
chain: {
|
2023-11-24 02:59:04 -08:00
|
|
|
type: "array",
|
|
|
|
string: true,
|
2023-11-21 03:30:01 -08:00
|
|
|
desc: "Chain to get the balance for. If not provided the balance for all chains is returned.",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
type AccountBalance = {
|
|
|
|
chain: string;
|
|
|
|
address: string | undefined;
|
|
|
|
balance: number | undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
async function getBalance(
|
|
|
|
chain: string,
|
|
|
|
privateKey: PrivateKey
|
|
|
|
): Promise<AccountBalance | undefined> {
|
|
|
|
const address = await DefaultStore.chains[chain].getAccountAddress(
|
|
|
|
privateKey
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
const balance = await DefaultStore.chains[chain].getAccountBalance(
|
|
|
|
privateKey
|
|
|
|
);
|
|
|
|
return { chain, address, balance };
|
|
|
|
} catch (e) {
|
|
|
|
console.error(`Error fetching balance for ${chain}`, e);
|
|
|
|
}
|
|
|
|
return { chain, address, balance: undefined };
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const argv = await parser.argv;
|
|
|
|
const chains = argv.chain
|
2023-11-24 02:59:04 -08:00
|
|
|
? argv.chain
|
2023-11-21 03:30:01 -08:00
|
|
|
: Object.keys(DefaultStore.chains).filter((chain) => chain !== "global");
|
|
|
|
|
|
|
|
const privateKey = toPrivateKey(argv["private-key"]);
|
|
|
|
|
|
|
|
const balances = await Promise.all(
|
|
|
|
chains.map((chain) => getBalance(chain, privateKey))
|
|
|
|
);
|
|
|
|
|
|
|
|
console.table(balances);
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|