-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathget-outbound-txs.ts
More file actions
147 lines (121 loc) · 4.37 KB
/
get-outbound-txs.ts
File metadata and controls
147 lines (121 loc) · 4.37 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { config as dotenvConfig } from "dotenv";
import {
ChainSlug,
DeploymentAddresses,
IntegrationTypes,
getAllAddresses,
} from "../../src";
import { mode } from "../deploy/config/config";
import SingleCapacitorArtifact from "../../out/SingleCapacitor.sol/SingleCapacitor.json";
import { getProviderFromChainSlug } from "../constants";
import { ethers } from "ethers";
dotenvConfig();
/**
* Usage
*
* --source Specify the source chain slug.
* This flag is required.
* Eg. npx --source=1 --destination=10 --startblock=12345 --endblock=12456 ts-node scripts/admin/get-outbound-txs.ts
*
* --destination Specify the destination chain slug.
* This flag is required.
*
* --startblock Specify the start block number.
* This flag is required.
*
* --endblock Specify the end block number.
* This flag is required.
*/
const sourceChainSlug = process.env.npm_config_source;
if (!sourceChainSlug) {
console.error("Error: source flag is required");
process.exit(1);
}
const destinationChainSlug = process.env.npm_config_destination;
if (!destinationChainSlug) {
console.error("Error: destination flag is required");
process.exit(1);
}
const startBlock = process.env.npm_config_startblock;
if (!startBlock) {
console.error("Error: startblock flag is required");
process.exit(1);
}
const endBlock = process.env.npm_config_endblock;
if (!endBlock) {
console.error("Error: endblock flag is required");
process.exit(1);
}
const addresses: DeploymentAddresses = getAllAddresses(mode);
export const main = async () => {
const sourceChain = sourceChainSlug;
const destinationChain = destinationChainSlug;
console.log(`\nProcessing path: ${sourceChain} -> ${destinationChain}\n`);
// Get addresses from prod_addresses.json
const sourceAddresses = addresses[sourceChain];
if (!sourceAddresses) {
console.error(`Error: No addresses found for source chain ${sourceChain}`);
process.exit(1);
}
const integration = sourceAddresses.integrations?.[destinationChain];
if (!integration) {
console.error(
`Error: No integration found for ${sourceChain} -> ${destinationChain}`
);
process.exit(1);
}
// Get FAST integration addresses (switchboard, socket, capacitor)
const fastIntegration = integration[IntegrationTypes.fast];
if (!fastIntegration) {
console.error(
`Error: No FAST integration found for ${sourceChain} -> ${destinationChain}`
);
process.exit(1);
}
const switchboardAddress = fastIntegration.switchboard;
const capacitorAddress = fastIntegration.capacitor;
const socketAddress = sourceAddresses.Socket;
console.log("Addresses:");
console.log(` Switchboard: ${switchboardAddress}`);
console.log(` Socket: ${socketAddress}`);
console.log(` Capacitor: ${capacitorAddress}\n`);
// Get provider and query events
const provider = getProviderFromChainSlug(parseInt(sourceChain) as ChainSlug);
const capacitorContract = new ethers.Contract(
capacitorAddress,
SingleCapacitorArtifact.abi,
provider
);
const fromBlock = parseInt(startBlock);
const toBlock = parseInt(endBlock);
console.log(`Querying events from block ${fromBlock} to ${toBlock}\n`);
// Query MessageAdded events in chunks of 5000 blocks
const CHUNK_SIZE = 5000;
const messageAddedEvents = [];
for (let currentBlock = fromBlock; currentBlock <= toBlock; currentBlock += CHUNK_SIZE) {
const chunkEnd = Math.min(currentBlock + CHUNK_SIZE - 1, toBlock);
console.log(`Querying chunk: ${currentBlock} to ${chunkEnd}`);
const events = await capacitorContract.queryFilter(
capacitorContract.filters.MessageAdded(),
currentBlock,
chunkEnd
);
messageAddedEvents.push(...events);
}
console.log(`Found ${messageAddedEvents.length} outbound transactions:\n`);
for (const event of messageAddedEvents) {
console.log(`Block: ${event.blockNumber}`);
console.log(` Transaction Hash: ${event.transactionHash}`);
console.log(` Packed Message: ${event.args?.packedMessage}`);
console.log(` Packet Count: ${event.args?.packetCount?.toString()}`);
console.log(` Root Hash: ${event.args?.newRootHash}`);
console.log("");
}
console.log("Script completed.");
};
main()
.then(() => process.exit(0))
.catch((error: Error) => {
console.error(error);
process.exit(1);
});