@tapforce/pod-bridge-sdk 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -49,11 +49,13 @@ Create a configuration object with source and destination chain details:
|
|
|
49
49
|
const config: PodBridgeConfig = {
|
|
50
50
|
bridged: {
|
|
51
51
|
rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY',
|
|
52
|
-
contractAddress: '0x...' // Source chain bridge contract
|
|
52
|
+
contractAddress: '0x...', // Source chain bridge contract
|
|
53
|
+
deploymentBlock: 9502541 // Optional: Start indexing from deployment block (avoids querying empty blocks)
|
|
53
54
|
},
|
|
54
55
|
pod: {
|
|
55
56
|
rpcUrl: 'https://pod-rpc.example.com',
|
|
56
|
-
contractAddress: '0x...' // Destination chain bridge contract
|
|
57
|
+
contractAddress: '0x...', // Destination chain bridge contract
|
|
58
|
+
deploymentBlock: 0 // Optional: POD deployment block
|
|
57
59
|
}
|
|
58
60
|
};
|
|
59
61
|
```
|
|
@@ -10,21 +10,21 @@ export declare class PodBridgeTrackerClient {
|
|
|
10
10
|
/**
|
|
11
11
|
* Get all deposits SENT by an address
|
|
12
12
|
* @param address The address that sent deposits
|
|
13
|
-
* @param fromBlock Starting block number (default: 0)
|
|
13
|
+
* @param fromBlock Starting block number (default: contract deployment block or 0)
|
|
14
14
|
* @returns Array of bridge requests sent by this address
|
|
15
15
|
*/
|
|
16
16
|
getDepositsSentBy(address: string, fromBlock?: number): Promise<BridgeRequest[]>;
|
|
17
17
|
/**
|
|
18
18
|
* Get all deposits RECEIVED by an address
|
|
19
19
|
* @param address The address that will receive deposits
|
|
20
|
-
* @param fromBlock Starting block number (default: 0)
|
|
20
|
+
* @param fromBlock Starting block number (default: contract deployment block or 0)
|
|
21
21
|
* @returns Array of bridge requests sent to this address
|
|
22
22
|
*/
|
|
23
23
|
getDepositsReceivedBy(address: string, fromBlock?: number): Promise<BridgeRequest[]>;
|
|
24
24
|
/**
|
|
25
25
|
* Get ALL deposits for an address (both sent and received)
|
|
26
26
|
* @param address The address to check
|
|
27
|
-
* @param fromBlock Starting block number (default: 0)
|
|
27
|
+
* @param fromBlock Starting block number (default: contract deployment block or 0)
|
|
28
28
|
* @returns Array of bridge requests with type indicator
|
|
29
29
|
*/
|
|
30
30
|
getAllDepositsFor(address: string, fromBlock?: number): Promise<BridgeRequestWithType[]>;
|
|
@@ -37,6 +37,7 @@ export declare class PodBridgeTrackerClient {
|
|
|
37
37
|
/**
|
|
38
38
|
* Batch check claim status for multiple deposits
|
|
39
39
|
* @param deposits Array of deposits to check
|
|
40
|
+
* @param fromBlock Starting block to query claims from
|
|
40
41
|
*/
|
|
41
42
|
private updateClaimStatus;
|
|
42
43
|
/**
|
|
@@ -19,14 +19,16 @@ class PodBridgeTrackerClient {
|
|
|
19
19
|
/**
|
|
20
20
|
* Get all deposits SENT by an address
|
|
21
21
|
* @param address The address that sent deposits
|
|
22
|
-
* @param fromBlock Starting block number (default: 0)
|
|
22
|
+
* @param fromBlock Starting block number (default: contract deployment block or 0)
|
|
23
23
|
* @returns Array of bridge requests sent by this address
|
|
24
24
|
*/
|
|
25
|
-
async getDepositsSentBy(address, fromBlock
|
|
25
|
+
async getDepositsSentBy(address, fromBlock) {
|
|
26
|
+
var _a;
|
|
27
|
+
const startBlock = (_a = fromBlock !== null && fromBlock !== void 0 ? fromBlock : this.config.bridged.deploymentBlock) !== null && _a !== void 0 ? _a : 0;
|
|
26
28
|
const deposits = [];
|
|
27
29
|
const currentBlock = await this.bridgedProvider.getBlockNumber();
|
|
28
30
|
const BLOCK_BATCH_SIZE = 10000;
|
|
29
|
-
for (let start =
|
|
31
|
+
for (let start = startBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
|
|
30
32
|
const end = Math.min(start + BLOCK_BATCH_SIZE - 1, currentBlock);
|
|
31
33
|
// With improved events, we can filter by 'from' directly!
|
|
32
34
|
const depositFilter = this.bridgedBridge.filters.Deposit(null, // id
|
|
@@ -41,6 +43,12 @@ class PodBridgeTrackerClient {
|
|
|
41
43
|
this.bridgedBridge.queryFilter(depositFilter, start, end),
|
|
42
44
|
this.bridgedBridge.queryFilter(depositNativeFilter, start, end)
|
|
43
45
|
]);
|
|
46
|
+
console.log('depositLogs', depositLogs);
|
|
47
|
+
console.log('depositNativeLogs', depositNativeLogs);
|
|
48
|
+
// Add small delay to avoid rate limiting
|
|
49
|
+
if (start + BLOCK_BATCH_SIZE <= currentBlock) {
|
|
50
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
51
|
+
}
|
|
44
52
|
// Process Deposit events
|
|
45
53
|
for (const log of depositLogs) {
|
|
46
54
|
const parsed = this.iface.parseLog({
|
|
@@ -83,20 +91,22 @@ class PodBridgeTrackerClient {
|
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
// Check claim status
|
|
86
|
-
await this.updateClaimStatus(deposits);
|
|
94
|
+
await this.updateClaimStatus(deposits, startBlock);
|
|
87
95
|
return deposits.sort((a, b) => b.timestamp - a.timestamp);
|
|
88
96
|
}
|
|
89
97
|
/**
|
|
90
98
|
* Get all deposits RECEIVED by an address
|
|
91
99
|
* @param address The address that will receive deposits
|
|
92
|
-
* @param fromBlock Starting block number (default: 0)
|
|
100
|
+
* @param fromBlock Starting block number (default: contract deployment block or 0)
|
|
93
101
|
* @returns Array of bridge requests sent to this address
|
|
94
102
|
*/
|
|
95
|
-
async getDepositsReceivedBy(address, fromBlock
|
|
103
|
+
async getDepositsReceivedBy(address, fromBlock) {
|
|
104
|
+
var _a;
|
|
105
|
+
const startBlock = (_a = fromBlock !== null && fromBlock !== void 0 ? fromBlock : this.config.bridged.deploymentBlock) !== null && _a !== void 0 ? _a : 0;
|
|
96
106
|
const deposits = [];
|
|
97
107
|
const currentBlock = await this.bridgedProvider.getBlockNumber();
|
|
98
108
|
const BLOCK_BATCH_SIZE = 10000;
|
|
99
|
-
for (let start =
|
|
109
|
+
for (let start = startBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
|
|
100
110
|
const end = Math.min(start + BLOCK_BATCH_SIZE - 1, currentBlock);
|
|
101
111
|
// With improved events, we can filter by 'to' directly!
|
|
102
112
|
const depositFilter = this.bridgedBridge.filters.Deposit(null, // id
|
|
@@ -111,6 +121,10 @@ class PodBridgeTrackerClient {
|
|
|
111
121
|
this.bridgedBridge.queryFilter(depositFilter, start, end),
|
|
112
122
|
this.bridgedBridge.queryFilter(depositNativeFilter, start, end)
|
|
113
123
|
]);
|
|
124
|
+
// Add small delay to avoid rate limiting
|
|
125
|
+
if (start + BLOCK_BATCH_SIZE <= currentBlock) {
|
|
126
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
127
|
+
}
|
|
114
128
|
// Process Deposit events
|
|
115
129
|
for (const log of depositLogs) {
|
|
116
130
|
const parsed = this.iface.parseLog({
|
|
@@ -153,16 +167,16 @@ class PodBridgeTrackerClient {
|
|
|
153
167
|
}
|
|
154
168
|
}
|
|
155
169
|
// Check claim status
|
|
156
|
-
await this.updateClaimStatus(deposits);
|
|
170
|
+
await this.updateClaimStatus(deposits, startBlock);
|
|
157
171
|
return deposits.sort((a, b) => b.timestamp - a.timestamp);
|
|
158
172
|
}
|
|
159
173
|
/**
|
|
160
174
|
* Get ALL deposits for an address (both sent and received)
|
|
161
175
|
* @param address The address to check
|
|
162
|
-
* @param fromBlock Starting block number (default: 0)
|
|
176
|
+
* @param fromBlock Starting block number (default: contract deployment block or 0)
|
|
163
177
|
* @returns Array of bridge requests with type indicator
|
|
164
178
|
*/
|
|
165
|
-
async getAllDepositsFor(address, fromBlock
|
|
179
|
+
async getAllDepositsFor(address, fromBlock) {
|
|
166
180
|
// Fetch both sent and received in parallel
|
|
167
181
|
const [sent, received] = await Promise.all([
|
|
168
182
|
this.getDepositsSentBy(address, fromBlock),
|
|
@@ -209,19 +223,41 @@ class PodBridgeTrackerClient {
|
|
|
209
223
|
/**
|
|
210
224
|
* Batch check claim status for multiple deposits
|
|
211
225
|
* @param deposits Array of deposits to check
|
|
226
|
+
* @param fromBlock Starting block to query claims from
|
|
212
227
|
*/
|
|
213
|
-
async updateClaimStatus(deposits) {
|
|
228
|
+
async updateClaimStatus(deposits, fromBlock) {
|
|
229
|
+
var _a;
|
|
214
230
|
if (deposits.length === 0) {
|
|
215
231
|
return;
|
|
216
232
|
}
|
|
233
|
+
console.log('updateClaimStatus');
|
|
217
234
|
try {
|
|
218
|
-
|
|
235
|
+
const startBlock = (_a = fromBlock !== null && fromBlock !== void 0 ? fromBlock : this.config.pod.deploymentBlock) !== null && _a !== void 0 ? _a : 0;
|
|
236
|
+
const currentBlock = await this.podProvider.getBlockNumber();
|
|
237
|
+
const BLOCK_BATCH_SIZE = 10000;
|
|
238
|
+
const allClaimLogs = [];
|
|
239
|
+
const allClaimNativeLogs = [];
|
|
240
|
+
// Get claim events from destination chain in batches
|
|
219
241
|
const claimFilter = this.podBridge.filters.Claim();
|
|
220
242
|
const claimNativeFilter = this.podBridge.filters.ClaimNative();
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
243
|
+
for (let start = startBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
|
|
244
|
+
const end = Math.min(start + BLOCK_BATCH_SIZE - 1, currentBlock);
|
|
245
|
+
console.log('updateClaimStatus', start, end);
|
|
246
|
+
const [claimLogs, claimNativeLogs] = await Promise.all([
|
|
247
|
+
this.podBridge.queryFilter(claimFilter, start, end),
|
|
248
|
+
this.podBridge.queryFilter(claimNativeFilter, start, end)
|
|
249
|
+
]);
|
|
250
|
+
console.log('claimLogs', claimLogs);
|
|
251
|
+
console.log('claimNativeLogs', claimNativeLogs);
|
|
252
|
+
allClaimLogs.push(...claimLogs);
|
|
253
|
+
allClaimNativeLogs.push(...claimNativeLogs);
|
|
254
|
+
// Add small delay to avoid rate limiting
|
|
255
|
+
if (start + BLOCK_BATCH_SIZE <= currentBlock) {
|
|
256
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const claimLogs = allClaimLogs;
|
|
260
|
+
const claimNativeLogs = allClaimNativeLogs;
|
|
225
261
|
// Create a map of claimed request IDs
|
|
226
262
|
const claimedMap = new Map();
|
|
227
263
|
for (const log of [...claimLogs, ...claimNativeLogs]) {
|