-
Notifications
You must be signed in to change notification settings - Fork 1
/
manual-redeem.ts
82 lines (55 loc) · 2.03 KB
/
manual-redeem.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
import { utils, providers, Wallet, BigNumber, Contract } from "ethers";
import { Provider } from "@ethersproject/abstract-provider";
import {
EthBridger,
registerCustomArbitrumNetwork
} from "@arbitrum/sdk";
import {
ParentToChildMessageStatus,
ParentTransactionReceipt
} from "@arbitrum/sdk";
import dotenv from "dotenv";
import { blueberryNetwork as childNetwork} from "../helpers/custom-network";
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 childWallet = new Wallet(walletPrivateKey, childProvider);
const main = async () => {
registerCustomArbitrumNetwork(childNetwork);
const txnHash =
"0xf222768b0b3b3aa6dd57a45db66b4f5b9955336e8e2f749a954311c381791010";
const receipt = await parentProvider.getTransactionReceipt(txnHash);
const parentReceipt = new ParentTransactionReceipt(receipt);
const messages = await parentReceipt.getParentToChildMessages(childWallet);
const parentToChildMsg = messages[0];
/**
* Check if already executed
*/
const status = await parentToChildMsg.status();
console.log(status)
console.log(ParentToChildMessageStatus.FUNDS_DEPOSITED_ON_CHILD)
console.log(ParentToChildMessageStatus.REDEEMED)
// console.log(status);
if (status == ParentToChildMessageStatus.REDEEMED) {
console.log(`Message already executed! Nothing else to do here`);
process.exit(1);
}
// // // /**
// // // * Now that its confirmed and not executed, we can execute our message in its outbox entry.
// // // */
const childTx = await parentToChildMsg.redeem();
const rec = await childTx.waitForRedeem();
console.log(
"The Child side of your transaction is now executed 🥳 :",
rec.transactionHash
);
};
main().catch((err) => {
console.error(err);
process.exit(1);
});