-
Notifications
You must be signed in to change notification settings - Fork 1
/
native-deposit.ts
104 lines (83 loc) · 3.35 KB
/
native-deposit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { utils, providers, Wallet } from "ethers";
import { Provider } from "@ethersproject/abstract-provider";
import {
EthBridger,
registerCustomArbitrumNetwork,
EthDepositMessageStatus,
} from "@arbitrum/sdk";
import dotenv from "dotenv";
import { reyaNetwork as childNetwork } from "../../helpers/custom-network-reya";
dotenv.config();
console.log("Environment Variables Loaded");
/**
* Set up: instantiate Parent / Child wallets connected to providers
*/
const walletPrivateKey: string = process.env.DEVNET_PRIVKEY as string;
const parentProvider = new providers.JsonRpcProvider(process.env.ParentRPC);
const childProvider = new providers.JsonRpcProvider(process.env.ChildRPC);
const parentWallet = new Wallet(walletPrivateKey, parentProvider);
const childWallet = new Wallet(walletPrivateKey, childProvider);
const main = async () => {
// await arbLog("Deposit token using Arbitrum SDK");
let baparent = await parentProvider
console.log()
// register - needed for retryables
registerCustomArbitrumNetwork(childNetwork)
const ethToChildDepositAmount = utils.parseEther("0.001");
console.log("Eth deposit amount is:", ethToChildDepositAmount.toString());
// Set up the Erc20Bridger
const ethBridger = new EthBridger(childNetwork);
// const approveTx = await ethBridger.approveGasToken({
// parentSigner: parentWallet
// });
//const approveRec = await approveTx.wait();
console.log("Eth Bridger Set Up");
// console.log(ethBridger);
const childWalletInitialEthBalance = await childWallet.getBalance();
const result = utils.formatEther(childWalletInitialEthBalance);
console.log(`your Child ETH balance is ${result.toString()}`);
// Optional transaction overrides
const overrides = {
gasLimit: 2000000, // Example gas limit
};
// Create the deposit parameters object
const depositParams = {
parentSigner: parentWallet,
amount: ethToChildDepositAmount,
overrides: overrides, // This is optional
};
const depositTx = await ethBridger.deposit(depositParams);
const depositRec = await depositTx.wait();
console.warn("deposit Parent receipt is:", depositRec.transactionHash);
/**
* With the transaction confirmed on Parent, we now wait for the Child side (i.e., balance credited to Child) to be confirmed as well.
* Here we're waiting for the Sequencer to include the Child message in its off-chain queue. The Sequencer should include it in under 10 minutes.
*/
console.warn("Now we wait for Child side of the transaction to be executed ⏳");
const childResult = await depositRec.waitForChildTransactionReceipt(childProvider);
/**
* The `complete` boolean tells us if the parent to child message was successful
*/
childResult.complete
? console.log(
`Child message successful: status: ${
EthDepositMessageStatus[await childResult.message.status()]
}`
)
: console.log(
`Child message failed: status ${
EthDepositMessageStatus[await childResult.message.status()]
}`
);
/**
* Our childWallet ETH balance should be updated now
*/
const childWalletUpdatedEthBalance = await childWallet.getBalance();
console.log(
`your Child ETH balance is updated from ${childWalletInitialEthBalance.toString()} to ${childWalletUpdatedEthBalance.toString()}`
);
};
main().catch((err) => {
console.error(err);
process.exit(1);
});