-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbackfillArbitrum.ts
36 lines (33 loc) · 1.55 KB
/
backfillArbitrum.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
import * as dotenv from 'dotenv';
dotenv.config();
import axios from 'axios';
import ora from 'ora';
import { initDb } from '../src/databases/utils';
import { AXIOS_CONFIG_JSON } from '../src/consts';
import { EVMWatcher, LOG_MESSAGE_PUBLISHED_TOPIC } from '../src/watchers/EVMWatcher';
import { Chain, contracts } from '@wormhole-foundation/sdk-base';
// This script exists because the Arbitrum RPC node only supports a 10 block range which is super slow
// This script only applies to Arbitrum mainnet
(async () => {
const db = initDb();
const chain: Chain = 'Arbitrum';
const endpoint = `https://api.arbiscan.io/api?module=logs&action=getLogs&address=${contracts.coreBridge(
'Mainnet',
'Arbitrum'
)}&topic0=${LOG_MESSAGE_PUBLISHED_TOPIC}&apikey=YourApiKeyToken`;
// fetch all message publish logs for core bridge contract from explorer
let log = ora('Fetching logs from Arbiscan...').start();
const blockNumbers = (await axios.get(endpoint, AXIOS_CONFIG_JSON)).data.result.map((x: any) =>
parseInt(x.blockNumber, 16)
);
log.succeed(`Fetched ${blockNumbers.length} logs from Arbiscan`);
// use the watcher to fetch corresponding blocks
log = ora('Fetching blocks...').start();
const watcher = new EVMWatcher('Mainnet', 'Arbitrum', 'finalized', 'vaa');
for (const blockNumber of blockNumbers) {
log.text = `Fetching block ${blockNumber}`;
const { vaasByBlock } = await watcher.getMessagesForBlocks(blockNumber, blockNumber);
await db.storeVaasByBlock(chain, vaasByBlock);
}
log.succeed('Uploaded messages to db successfully');
})();