1+ import { getBalance } from "viem/actions" ;
2+ import * as MasterAccountManager from "../src/helper/MasterAccountManager" ;
3+ import { createPublicClient , formatEther , http } from "viem" ;
4+ import { nagaDev } from "@lit-protocol/networks" ;
5+ import { generatePrivateKey , privateKeyToAccount } from "viem/accounts" ;
6+ import { fundAccount } from "../src/helper/fundAccount" ;
7+
8+ const FUNDING_AMOUNT = 0.1 ;
9+ const TOPUP_IF_LESS_THAN = 0.05 ;
10+ const NUMBER_OF_WALLETS = 500 ;
11+
12+ ( async ( ) => {
13+ console . log ( "🛜 Network:" , process . env [ 'NETWORK' ] ) ;
14+ console . log ( "🔗 RPC URL:" , nagaDev . getRpcUrl ( ) ) ;
15+ const masterAccount = MasterAccountManager . getMasterAccount ( ) ;
16+
17+ console . log ( "🔑 Master account address:" , masterAccount . address ) ;
18+
19+ const publicClient = createPublicClient ( {
20+ chain : nagaDev . getChainConfig ( ) ,
21+ transport : http ( ) ,
22+ } )
23+
24+
25+ const balance = formatEther ( await getBalance ( publicClient , {
26+ address : masterAccount . address ,
27+ } ) ) ;
28+
29+ console . log ( "💰 Master account balance:" , balance ) ;
30+
31+ if ( Number ( balance ) < 0 ) {
32+ throw new Error ( "🚨 Master account balance is less than 0 ETH" ) ;
33+ }
34+
35+ // --- Fund Wallets ---
36+ const masterAccountsFromPool = MasterAccountManager . getMasterAccountsFromPool ( ) ;
37+ console . log ( "🔑 Total master accounts in pool:" , masterAccountsFromPool . length ) ;
38+
39+ // Check and top up wallets from pool
40+ await MasterAccountManager . checkAndTopupWalletsFromPool ( {
41+ publicClient,
42+ masterAccount,
43+ networkModule : nagaDev ,
44+ lessThan : TOPUP_IF_LESS_THAN ,
45+ thenFundWith : FUNDING_AMOUNT ,
46+ } ) ;
47+
48+ if ( masterAccountsFromPool . length < NUMBER_OF_WALLETS ) {
49+ // find the difference
50+ const walletsToGenerateAndFund = NUMBER_OF_WALLETS - masterAccountsFromPool . length ;
51+ console . log ( "🔑 Wallets to generate and fund:" , walletsToGenerateAndFund ) ;
52+
53+ // check the current balance of the available wallets first
54+ // generate and fund wallets
55+ await MasterAccountManager . generateAndFundWalletsFromPool ( {
56+ publicClient,
57+ masterAccount,
58+ networkModule : nagaDev ,
59+ walletsToGenerateAndFund,
60+ lessThan : TOPUP_IF_LESS_THAN ,
61+ thenFundWith : FUNDING_AMOUNT ,
62+ } ) ;
63+ }
64+
65+ } ) ( ) ;
0 commit comments