@tapforce/pod-bridge-sdk 1.1.7 → 1.1.9
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 +98 -74
- package/dist/clients/action/{pod-to-bridged-client.d.ts → pod-to-source-chain-client.d.ts} +1 -1
- package/dist/clients/action/{pod-to-bridged-client.js → pod-to-source-chain-client.js} +5 -5
- package/dist/clients/action/{bridged-to-pod-client.d.ts → source-chain-to-pod-client.d.ts} +1 -1
- package/dist/clients/action/{bridged-to-pod-client.js → source-chain-to-pod-client.js} +5 -5
- package/dist/clients/tracker/client.d.ts +7 -3
- package/dist/clients/tracker/client.js +112 -63
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -5
- package/dist/libs/types/pod-bridge.types.d.ts +25 -12
- package/dist/libs/types/pod-bridge.types.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Pod Bridge SDK
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for interacting with
|
|
3
|
+
TypeScript SDK for interacting with Bridges between POD and other chains - enabling cross-chain token transfers between POD and other EVM chains (e.g., Sepolia).
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -34,8 +34,8 @@ pnpm add @tapforce/pod-bridge-sdk
|
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
36
|
import {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
SourceChainToPodActionClient,
|
|
38
|
+
PodToSourceChainActionClient,
|
|
39
39
|
PodBridgeTrackerClient,
|
|
40
40
|
PodBridgeConfig
|
|
41
41
|
} from '@tapforce/pod-bridge-sdk';
|
|
@@ -47,13 +47,13 @@ Create a configuration object with source and destination chain details:
|
|
|
47
47
|
|
|
48
48
|
```typescript
|
|
49
49
|
const config: PodBridgeConfig = {
|
|
50
|
-
|
|
50
|
+
sourceChain: {
|
|
51
51
|
rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY',
|
|
52
52
|
contractAddress: '0x...', // Source chain bridge contract
|
|
53
53
|
deploymentBlock: 9502541 // Optional: Start indexing from deployment block (avoids querying empty blocks)
|
|
54
54
|
},
|
|
55
55
|
pod: {
|
|
56
|
-
rpcUrl: 'https://
|
|
56
|
+
rpcUrl: 'https://rpc.v1.dev.pod.network',
|
|
57
57
|
contractAddress: '0x...', // Destination chain bridge contract
|
|
58
58
|
deploymentBlock: 0 // Optional: POD deployment block
|
|
59
59
|
}
|
|
@@ -66,30 +66,30 @@ const config: PodBridgeConfig = {
|
|
|
66
66
|
|
|
67
67
|
The SDK provides two action clients for different bridge directions:
|
|
68
68
|
|
|
69
|
-
- **`
|
|
70
|
-
- **`
|
|
69
|
+
- **`SourceChainToPodActionClient`**: For Source Chain → POD transfers (e.g., Sepolia → POD)
|
|
70
|
+
- **`PodToSourceChainActionClient`**: For POD → Source Chain transfers (e.g., POD → Sepolia)
|
|
71
71
|
|
|
72
72
|
#### Configuration for Action Clients
|
|
73
73
|
|
|
74
74
|
```typescript
|
|
75
75
|
const actionConfig = {
|
|
76
|
-
|
|
77
|
-
contractAddress: '0x...' //
|
|
76
|
+
sourceChain: {
|
|
77
|
+
contractAddress: '0x...' // Source chain bridge contract (e.g., Sepolia)
|
|
78
78
|
},
|
|
79
79
|
pod: {
|
|
80
80
|
contractAddress: '0x...' // POD chain bridge contract
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
const
|
|
85
|
-
const
|
|
84
|
+
const sourceChainToPodClient = new SourceChainToPodActionClient(actionConfig);
|
|
85
|
+
const podToSourceChainClient = new PodToSourceChainActionClient(actionConfig);
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
#### Deposit from
|
|
88
|
+
#### Deposit from Source Chain (e.g., Sepolia → POD)
|
|
89
89
|
|
|
90
90
|
```typescript
|
|
91
|
-
// Create unsigned transaction for ERC20 deposit on
|
|
92
|
-
const unsignedTx =
|
|
91
|
+
// Create unsigned transaction for ERC20 deposit on Source chain
|
|
92
|
+
const unsignedTx = sourceChainToPodClient.depositToken({
|
|
93
93
|
token: '0x...', // ERC20 token address
|
|
94
94
|
amount: '1000000000000000000', // Amount in wei (1 token with 18 decimals)
|
|
95
95
|
destinationWalletAddress: '0x...', // Recipient address on POD
|
|
@@ -97,7 +97,7 @@ const unsignedTx = bridgedToPodClient.depositToken({
|
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
// Deposit native tokens
|
|
100
|
-
const unsignedNativeTx =
|
|
100
|
+
const unsignedNativeTx = sourceChainToPodClient.depositNative({
|
|
101
101
|
amount: '1000000000000000000', // Amount in wei (1 ETH)
|
|
102
102
|
destinationWalletAddress: '0x...', // Recipient address on POD
|
|
103
103
|
from: '0x...' // Optional: sender address
|
|
@@ -107,13 +107,13 @@ const unsignedNativeTx = bridgedToPodClient.depositNative({
|
|
|
107
107
|
// const tx = await signer.sendTransaction(unsignedTx);
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
#### Claim on POD from
|
|
110
|
+
#### Claim on POD from Source Chain Deposits
|
|
111
111
|
|
|
112
|
-
For claiming on POD from
|
|
112
|
+
For claiming on POD from Source chain deposits, use block number-based claims:
|
|
113
113
|
|
|
114
114
|
```typescript
|
|
115
115
|
// Create unsigned claim transaction for ERC20 on POD
|
|
116
|
-
const unsignedTx =
|
|
116
|
+
const unsignedTx = sourceChainToPodClient.claimWithBlockNumber({
|
|
117
117
|
id: '123', // Request ID from deposit event
|
|
118
118
|
token: '0x...', // Token address on source chain
|
|
119
119
|
blockNumber: 12345678, // Block number of deposit on source chain
|
|
@@ -121,49 +121,49 @@ const unsignedTx = bridgedToPodClient.claimWithBlockNumber({
|
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
// For native tokens
|
|
124
|
-
const unsignedNativeTx =
|
|
124
|
+
const unsignedNativeTx = sourceChainToPodClient.claimNativeWithBlockNumber({
|
|
125
125
|
id: '123',
|
|
126
126
|
blockNumber: 12345678,
|
|
127
127
|
from: '0x...'
|
|
128
128
|
});
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
#### Deposit from POD (POD →
|
|
131
|
+
#### Deposit from POD (POD → Source Chain)
|
|
132
132
|
|
|
133
133
|
```typescript
|
|
134
134
|
// Create unsigned transaction for ERC20 deposit on POD
|
|
135
|
-
const unsignedTx =
|
|
135
|
+
const unsignedTx = podToSourceChainClient.depositToken({
|
|
136
136
|
token: '0x...', // ERC20 token address
|
|
137
137
|
amount: '1000000000000000000', // Amount in wei
|
|
138
|
-
destinationWalletAddress: '0x...', // Recipient address on
|
|
138
|
+
destinationWalletAddress: '0x...', // Recipient address on Source chain
|
|
139
139
|
from: '0x...' // Optional: sender address
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
// Deposit native tokens
|
|
143
|
-
const unsignedNativeTx =
|
|
143
|
+
const unsignedNativeTx = podToSourceChainClient.depositNative({
|
|
144
144
|
amount: '1000000000000000000',
|
|
145
145
|
destinationWalletAddress: '0x...',
|
|
146
146
|
from: '0x...'
|
|
147
147
|
});
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
-
#### Claim on
|
|
150
|
+
#### Claim on Source Chain from POD Deposits
|
|
151
151
|
|
|
152
|
-
For claiming on
|
|
152
|
+
For claiming on Source chain from POD deposits, use certificate-based claims. First, get the certified log from the POD deposit transaction:
|
|
153
153
|
|
|
154
154
|
```typescript
|
|
155
155
|
// Get certified log from POD deposit transaction
|
|
156
156
|
const depositTxHash = '0x...'; // Transaction hash of deposit on POD
|
|
157
157
|
const certifiedLog = await trackerClient.getDepositCertifiedLog(depositTxHash);
|
|
158
158
|
|
|
159
|
-
// Create unsigned claim transaction for ERC20 on
|
|
160
|
-
const unsignedTx =
|
|
159
|
+
// Create unsigned claim transaction for ERC20 on Source chain
|
|
160
|
+
const unsignedTx = podToSourceChainClient.claimWithCertificate({
|
|
161
161
|
certifiedLog,
|
|
162
162
|
from: '0x...' // Optional: claimer address
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
// For native tokens
|
|
166
|
-
const unsignedNativeTx =
|
|
166
|
+
const unsignedNativeTx = podToSourceChainClient.claimNativeWithCertificate({
|
|
167
167
|
certifiedLog,
|
|
168
168
|
from: '0x...'
|
|
169
169
|
});
|
|
@@ -188,13 +188,16 @@ const deposits = await trackerClient.getDepositsSentBy(
|
|
|
188
188
|
|
|
189
189
|
deposits.forEach(deposit => {
|
|
190
190
|
console.log(`Request ID: ${deposit.requestId}`);
|
|
191
|
-
console.log(`
|
|
192
|
-
console.log(`
|
|
193
|
-
console.log(`
|
|
191
|
+
console.log(`Deposit Chain: ${deposit.deposit.chain}`);
|
|
192
|
+
console.log(`From: ${deposit.deposit.from} -> To: ${deposit.deposit.to}`);
|
|
193
|
+
console.log(`Token: ${deposit.deposit.token}`);
|
|
194
|
+
console.log(`Amount: ${deposit.deposit.amount}`);
|
|
195
|
+
console.log(`Block: ${deposit.deposit.blockNumber}, Time: ${deposit.deposit.timestamp}`);
|
|
194
196
|
console.log(`Claimed: ${deposit.isClaimed}`);
|
|
195
|
-
if (deposit.isClaimed) {
|
|
196
|
-
console.log(`
|
|
197
|
-
console.log(`Claimed
|
|
197
|
+
if (deposit.isClaimed && deposit.claim) {
|
|
198
|
+
console.log(`Claim Chain: ${deposit.claim.chain}`);
|
|
199
|
+
console.log(`Claimed by: ${deposit.claim.claimer}`);
|
|
200
|
+
console.log(`Claimed tx: ${deposit.claim.txHash}`);
|
|
198
201
|
}
|
|
199
202
|
});
|
|
200
203
|
```
|
|
@@ -250,25 +253,25 @@ processedStatuses.forEach((isProcessed, index) => {
|
|
|
250
253
|
|
|
251
254
|
## API Reference
|
|
252
255
|
|
|
253
|
-
###
|
|
256
|
+
### SourceChainToPodActionClient
|
|
254
257
|
|
|
255
|
-
Handles transactions for
|
|
258
|
+
Handles transactions for Source Chain → POD direction.
|
|
256
259
|
|
|
257
260
|
#### Constructor
|
|
258
261
|
|
|
259
262
|
```typescript
|
|
260
|
-
new
|
|
263
|
+
new SourceChainToPodActionClient(config: PodBridgeActionsClientConfig)
|
|
261
264
|
```
|
|
262
265
|
|
|
263
266
|
#### Methods
|
|
264
267
|
|
|
265
|
-
- **`depositToken(args)`**: Create unsigned transaction for ERC20 deposit on
|
|
268
|
+
- **`depositToken(args)`**: Create unsigned transaction for ERC20 deposit on Source chain
|
|
266
269
|
- `token`: Token address
|
|
267
270
|
- `amount`: Amount in wei (string | bigint)
|
|
268
271
|
- `destinationWalletAddress`: Recipient address on POD
|
|
269
272
|
- `from?`: Optional sender address
|
|
270
273
|
|
|
271
|
-
- **`depositNative(args)`**: Create unsigned transaction for native token deposit on
|
|
274
|
+
- **`depositNative(args)`**: Create unsigned transaction for native token deposit on Source chain
|
|
272
275
|
- `amount`: Amount in wei (string | bigint)
|
|
273
276
|
- `destinationWalletAddress`: Recipient address on POD
|
|
274
277
|
- `from?`: Optional sender address
|
|
@@ -276,22 +279,22 @@ new BridgedToPodActionClient(config: PodBridgeActionsClientConfig)
|
|
|
276
279
|
- **`claimWithBlockNumber(args)`**: Create unsigned transaction for claiming on POD with block number
|
|
277
280
|
- `id`: Request ID
|
|
278
281
|
- `token`: Token address
|
|
279
|
-
- `blockNumber`: Block number of deposit on
|
|
282
|
+
- `blockNumber`: Block number of deposit on Source chain
|
|
280
283
|
- `from?`: Optional claimer address
|
|
281
284
|
|
|
282
285
|
- **`claimNativeWithBlockNumber(args)`**: Create unsigned transaction for claiming native tokens on POD with block number
|
|
283
286
|
- `id`: Request ID
|
|
284
|
-
- `blockNumber`: Block number of deposit on
|
|
287
|
+
- `blockNumber`: Block number of deposit on Source chain
|
|
285
288
|
- `from?`: Optional claimer address
|
|
286
289
|
|
|
287
|
-
###
|
|
290
|
+
### PodToSourceChainActionClient
|
|
288
291
|
|
|
289
|
-
Handles transactions for POD →
|
|
292
|
+
Handles transactions for POD → Source Chain direction.
|
|
290
293
|
|
|
291
294
|
#### Constructor
|
|
292
295
|
|
|
293
296
|
```typescript
|
|
294
|
-
new
|
|
297
|
+
new PodToSourceChainActionClient(config: PodBridgeActionsClientConfig)
|
|
295
298
|
```
|
|
296
299
|
|
|
297
300
|
#### Methods
|
|
@@ -299,19 +302,19 @@ new PodToBridgedActionClient(config: PodBridgeActionsClientConfig)
|
|
|
299
302
|
- **`depositToken(args)`**: Create unsigned transaction for ERC20 deposit on POD
|
|
300
303
|
- `token`: Token address
|
|
301
304
|
- `amount`: Amount in wei (string | bigint)
|
|
302
|
-
- `destinationWalletAddress`: Recipient address on
|
|
305
|
+
- `destinationWalletAddress`: Recipient address on Source chain
|
|
303
306
|
- `from?`: Optional sender address
|
|
304
307
|
|
|
305
308
|
- **`depositNative(args)`**: Create unsigned transaction for native token deposit on POD
|
|
306
309
|
- `amount`: Amount in wei (string | bigint)
|
|
307
|
-
- `destinationWalletAddress`: Recipient address on
|
|
310
|
+
- `destinationWalletAddress`: Recipient address on Source chain
|
|
308
311
|
- `from?`: Optional sender address
|
|
309
312
|
|
|
310
|
-
- **`claimWithCertificate(args)`**: Create unsigned transaction for claiming on
|
|
313
|
+
- **`claimWithCertificate(args)`**: Create unsigned transaction for claiming on Source chain with certificate
|
|
311
314
|
- `certifiedLog`: Certified log from POD certificate system
|
|
312
315
|
- `from?`: Optional claimer address
|
|
313
316
|
|
|
314
|
-
- **`claimNativeWithCertificate(args)`**: Create unsigned transaction for claiming native tokens on
|
|
317
|
+
- **`claimNativeWithCertificate(args)`**: Create unsigned transaction for claiming native tokens on Source chain with certificate
|
|
315
318
|
- `certifiedLog`: Certified log from POD certificate system
|
|
316
319
|
- `from?`: Optional claimer address
|
|
317
320
|
|
|
@@ -334,7 +337,7 @@ new PodToBridgedActionClient(config: PodBridgeActionsClientConfig)
|
|
|
334
337
|
- **`areRequestsProcessed(deposits)`**: Batch check if requests are processed
|
|
335
338
|
- Returns: `Promise<boolean[]>`
|
|
336
339
|
|
|
337
|
-
- **`getDepositCertifiedLog(txHash)`**: Get certified log for claiming on
|
|
340
|
+
- **`getDepositCertifiedLog(txHash)`**: Get certified log for claiming on Source chain from POD deposit
|
|
338
341
|
- `txHash`: Transaction hash of deposit on POD
|
|
339
342
|
- Returns: `Promise<CertifiedLog>` with attestations and merkle proof
|
|
340
343
|
|
|
@@ -343,19 +346,40 @@ new PodToBridgedActionClient(config: PodBridgeActionsClientConfig)
|
|
|
343
346
|
### BridgeRequest
|
|
344
347
|
|
|
345
348
|
```typescript
|
|
349
|
+
enum BridgeChain {
|
|
350
|
+
SOURCE_CHAIN = 'sourceChain',
|
|
351
|
+
POD = 'pod'
|
|
352
|
+
}
|
|
353
|
+
|
|
346
354
|
interface BridgeRequest {
|
|
347
355
|
requestId: string;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
356
|
+
|
|
357
|
+
// Deposit information
|
|
358
|
+
deposit: {
|
|
359
|
+
chain: BridgeChain; // Which chain the deposit occurred on
|
|
360
|
+
txHash: string;
|
|
361
|
+
from: string; // Sender address
|
|
362
|
+
to: string; // Recipient address on destination chain
|
|
363
|
+
token: string; // Token address (or 0x0 for native)
|
|
364
|
+
amount: string; // Amount in wei
|
|
365
|
+
chainId: number;
|
|
366
|
+
blockNumber: number; // Block number (for POD, this is essentially a timestamp)
|
|
367
|
+
timestamp: number; // Unix timestamp
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// Claim information (optional, only if claimed)
|
|
371
|
+
claim?: {
|
|
372
|
+
chain: BridgeChain; // Which chain the claim occurred on
|
|
373
|
+
txHash: string;
|
|
374
|
+
claimer: string; // Address that claimed
|
|
375
|
+
chainId: number;
|
|
376
|
+
blockNumber: number; // Block number (for POD, this is essentially a timestamp)
|
|
377
|
+
timestamp: number; // Unix timestamp
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// Status
|
|
355
381
|
isClaimed: boolean;
|
|
356
|
-
|
|
357
|
-
claimedAt?: number;
|
|
358
|
-
claimedBy?: string;
|
|
382
|
+
isClaimable: boolean; // Can be claimed (finalized and not yet claimed)
|
|
359
383
|
}
|
|
360
384
|
```
|
|
361
385
|
|
|
@@ -401,12 +425,12 @@ interface CertifiedLog {
|
|
|
401
425
|
The SDK supports two bridge implementations:
|
|
402
426
|
|
|
403
427
|
1. **BridgeDepositWithdraw** (Certificate-based)
|
|
404
|
-
- Used for claiming on
|
|
428
|
+
- Used for claiming on Source chain from POD deposits
|
|
405
429
|
- Requires certified logs from POD's certificate system
|
|
406
430
|
- Methods: `claimWithCertificate`, `claimNativeWithCertificate`
|
|
407
431
|
|
|
408
432
|
2. **BridgeMintBurn** (Precompile-based)
|
|
409
|
-
- Used for claiming on POD from
|
|
433
|
+
- Used for claiming on POD from Source chain deposits
|
|
410
434
|
- Uses block number verification via precompiles
|
|
411
435
|
- Methods: `claimWithBlockNumber`, `claimNativeWithBlockNumber`
|
|
412
436
|
|
|
@@ -416,11 +440,11 @@ The SDK supports two bridge implementations:
|
|
|
416
440
|
|
|
417
441
|
```typescript
|
|
418
442
|
import { ethers } from 'ethers';
|
|
419
|
-
import {
|
|
443
|
+
import { SourceChainToPodActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
|
|
420
444
|
|
|
421
445
|
// Setup
|
|
422
446
|
const trackerConfig = {
|
|
423
|
-
|
|
447
|
+
sourceChain: {
|
|
424
448
|
rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY',
|
|
425
449
|
contractAddress: '0xSepoliaBridgeContract'
|
|
426
450
|
},
|
|
@@ -431,13 +455,13 @@ const trackerConfig = {
|
|
|
431
455
|
};
|
|
432
456
|
|
|
433
457
|
const actionConfig = {
|
|
434
|
-
|
|
458
|
+
sourceChain: { contractAddress: '0xSepoliaBridgeContract' },
|
|
435
459
|
pod: { contractAddress: '0xPodBridgeContract' }
|
|
436
460
|
};
|
|
437
461
|
|
|
438
|
-
const actionClient = new
|
|
462
|
+
const actionClient = new SourceChainToPodActionClient(actionConfig);
|
|
439
463
|
const trackerClient = new PodBridgeTrackerClient(trackerConfig);
|
|
440
|
-
const sepoliaProvider = new ethers.JsonRpcProvider(trackerConfig.
|
|
464
|
+
const sepoliaProvider = new ethers.JsonRpcProvider(trackerConfig.sourceChain.rpcUrl);
|
|
441
465
|
const sepoliaSigner = new ethers.Wallet('PRIVATE_KEY', sepoliaProvider);
|
|
442
466
|
|
|
443
467
|
// Step 1: Deposit tokens on Sepolia
|
|
@@ -456,15 +480,15 @@ const deposits = await trackerClient.getDepositsSentBy(await sepoliaSigner.getAd
|
|
|
456
480
|
const latestDeposit = deposits[0];
|
|
457
481
|
|
|
458
482
|
console.log(`Request ID: ${latestDeposit.requestId}`);
|
|
459
|
-
console.log(`Amount: ${ethers.formatEther(latestDeposit.amount)}`);
|
|
483
|
+
console.log(`Amount: ${ethers.formatEther(latestDeposit.deposit.amount)}`);
|
|
460
484
|
|
|
461
485
|
// Step 3: Wait for finality and claim on POD
|
|
462
486
|
const canClaim = await trackerClient.canBeClaimed(latestDeposit);
|
|
463
487
|
if (canClaim) {
|
|
464
488
|
const claimTx = actionClient.claimWithBlockNumber({
|
|
465
489
|
id: latestDeposit.requestId,
|
|
466
|
-
token: latestDeposit.token,
|
|
467
|
-
blockNumber: latestDeposit.blockNumber
|
|
490
|
+
token: latestDeposit.deposit.token,
|
|
491
|
+
blockNumber: latestDeposit.deposit.blockNumber
|
|
468
492
|
});
|
|
469
493
|
|
|
470
494
|
// Submit claim on POD
|
|
@@ -480,11 +504,11 @@ if (canClaim) {
|
|
|
480
504
|
|
|
481
505
|
```typescript
|
|
482
506
|
import { ethers } from 'ethers';
|
|
483
|
-
import {
|
|
507
|
+
import { PodToSourceChainActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
|
|
484
508
|
|
|
485
509
|
// Setup
|
|
486
510
|
const trackerConfig = {
|
|
487
|
-
|
|
511
|
+
sourceChain: {
|
|
488
512
|
rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY',
|
|
489
513
|
contractAddress: '0xSepoliaBridgeContract'
|
|
490
514
|
},
|
|
@@ -495,11 +519,11 @@ const trackerConfig = {
|
|
|
495
519
|
};
|
|
496
520
|
|
|
497
521
|
const actionConfig = {
|
|
498
|
-
|
|
522
|
+
sourceChain: { contractAddress: '0xSepoliaBridgeContract' },
|
|
499
523
|
pod: { contractAddress: '0xPodBridgeContract' }
|
|
500
524
|
};
|
|
501
525
|
|
|
502
|
-
const actionClient = new
|
|
526
|
+
const actionClient = new PodToSourceChainActionClient(actionConfig);
|
|
503
527
|
const trackerClient = new PodBridgeTrackerClient(trackerConfig);
|
|
504
528
|
const podProvider = new ethers.JsonRpcProvider(trackerConfig.pod.rpcUrl);
|
|
505
529
|
const podSigner = new ethers.Wallet('PRIVATE_KEY', podProvider);
|
|
@@ -524,7 +548,7 @@ const claimTx = actionClient.claimWithCertificate({
|
|
|
524
548
|
certifiedLog
|
|
525
549
|
});
|
|
526
550
|
|
|
527
|
-
const sepoliaProvider = new ethers.JsonRpcProvider(trackerConfig.
|
|
551
|
+
const sepoliaProvider = new ethers.JsonRpcProvider(trackerConfig.sourceChain.rpcUrl);
|
|
528
552
|
const sepoliaSigner = new ethers.Wallet('PRIVATE_KEY', sepoliaProvider);
|
|
529
553
|
const claim = await sepoliaSigner.sendTransaction(claimTx);
|
|
530
554
|
await claim.wait();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsignedTransaction, CertifiedLog, PodBridgeActionsClientConfig } from "../../libs/types/pod-bridge.types";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class PodToSourceChainActionClient {
|
|
3
3
|
private readonly config;
|
|
4
4
|
private readonly iface;
|
|
5
5
|
constructor(config: PodBridgeActionsClientConfig);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PodToSourceChainActionClient = void 0;
|
|
4
4
|
const ethers_1 = require("ethers");
|
|
5
5
|
const bridge_abi_1 = require("../../libs/abi/bridge.abi");
|
|
6
|
-
class
|
|
6
|
+
class PodToSourceChainActionClient {
|
|
7
7
|
constructor(config) {
|
|
8
8
|
this.config = config;
|
|
9
9
|
this.iface = new ethers_1.Interface(bridge_abi_1.POD_BRIDGE_ABI);
|
|
@@ -55,7 +55,7 @@ class PodToBridgedActionClient {
|
|
|
55
55
|
claimWithCertificate(args) {
|
|
56
56
|
const data = this.iface.encodeFunctionData('claim', [args.certifiedLog]);
|
|
57
57
|
return {
|
|
58
|
-
to: this.config.
|
|
58
|
+
to: this.config.sourceChain.contractAddress,
|
|
59
59
|
data,
|
|
60
60
|
value: '0',
|
|
61
61
|
from: args === null || args === void 0 ? void 0 : args.from
|
|
@@ -71,11 +71,11 @@ class PodToBridgedActionClient {
|
|
|
71
71
|
claimNativeWithCertificate(args) {
|
|
72
72
|
const data = this.iface.encodeFunctionData('claimNative', [args.certifiedLog]);
|
|
73
73
|
return {
|
|
74
|
-
to: this.config.
|
|
74
|
+
to: this.config.sourceChain.contractAddress,
|
|
75
75
|
data,
|
|
76
76
|
value: '0',
|
|
77
77
|
from: args === null || args === void 0 ? void 0 : args.from
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
exports.
|
|
81
|
+
exports.PodToSourceChainActionClient = PodToSourceChainActionClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsignedTransaction, PodBridgeActionsClientConfig } from "../../libs/types/pod-bridge.types";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class SourceChainToPodActionClient {
|
|
3
3
|
private readonly config;
|
|
4
4
|
private readonly iface;
|
|
5
5
|
constructor(config: PodBridgeActionsClientConfig);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SourceChainToPodActionClient = void 0;
|
|
4
4
|
const ethers_1 = require("ethers");
|
|
5
5
|
const bridge_abi_1 = require("../../libs/abi/bridge.abi");
|
|
6
|
-
class
|
|
6
|
+
class SourceChainToPodActionClient {
|
|
7
7
|
constructor(config) {
|
|
8
8
|
this.config = config;
|
|
9
9
|
this.iface = new ethers_1.Interface(bridge_abi_1.POD_BRIDGE_ABI);
|
|
@@ -24,7 +24,7 @@ class BridgedToPodActionClient {
|
|
|
24
24
|
args.destinationWalletAddress
|
|
25
25
|
]);
|
|
26
26
|
return {
|
|
27
|
-
to: this.config.
|
|
27
|
+
to: this.config.sourceChain.contractAddress,
|
|
28
28
|
data,
|
|
29
29
|
value: '0',
|
|
30
30
|
from: args === null || args === void 0 ? void 0 : args.from
|
|
@@ -41,7 +41,7 @@ class BridgedToPodActionClient {
|
|
|
41
41
|
depositNative(args) {
|
|
42
42
|
const data = this.iface.encodeFunctionData('depositNative', [args.destinationWalletAddress]);
|
|
43
43
|
return {
|
|
44
|
-
to: this.config.
|
|
44
|
+
to: this.config.sourceChain.contractAddress,
|
|
45
45
|
data,
|
|
46
46
|
value: args.amount.toString(),
|
|
47
47
|
from: args === null || args === void 0 ? void 0 : args.from
|
|
@@ -89,4 +89,4 @@ class BridgedToPodActionClient {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
exports.
|
|
92
|
+
exports.SourceChainToPodActionClient = SourceChainToPodActionClient;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { PodBridgeConfig, BridgeRequest, BridgeRequestWithType, CertifiedLog } from "../../libs/types/pod-bridge.types";
|
|
2
2
|
export declare class PodBridgeTrackerClient {
|
|
3
3
|
private readonly config;
|
|
4
|
-
private readonly
|
|
4
|
+
private readonly sourceChainProvider;
|
|
5
5
|
private readonly podProvider;
|
|
6
|
-
private readonly
|
|
6
|
+
private readonly sourceChainBridge;
|
|
7
7
|
private readonly podBridge;
|
|
8
8
|
private readonly iface;
|
|
9
|
+
private sourceChainId;
|
|
10
|
+
private podChainId;
|
|
9
11
|
constructor(config: PodBridgeConfig);
|
|
12
|
+
private initChainIds;
|
|
13
|
+
private ensureChainIds;
|
|
10
14
|
/**
|
|
11
15
|
* Get all deposits SENT by an address
|
|
12
16
|
* @param address The address that sent deposits
|
|
@@ -33,7 +37,7 @@ export declare class PodBridgeTrackerClient {
|
|
|
33
37
|
* @param deposit The bridge request to check
|
|
34
38
|
* @returns True if the deposit can be claimed
|
|
35
39
|
*/
|
|
36
|
-
canBeClaimed(deposit:
|
|
40
|
+
canBeClaimed(deposit: BridgeRequest): Promise<boolean>;
|
|
37
41
|
/**
|
|
38
42
|
* Batch check claim status for multiple deposits
|
|
39
43
|
* @param deposits Array of deposits to check
|
|
@@ -7,14 +7,40 @@ const bridge_abi_1 = require("../../libs/abi/bridge.abi");
|
|
|
7
7
|
class PodBridgeTrackerClient {
|
|
8
8
|
constructor(config) {
|
|
9
9
|
this.config = config;
|
|
10
|
+
this.sourceChainId = null;
|
|
11
|
+
this.podChainId = null;
|
|
10
12
|
// Initialize providers
|
|
11
|
-
this.
|
|
13
|
+
this.sourceChainProvider = new ethers_1.ethers.JsonRpcProvider(config.sourceChain.rpcUrl);
|
|
12
14
|
this.podProvider = new ethers_1.ethers.JsonRpcProvider(config.pod.rpcUrl);
|
|
13
15
|
// Initialize contract instances
|
|
14
|
-
this.
|
|
16
|
+
this.sourceChainBridge = new ethers_1.Contract(config.sourceChain.contractAddress, bridge_abi_1.POD_BRIDGE_ABI, this.sourceChainProvider);
|
|
15
17
|
this.podBridge = new ethers_1.Contract(config.pod.contractAddress, bridge_abi_1.POD_BRIDGE_ABI, this.podProvider);
|
|
16
18
|
// Interface for parsing logs
|
|
17
19
|
this.iface = new ethers_1.Interface(bridge_abi_1.POD_BRIDGE_ABI);
|
|
20
|
+
// Fetch chain IDs asynchronously
|
|
21
|
+
this.initChainIds();
|
|
22
|
+
}
|
|
23
|
+
async initChainIds() {
|
|
24
|
+
try {
|
|
25
|
+
const sourceNetwork = await this.sourceChainProvider.getNetwork();
|
|
26
|
+
this.sourceChainId = Number(sourceNetwork.chainId);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('Failed to fetch chain IDs:', error);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const podNetwork = await this.podProvider.getNetwork();
|
|
33
|
+
this.podChainId = Number(podNetwork.chainId);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
this.podChainId = 1293;
|
|
37
|
+
console.error('Failed to fetch chain IDs:', error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async ensureChainIds() {
|
|
41
|
+
if (this.sourceChainId === null || this.podChainId === null) {
|
|
42
|
+
await this.initChainIds();
|
|
43
|
+
}
|
|
18
44
|
}
|
|
19
45
|
/**
|
|
20
46
|
* Get all deposits SENT by an address
|
|
@@ -24,25 +50,26 @@ class PodBridgeTrackerClient {
|
|
|
24
50
|
*/
|
|
25
51
|
async getDepositsSentBy(address, fromBlock) {
|
|
26
52
|
var _a;
|
|
27
|
-
|
|
53
|
+
await this.ensureChainIds();
|
|
54
|
+
const startBlock = (_a = fromBlock !== null && fromBlock !== void 0 ? fromBlock : this.config.sourceChain.deploymentBlock) !== null && _a !== void 0 ? _a : 0;
|
|
28
55
|
const deposits = [];
|
|
29
|
-
const currentBlock = await this.
|
|
56
|
+
const currentBlock = await this.sourceChainProvider.getBlockNumber();
|
|
30
57
|
const BLOCK_BATCH_SIZE = 10000;
|
|
31
58
|
console.log('currentBlock', currentBlock);
|
|
32
59
|
for (let start = startBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
|
|
33
60
|
const end = Math.min(start + BLOCK_BATCH_SIZE - 1, currentBlock);
|
|
34
61
|
// With improved events, we can filter by 'from' directly!
|
|
35
|
-
const depositFilter = this.
|
|
62
|
+
const depositFilter = this.sourceChainBridge.filters.Deposit(null, // id
|
|
36
63
|
address, // from (indexed) - Filter by sender!
|
|
37
64
|
null // to
|
|
38
65
|
);
|
|
39
|
-
const depositNativeFilter = this.
|
|
66
|
+
const depositNativeFilter = this.sourceChainBridge.filters.DepositNative(null, // id
|
|
40
67
|
address, // from (indexed) - Filter by sender!
|
|
41
68
|
null // to
|
|
42
69
|
);
|
|
43
70
|
const [depositLogs, depositNativeLogs] = await Promise.all([
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
71
|
+
this.sourceChainBridge.queryFilter(depositFilter, start, end),
|
|
72
|
+
this.sourceChainBridge.queryFilter(depositNativeFilter, start, end)
|
|
46
73
|
]);
|
|
47
74
|
console.log('depositLogs', depositLogs);
|
|
48
75
|
console.log('depositNativeLogs', depositNativeLogs);
|
|
@@ -59,13 +86,17 @@ class PodBridgeTrackerClient {
|
|
|
59
86
|
if (parsed) {
|
|
60
87
|
deposits.push({
|
|
61
88
|
requestId: parsed.args.id.toString(),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
deposit: {
|
|
90
|
+
chain: pod_bridge_types_1.BridgeChain.SOURCE_CHAIN,
|
|
91
|
+
txHash: log.transactionHash,
|
|
92
|
+
from: parsed.args.from,
|
|
93
|
+
to: parsed.args.to,
|
|
94
|
+
token: parsed.args.token,
|
|
95
|
+
amount: parsed.args.amount.toString(),
|
|
96
|
+
chainId: this.sourceChainId,
|
|
97
|
+
blockNumber: Number(parsed.args.blockNumber),
|
|
98
|
+
timestamp: Number(parsed.args.timestamp)
|
|
99
|
+
},
|
|
69
100
|
isClaimed: false,
|
|
70
101
|
isClaimable: false
|
|
71
102
|
});
|
|
@@ -80,13 +111,17 @@ class PodBridgeTrackerClient {
|
|
|
80
111
|
if (parsed) {
|
|
81
112
|
deposits.push({
|
|
82
113
|
requestId: parsed.args.id.toString(),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
deposit: {
|
|
115
|
+
chain: pod_bridge_types_1.BridgeChain.SOURCE_CHAIN,
|
|
116
|
+
txHash: log.transactionHash,
|
|
117
|
+
from: parsed.args.from,
|
|
118
|
+
to: parsed.args.to,
|
|
119
|
+
token: ethers_1.ethers.ZeroAddress, // Native token
|
|
120
|
+
amount: parsed.args.amount.toString(),
|
|
121
|
+
chainId: this.sourceChainId,
|
|
122
|
+
blockNumber: Number(parsed.args.blockNumber),
|
|
123
|
+
timestamp: Number(parsed.args.timestamp)
|
|
124
|
+
},
|
|
90
125
|
isClaimed: false,
|
|
91
126
|
isClaimable: false
|
|
92
127
|
});
|
|
@@ -95,7 +130,7 @@ class PodBridgeTrackerClient {
|
|
|
95
130
|
}
|
|
96
131
|
// Check claim status (queries POD chain, not bridged)
|
|
97
132
|
await this.updateClaimStatus(deposits);
|
|
98
|
-
return deposits.sort((a, b) => b.timestamp - a.timestamp);
|
|
133
|
+
return deposits.sort((a, b) => b.deposit.timestamp - a.deposit.timestamp);
|
|
99
134
|
}
|
|
100
135
|
/**
|
|
101
136
|
* Get all deposits RECEIVED by an address
|
|
@@ -105,24 +140,25 @@ class PodBridgeTrackerClient {
|
|
|
105
140
|
*/
|
|
106
141
|
async getDepositsReceivedBy(address, fromBlock) {
|
|
107
142
|
var _a;
|
|
108
|
-
|
|
143
|
+
await this.ensureChainIds();
|
|
144
|
+
const startBlock = (_a = fromBlock !== null && fromBlock !== void 0 ? fromBlock : this.config.sourceChain.deploymentBlock) !== null && _a !== void 0 ? _a : 0;
|
|
109
145
|
const deposits = [];
|
|
110
|
-
const currentBlock = await this.
|
|
146
|
+
const currentBlock = await this.sourceChainProvider.getBlockNumber();
|
|
111
147
|
const BLOCK_BATCH_SIZE = 10000;
|
|
112
148
|
for (let start = startBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
|
|
113
149
|
const end = Math.min(start + BLOCK_BATCH_SIZE - 1, currentBlock);
|
|
114
150
|
// With improved events, we can filter by 'to' directly!
|
|
115
|
-
const depositFilter = this.
|
|
151
|
+
const depositFilter = this.sourceChainBridge.filters.Deposit(null, // id
|
|
116
152
|
null, // from
|
|
117
153
|
address // to (indexed) - Filter by recipient!
|
|
118
154
|
);
|
|
119
|
-
const depositNativeFilter = this.
|
|
155
|
+
const depositNativeFilter = this.sourceChainBridge.filters.DepositNative(null, // id
|
|
120
156
|
null, // from
|
|
121
157
|
address // to (indexed) - Filter by recipient!
|
|
122
158
|
);
|
|
123
159
|
const [depositLogs, depositNativeLogs] = await Promise.all([
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
160
|
+
this.sourceChainBridge.queryFilter(depositFilter, start, end),
|
|
161
|
+
this.sourceChainBridge.queryFilter(depositNativeFilter, start, end)
|
|
126
162
|
]);
|
|
127
163
|
// Add small delay to avoid rate limiting
|
|
128
164
|
if (start + BLOCK_BATCH_SIZE <= currentBlock) {
|
|
@@ -137,13 +173,17 @@ class PodBridgeTrackerClient {
|
|
|
137
173
|
if (parsed) {
|
|
138
174
|
deposits.push({
|
|
139
175
|
requestId: parsed.args.id.toString(),
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
176
|
+
deposit: {
|
|
177
|
+
chain: pod_bridge_types_1.BridgeChain.SOURCE_CHAIN,
|
|
178
|
+
txHash: log.transactionHash,
|
|
179
|
+
from: parsed.args.from,
|
|
180
|
+
to: parsed.args.to,
|
|
181
|
+
token: parsed.args.token,
|
|
182
|
+
amount: parsed.args.amount.toString(),
|
|
183
|
+
chainId: this.sourceChainId,
|
|
184
|
+
blockNumber: Number(parsed.args.blockNumber),
|
|
185
|
+
timestamp: Number(parsed.args.timestamp)
|
|
186
|
+
},
|
|
147
187
|
isClaimed: false,
|
|
148
188
|
isClaimable: false
|
|
149
189
|
});
|
|
@@ -158,13 +198,17 @@ class PodBridgeTrackerClient {
|
|
|
158
198
|
if (parsed) {
|
|
159
199
|
deposits.push({
|
|
160
200
|
requestId: parsed.args.id.toString(),
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
201
|
+
deposit: {
|
|
202
|
+
chain: pod_bridge_types_1.BridgeChain.SOURCE_CHAIN,
|
|
203
|
+
txHash: log.transactionHash,
|
|
204
|
+
from: parsed.args.from,
|
|
205
|
+
to: parsed.args.to,
|
|
206
|
+
token: ethers_1.ethers.ZeroAddress,
|
|
207
|
+
amount: parsed.args.amount.toString(),
|
|
208
|
+
chainId: this.sourceChainId,
|
|
209
|
+
blockNumber: Number(parsed.args.blockNumber),
|
|
210
|
+
timestamp: Number(parsed.args.timestamp)
|
|
211
|
+
},
|
|
168
212
|
isClaimed: false,
|
|
169
213
|
isClaimable: false
|
|
170
214
|
});
|
|
@@ -173,7 +217,7 @@ class PodBridgeTrackerClient {
|
|
|
173
217
|
}
|
|
174
218
|
// Check claim status (queries POD chain, not bridged)
|
|
175
219
|
await this.updateClaimStatus(deposits);
|
|
176
|
-
return deposits.sort((a, b) => b.timestamp - a.timestamp);
|
|
220
|
+
return deposits.sort((a, b) => b.deposit.timestamp - a.deposit.timestamp);
|
|
177
221
|
}
|
|
178
222
|
/**
|
|
179
223
|
* Get ALL deposits for an address (both sent and received)
|
|
@@ -200,20 +244,20 @@ class PodBridgeTrackerClient {
|
|
|
200
244
|
const allDeposits = [...sentWithType, ...receivedWithType];
|
|
201
245
|
const uniqueDeposits = new Map();
|
|
202
246
|
for (const deposit of allDeposits) {
|
|
203
|
-
const key = `${deposit.requestId}-${deposit.txHash}`;
|
|
247
|
+
const key = `${deposit.requestId}-${deposit.deposit.txHash}`;
|
|
204
248
|
if (!uniqueDeposits.has(key)) {
|
|
205
249
|
uniqueDeposits.set(key, deposit);
|
|
206
250
|
}
|
|
207
251
|
else {
|
|
208
252
|
// If deposit appears in both (sent to self), mark as both
|
|
209
253
|
const existing = uniqueDeposits.get(key);
|
|
210
|
-
if (existing.from === address && existing.to === address) {
|
|
254
|
+
if (existing.deposit.from === address && existing.deposit.to === address) {
|
|
211
255
|
uniqueDeposits.set(key, { ...existing, type: pod_bridge_types_1.DepositType.SENT });
|
|
212
256
|
}
|
|
213
257
|
}
|
|
214
258
|
}
|
|
215
259
|
return Array.from(uniqueDeposits.values())
|
|
216
|
-
.sort((a, b) => b.timestamp - a.timestamp);
|
|
260
|
+
.sort((a, b) => b.deposit.timestamp - a.deposit.timestamp);
|
|
217
261
|
}
|
|
218
262
|
/**
|
|
219
263
|
* Check if deposits can be claimed (block finalized on source chain)
|
|
@@ -221,9 +265,9 @@ class PodBridgeTrackerClient {
|
|
|
221
265
|
* @returns True if the deposit can be claimed
|
|
222
266
|
*/
|
|
223
267
|
async canBeClaimed(deposit) {
|
|
224
|
-
const currentBlock = await this.
|
|
268
|
+
const currentBlock = await this.sourceChainProvider.getBlockNumber();
|
|
225
269
|
const finalizedBlock = currentBlock - 15; // ~15 minutes on Sepolia
|
|
226
|
-
return deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
|
|
270
|
+
return deposit.deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
|
|
227
271
|
}
|
|
228
272
|
/**
|
|
229
273
|
* Batch check claim status for multiple deposits
|
|
@@ -236,7 +280,7 @@ class PodBridgeTrackerClient {
|
|
|
236
280
|
console.log('updateClaimStatus');
|
|
237
281
|
try {
|
|
238
282
|
// Get unique recipient addresses from deposits
|
|
239
|
-
const uniqueRecipients = [...new Set(deposits.map(d => d.to))];
|
|
283
|
+
const uniqueRecipients = [...new Set(deposits.map(d => d.deposit.to))];
|
|
240
284
|
console.log('Querying claims for recipients:', uniqueRecipients);
|
|
241
285
|
// Get claim events from destination chain (POD) filtered by recipient addresses
|
|
242
286
|
// Note: POD uses timestamps instead of traditional blocks
|
|
@@ -279,29 +323,34 @@ class PodBridgeTrackerClient {
|
|
|
279
323
|
}
|
|
280
324
|
}
|
|
281
325
|
// Get current block to check finalization
|
|
282
|
-
const currentBlock = await this.
|
|
283
|
-
const finalizedBlock = currentBlock -
|
|
326
|
+
const currentBlock = await this.sourceChainProvider.getBlockNumber();
|
|
327
|
+
const finalizedBlock = currentBlock - 64; // 2 epoch (32 x 2 blocks) ~15 minutes on Sepolia
|
|
284
328
|
// Update deposit status
|
|
285
329
|
for (const deposit of deposits) {
|
|
286
330
|
const claimInfo = claimedMap.get(deposit.requestId);
|
|
287
331
|
if (claimInfo) {
|
|
288
332
|
deposit.isClaimed = true;
|
|
289
|
-
deposit.
|
|
290
|
-
|
|
291
|
-
|
|
333
|
+
deposit.claim = {
|
|
334
|
+
chain: pod_bridge_types_1.BridgeChain.POD,
|
|
335
|
+
txHash: claimInfo.txHash,
|
|
336
|
+
claimer: claimInfo.claimer,
|
|
337
|
+
chainId: this.podChainId,
|
|
338
|
+
blockNumber: 0, // POD has single block - using timestamp
|
|
339
|
+
timestamp: claimInfo.timestamp
|
|
340
|
+
};
|
|
292
341
|
}
|
|
293
342
|
// Check if deposit is claimable (finalized and not claimed)
|
|
294
|
-
deposit.isClaimable = deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
|
|
343
|
+
deposit.isClaimable = deposit.deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
|
|
295
344
|
}
|
|
296
345
|
}
|
|
297
346
|
catch (error) {
|
|
298
347
|
console.error('Error checking claim status:', error);
|
|
299
348
|
// Fallback: Still calculate isClaimable based on finalization even if claim check fails
|
|
300
349
|
try {
|
|
301
|
-
const currentBlock = await this.
|
|
302
|
-
const finalizedBlock = currentBlock - 15
|
|
350
|
+
const currentBlock = await this.sourceChainProvider.getBlockNumber();
|
|
351
|
+
const finalizedBlock = currentBlock - 64; // 2 epoch (32 x 2 blocks) ~15 minutes on Sepolia
|
|
303
352
|
for (const deposit of deposits) {
|
|
304
|
-
deposit.isClaimable = deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
|
|
353
|
+
deposit.isClaimable = deposit.deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
|
|
305
354
|
}
|
|
306
355
|
}
|
|
307
356
|
catch (fallbackError) {
|
|
@@ -319,9 +368,9 @@ class PodBridgeTrackerClient {
|
|
|
319
368
|
return [];
|
|
320
369
|
try {
|
|
321
370
|
const ids = deposits.map(d => d.requestId);
|
|
322
|
-
const tokens = deposits.map(d => d.token);
|
|
323
|
-
const amounts = deposits.map(d => d.amount);
|
|
324
|
-
const tos = deposits.map(d => d.to);
|
|
371
|
+
const tokens = deposits.map(d => d.deposit.token);
|
|
372
|
+
const amounts = deposits.map(d => d.deposit.amount);
|
|
373
|
+
const tos = deposits.map(d => d.deposit.to);
|
|
325
374
|
return await this.podBridge.areRequestsProcessed(ids, tokens, amounts, tos);
|
|
326
375
|
}
|
|
327
376
|
catch (error) {
|
|
@@ -330,7 +379,7 @@ class PodBridgeTrackerClient {
|
|
|
330
379
|
const results = [];
|
|
331
380
|
for (const deposit of deposits) {
|
|
332
381
|
try {
|
|
333
|
-
const hash = this.computeRequestHash(deposit.requestId, deposit.token, deposit.amount, deposit.to);
|
|
382
|
+
const hash = this.computeRequestHash(deposit.requestId, deposit.deposit.token, deposit.deposit.amount, deposit.deposit.to);
|
|
334
383
|
const isProcessed = await this.podBridge.processedRequests(hash);
|
|
335
384
|
results.push(isProcessed);
|
|
336
385
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { PodToSourceChainActionClient } from './clients/action/pod-to-source-chain-client';
|
|
2
|
+
export { SourceChainToPodActionClient } from './clients/action/source-chain-to-pod-client';
|
|
3
3
|
export { PodBridgeTrackerClient } from './clients/tracker/client';
|
|
4
4
|
export { POD_BRIDGE_ABI } from './libs/abi/bridge.abi';
|
|
5
|
-
export { PodBridgeConfig, BridgeRequest, BridgeRequestWithType, DepositType, UnsignedTransaction, CertifiedLog, PodAttestation, PodMetadata, PodTransactionReceipt, } from './libs/types/pod-bridge.types';
|
|
5
|
+
export { PodBridgeConfig, BridgeRequest, BridgeRequestWithType, BridgeChain, DepositType, UnsignedTransaction, CertifiedLog, PodAttestation, PodMetadata, PodTransactionReceipt, PodBridgeActionsClientConfig, PodBridgeChainConfig } from './libs/types/pod-bridge.types';
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DepositType = exports.POD_BRIDGE_ABI = exports.PodBridgeTrackerClient = exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.DepositType = exports.BridgeChain = exports.POD_BRIDGE_ABI = exports.PodBridgeTrackerClient = exports.SourceChainToPodActionClient = exports.PodToSourceChainActionClient = void 0;
|
|
4
|
+
var pod_to_source_chain_client_1 = require("./clients/action/pod-to-source-chain-client");
|
|
5
|
+
Object.defineProperty(exports, "PodToSourceChainActionClient", { enumerable: true, get: function () { return pod_to_source_chain_client_1.PodToSourceChainActionClient; } });
|
|
6
|
+
var source_chain_to_pod_client_1 = require("./clients/action/source-chain-to-pod-client");
|
|
7
|
+
Object.defineProperty(exports, "SourceChainToPodActionClient", { enumerable: true, get: function () { return source_chain_to_pod_client_1.SourceChainToPodActionClient; } });
|
|
8
8
|
var client_1 = require("./clients/tracker/client");
|
|
9
9
|
Object.defineProperty(exports, "PodBridgeTrackerClient", { enumerable: true, get: function () { return client_1.PodBridgeTrackerClient; } });
|
|
10
10
|
var bridge_abi_1 = require("./libs/abi/bridge.abi");
|
|
11
11
|
Object.defineProperty(exports, "POD_BRIDGE_ABI", { enumerable: true, get: function () { return bridge_abi_1.POD_BRIDGE_ABI; } });
|
|
12
12
|
var pod_bridge_types_1 = require("./libs/types/pod-bridge.types");
|
|
13
|
+
Object.defineProperty(exports, "BridgeChain", { enumerable: true, get: function () { return pod_bridge_types_1.BridgeChain; } });
|
|
13
14
|
Object.defineProperty(exports, "DepositType", { enumerable: true, get: function () { return pod_bridge_types_1.DepositType; } });
|
|
@@ -9,31 +9,44 @@ export interface PodBridgeChainConfig {
|
|
|
9
9
|
* * pod: Configuration for the POD chain. BridgeMintBurn contract address
|
|
10
10
|
*/
|
|
11
11
|
export interface PodBridgeConfig {
|
|
12
|
-
|
|
12
|
+
sourceChain: PodBridgeChainConfig;
|
|
13
13
|
pod: PodBridgeChainConfig;
|
|
14
14
|
}
|
|
15
15
|
export interface PodBridgeActionsClientConfig {
|
|
16
|
-
|
|
16
|
+
sourceChain: {
|
|
17
17
|
contractAddress: string;
|
|
18
18
|
};
|
|
19
19
|
pod: {
|
|
20
20
|
contractAddress: string;
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
export declare enum BridgeChain {
|
|
24
|
+
SOURCE_CHAIN = "sourceChain",
|
|
25
|
+
POD = "pod"
|
|
26
|
+
}
|
|
23
27
|
export interface BridgeRequest {
|
|
24
28
|
requestId: string;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
deposit: {
|
|
30
|
+
chain: BridgeChain;
|
|
31
|
+
txHash: string;
|
|
32
|
+
from: string;
|
|
33
|
+
to: string;
|
|
34
|
+
token: string;
|
|
35
|
+
amount: string;
|
|
36
|
+
chainId: number;
|
|
37
|
+
blockNumber: number;
|
|
38
|
+
timestamp: number;
|
|
39
|
+
};
|
|
40
|
+
claim?: {
|
|
41
|
+
chain: BridgeChain;
|
|
42
|
+
txHash: string;
|
|
43
|
+
claimer: string;
|
|
44
|
+
chainId: number;
|
|
45
|
+
blockNumber: number;
|
|
46
|
+
timestamp: number;
|
|
47
|
+
};
|
|
32
48
|
isClaimed: boolean;
|
|
33
49
|
isClaimable: boolean;
|
|
34
|
-
claimedTxHash?: string;
|
|
35
|
-
claimedAt?: number;
|
|
36
|
-
claimedBy?: string;
|
|
37
50
|
}
|
|
38
51
|
export declare enum DepositType {
|
|
39
52
|
SENT = "sent",
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DepositType = void 0;
|
|
3
|
+
exports.DepositType = exports.BridgeChain = void 0;
|
|
4
|
+
var BridgeChain;
|
|
5
|
+
(function (BridgeChain) {
|
|
6
|
+
BridgeChain["SOURCE_CHAIN"] = "sourceChain";
|
|
7
|
+
BridgeChain["POD"] = "pod";
|
|
8
|
+
})(BridgeChain || (exports.BridgeChain = BridgeChain = {}));
|
|
4
9
|
var DepositType;
|
|
5
10
|
(function (DepositType) {
|
|
6
11
|
DepositType["SENT"] = "sent";
|