-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendParentToChild.ts
113 lines (90 loc) · 3.6 KB
/
sendParentToChild.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
105
106
107
108
109
110
111
112
113
import { utils, providers, Wallet, BigNumber, Contract } from "ethers";
import { Provider } from "@ethersproject/abstract-provider";
import {
EthBridger,
registerCustomArbitrumNetwork,
ParentToChildMessageGasEstimator
} from "@arbitrum/sdk";
import dotenv from "dotenv";
import { blueberryNetwork as childNetwork } from "../../helpers/custom-network";
import { getBaseFee } from "../../helpers/helpter";
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 () => {
// register - needed for retryables
registerCustomArbitrumNetwork(childNetwork);
const parentToChildMessageGasEstimate = new ParentToChildMessageGasEstimator(childProvider);
const counter = "0xEEeBe2F778AA186e88dCf2FEb8f8231565769C27";
const abi = ["function increment()"];
const iface = new utils.Interface(abi);
const calldata = iface.encodeFunctionData("increment");
const RetryablesGasOverrides = {
gasLimit: {
base: undefined, // when undefined, the value will be estimated from rpc
min: BigNumber.from(10000), // set a minimum gas limit, using 10000 as an example
percentIncrease: BigNumber.from(30), // how much to increase the base for buffer
},
maxSubmissionFee: {
base: undefined,
percentIncrease: BigNumber.from(30),
},
maxFeePerGas: {
base: undefined,
percentIncrease: BigNumber.from(30),
},
};
const ParentToChildMessageGasParams = await parentToChildMessageGasEstimate.estimateAll(
{
from: await parentWallet.address,
to: await counter,
l2CallValue: BigNumber.from(0),
excessFeeRefundAddress: await childWallet.address,
callValueRefundAddress: await childWallet.address,
data: calldata,
},
await getBaseFee(parentProvider),
parentProvider,
RetryablesGasOverrides //if provided, it will override the estimated values. Note that providing "RetryablesGasOverrides" is totally optional.
);
const walletAddress = await parentWallet.address;
const ethBridger = new EthBridger(childNetwork);
const approveTxGas = await ethBridger.approveGasToken({
parentSigner: parentWallet,
});
const approveRecGas = await approveTxGas.wait();
const inboxAddress = ethBridger.childNetwork.ethBridge.inbox;
const inboxAbi = [
"function createRetryableTicket(address to,uint256 childCallValue, uint256 maxSubmissionCost, address excessFeeRefundAddress,address callValueRefundAddress,uint256 gasLimit,uint256 maxFeePerGas,uint256 tokenTotalFeeAmount,bytes calldata data) external payable returns (uint256) ",
];
const inboxContract = new Contract(inboxAddress, inboxAbi, parentWallet);
let { data } = await inboxContract.populateTransaction.createRetryableTicket(
counter,
0,
ParentToChildMessageGasParams.maxSubmissionCost,
walletAddress,
walletAddress,
ParentToChildMessageGasParams.gasLimit,
ParentToChildMessageGasParams.maxFeePerGas,
ParentToChildMessageGasParams.deposit,
calldata
);
const depositTx = await parentWallet.sendTransaction({
to: inboxAddress,
data,
gasLimit: 8000000,
});
let rec = await depositTx.wait();
console.log(rec);
};
main().catch((err) => {
console.error(err);
process.exit(1);
});