@tapforce/pod-bridge-sdk 1.1.8 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pod Bridge SDK
2
2
 
3
- TypeScript SDK for interacting with the Pod Bridge - enabling cross-chain token transfers between POD and other EVM chains (e.g., Sepolia).
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
- BridgedToPodActionClient,
38
- PodToBridgedActionClient,
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
- bridged: {
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://pod-rpc.example.com',
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
- - **`BridgedToPodActionClient`**: For Bridged → POD transfers (e.g., Sepolia → POD)
70
- - **`PodToBridgedActionClient`**: For POD → Bridged transfers (e.g., POD → Sepolia)
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
- bridged: {
77
- contractAddress: '0x...' // Bridged chain bridge contract (e.g., Sepolia)
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 bridgedToPodClient = new BridgedToPodActionClient(actionConfig);
85
- const podToBridgedClient = new PodToBridgedActionClient(actionConfig);
84
+ const sourceChainToPodClient = new SourceChainToPodActionClient(actionConfig);
85
+ const podToSourceChainClient = new PodToSourceChainActionClient(actionConfig);
86
86
  ```
87
87
 
88
- #### Deposit from Bridged Chain (e.g., Sepolia → POD)
88
+ #### Deposit from Source Chain (e.g., Sepolia → POD)
89
89
 
90
90
  ```typescript
91
- // Create unsigned transaction for ERC20 deposit on Bridged chain
92
- const unsignedTx = bridgedToPodClient.depositToken({
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 = bridgedToPodClient.depositNative({
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 Bridged Chain Deposits
110
+ #### Claim on POD from Source Chain Deposits
111
111
 
112
- For claiming on POD from Bridged chain deposits, use block number-based claims:
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 = bridgedToPodClient.claimWithBlockNumber({
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 = bridgedToPodClient.claimNativeWithBlockNumber({
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 → Bridged Chain)
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 = podToBridgedClient.depositToken({
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 Bridged chain
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 = podToBridgedClient.depositNative({
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 Bridged Chain from POD Deposits
150
+ #### Claim on Source Chain from POD Deposits
151
151
 
152
- For claiming on Bridged chain from POD deposits, use certificate-based claims. First, get the certified log from the POD deposit transaction:
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 Bridged chain
160
- const unsignedTx = podToBridgedClient.claimWithCertificate({
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 = podToBridgedClient.claimNativeWithCertificate({
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(`From: ${deposit.from} -> To: ${deposit.to}`);
192
- console.log(`Token: ${deposit.token}`);
193
- console.log(`Amount: ${deposit.amount}`);
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(`Claimed by: ${deposit.claimedBy}`);
197
- console.log(`Claimed tx: ${deposit.claimedTxHash}`);
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
- ### BridgedToPodActionClient
256
+ ### SourceChainToPodActionClient
254
257
 
255
- Handles transactions for Bridged → POD direction.
258
+ Handles transactions for Source Chain → POD direction.
256
259
 
257
260
  #### Constructor
258
261
 
259
262
  ```typescript
260
- new BridgedToPodActionClient(config: PodBridgeActionsClientConfig)
263
+ new SourceChainToPodActionClient(config: PodBridgeActionsClientConfig)
261
264
  ```
262
265
 
263
266
  #### Methods
264
267
 
265
- - **`depositToken(args)`**: Create unsigned transaction for ERC20 deposit on Bridged chain
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 Bridged chain
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 Bridged chain
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 Bridged chain
287
+ - `blockNumber`: Block number of deposit on Source chain
285
288
  - `from?`: Optional claimer address
286
289
 
287
- ### PodToBridgedActionClient
290
+ ### PodToSourceChainActionClient
288
291
 
289
- Handles transactions for POD → Bridged direction.
292
+ Handles transactions for POD → Source Chain direction.
290
293
 
291
294
  #### Constructor
292
295
 
293
296
  ```typescript
294
- new PodToBridgedActionClient(config: PodBridgeActionsClientConfig)
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 Bridged chain
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 Bridged chain
310
+ - `destinationWalletAddress`: Recipient address on Source chain
308
311
  - `from?`: Optional sender address
309
312
 
310
- - **`claimWithCertificate(args)`**: Create unsigned transaction for claiming on Bridged chain with certificate
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 Bridged chain with certificate
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 Sepolia from POD deposit
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
- blockNumber: number;
349
- timestamp: number;
350
- txHash: string;
351
- from: string;
352
- to: string;
353
- token: string; // Token address or ZeroAddress for native
354
- amount: string; // Amount in wei
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
- claimedTxHash?: string;
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 Sepolia from POD deposits
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 Sepolia deposits
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 { BridgedToPodActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
443
+ import { SourceChainToPodActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
420
444
 
421
445
  // Setup
422
446
  const trackerConfig = {
423
- bridged: {
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
- bridged: { contractAddress: '0xSepoliaBridgeContract' },
458
+ sourceChain: { contractAddress: '0xSepoliaBridgeContract' },
435
459
  pod: { contractAddress: '0xPodBridgeContract' }
436
460
  };
437
461
 
438
- const actionClient = new BridgedToPodActionClient(actionConfig);
462
+ const actionClient = new SourceChainToPodActionClient(actionConfig);
439
463
  const trackerClient = new PodBridgeTrackerClient(trackerConfig);
440
- const sepoliaProvider = new ethers.JsonRpcProvider(trackerConfig.bridged.rpcUrl);
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 { PodToBridgedActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
507
+ import { PodToSourceChainActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
484
508
 
485
509
  // Setup
486
510
  const trackerConfig = {
487
- bridged: {
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
- bridged: { contractAddress: '0xSepoliaBridgeContract' },
522
+ sourceChain: { contractAddress: '0xSepoliaBridgeContract' },
499
523
  pod: { contractAddress: '0xPodBridgeContract' }
500
524
  };
501
525
 
502
- const actionClient = new PodToBridgedActionClient(actionConfig);
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.bridged.rpcUrl);
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,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 bridgedProvider;
4
+ private readonly sourceChainProvider;
5
5
  private readonly podProvider;
6
- private readonly bridgedBridge;
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: Pick<BridgeRequest, 'isClaimed' | 'blockNumber'>): Promise<boolean>;
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.bridgedProvider = new ethers_1.ethers.JsonRpcProvider(config.sourceChain.rpcUrl);
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.bridgedBridge = new ethers_1.Contract(config.sourceChain.contractAddress, bridge_abi_1.POD_BRIDGE_ABI, this.bridgedProvider);
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;
53
+ await this.ensureChainIds();
27
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.bridgedProvider.getBlockNumber();
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.bridgedBridge.filters.Deposit(null, // id
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.bridgedBridge.filters.DepositNative(null, // id
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.bridgedBridge.queryFilter(depositFilter, start, end),
45
- this.bridgedBridge.queryFilter(depositNativeFilter, start, end)
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,18 +86,19 @@ class PodBridgeTrackerClient {
59
86
  if (parsed) {
60
87
  deposits.push({
61
88
  requestId: parsed.args.id.toString(),
62
- blockNumber: Number(parsed.args.blockNumber),
63
- timestamp: Number(parsed.args.timestamp),
64
- txHash: log.transactionHash,
65
- from: parsed.args.from,
66
- to: parsed.args.to,
67
- token: parsed.args.token,
68
- amount: parsed.args.amount.toString(),
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
- isClaimable: false,
71
- claimedTxHash: null,
72
- claimedAt: null,
73
- claimedBy: null
101
+ isClaimable: false
74
102
  });
75
103
  }
76
104
  }
@@ -83,25 +111,26 @@ class PodBridgeTrackerClient {
83
111
  if (parsed) {
84
112
  deposits.push({
85
113
  requestId: parsed.args.id.toString(),
86
- blockNumber: Number(parsed.args.blockNumber),
87
- timestamp: Number(parsed.args.timestamp),
88
- txHash: log.transactionHash,
89
- from: parsed.args.from,
90
- to: parsed.args.to,
91
- token: ethers_1.ethers.ZeroAddress, // Native token
92
- amount: parsed.args.amount.toString(),
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
+ },
93
125
  isClaimed: false,
94
- isClaimable: false,
95
- claimedTxHash: null,
96
- claimedAt: null,
97
- claimedBy: null
126
+ isClaimable: false
98
127
  });
99
128
  }
100
129
  }
101
130
  }
102
131
  // Check claim status (queries POD chain, not bridged)
103
132
  await this.updateClaimStatus(deposits);
104
- return deposits.sort((a, b) => b.timestamp - a.timestamp);
133
+ return deposits.sort((a, b) => b.deposit.timestamp - a.deposit.timestamp);
105
134
  }
106
135
  /**
107
136
  * Get all deposits RECEIVED by an address
@@ -111,24 +140,25 @@ class PodBridgeTrackerClient {
111
140
  */
112
141
  async getDepositsReceivedBy(address, fromBlock) {
113
142
  var _a;
143
+ await this.ensureChainIds();
114
144
  const startBlock = (_a = fromBlock !== null && fromBlock !== void 0 ? fromBlock : this.config.sourceChain.deploymentBlock) !== null && _a !== void 0 ? _a : 0;
115
145
  const deposits = [];
116
- const currentBlock = await this.bridgedProvider.getBlockNumber();
146
+ const currentBlock = await this.sourceChainProvider.getBlockNumber();
117
147
  const BLOCK_BATCH_SIZE = 10000;
118
148
  for (let start = startBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
119
149
  const end = Math.min(start + BLOCK_BATCH_SIZE - 1, currentBlock);
120
150
  // With improved events, we can filter by 'to' directly!
121
- const depositFilter = this.bridgedBridge.filters.Deposit(null, // id
151
+ const depositFilter = this.sourceChainBridge.filters.Deposit(null, // id
122
152
  null, // from
123
153
  address // to (indexed) - Filter by recipient!
124
154
  );
125
- const depositNativeFilter = this.bridgedBridge.filters.DepositNative(null, // id
155
+ const depositNativeFilter = this.sourceChainBridge.filters.DepositNative(null, // id
126
156
  null, // from
127
157
  address // to (indexed) - Filter by recipient!
128
158
  );
129
159
  const [depositLogs, depositNativeLogs] = await Promise.all([
130
- this.bridgedBridge.queryFilter(depositFilter, start, end),
131
- this.bridgedBridge.queryFilter(depositNativeFilter, start, end)
160
+ this.sourceChainBridge.queryFilter(depositFilter, start, end),
161
+ this.sourceChainBridge.queryFilter(depositNativeFilter, start, end)
132
162
  ]);
133
163
  // Add small delay to avoid rate limiting
134
164
  if (start + BLOCK_BATCH_SIZE <= currentBlock) {
@@ -143,18 +173,19 @@ class PodBridgeTrackerClient {
143
173
  if (parsed) {
144
174
  deposits.push({
145
175
  requestId: parsed.args.id.toString(),
146
- blockNumber: Number(parsed.args.blockNumber),
147
- timestamp: Number(parsed.args.timestamp),
148
- txHash: log.transactionHash,
149
- from: parsed.args.from,
150
- to: parsed.args.to,
151
- token: parsed.args.token,
152
- amount: parsed.args.amount.toString(),
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
+ },
153
187
  isClaimed: false,
154
- isClaimable: false,
155
- claimedTxHash: null,
156
- claimedAt: null,
157
- claimedBy: null
188
+ isClaimable: false
158
189
  });
159
190
  }
160
191
  }
@@ -167,25 +198,26 @@ class PodBridgeTrackerClient {
167
198
  if (parsed) {
168
199
  deposits.push({
169
200
  requestId: parsed.args.id.toString(),
170
- blockNumber: Number(parsed.args.blockNumber),
171
- timestamp: Number(parsed.args.timestamp),
172
- txHash: log.transactionHash,
173
- from: parsed.args.from,
174
- to: parsed.args.to,
175
- token: ethers_1.ethers.ZeroAddress,
176
- amount: parsed.args.amount.toString(),
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
+ },
177
212
  isClaimed: false,
178
- isClaimable: false,
179
- claimedTxHash: null,
180
- claimedAt: null,
181
- claimedBy: null
213
+ isClaimable: false
182
214
  });
183
215
  }
184
216
  }
185
217
  }
186
218
  // Check claim status (queries POD chain, not bridged)
187
219
  await this.updateClaimStatus(deposits);
188
- return deposits.sort((a, b) => b.timestamp - a.timestamp);
220
+ return deposits.sort((a, b) => b.deposit.timestamp - a.deposit.timestamp);
189
221
  }
190
222
  /**
191
223
  * Get ALL deposits for an address (both sent and received)
@@ -212,20 +244,20 @@ class PodBridgeTrackerClient {
212
244
  const allDeposits = [...sentWithType, ...receivedWithType];
213
245
  const uniqueDeposits = new Map();
214
246
  for (const deposit of allDeposits) {
215
- const key = `${deposit.requestId}-${deposit.txHash}`;
247
+ const key = `${deposit.requestId}-${deposit.deposit.txHash}`;
216
248
  if (!uniqueDeposits.has(key)) {
217
249
  uniqueDeposits.set(key, deposit);
218
250
  }
219
251
  else {
220
252
  // If deposit appears in both (sent to self), mark as both
221
253
  const existing = uniqueDeposits.get(key);
222
- if (existing.from === address && existing.to === address) {
254
+ if (existing.deposit.from === address && existing.deposit.to === address) {
223
255
  uniqueDeposits.set(key, { ...existing, type: pod_bridge_types_1.DepositType.SENT });
224
256
  }
225
257
  }
226
258
  }
227
259
  return Array.from(uniqueDeposits.values())
228
- .sort((a, b) => b.timestamp - a.timestamp);
260
+ .sort((a, b) => b.deposit.timestamp - a.deposit.timestamp);
229
261
  }
230
262
  /**
231
263
  * Check if deposits can be claimed (block finalized on source chain)
@@ -233,9 +265,9 @@ class PodBridgeTrackerClient {
233
265
  * @returns True if the deposit can be claimed
234
266
  */
235
267
  async canBeClaimed(deposit) {
236
- const currentBlock = await this.bridgedProvider.getBlockNumber();
268
+ const currentBlock = await this.sourceChainProvider.getBlockNumber();
237
269
  const finalizedBlock = currentBlock - 15; // ~15 minutes on Sepolia
238
- return deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
270
+ return deposit.deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
239
271
  }
240
272
  /**
241
273
  * Batch check claim status for multiple deposits
@@ -248,7 +280,7 @@ class PodBridgeTrackerClient {
248
280
  console.log('updateClaimStatus');
249
281
  try {
250
282
  // Get unique recipient addresses from deposits
251
- const uniqueRecipients = [...new Set(deposits.map(d => d.to))];
283
+ const uniqueRecipients = [...new Set(deposits.map(d => d.deposit.to))];
252
284
  console.log('Querying claims for recipients:', uniqueRecipients);
253
285
  // Get claim events from destination chain (POD) filtered by recipient addresses
254
286
  // Note: POD uses timestamps instead of traditional blocks
@@ -291,29 +323,34 @@ class PodBridgeTrackerClient {
291
323
  }
292
324
  }
293
325
  // Get current block to check finalization
294
- const currentBlock = await this.bridgedProvider.getBlockNumber();
326
+ const currentBlock = await this.sourceChainProvider.getBlockNumber();
295
327
  const finalizedBlock = currentBlock - 64; // 2 epoch (32 x 2 blocks) ~15 minutes on Sepolia
296
328
  // Update deposit status
297
329
  for (const deposit of deposits) {
298
330
  const claimInfo = claimedMap.get(deposit.requestId);
299
331
  if (claimInfo) {
300
332
  deposit.isClaimed = true;
301
- deposit.claimedTxHash = claimInfo.txHash;
302
- deposit.claimedAt = claimInfo.timestamp;
303
- deposit.claimedBy = claimInfo.claimer;
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
+ };
304
341
  }
305
342
  // Check if deposit is claimable (finalized and not claimed)
306
- deposit.isClaimable = deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
343
+ deposit.isClaimable = deposit.deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
307
344
  }
308
345
  }
309
346
  catch (error) {
310
347
  console.error('Error checking claim status:', error);
311
348
  // Fallback: Still calculate isClaimable based on finalization even if claim check fails
312
349
  try {
313
- const currentBlock = await this.bridgedProvider.getBlockNumber();
350
+ const currentBlock = await this.sourceChainProvider.getBlockNumber();
314
351
  const finalizedBlock = currentBlock - 64; // 2 epoch (32 x 2 blocks) ~15 minutes on Sepolia
315
352
  for (const deposit of deposits) {
316
- deposit.isClaimable = deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
353
+ deposit.isClaimable = deposit.deposit.blockNumber <= finalizedBlock && !deposit.isClaimed;
317
354
  }
318
355
  }
319
356
  catch (fallbackError) {
@@ -331,9 +368,9 @@ class PodBridgeTrackerClient {
331
368
  return [];
332
369
  try {
333
370
  const ids = deposits.map(d => d.requestId);
334
- const tokens = deposits.map(d => d.token);
335
- const amounts = deposits.map(d => d.amount);
336
- 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);
337
374
  return await this.podBridge.areRequestsProcessed(ids, tokens, amounts, tos);
338
375
  }
339
376
  catch (error) {
@@ -342,7 +379,7 @@ class PodBridgeTrackerClient {
342
379
  const results = [];
343
380
  for (const deposit of deposits) {
344
381
  try {
345
- 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);
346
383
  const isProcessed = await this.podBridge.processedRequests(hash);
347
384
  results.push(isProcessed);
348
385
  }
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { PodToSourceChainActionClient } from './clients/action/pod-to-source-cha
2
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, PodBridgeActionsClientConfig, PodBridgeChainConfig } 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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DepositType = exports.POD_BRIDGE_ABI = exports.PodBridgeTrackerClient = exports.SourceChainToPodActionClient = exports.PodToSourceChainActionClient = void 0;
3
+ exports.DepositType = exports.BridgeChain = exports.POD_BRIDGE_ABI = exports.PodBridgeTrackerClient = exports.SourceChainToPodActionClient = exports.PodToSourceChainActionClient = void 0;
4
4
  var pod_to_source_chain_client_1 = require("./clients/action/pod-to-source-chain-client");
5
5
  Object.defineProperty(exports, "PodToSourceChainActionClient", { enumerable: true, get: function () { return pod_to_source_chain_client_1.PodToSourceChainActionClient; } });
6
6
  var source_chain_to_pod_client_1 = require("./clients/action/source-chain-to-pod-client");
@@ -10,4 +10,5 @@ Object.defineProperty(exports, "PodBridgeTrackerClient", { enumerable: true, get
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; } });
@@ -20,20 +20,33 @@ export interface PodBridgeActionsClientConfig {
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
- blockNumber: number;
26
- timestamp: number;
27
- txHash: string;
28
- from: string;
29
- to: string;
30
- token: string;
31
- amount: string;
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 | null;
35
- claimedAt: number | null;
36
- claimedBy: string | null;
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapforce/pod-bridge-sdk",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "SDK for interacting with Bridges between pod and other chains",
5
5
  "keywords": [
6
6
  "pod",