fund_wallets
Distribute ETH equally across multiple managed wallets to prepare them for coordinated trading operations on Base network.
Instructions
Send ETH from main wallet (DEPLOYER_PRIVATE_KEY) to all managed wallets equally.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| total_eth_amount | Yes | Total ETH to distribute equally across all managed wallets (e.g. '0.01') |
Implementation Reference
- src/index.ts:287-365 (handler)The main handler function for the `fund_wallets` tool. It splits the total ETH amount across managed wallets and initiates transactions from the main wallet.
async function handleFundWallets( args: z.infer<typeof FundWalletsSchema> ): Promise<string> { if (wallets.length === 0) { return JSON.stringify({ success: false, error: "No managed wallets to fund. Create or import wallets first.", }); } const mainWallet = getMainWallet(); const totalWei = ethers.parseEther(args.total_eth_amount); const perWalletWei = totalWei / BigInt(wallets.length); if (perWalletWei === 0n) { return JSON.stringify({ success: false, error: "Amount too small to split across wallets", }); } // Check main wallet balance const mainBalance = await mainWallet.provider!.getBalance(mainWallet.address); const gasBuffer = 21_000n * 3n * BigInt(wallets.length); // rough gas buffer const feeData = await mainWallet.provider!.getFeeData(); const gasPrice = feeData.gasPrice ?? 0n; const totalGas = gasBuffer * gasPrice; if (mainBalance < totalWei + totalGas) { return JSON.stringify({ success: false, error: `Insufficient balance. Need ~${formatEth(totalWei + totalGas)} ETH, have ${formatEth(mainBalance)} ETH`, }); } // Get starting nonce let nonce = await mainWallet.getNonce(); // Send transfers in parallel with sequential nonces const txPromises = wallets.map((w, i) => { const currentNonce = nonce + i; return mainWallet .sendTransaction({ to: w.address, value: perWalletWei, nonce: currentNonce, gasLimit: 21_000n, }) .then(async (tx) => { const receipt = await tx.wait(); return { address: w.address, label: w.label, amount: formatEth(perWalletWei), txHash: tx.hash, success: receipt !== null && receipt.status === 1, }; }) .catch((err: unknown) => ({ address: w.address, label: w.label, amount: formatEth(perWalletWei), txHash: "", success: false, error: err instanceof Error ? err.message : String(err), })); }); const results = await Promise.allSettled(txPromises); const outcomes = results.map((r) => r.status === "fulfilled" ? r.value : { success: false, error: "Promise rejected" } ); const succeeded = outcomes.filter((o) => o.success).length; return JSON.stringify( { success: succeeded > 0, funded: succeeded, - src/index.ts:125-129 (schema)Input schema for the `fund_wallets` tool, defining the `total_eth_amount` argument.
const FundWalletsSchema = z.object({ total_eth_amount: z .string() .describe("Total ETH to distribute equally across all managed wallets (e.g. '0.01')"), }); - src/index.ts:808-821 (registration)The definition of the `fund_wallets` tool in the MCP tools array, providing its name, description, and input schema.
{ name: "fund_wallets", description: "Send ETH from main wallet (DEPLOYER_PRIVATE_KEY) to all managed wallets equally.", inputSchema: { type: "object" as const, properties: { total_eth_amount: { type: "string", description: "Total ETH to distribute equally across all managed wallets (e.g. '0.01')", }, }, required: ["total_eth_amount"],