Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions e2e/artillery/init-wallets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { getBalance } from "viem/actions";
import * as MasterAccountManager from "../src/helper/MasterAccountManager";
import { createPublicClient, formatEther, http } from "viem";
import { nagaDev } from "@lit-protocol/networks";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { fundAccount } from "../src/helper/fundAccount";

const FUNDING_AMOUNT = 0.1;
const TOPUP_IF_LESS_THAN = 0.05;
const NUMBER_OF_WALLETS = 500;

(async () => {
console.log("🛜 Network:", process.env['NETWORK']);
console.log("🔗 RPC URL:", nagaDev.getRpcUrl());
const masterAccount = MasterAccountManager.getMasterAccount();

console.log("🔑 Master account address:", masterAccount.address);

const publicClient = createPublicClient({
chain: nagaDev.getChainConfig(),
transport: http(),
})


const balance = formatEther(await getBalance(publicClient, {
address: masterAccount.address,
}));

console.log("💰 Master account balance:", balance);

if (Number(balance) < 0) {
throw new Error("🚨 Master account balance is less than 0 ETH");
}

// --- Fund Wallets ---
const masterAccountsFromPool = MasterAccountManager.getMasterAccountsFromPool();
console.log("🔑 Total master accounts in pool:", masterAccountsFromPool.length);

// Check and top up wallets from pool
await MasterAccountManager.checkAndTopupWalletsFromPool({
publicClient,
masterAccount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, we're using the first available master account from L15 to fund all other master accounts from the file that need topping up?

networkModule: nagaDev,
lessThan: TOPUP_IF_LESS_THAN,
thenFundWith: FUNDING_AMOUNT,
});

if (masterAccountsFromPool.length < NUMBER_OF_WALLETS) {
// find the difference
const walletsToGenerateAndFund = NUMBER_OF_WALLETS - masterAccountsFromPool.length;
console.log("🔑 Wallets to generate and fund:", walletsToGenerateAndFund);

// check the current balance of the available wallets first
// generate and fund wallets
await MasterAccountManager.generateAndFundWalletsFromPool({
publicClient,
masterAccount,
networkModule: nagaDev,
walletsToGenerateAndFund,
lessThan: TOPUP_IF_LESS_THAN,
thenFundWith: FUNDING_AMOUNT,
});
}

})();
Loading
Loading