@tapforce/pod-bridge-sdk 1.0.3 → 1.1.1

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
@@ -34,7 +34,8 @@ pnpm add @tapforce/pod-bridge-sdk
34
34
 
35
35
  ```typescript
36
36
  import {
37
- PodBridgeActionClient,
37
+ BridgedToPodActionClient,
38
+ PodToBridgedActionClient,
38
39
  PodBridgeTrackerClient,
39
40
  PodBridgeConfig
40
41
  } from '@tapforce/pod-bridge-sdk';
@@ -48,97 +49,122 @@ Create a configuration object with source and destination chain details:
48
49
  const config: PodBridgeConfig = {
49
50
  bridged: {
50
51
  rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY',
51
- 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)
52
54
  },
53
55
  pod: {
54
56
  rpcUrl: 'https://pod-rpc.example.com',
55
- contractAddress: '0x...' // Destination chain bridge contract
57
+ contractAddress: '0x...', // Destination chain bridge contract
58
+ deploymentBlock: 0 // Optional: POD deployment block
56
59
  }
57
60
  };
58
61
  ```
59
62
 
60
63
  ## Usage
61
64
 
62
- ### 1. Action Client - Creating Transactions
65
+ ### 1. Action Clients - Creating Transactions
63
66
 
64
- The `PodBridgeActionClient` creates unsigned transactions that you can sign and broadcast.
67
+ The SDK provides two action clients for different bridge directions:
65
68
 
66
- #### Deposit ERC20 Tokens
69
+ - **`BridgedToPodActionClient`**: For Bridged → POD transfers (e.g., Sepolia → POD)
70
+ - **`PodToBridgedActionClient`**: For POD → Bridged transfers (e.g., POD → Sepolia)
71
+
72
+ #### Configuration for Action Clients
67
73
 
68
74
  ```typescript
69
- const actionClient = new PodBridgeActionClient();
75
+ const actionConfig = {
76
+ bridged: {
77
+ contractAddress: '0x...' // Bridged chain bridge contract (e.g., Sepolia)
78
+ },
79
+ pod: {
80
+ contractAddress: '0x...' // POD chain bridge contract
81
+ }
82
+ };
70
83
 
71
- // Create unsigned transaction for ERC20 deposit
72
- const unsignedTx = actionClient.depositToken({
84
+ const bridgedToPodClient = new BridgedToPodActionClient(actionConfig);
85
+ const podToBridgedClient = new PodToBridgedActionClient(actionConfig);
86
+ ```
87
+
88
+ #### Deposit from Bridged Chain (e.g., Sepolia → POD)
89
+
90
+ ```typescript
91
+ // Create unsigned transaction for ERC20 deposit on Bridged chain
92
+ const unsignedTx = bridgedToPodClient.depositToken({
73
93
  token: '0x...', // ERC20 token address
74
94
  amount: '1000000000000000000', // Amount in wei (1 token with 18 decimals)
75
- recipient: '0x...', // Recipient address on destination chain
76
- contractAddress: config.source.contractAddress,
95
+ destinationWalletAddress: '0x...', // Recipient address on POD
77
96
  from: '0x...' // Optional: sender address
78
97
  });
79
98
 
80
- // Sign and send transaction using your wallet/provider
81
- // const tx = await signer.sendTransaction(unsignedTx);
82
- ```
83
-
84
- #### Deposit Native Tokens (ETH)
85
-
86
- ```typescript
87
- // Create unsigned transaction for native token deposit
88
- const unsignedTx = actionClient.depositNative({
99
+ // Deposit native tokens
100
+ const unsignedNativeTx = bridgedToPodClient.depositNative({
89
101
  amount: '1000000000000000000', // Amount in wei (1 ETH)
90
- recipient: '0x...', // Recipient address on destination chain
91
- contractAddress: config.source.contractAddress,
102
+ destinationWalletAddress: '0x...', // Recipient address on POD
92
103
  from: '0x...' // Optional: sender address
93
104
  });
94
105
 
95
- // Sign and send transaction
106
+ // Sign and send transaction using your wallet/provider
96
107
  // const tx = await signer.sendTransaction(unsignedTx);
97
108
  ```
98
109
 
99
- #### Claim Tokens (with Certificate) - Sepolia from POD
110
+ #### Claim on POD from Bridged Chain Deposits
100
111
 
101
- For claiming on Sepolia from POD deposits, use certificate-based claims. First, get the certified log from the POD deposit transaction:
112
+ For claiming on POD from Bridged chain deposits, use block number-based claims:
102
113
 
103
114
  ```typescript
104
- // Get certified log from POD deposit transaction
105
- const depositTxHash = '0x...'; // Transaction hash of deposit on POD
106
- const certifiedLog = await trackerClient.getDepositCertifiedLog(depositTxHash);
107
-
108
- // Create unsigned claim transaction for ERC20
109
- const unsignedTx = actionClient.claimWithCertificate({
110
- certifiedLog,
111
- contractAddress: config.bridged.contractAddress, // Sepolia bridge contract
115
+ // Create unsigned claim transaction for ERC20 on POD
116
+ const unsignedTx = bridgedToPodClient.claimWithBlockNumber({
117
+ id: '123', // Request ID from deposit event
118
+ token: '0x...', // Token address on source chain
119
+ blockNumber: 12345678, // Block number of deposit on source chain
112
120
  from: '0x...' // Optional: claimer address
113
121
  });
114
122
 
115
123
  // For native tokens
116
- const unsignedNativeTx = actionClient.claimNativeWithCertificate({
117
- certifiedLog,
118
- contractAddress: config.bridged.contractAddress,
124
+ const unsignedNativeTx = bridgedToPodClient.claimNativeWithBlockNumber({
125
+ id: '123',
126
+ blockNumber: 12345678,
119
127
  from: '0x...'
120
128
  });
121
129
  ```
122
130
 
123
- #### Claim Tokens (with Block Number) - POD from Sepolia
131
+ #### Deposit from POD (POD Bridged Chain)
124
132
 
125
- For claiming on POD from Sepolia deposits, use block number-based claims:
133
+ ```typescript
134
+ // Create unsigned transaction for ERC20 deposit on POD
135
+ const unsignedTx = podToBridgedClient.depositToken({
136
+ token: '0x...', // ERC20 token address
137
+ amount: '1000000000000000000', // Amount in wei
138
+ destinationWalletAddress: '0x...', // Recipient address on Bridged chain
139
+ from: '0x...' // Optional: sender address
140
+ });
141
+
142
+ // Deposit native tokens
143
+ const unsignedNativeTx = podToBridgedClient.depositNative({
144
+ amount: '1000000000000000000',
145
+ destinationWalletAddress: '0x...',
146
+ from: '0x...'
147
+ });
148
+ ```
149
+
150
+ #### Claim on Bridged Chain from POD Deposits
151
+
152
+ For claiming on Bridged chain from POD deposits, use certificate-based claims. First, get the certified log from the POD deposit transaction:
126
153
 
127
154
  ```typescript
128
- // Create unsigned claim transaction for ERC20
129
- const unsignedTx = actionClient.claimWithBlockNumber({
130
- id: '123', // Request ID from deposit event
131
- token: '0x...', // Token address on source chain
132
- blockNumber: 12345678, // Block number of deposit on source chain
133
- contractAddress: config.destination.contractAddress,
155
+ // Get certified log from POD deposit transaction
156
+ const depositTxHash = '0x...'; // Transaction hash of deposit on POD
157
+ const certifiedLog = await trackerClient.getDepositCertifiedLog(depositTxHash);
158
+
159
+ // Create unsigned claim transaction for ERC20 on Bridged chain
160
+ const unsignedTx = podToBridgedClient.claimWithCertificate({
161
+ certifiedLog,
134
162
  from: '0x...' // Optional: claimer address
135
163
  });
136
164
 
137
165
  // For native tokens
138
- const unsignedNativeTx = actionClient.claimNativeWithBlockNumber({
139
- id: '123',
140
- blockNumber: 12345678,
141
- contractAddress: config.destination.contractAddress,
166
+ const unsignedNativeTx = podToBridgedClient.claimNativeWithCertificate({
167
+ certifiedLog,
142
168
  from: '0x...'
143
169
  });
144
170
  ```
@@ -224,44 +250,69 @@ processedStatuses.forEach((isProcessed, index) => {
224
250
 
225
251
  ## API Reference
226
252
 
227
- ### PodBridgeActionClient
253
+ ### BridgedToPodActionClient
254
+
255
+ Handles transactions for Bridged → POD direction.
256
+
257
+ #### Constructor
258
+
259
+ ```typescript
260
+ new BridgedToPodActionClient(config: PodBridgeActionsClientConfig)
261
+ ```
228
262
 
229
263
  #### Methods
230
264
 
231
- - **`depositToken(args)`**: Create unsigned transaction for ERC20 deposit
265
+ - **`depositToken(args)`**: Create unsigned transaction for ERC20 deposit on Bridged chain
232
266
  - `token`: Token address
233
267
  - `amount`: Amount in wei (string | bigint)
234
- - `recipient`: Recipient address on destination chain
235
- - `contractAddress`: Bridge contract address
268
+ - `destinationWalletAddress`: Recipient address on POD
236
269
  - `from?`: Optional sender address
237
270
 
238
- - **`depositNative(args)`**: Create unsigned transaction for native token deposit
271
+ - **`depositNative(args)`**: Create unsigned transaction for native token deposit on Bridged chain
239
272
  - `amount`: Amount in wei (string | bigint)
240
- - `recipient`: Recipient address on destination chain
241
- - `contractAddress`: Bridge contract address
273
+ - `destinationWalletAddress`: Recipient address on POD
242
274
  - `from?`: Optional sender address
243
275
 
244
- - **`claimWithCertificate(args)`**: Create unsigned transaction for claiming with certificate
245
- - `certifiedLog`: Certified log from POD certificate system
246
- - `contractAddress`: Bridge contract address
276
+ - **`claimWithBlockNumber(args)`**: Create unsigned transaction for claiming on POD with block number
277
+ - `id`: Request ID
278
+ - `token`: Token address
279
+ - `blockNumber`: Block number of deposit on Bridged chain
247
280
  - `from?`: Optional claimer address
248
281
 
249
- - **`claimNativeWithCertificate(args)`**: Create unsigned transaction for claiming native tokens with certificate
250
- - `certifiedLog`: Certified log from POD certificate system
251
- - `contractAddress`: Bridge contract address
282
+ - **`claimNativeWithBlockNumber(args)`**: Create unsigned transaction for claiming native tokens on POD with block number
283
+ - `id`: Request ID
284
+ - `blockNumber`: Block number of deposit on Bridged chain
252
285
  - `from?`: Optional claimer address
253
286
 
254
- - **`claimWithBlockNumber(args)`**: Create unsigned transaction for claiming with block number
255
- - `id`: Request ID
287
+ ### PodToBridgedActionClient
288
+
289
+ Handles transactions for POD → Bridged direction.
290
+
291
+ #### Constructor
292
+
293
+ ```typescript
294
+ new PodToBridgedActionClient(config: PodBridgeActionsClientConfig)
295
+ ```
296
+
297
+ #### Methods
298
+
299
+ - **`depositToken(args)`**: Create unsigned transaction for ERC20 deposit on POD
256
300
  - `token`: Token address
257
- - `blockNumber`: Block number of deposit
258
- - `contractAddress`: Bridge contract address
301
+ - `amount`: Amount in wei (string | bigint)
302
+ - `destinationWalletAddress`: Recipient address on Bridged chain
303
+ - `from?`: Optional sender address
304
+
305
+ - **`depositNative(args)`**: Create unsigned transaction for native token deposit on POD
306
+ - `amount`: Amount in wei (string | bigint)
307
+ - `destinationWalletAddress`: Recipient address on Bridged chain
308
+ - `from?`: Optional sender address
309
+
310
+ - **`claimWithCertificate(args)`**: Create unsigned transaction for claiming on Bridged chain with certificate
311
+ - `certifiedLog`: Certified log from POD certificate system
259
312
  - `from?`: Optional claimer address
260
313
 
261
- - **`claimNativeWithBlockNumber(args)`**: Create unsigned transaction for claiming native tokens with block number
262
- - `id`: Request ID
263
- - `blockNumber`: Block number of deposit
264
- - `contractAddress`: Bridge contract address
314
+ - **`claimNativeWithCertificate(args)`**: Create unsigned transaction for claiming native tokens on Bridged chain with certificate
315
+ - `certifiedLog`: Certified log from POD certificate system
265
316
  - `from?`: Optional claimer address
266
317
 
267
318
  ### PodBridgeTrackerClient
@@ -365,10 +416,10 @@ The SDK supports two bridge implementations:
365
416
 
366
417
  ```typescript
367
418
  import { ethers } from 'ethers';
368
- import { PodBridgeActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
419
+ import { BridgedToPodActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
369
420
 
370
421
  // Setup
371
- const config = {
422
+ const trackerConfig = {
372
423
  bridged: {
373
424
  rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY',
374
425
  contractAddress: '0xSepoliaBridgeContract'
@@ -379,17 +430,21 @@ const config = {
379
430
  }
380
431
  };
381
432
 
382
- const actionClient = new PodBridgeActionClient();
383
- const trackerClient = new PodBridgeTrackerClient(config);
384
- const sepoliaProvider = new ethers.JsonRpcProvider(config.bridged.rpcUrl);
433
+ const actionConfig = {
434
+ bridged: { contractAddress: '0xSepoliaBridgeContract' },
435
+ pod: { contractAddress: '0xPodBridgeContract' }
436
+ };
437
+
438
+ const actionClient = new BridgedToPodActionClient(actionConfig);
439
+ const trackerClient = new PodBridgeTrackerClient(trackerConfig);
440
+ const sepoliaProvider = new ethers.JsonRpcProvider(trackerConfig.bridged.rpcUrl);
385
441
  const sepoliaSigner = new ethers.Wallet('PRIVATE_KEY', sepoliaProvider);
386
442
 
387
443
  // Step 1: Deposit tokens on Sepolia
388
444
  const depositTx = actionClient.depositToken({
389
445
  token: '0xTokenAddress',
390
446
  amount: ethers.parseEther('10').toString(),
391
- destinationWalletAddress: await sepoliaSigner.getAddress(),
392
- contractAddress: config.bridged.contractAddress
447
+ destinationWalletAddress: await sepoliaSigner.getAddress()
393
448
  });
394
449
 
395
450
  const tx = await sepoliaSigner.sendTransaction(depositTx);
@@ -409,12 +464,11 @@ if (canClaim) {
409
464
  const claimTx = actionClient.claimWithBlockNumber({
410
465
  id: latestDeposit.requestId,
411
466
  token: latestDeposit.token,
412
- blockNumber: latestDeposit.blockNumber,
413
- contractAddress: config.pod.contractAddress
467
+ blockNumber: latestDeposit.blockNumber
414
468
  });
415
469
 
416
470
  // Submit claim on POD
417
- const podProvider = new ethers.JsonRpcProvider(config.pod.rpcUrl);
471
+ const podProvider = new ethers.JsonRpcProvider(trackerConfig.pod.rpcUrl);
418
472
  const podSigner = new ethers.Wallet('PRIVATE_KEY', podProvider);
419
473
  const claim = await podSigner.sendTransaction(claimTx);
420
474
  await claim.wait();
@@ -426,10 +480,10 @@ if (canClaim) {
426
480
 
427
481
  ```typescript
428
482
  import { ethers } from 'ethers';
429
- import { PodBridgeActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
483
+ import { PodToBridgedActionClient, PodBridgeTrackerClient } from '@tapforce/pod-bridge-sdk';
430
484
 
431
485
  // Setup
432
- const config = {
486
+ const trackerConfig = {
433
487
  bridged: {
434
488
  rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY',
435
489
  contractAddress: '0xSepoliaBridgeContract'
@@ -440,17 +494,21 @@ const config = {
440
494
  }
441
495
  };
442
496
 
443
- const actionClient = new PodBridgeActionClient();
444
- const trackerClient = new PodBridgeTrackerClient(config);
445
- const podProvider = new ethers.JsonRpcProvider(config.pod.rpcUrl);
497
+ const actionConfig = {
498
+ bridged: { contractAddress: '0xSepoliaBridgeContract' },
499
+ pod: { contractAddress: '0xPodBridgeContract' }
500
+ };
501
+
502
+ const actionClient = new PodToBridgedActionClient(actionConfig);
503
+ const trackerClient = new PodBridgeTrackerClient(trackerConfig);
504
+ const podProvider = new ethers.JsonRpcProvider(trackerConfig.pod.rpcUrl);
446
505
  const podSigner = new ethers.Wallet('PRIVATE_KEY', podProvider);
447
506
 
448
507
  // Step 1: Deposit tokens on POD
449
508
  const depositTx = actionClient.depositToken({
450
509
  token: '0xTokenAddress',
451
510
  amount: ethers.parseEther('10').toString(),
452
- destinationWalletAddress: await podSigner.getAddress(),
453
- contractAddress: config.pod.contractAddress
511
+ destinationWalletAddress: await podSigner.getAddress()
454
512
  });
455
513
 
456
514
  const tx = await podSigner.sendTransaction(depositTx);
@@ -463,11 +521,10 @@ console.log('Got certified log with attestations');
463
521
 
464
522
  // Step 3: Claim on Sepolia using certified log
465
523
  const claimTx = actionClient.claimWithCertificate({
466
- certifiedLog,
467
- contractAddress: config.bridged.contractAddress
524
+ certifiedLog
468
525
  });
469
526
 
470
- const sepoliaProvider = new ethers.JsonRpcProvider(config.bridged.rpcUrl);
527
+ const sepoliaProvider = new ethers.JsonRpcProvider(trackerConfig.bridged.rpcUrl);
471
528
  const sepoliaSigner = new ethers.Wallet('PRIVATE_KEY', sepoliaProvider);
472
529
  const claim = await sepoliaSigner.sendTransaction(claimTx);
473
530
  await claim.wait();
@@ -1,7 +1,8 @@
1
- import { UnsignedTransaction, CertifiedLog } from "../../libs/types/pod-bridge.types";
2
- export declare class PodBridgeActionClient {
1
+ import { UnsignedTransaction, PodBridgeActionsClientConfig } from "../../libs/types/pod-bridge.types";
2
+ export declare class BridgedToPodActionClient {
3
+ private readonly config;
3
4
  private readonly iface;
4
- constructor();
5
+ constructor(config: PodBridgeActionsClientConfig);
5
6
  /**
6
7
  * Create unsigned transaction for depositing ERC20 tokens
7
8
  * @param args.token Token address to deposit
@@ -15,7 +16,6 @@ export declare class PodBridgeActionClient {
15
16
  token: string;
16
17
  amount: string | bigint;
17
18
  destinationWalletAddress: string;
18
- contractAddress: string;
19
19
  from?: string;
20
20
  }): UnsignedTransaction;
21
21
  /**
@@ -29,33 +29,6 @@ export declare class PodBridgeActionClient {
29
29
  depositNative(args: {
30
30
  amount: string | bigint;
31
31
  destinationWalletAddress: string;
32
- contractAddress: string;
33
- from?: string;
34
- }): UnsignedTransaction;
35
- /**
36
- * Create unsigned transaction for claiming tokens (BridgeDepositWithdraw - with certificates)
37
- * Used for claiming on Sepolia from POD deposits
38
- * @param args.certifiedLog Certified log from POD certificate system
39
- * @param args.contractAddress Bridge contract address (destination chain)
40
- * @param args.from Optional sender address
41
- * @returns Unsigned transaction template with encoded claim call
42
- */
43
- claimWithCertificate(args: {
44
- certifiedLog: CertifiedLog;
45
- contractAddress: string;
46
- from?: string;
47
- }): UnsignedTransaction;
48
- /**
49
- * Create unsigned transaction for claiming native tokens (BridgeDepositWithdraw - with certificates)
50
- * Used for claiming native tokens on Sepolia from POD deposits
51
- * @param args.certifiedLog Certified log from POD certificate system
52
- * @param args.contractAddress Bridge contract address (destination chain)
53
- * @param args.from Optional sender address
54
- * @returns Unsigned transaction template with encoded claimNative call
55
- */
56
- claimNativeWithCertificate(args: {
57
- certifiedLog: CertifiedLog;
58
- contractAddress: string;
59
32
  from?: string;
60
33
  }): UnsignedTransaction;
61
34
  /**
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PodBridgeActionClient = void 0;
3
+ exports.BridgedToPodActionClient = void 0;
4
4
  const ethers_1 = require("ethers");
5
5
  const bridge_abi_1 = require("../../libs/abi/bridge.abi");
6
- class PodBridgeActionClient {
7
- constructor() {
6
+ class BridgedToPodActionClient {
7
+ constructor(config) {
8
+ this.config = config;
8
9
  this.iface = new ethers_1.Interface(bridge_abi_1.POD_BRIDGE_ABI);
9
10
  }
10
11
  /**
@@ -23,7 +24,7 @@ class PodBridgeActionClient {
23
24
  args.destinationWalletAddress
24
25
  ]);
25
26
  return {
26
- to: args.contractAddress,
27
+ to: this.config.bridged.contractAddress,
27
28
  data,
28
29
  value: '0',
29
30
  from: args === null || args === void 0 ? void 0 : args.from
@@ -40,46 +41,12 @@ class PodBridgeActionClient {
40
41
  depositNative(args) {
41
42
  const data = this.iface.encodeFunctionData('depositNative', [args.destinationWalletAddress]);
42
43
  return {
43
- to: args.contractAddress,
44
+ to: this.config.bridged.contractAddress,
44
45
  data,
45
46
  value: args.amount.toString(),
46
47
  from: args === null || args === void 0 ? void 0 : args.from
47
48
  };
48
49
  }
49
- /**
50
- * Create unsigned transaction for claiming tokens (BridgeDepositWithdraw - with certificates)
51
- * Used for claiming on Sepolia from POD deposits
52
- * @param args.certifiedLog Certified log from POD certificate system
53
- * @param args.contractAddress Bridge contract address (destination chain)
54
- * @param args.from Optional sender address
55
- * @returns Unsigned transaction template with encoded claim call
56
- */
57
- claimWithCertificate(args) {
58
- const data = this.iface.encodeFunctionData('claim', [args.certifiedLog]);
59
- return {
60
- to: args.contractAddress,
61
- data,
62
- value: '0',
63
- from: args === null || args === void 0 ? void 0 : args.from
64
- };
65
- }
66
- /**
67
- * Create unsigned transaction for claiming native tokens (BridgeDepositWithdraw - with certificates)
68
- * Used for claiming native tokens on Sepolia from POD deposits
69
- * @param args.certifiedLog Certified log from POD certificate system
70
- * @param args.contractAddress Bridge contract address (destination chain)
71
- * @param args.from Optional sender address
72
- * @returns Unsigned transaction template with encoded claimNative call
73
- */
74
- claimNativeWithCertificate(args) {
75
- const data = this.iface.encodeFunctionData('claimNative', [args.certifiedLog]);
76
- return {
77
- to: args.contractAddress,
78
- data,
79
- value: '0',
80
- from: args === null || args === void 0 ? void 0 : args.from
81
- };
82
- }
83
50
  /**
84
51
  * Create unsigned transaction for claiming tokens (BridgeMintBurn - using precompiles)
85
52
  * Used for claiming on POD from Sepolia deposits
@@ -97,7 +64,7 @@ class PodBridgeActionClient {
97
64
  args.blockNumber
98
65
  ]);
99
66
  return {
100
- to: args.contractAddress,
67
+ to: this.config.pod.contractAddress,
101
68
  data,
102
69
  value: '0',
103
70
  from: args === null || args === void 0 ? void 0 : args.from
@@ -115,11 +82,11 @@ class PodBridgeActionClient {
115
82
  claimNativeWithBlockNumber(args) {
116
83
  const data = this.iface.encodeFunctionData('claimNative(uint256,uint256)', [args.id, args.blockNumber]);
117
84
  return {
118
- to: args.contractAddress,
85
+ to: this.config.pod.contractAddress,
119
86
  data,
120
87
  value: '0',
121
88
  from: args === null || args === void 0 ? void 0 : args.from
122
89
  };
123
90
  }
124
91
  }
125
- exports.PodBridgeActionClient = PodBridgeActionClient;
92
+ exports.BridgedToPodActionClient = BridgedToPodActionClient;
@@ -0,0 +1,54 @@
1
+ import { UnsignedTransaction, CertifiedLog, PodBridgeActionsClientConfig } from "../../libs/types/pod-bridge.types";
2
+ export declare class PodToBridgedActionClient {
3
+ private readonly config;
4
+ private readonly iface;
5
+ constructor(config: PodBridgeActionsClientConfig);
6
+ /**
7
+ * Create unsigned transaction for depositing ERC20 tokens from POD to Bridged chain
8
+ * @param args.token Token address to deposit
9
+ * @param args.amount Amount to deposit (in wei)
10
+ * @param args.destinationWalletAddress Recipient address on destination chain
11
+ * @param args.from Optional sender address
12
+ * @returns Unsigned transaction template with encoded deposit call
13
+ */
14
+ depositToken(args: {
15
+ token: string;
16
+ amount: string | bigint;
17
+ destinationWalletAddress: string;
18
+ from?: string;
19
+ }): UnsignedTransaction;
20
+ /**
21
+ * Create unsigned transaction for depositing native tokens from POD to Bridged chain
22
+ * @param args.amount Amount to deposit (in wei) - also set as transaction value
23
+ * @param args.destinationWalletAddress Recipient address on destination chain
24
+ * @param args.from Optional sender address
25
+ * @returns Unsigned transaction template with encoded depositNative call
26
+ */
27
+ depositNative(args: {
28
+ amount: string | bigint;
29
+ destinationWalletAddress: string;
30
+ from?: string;
31
+ }): UnsignedTransaction;
32
+ /**
33
+ * Create unsigned transaction for claiming tokens on Bridged chain (BridgeDepositWithdraw - with certificates)
34
+ * Used for claiming on Bridged chain from POD deposits
35
+ * @param args.certifiedLog Certified log from POD certificate system
36
+ * @param args.from Optional sender address
37
+ * @returns Unsigned transaction template with encoded claim call
38
+ */
39
+ claimWithCertificate(args: {
40
+ certifiedLog: CertifiedLog;
41
+ from?: string;
42
+ }): UnsignedTransaction;
43
+ /**
44
+ * Create unsigned transaction for claiming native tokens on Bridged chain (BridgeDepositWithdraw - with certificates)
45
+ * Used for claiming native tokens on Bridged chain from POD deposits
46
+ * @param args.certifiedLog Certified log from POD certificate system
47
+ * @param args.from Optional sender address
48
+ * @returns Unsigned transaction template with encoded claimNative call
49
+ */
50
+ claimNativeWithCertificate(args: {
51
+ certifiedLog: CertifiedLog;
52
+ from?: string;
53
+ }): UnsignedTransaction;
54
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PodToBridgedActionClient = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const bridge_abi_1 = require("../../libs/abi/bridge.abi");
6
+ class PodToBridgedActionClient {
7
+ constructor(config) {
8
+ this.config = config;
9
+ this.iface = new ethers_1.Interface(bridge_abi_1.POD_BRIDGE_ABI);
10
+ }
11
+ /**
12
+ * Create unsigned transaction for depositing ERC20 tokens from POD to Bridged chain
13
+ * @param args.token Token address to deposit
14
+ * @param args.amount Amount to deposit (in wei)
15
+ * @param args.destinationWalletAddress Recipient address on destination chain
16
+ * @param args.from Optional sender address
17
+ * @returns Unsigned transaction template with encoded deposit call
18
+ */
19
+ depositToken(args) {
20
+ const data = this.iface.encodeFunctionData('deposit', [
21
+ args.token,
22
+ args.amount,
23
+ args.destinationWalletAddress
24
+ ]);
25
+ return {
26
+ to: this.config.pod.contractAddress,
27
+ data,
28
+ value: '0',
29
+ from: args === null || args === void 0 ? void 0 : args.from
30
+ };
31
+ }
32
+ /**
33
+ * Create unsigned transaction for depositing native tokens from POD to Bridged chain
34
+ * @param args.amount Amount to deposit (in wei) - also set as transaction value
35
+ * @param args.destinationWalletAddress Recipient address on destination chain
36
+ * @param args.from Optional sender address
37
+ * @returns Unsigned transaction template with encoded depositNative call
38
+ */
39
+ depositNative(args) {
40
+ const data = this.iface.encodeFunctionData('depositNative', [args.destinationWalletAddress]);
41
+ return {
42
+ to: this.config.pod.contractAddress,
43
+ data,
44
+ value: args.amount.toString(),
45
+ from: args === null || args === void 0 ? void 0 : args.from
46
+ };
47
+ }
48
+ /**
49
+ * Create unsigned transaction for claiming tokens on Bridged chain (BridgeDepositWithdraw - with certificates)
50
+ * Used for claiming on Bridged chain from POD deposits
51
+ * @param args.certifiedLog Certified log from POD certificate system
52
+ * @param args.from Optional sender address
53
+ * @returns Unsigned transaction template with encoded claim call
54
+ */
55
+ claimWithCertificate(args) {
56
+ const data = this.iface.encodeFunctionData('claim', [args.certifiedLog]);
57
+ return {
58
+ to: this.config.bridged.contractAddress,
59
+ data,
60
+ value: '0',
61
+ from: args === null || args === void 0 ? void 0 : args.from
62
+ };
63
+ }
64
+ /**
65
+ * Create unsigned transaction for claiming native tokens on Bridged chain (BridgeDepositWithdraw - with certificates)
66
+ * Used for claiming native tokens on Bridged chain from POD deposits
67
+ * @param args.certifiedLog Certified log from POD certificate system
68
+ * @param args.from Optional sender address
69
+ * @returns Unsigned transaction template with encoded claimNative call
70
+ */
71
+ claimNativeWithCertificate(args) {
72
+ const data = this.iface.encodeFunctionData('claimNative', [args.certifiedLog]);
73
+ return {
74
+ to: this.config.bridged.contractAddress,
75
+ data,
76
+ value: '0',
77
+ from: args === null || args === void 0 ? void 0 : args.from
78
+ };
79
+ }
80
+ }
81
+ exports.PodToBridgedActionClient = PodToBridgedActionClient;
@@ -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 = 0) {
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 = fromBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
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,10 @@ class PodBridgeTrackerClient {
41
43
  this.bridgedBridge.queryFilter(depositFilter, start, end),
42
44
  this.bridgedBridge.queryFilter(depositNativeFilter, start, end)
43
45
  ]);
46
+ // Add small delay to avoid rate limiting
47
+ if (start + BLOCK_BATCH_SIZE <= currentBlock) {
48
+ await new Promise(resolve => setTimeout(resolve, 100));
49
+ }
44
50
  // Process Deposit events
45
51
  for (const log of depositLogs) {
46
52
  const parsed = this.iface.parseLog({
@@ -83,20 +89,22 @@ class PodBridgeTrackerClient {
83
89
  }
84
90
  }
85
91
  // Check claim status
86
- await this.updateClaimStatus(deposits);
92
+ await this.updateClaimStatus(deposits, startBlock);
87
93
  return deposits.sort((a, b) => b.timestamp - a.timestamp);
88
94
  }
89
95
  /**
90
96
  * Get all deposits RECEIVED by an address
91
97
  * @param address The address that will receive deposits
92
- * @param fromBlock Starting block number (default: 0)
98
+ * @param fromBlock Starting block number (default: contract deployment block or 0)
93
99
  * @returns Array of bridge requests sent to this address
94
100
  */
95
- async getDepositsReceivedBy(address, fromBlock = 0) {
101
+ async getDepositsReceivedBy(address, fromBlock) {
102
+ var _a;
103
+ const startBlock = (_a = fromBlock !== null && fromBlock !== void 0 ? fromBlock : this.config.bridged.deploymentBlock) !== null && _a !== void 0 ? _a : 0;
96
104
  const deposits = [];
97
105
  const currentBlock = await this.bridgedProvider.getBlockNumber();
98
106
  const BLOCK_BATCH_SIZE = 10000;
99
- for (let start = fromBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
107
+ for (let start = startBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
100
108
  const end = Math.min(start + BLOCK_BATCH_SIZE - 1, currentBlock);
101
109
  // With improved events, we can filter by 'to' directly!
102
110
  const depositFilter = this.bridgedBridge.filters.Deposit(null, // id
@@ -111,6 +119,10 @@ class PodBridgeTrackerClient {
111
119
  this.bridgedBridge.queryFilter(depositFilter, start, end),
112
120
  this.bridgedBridge.queryFilter(depositNativeFilter, start, end)
113
121
  ]);
122
+ // Add small delay to avoid rate limiting
123
+ if (start + BLOCK_BATCH_SIZE <= currentBlock) {
124
+ await new Promise(resolve => setTimeout(resolve, 100));
125
+ }
114
126
  // Process Deposit events
115
127
  for (const log of depositLogs) {
116
128
  const parsed = this.iface.parseLog({
@@ -153,16 +165,16 @@ class PodBridgeTrackerClient {
153
165
  }
154
166
  }
155
167
  // Check claim status
156
- await this.updateClaimStatus(deposits);
168
+ await this.updateClaimStatus(deposits, startBlock);
157
169
  return deposits.sort((a, b) => b.timestamp - a.timestamp);
158
170
  }
159
171
  /**
160
172
  * Get ALL deposits for an address (both sent and received)
161
173
  * @param address The address to check
162
- * @param fromBlock Starting block number (default: 0)
174
+ * @param fromBlock Starting block number (default: contract deployment block or 0)
163
175
  * @returns Array of bridge requests with type indicator
164
176
  */
165
- async getAllDepositsFor(address, fromBlock = 0) {
177
+ async getAllDepositsFor(address, fromBlock) {
166
178
  // Fetch both sent and received in parallel
167
179
  const [sent, received] = await Promise.all([
168
180
  this.getDepositsSentBy(address, fromBlock),
@@ -209,19 +221,37 @@ class PodBridgeTrackerClient {
209
221
  /**
210
222
  * Batch check claim status for multiple deposits
211
223
  * @param deposits Array of deposits to check
224
+ * @param fromBlock Starting block to query claims from
212
225
  */
213
- async updateClaimStatus(deposits) {
226
+ async updateClaimStatus(deposits, fromBlock) {
227
+ var _a;
214
228
  if (deposits.length === 0) {
215
229
  return;
216
230
  }
217
231
  try {
218
- // Get claim events from destination chain
232
+ const startBlock = (_a = fromBlock !== null && fromBlock !== void 0 ? fromBlock : this.config.pod.deploymentBlock) !== null && _a !== void 0 ? _a : 0;
233
+ const currentBlock = await this.podProvider.getBlockNumber();
234
+ const BLOCK_BATCH_SIZE = 10000;
235
+ const allClaimLogs = [];
236
+ const allClaimNativeLogs = [];
237
+ // Get claim events from destination chain in batches
219
238
  const claimFilter = this.podBridge.filters.Claim();
220
239
  const claimNativeFilter = this.podBridge.filters.ClaimNative();
221
- const [claimLogs, claimNativeLogs] = await Promise.all([
222
- this.podBridge.queryFilter(claimFilter),
223
- this.podBridge.queryFilter(claimNativeFilter)
224
- ]);
240
+ for (let start = startBlock; start <= currentBlock; start += BLOCK_BATCH_SIZE) {
241
+ const end = Math.min(start + BLOCK_BATCH_SIZE - 1, currentBlock);
242
+ const [claimLogs, claimNativeLogs] = await Promise.all([
243
+ this.podBridge.queryFilter(claimFilter, start, end),
244
+ this.podBridge.queryFilter(claimNativeFilter, start, end)
245
+ ]);
246
+ allClaimLogs.push(...claimLogs);
247
+ allClaimNativeLogs.push(...claimNativeLogs);
248
+ // Add small delay to avoid rate limiting
249
+ if (start + BLOCK_BATCH_SIZE <= currentBlock) {
250
+ await new Promise(resolve => setTimeout(resolve, 100));
251
+ }
252
+ }
253
+ const claimLogs = allClaimLogs;
254
+ const claimNativeLogs = allClaimNativeLogs;
225
255
  // Create a map of claimed request IDs
226
256
  const claimedMap = new Map();
227
257
  for (const log of [...claimLogs, ...claimNativeLogs]) {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { PodBridgeActionClient } from './clients/action/client';
1
+ export { PodToBridgedActionClient } from './clients/action/pod-to-bridged-client';
2
+ export { BridgedToPodActionClient } from './clients/action/bridged-to-pod-client';
2
3
  export { PodBridgeTrackerClient } from './clients/tracker/client';
3
4
  export { POD_BRIDGE_ABI } from './libs/abi/bridge.abi';
4
5
  export { PodBridgeConfig, BridgeRequest, BridgeRequestWithType, DepositType, UnsignedTransaction, CertifiedLog, PodAttestation, PodMetadata, PodTransactionReceipt, } from './libs/types/pod-bridge.types';
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DepositType = exports.POD_BRIDGE_ABI = exports.PodBridgeTrackerClient = exports.PodBridgeActionClient = void 0;
4
- var client_1 = require("./clients/action/client");
5
- Object.defineProperty(exports, "PodBridgeActionClient", { enumerable: true, get: function () { return client_1.PodBridgeActionClient; } });
6
- var client_2 = require("./clients/tracker/client");
7
- Object.defineProperty(exports, "PodBridgeTrackerClient", { enumerable: true, get: function () { return client_2.PodBridgeTrackerClient; } });
3
+ exports.DepositType = exports.POD_BRIDGE_ABI = exports.PodBridgeTrackerClient = exports.BridgedToPodActionClient = exports.PodToBridgedActionClient = void 0;
4
+ var pod_to_bridged_client_1 = require("./clients/action/pod-to-bridged-client");
5
+ Object.defineProperty(exports, "PodToBridgedActionClient", { enumerable: true, get: function () { return pod_to_bridged_client_1.PodToBridgedActionClient; } });
6
+ var bridged_to_pod_client_1 = require("./clients/action/bridged-to-pod-client");
7
+ Object.defineProperty(exports, "BridgedToPodActionClient", { enumerable: true, get: function () { return bridged_to_pod_client_1.BridgedToPodActionClient; } });
8
+ var client_1 = require("./clients/tracker/client");
9
+ Object.defineProperty(exports, "PodBridgeTrackerClient", { enumerable: true, get: function () { return client_1.PodBridgeTrackerClient; } });
8
10
  var bridge_abi_1 = require("./libs/abi/bridge.abi");
9
11
  Object.defineProperty(exports, "POD_BRIDGE_ABI", { enumerable: true, get: function () { return bridge_abi_1.POD_BRIDGE_ABI; } });
10
12
  var pod_bridge_types_1 = require("./libs/types/pod-bridge.types");
@@ -1,6 +1,7 @@
1
1
  export interface PodBridgeChainConfig {
2
2
  rpcUrl: string;
3
3
  contractAddress: string;
4
+ deploymentBlock?: number;
4
5
  }
5
6
  /**
6
7
  * Configuration for the bridge
@@ -11,6 +12,14 @@ export interface PodBridgeConfig {
11
12
  bridged: PodBridgeChainConfig;
12
13
  pod: PodBridgeChainConfig;
13
14
  }
15
+ export interface PodBridgeActionsClientConfig {
16
+ bridged: {
17
+ contractAddress: string;
18
+ };
19
+ pod: {
20
+ contractAddress: string;
21
+ };
22
+ }
14
23
  export interface BridgeRequest {
15
24
  requestId: string;
16
25
  blockNumber: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapforce/pod-bridge-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "description": "SDK for interacting with Bridges between pod and other chains",
5
5
  "keywords": [
6
6
  "pod",