-
Notifications
You must be signed in to change notification settings - Fork 292
/
Copy pathmonitor-eth-deposit-status.ts
68 lines (59 loc) · 2.17 KB
/
monitor-eth-deposit-status.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
import { providers } from 'ethers';
import { arbLog, requireEnvVariables, addCustomNetworkFromFile } from 'arb-shared-dependencies';
import { EthL1L3Bridger, ParentToChildMessageStatus, getArbitrumNetwork } from '@arbitrum/sdk';
require('dotenv').config();
requireEnvVariables(['CHAIN_RPC', 'PARENT_CHAIN_RPC', 'L1_RPC']);
/**
* Set up: instantiate wallets connected to providers
*/
const l1Provider = new providers.JsonRpcProvider(process.env.L1_RPC);
const l2Provider = new providers.JsonRpcProvider(process.env.PARENT_CHAIN_RPC);
const l3Provider = new providers.JsonRpcProvider(process.env.CHAIN_RPC);
const statusToText = {
NA: 'N/A',
[ParentToChildMessageStatus.REDEEMED]: 'REDEEMED',
[ParentToChildMessageStatus.CREATION_FAILED]: 'CREATION_FAILED',
[ParentToChildMessageStatus.EXPIRED]: 'EXPIRED',
[ParentToChildMessageStatus.FUNDS_DEPOSITED_ON_CHILD]: 'FUNDS_DEPOSITED_ON_L2',
[ParentToChildMessageStatus.NOT_YET_CREATED]: 'NOT_YET_CREATED',
};
const main = async (txHash: string) => {
await arbLog(`Monitoring deposit status`);
/**
* Add the custom network configuration to the SDK if present
*/
addCustomNetworkFromFile();
/**
* Use L3 Network to initialize a bridger
*/
const l3Network = await getArbitrumNetwork(l3Provider);
const bridger = new EthL1L3Bridger(l3Network);
/**
* Get deposit status
*/
console.log('Getting deposit status...');
const depositStatus = await bridger.getDepositStatus({
txHash,
l1Provider,
l2Provider,
l3Provider,
});
/**
* If any of these retryables fail (i.e. FUNDS_DEPOSITED_ON_CHILD), manually redeem them in the order displayed below
* Note that anyone can manually redeem these retryables, not just the sender of the deposit
*/
console.log(`L1-to-L2 retryable: ${statusToText[await depositStatus.l2Retryable.status()]}`);
console.log(
`L2-to-L3 retryable: ${
statusToText[
(await depositStatus.l3Retryable?.status()) || ParentToChildMessageStatus.NOT_YET_CREATED
]
}`,
);
console.log(`Completed: ${depositStatus.completed}`);
};
if (!process.argv[2]) {
console.error('Please provide a transaction hash');
process.exit(1);
}
main(process.argv[2]);