🌳
pt0/donateapp/binF/bridgeToArbAI.mjs
1import { formatEther, parseEther, Contract } from 'ethers'
7const arbInboxAddr = '0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f'
8const inboxAbi = ['function depositEth() external payable returns (uint256)']
10const minScratchBalance = 0.001
11const bridgeAmount = 0.003
12const fundScratchAmount = 0.002
14export const bridgetoarb = async () => {
15 const peatWallet = getPeatWal()
16 const scratchWallet = getPeatScratchWallet()
17 const mainnetProv = getAlchemyProv('homestead')
18 const arbProv = getAlchemyProv('arbitrum')
20 const [peatMainnetBal, peatArbBal, scratchArbBal] = await Promise.all([
21 mainnetProv.getBalance(peatWallet.address),
22 arbProv.getBalance(peatWallet.address),
23 arbProv.getBalance(scratchWallet.address),
24 ])
27 peatWallet: peatWallet.address,
28 peatMainnetEth: formatEther(peatMainnetBal),
29 peatArbitrumEth: formatEther(peatArbBal),
30 scratchWallet: scratchWallet.address,
31 scratchArbitrumEth: formatEther(scratchArbBal),
32 })
34 if (parseFloat(formatEther(scratchArbBal)) >= minScratchBalance) {
35 console.log('Scratch wallet balance sufficient, no funding needed')
36 return
37 }
39 const fundAmt = parseEther(String(fundScratchAmount))
41 if (peatArbBal >= fundAmt) {
42 console.log(`Funding scratch wallet from peatWal on Arbitrum...`)
43 const tx = await safeSendEth({
44 signer: peatWallet.connect(arbProv),
45 destAddr: scratchWallet.address,
46 value: fundAmt,
47 })
48 console.log('Fund tx:', tx.hash)
49 await tx.wait()
50 console.log('Scratch wallet funded on Arbitrum')
51 return
52 }
54 const bridgeAmt = parseEther(String(bridgeAmount))
55 if (peatMainnetBal < bridgeAmt) {
56 console.log(`peatWal mainnet balance too low to bridge ${bridgeAmount} ETH`)
57 return
58 }
60 console.log(`Bridging ${bridgeAmount} ETH from peatWal mainnet to Arbitrum...`)
61 const connectedWallet = peatWallet.connect(mainnetProv)
62 const inbox = new Contract(arbInboxAddr, inboxAbi, connectedWallet)
64 const tx = await inbox.depositEth({ value: bridgeAmt })
65 console.log('Bridge tx:', tx.hash)
66 await tx.wait()
67 console.log('Confirmed on mainnet. Funds arrive on Arbitrum in ~15 min.')
68 console.log('Run this action again after funds arrive to fund scratch wallet.')
71bridgetoarb.needsEnvConf = true