@agglayer/sdk 1.0.0-beta.17 → 1.0.0-beta.19

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
@@ -3,349 +3,644 @@
3
3
  [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg?style=flat-square)](https://opensource.org/licenses/ISC)
4
4
  [![TypeScript](https://img.shields.io/badge/TypeScript-4.9+-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
5
5
  [![Node.js](https://img.shields.io/badge/Node.js-18+-green?style=flat-square&logo=node.js)](https://nodejs.org/)
6
- [![Bun](https://img.shields.io/badge/Bun-1.0+-black?style=flat-square&logo=bun)](https://bun.sh/)
6
+ [![NPM Version](https://img.shields.io/npm/v/@agglayer/sdk?style=flat-square)](https://www.npmjs.com/package/@agglayer/sdk)
7
7
 
8
- A comprehensive TypeScript SDK for interacting with AggLayer's ARC API and blockchain operations. Built with modular architecture, type safety, and developer experience in mind.
8
+ A comprehensive TypeScript SDK for interacting with the AggLayer ecosystem, providing seamless integration with ARC API services and blockchain operations. Engineered with enterprise-grade architecture, **flexible zero-config setup**, strict type safety, and exceptional developer experience.
9
9
 
10
10
  ## 🚀 Quick Start
11
11
 
12
12
  ### Installation
13
13
 
14
14
  ```bash
15
- # Install latest stable version
15
+ # Production (stable) - NOT YET AVAILABLE
16
16
  npm install @agglayer/sdk
17
17
 
18
- # Install beta version (for testing)
18
+ # Beta (testing)
19
19
  npm install @agglayer/sdk@beta
20
-
21
- # Install alpha version (experimental)
22
- npm install @agglayer/sdk@alpha
23
20
  ```
24
21
 
25
22
  ### Basic Usage
26
23
 
27
24
  ```typescript
28
- import { AggLayerSDK } from '@agglayer/sdk';
25
+ import { AggLayerSDK, SDK_MODES } from '@agglayer/sdk';
29
26
 
30
- // Initialize SDK with default Core module
27
+ // 🎯 NEW: Flexible Configuration - Zero setup required!
28
+ // No configuration needed - uses intelligent defaults
31
29
  const sdk = new AggLayerSDK();
32
- ```
33
-
34
- ## 📋 Release Channels
35
-
36
- | Channel | Description | Stability | Usage |
37
- | -------- | -------------------------------- | ------------------- | --------------------------------- |
38
- | `latest` | Stable releases (v1.0.0, v2.0.0) | ✅ Production Ready | `npm install @agglayer/sdk` |
39
- | `beta` | Beta releases (v1.0.0-beta.1) | ⚠️ Testing | `npm install @agglayer/sdk@beta` |
40
- | `alpha` | Alpha releases (v1.0.0-alpha.1) | 🚧 Experimental | `npm install @agglayer/sdk@alpha` |
41
- | `dev` | Development releases | 🔧 Development | `npm install @agglayer/sdk@dev` |
42
30
 
43
- ## 🏗️ Architecture
44
-
45
- The SDK is built with a modular architecture supporting two main modules:
46
-
47
- ### Core Module
31
+ // Or explicitly configure modes and settings
32
+ const sdkWithConfig = new AggLayerSDK({
33
+ mode: [SDK_MODES.CORE, SDK_MODES.NATIVE],
34
+ core: {
35
+ apiBaseUrl: 'https://api.agglayer.com',
36
+ apiTimeout: 30000,
37
+ },
38
+ native: {
39
+ defaultNetwork: 1, // Ethereum mainnet
40
+ },
41
+ });
48
42
 
49
- - **ARC API Integration**: Interact with AggLayer's REST API
50
- - **Chain Metadata**: Retrieve supported chains and tokens
51
- - **Route Discovery**: Find optimal bridging routes
52
- - **Transaction Building**: Build complex multi-step transactions
43
+ // Access modules
44
+ const core = sdk.getCore();
45
+ const native = sdkWithConfig.getNative();
46
+ ```
53
47
 
54
- ### Native Module
48
+ ## Usage Examples
55
49
 
56
- - **ERC20 Operations**: Token balance, transfers, approvals
57
- - **Bridge Operations**: Cross-chain bridge interactions
58
- - **Multi-Chain Support**: Work with multiple blockchain networks
59
- - **Raw Wei Handling**: All amounts returned as unformatted Wei strings
50
+ ### Core Module - ARC API Operations
60
51
 
61
- ## 📖 Usage Examples
52
+ The Core module provides high-level abstractions for AggLayer's ARC API, enabling route discovery, transaction building, and chain metadata management.
62
53
 
63
- ### Core Module - API Operations
54
+ #### Chain & Token Metadata
64
55
 
65
56
  ```typescript
66
- // Get Core client
67
57
  const core = sdk.getCore();
68
58
 
69
- // Retrieve all supported chains
59
+ // Retrieve metadata for all supported chains
70
60
  const chains = await core.getAllChains();
71
- console.log('Supported chains:', chains);
61
+ console.log(`Found ${chains.chains.length} supported chains`);
72
62
 
73
- // Get chain metadata for specific networks
63
+ // Get specific chain metadata by Chain ID
74
64
  const chainData = await core.getChainMetadataByChainIds([1, 137, 11155111]);
75
65
  console.log('Chain metadata:', chainData);
76
66
 
77
- // Find bridging routes
67
+ // Get all tokens grouped by Chain (expensive operation - use sparingly)
68
+ const allTokens = await core.getAllTokens();
69
+
70
+ // Recommended: Get chain data with tokens for specific chains
71
+ const chainTokenData = await core.getChainDataAndTokensByChainIds([1, 137]);
72
+
73
+ // NOTE: All above functions manage pagination internally
74
+ ```
75
+
76
+ #### Route Discovery & Transaction Building
77
+
78
+ ```typescript
79
+ // Find optimal bridging routes
78
80
  const routes = await core.getRoutes({
79
- fromChainId: 1,
80
- toChainId: 137,
81
+ fromChainId: 1, // Ethereum Mainnet
82
+ toChainId: 137, // Polygon
81
83
  fromTokenAddress: '0xA0b86a33E6441b8c4C8C0e4b8c4C8C0e4b8c4C8C0',
82
84
  toTokenAddress: '0xB0b86a33E6441b8c4C8C0e4b8c4C8C0e4b8c4C8C0',
83
85
  amount: '1000000000000000000', // 1 token in wei
84
- fromAddress: '0x1234567890123456789012345678901234567890',
86
+ fromAddress: '0x2254E4D1B41F2Dd3969a79b994E6ee8C3C6F2C71',
87
+ slippage: 0.5, // 0.5% slippage tolerance
85
88
  });
86
89
 
87
- // Build transaction from route steps
88
- const transaction = await core.buildTransaction({
89
- steps: routes.steps,
90
- fromAddress: '0x1234567890123456789012345678901234567890',
90
+ // Get unsigned transaction from route
91
+ const unsignedTx = await core.getUnsignedTransaction(routes);
92
+ console.log('Transaction data:', unsignedTx.data);
93
+
94
+ // Build claim transaction for completed bridge
95
+ const claimTx = await core.getClaimUnsignedTransaction({
96
+ sourceNetworkId: 1,
97
+ depositCount: 12345,
98
+ });
99
+ ```
100
+
101
+ > NOTE: `getClaimUnsignedTransaction()` expects Agglayer Network ID, not Chain ID
102
+
103
+ #### Transaction History & Monitoring
104
+
105
+ ```typescript
106
+ // Get transaction history with pagination
107
+ const transactions = await core.getTransactions({
108
+ limit: 50,
109
+ startAfter: 'nextStartAfterCursor', // cursor-based pagination
91
110
  });
111
+
112
+ console.log(`Retrieved ${transactions.transactions.length} transactions`);
92
113
  ```
93
114
 
94
115
  ### Native Module - Blockchain Operations
95
116
 
117
+ The Native module provides direct blockchain interaction capabilities with agglayer chains.
118
+ Majority of interaction will happen via the `ERC20` class
119
+
120
+ #### Network & Balance Management
121
+
96
122
  ```typescript
97
- // Get Native client
98
123
  const native = sdk.getNative();
99
124
 
100
- // Get native token balance
125
+ const chainDetails = getNetwork(1);
126
+ // Get native token balance (ETH, MATIC, etc.)
101
127
  const nativeBalance = await native.getNativeBalance(
102
- '0x1234567890123456789012345678901234567890',
103
- 11155111 // Sepolia
128
+ '0xFromAddress12345678901234567890123456789012345',
129
+ 1
104
130
  );
105
- console.log('Native balance (wei):', nativeBalance);
131
+ console.log(`ETH balance: ${nativeBalance} wei`);
106
132
 
107
- // Create ERC20 instance
108
- const erc20 = native.erc20(
109
- '0x1234567890123456789012345678901234567890', // USDC on Sepolia
133
+ // Access chain registry for network information
134
+ const chainRegistry = native.getChainRegistry();
135
+ const ethereumConfig = chainRegistry.getChain(1);
136
+ const ethereumConfig = native.getNetwork(1); // OR for convinence
137
+ console.log(`RPC URL: ${sepoliaConfig.rpcUrl}`);
138
+ ```
139
+
140
+ #### ERC20 Token Operations (balance, approve, transfer)
141
+
142
+ ```typescript
143
+ // Create ERC20 instance for USDC on Sepolia
144
+ const usdc = native.erc20(
145
+ '0x44499312f493F62f2DFd3C6435Ca3603EbFCeeBa',
110
146
  11155111
111
147
  );
112
148
 
113
- // Get ERC20 token balance
114
- const tokenBalance = await erc20.getBalance(
115
- '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd'
149
+ // Read operations
150
+ const balance = await usdc.getBalance(
151
+ '0xFromAddress12345678901234567890123456789012345'
152
+ );
153
+ const allowance = await usdc.getAllowance(
154
+ '0xFromAddress12345678901234567890123456789012345', // owner
155
+ '0x1234567890123456789012345678901234567890' // spender
156
+ );
157
+
158
+ // Build approve transaction (not executed)
159
+ const approveTx = await usdc.buildApprove(
160
+ '0xSpenderAddress1234567890123456789012345678901', // spender
161
+ '1000000', // 1 USDC allowance
162
+ '0xFromAddress12345678901234567890123456789012345' // from
116
163
  );
117
- console.log('Token balance (wei):', tokenBalance);
118
164
 
119
- // Build transfer transaction
120
- const transferTx = await erc20.buildTransfer(
121
- '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd', // recipient
122
- '1000000000', // 1000 USDC (6 decimals) in wei
123
- '0x1111111111111111111111111111111111111111' // from address
165
+ // Build transaction parameters (not executed)
166
+ const transferTx = await usdc.buildTransfer(
167
+ '0xRecipientAddress123456789012345678901234567890',
168
+ '1000000', // 1 USDC (6 decimals)
169
+ '0xFromAddress12345678901234567890123456789012345' // from
124
170
  );
125
171
 
126
- // Build approval transaction
127
- const approvalTx = await erc20.buildApprove(
128
- '0x2222222222222222222222222222222222222222', // spender
129
- '1000000000', // amount in wei
130
- '0x1111111111111111111111111111111111111111' // from address
172
+ // Build transferFrom transaction
173
+ const transferFromTx = await usdc.buildTransferFrom(
174
+ '0xFromAddress12345678901234567890123456789012345', // from
175
+ '0xToAddress1234567890123456789012345678901234567', // to
176
+ '500000', // 0.5 USDC
177
+ '0xFromAddress12345678901234567890123456789012345' // spender
131
178
  );
132
179
  ```
133
180
 
134
- ### Bridge Operations
181
+ #### Cross-Chain Bridge Operations
135
182
 
136
183
  ```typescript
137
- // Create bridge instance
184
+ // Direct token bridging via ERC20 instance
185
+ const bridgeTx = await usdc.bridgeTo(
186
+ 137, // Polygon destination
187
+ '0xRecipientOnPolygon1234567890123456789012345678',
188
+ '1000000', // 1 USDC
189
+ '0xFromAddress12345678901234567890123456789012345', // from
190
+ {
191
+ forceUpdateGlobalExitRoot: true,
192
+ permitData: '0x', // optional permit data
193
+ }
194
+ );
195
+
196
+ // Advanced bridge operations via Bridge instance
138
197
  const bridge = native.bridge(
139
- '0x3333333333333333333333333333333333333333', // bridge contract
198
+ '0x528e26b25a34a4A5d0dbDa1d57D318153d2ED582', // bridge contract
140
199
  11155111 // Sepolia
141
200
  );
142
201
 
143
- // Build bridge transaction
144
- const bridgeTx = await bridge.buildBridgeTransaction({
145
- toChainId: 137, // Polygon
146
- tokenAddress: '0x1234567890123456789012345678901234567890',
147
- amount: '1000000000',
148
- recipient: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
149
- fromAddress: '0x1111111111111111111111111111111111111111',
202
+ // Build bridge asset transaction
203
+ const bridgeAssetTx = await bridge.buildBridgeAsset(
204
+ {
205
+ destinationNetwork: 137,
206
+ destinationAddress: '0xRecipientAddress123456789012345678901234567890',
207
+ amount: '1000000000000000000', // 1 token in wei
208
+ token: '0x44499312f493F62f2DFd3C6435Ca3603EbFCeeBa',
209
+ forceUpdateGlobalExitRoot: true,
210
+ },
211
+ '0xFromAddress12345678901234567890123456789012345'
212
+ );
213
+
214
+ // Build claim transaction from bridge tx hash
215
+ const claimAssetTx = await bridge.buildClaimAssetFromHash(
216
+ '0xBridgeTxHash123456789012345678901234567890123456789012345678',
217
+ 11155111, // source network where bridge tx occurred
218
+ 0, // bridge event index in tx (usually 0)
219
+ '0xFromAddress12345678901234567890123456789012345' // claimer address
220
+ );
221
+
222
+ // Check if bridge deposit is already claimed
223
+ const isClaimed = await bridge.isClaimed({
224
+ leafIndex: 12345,
225
+ sourceBridgeNetwork: 11155111,
226
+ });
227
+
228
+ // Get wrapped token address on destination chain
229
+ const wrappedToken = await bridge.getWrappedTokenAddress({
230
+ originNetwork: 11155111,
231
+ originTokenAddress: '0x44499312f493F62f2DFd3C6435Ca3603EbFCeeBa',
150
232
  });
151
233
  ```
152
234
 
235
+ #### Bridge Message Operations
236
+
237
+ ```typescript
238
+ // Build bridge message transaction (for arbitrary data)
239
+ const bridgeMessageTx = await bridge.buildBridgeMessage(
240
+ {
241
+ destinationNetwork: 137,
242
+ destinationAddress: '0xRecipientContract123456789012345678901234567',
243
+ forceUpdateGlobalExitRoot: true,
244
+ metadata: '0x1234', // arbitrary data payload
245
+ },
246
+ '0xFromAddress12345678901234567890123456789012345'
247
+ );
248
+
249
+ // Build claim message transaction from bridge tx hash
250
+ const claimMessageTx = await bridge.buildClaimMessageFromHash(
251
+ '0xBridgeMessageTxHash12345678901234567890123456789012345678901234',
252
+ 11155111, // source network
253
+ 0, // message event index
254
+ '0xFromAddress12345678901234567890123456789012345' // claimer
255
+ );
256
+ ```
257
+
153
258
  ## ⚙️ Configuration
154
259
 
155
- ### SDK Configuration
260
+ ### SDK Configuration Options
261
+
262
+ The SDK provides comprehensive configuration capabilities for both modules with sensible defaults and extensive customization options.
263
+
264
+ #### Complete Configuration Example
156
265
 
157
266
  ```typescript
158
267
  import { AggLayerSDK, SDK_MODES } from '@agglayer/sdk';
159
268
 
160
269
  const sdk = new AggLayerSDK({
161
- mode: [SDK_MODES.CORE, SDK_MODES.NATIVE], // Enable both modules
270
+ // Module Selection - Choose which modules to enable
271
+ mode: [SDK_MODES.CORE, SDK_MODES.NATIVE],
272
+
273
+ // Core Module Configuration
162
274
  core: {
163
- apiBaseUrl: 'https://api.agglayer.com',
164
- apiTimeout: 30000, // 30 seconds
275
+ // ARC API Configuration
276
+ apiBaseUrl: 'https://api.agglayer.com', // Default: 'https://api.agglayer.com'
277
+ apiTimeout: 30000, // Default: 30000 (30 seconds)
278
+ // Implementation pending for websocket
279
+ // websocketBaseUrl: 'wss://ws.agglayer.com', // Optional: For transactions history
165
280
  },
281
+
282
+ // Native Module Configuration
166
283
  native: {
167
- defaultNetwork: 11155111, // Default chain ID
284
+ // Default network for operations
285
+ defaultNetwork: 1, // Default: 1 (Ethereum)
286
+
287
+ // Custom chain configurations
168
288
  chains: [
169
289
  {
170
- id: 1,
290
+ chainId: 1,
291
+ networkId: 1,
171
292
  name: 'Ethereum Mainnet',
172
- rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/your-key',
173
- nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
293
+ rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
294
+ nativeCurrency: {
295
+ name: 'Ether',
296
+ symbol: 'ETH',
297
+ decimals: 18,
298
+ },
299
+ blockExplorer: {
300
+ name: 'Etherscan',
301
+ url: 'https://etherscan.io',
302
+ },
303
+ bridgeAddress: '0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe',
304
+ proofApiUrl: 'https://proof-api.polygonzkevmchain.com',
305
+ isTestnet: false,
174
306
  },
175
307
  {
176
- id: 137,
177
- name: 'Polygon',
178
- rpcUrl: 'https://polygon-rpc.com',
179
- nativeCurrency: { name: 'MATIC', symbol: 'MATIC', decimals: 18 },
308
+ chainId: 137,
309
+ networkId: 137,
310
+ name: 'Polygon Mainnet',
311
+ rpcUrl: 'https://polygon-mainnet.g.alchemy.com/v2/your-api-key',
312
+ nativeCurrency: {
313
+ name: 'MATIC',
314
+ symbol: 'MATIC',
315
+ decimals: 18,
316
+ },
317
+ bridgeAddress: '0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe',
318
+ isTestnet: false,
180
319
  },
181
320
  ],
321
+
322
+ // Override RPC URLs for existing chains
182
323
  customRpcUrls: {
183
- 1: 'https://your-custom-eth-rpc.com',
184
- 137: 'https://your-custom-polygon-rpc.com',
324
+ 1: 'https://your-premium-ethereum-rpc.com',
325
+ 137: 'https://your-premium-polygon-rpc.com',
326
+ 11155111: 'https://sepolia.infura.io/v3/your-project-id',
185
327
  },
186
328
  },
187
329
  });
188
330
  ```
189
331
 
190
- ### Module-Specific Usage
332
+ #### Core Module Configuration
191
333
 
192
334
  ```typescript
193
- // Core-only configuration
194
- const coreOnlySdk = new AggLayerSDK({
335
+ interface CoreConfig {
336
+ apiBaseUrl?: string; // ARC API base URL
337
+ apiTimeout?: number; // Request timeout in milliseconds
338
+ // websocketBaseUrl?: string; // WebSocket endpoint for real-time updates
339
+ }
340
+ ```
341
+
342
+ **Default Values:**
343
+
344
+ - `apiBaseUrl`: `'https://arc-api.polygon.technology'`
345
+ - `apiTimeout`: `30000` (30 seconds)
346
+
347
+ #### Native Module Configuration
348
+
349
+ ```typescript
350
+ interface NativeConfig {
351
+ defaultNetwork?: number; // Default chain ID for operations
352
+ chains?: ChainConfig[]; // Custom chain configurations
353
+ customRpcUrls?: Record<number, string>; // Override RPC URLs by chain ID
354
+ }
355
+
356
+ interface ChainConfig {
357
+ chainId: number; // EIP-155 chain identifier
358
+ networkId: number; // Network identifier (usually same as chainId)
359
+ name: string; // Human-readable chain name
360
+ rpcUrl: string; // RPC endpoint URL
361
+ nativeCurrency: {
362
+ // Native token configuration
363
+ name: string;
364
+ symbol: string;
365
+ decimals: number;
366
+ };
367
+ blockExplorer?: {
368
+ // Optional block explorer
369
+ name: string;
370
+ url: string;
371
+ };
372
+ bridgeAddress?: string; // Bridge contract address
373
+ proofApiUrl?: string; // Proof generation API endpoint
374
+ isTestnet?: boolean; // Network type flag
375
+ isLocal?: boolean; // Local development network flag
376
+ }
377
+ ```
378
+
379
+ **Default Values:**
380
+
381
+ - `defaultNetwork`: `1` (Ethereum mainnet)
382
+ - `chains`: Built-in registry with major networks
383
+ - `customRpcUrls`: `{}`
384
+
385
+ ### Module-Specific Configurations
386
+
387
+ #### Core-Only Setup (API Integration)
388
+
389
+ ```typescript
390
+ const coreOnlySDK = new AggLayerSDK({
195
391
  mode: [SDK_MODES.CORE],
196
392
  core: {
197
393
  apiBaseUrl: 'https://api.agglayer.com',
394
+ apiTimeout: 45000, // Increased timeout for complex operations
395
+ // websocketBaseUrl: 'wss://ws.agglayer.com'
198
396
  },
199
- native: {} as any, // Required but unused
200
397
  });
201
398
 
202
- // Native-only configuration
203
- const nativeOnlySdk = new AggLayerSDK({
399
+ const core = coreOnlySDK.getCore();
400
+ ```
401
+
402
+ #### Native-Only Setup (Blockchain Operations)
403
+
404
+ ```typescript
405
+ const nativeOnlySDK = new AggLayerSDK({
204
406
  mode: [SDK_MODES.NATIVE],
205
- core: {} as any, // Required but unused
206
407
  native: {
207
- defaultNetwork: 11155111,
208
- chains: [
209
- /* your chains */
210
- ],
408
+ defaultNetwork: 1, // Ethereum Mainnet
409
+ customRpcUrls: {
410
+ 1: 'https://eth-mainnet.g.alchemy.com/v2/your-key',
411
+ 137: 'https://polygon-mainnet.g.alchemy.com/v2/your-key',
412
+ },
211
413
  },
212
414
  });
415
+
416
+ const native = nativeOnlySDK.getNative();
213
417
  ```
214
418
 
215
- ## 🚀 Release Process
419
+ #### Environment-Specific Configurations
216
420
 
217
- The SDK uses a tag-based release workflow for all releases:
421
+ ```typescript
422
+ // Development Configuration
423
+ const devConfig = {
424
+ mode: [SDK_MODES.CORE, SDK_MODES.NATIVE],
425
+ core: {
426
+ apiBaseUrl: 'http://localhost:3001', // Local development server
427
+ apiTimeout: 10000,
428
+ },
429
+ native: {
430
+ defaultNetwork: 11155111, // Sepolia testnet
431
+ customRpcUrls: {
432
+ 11155111: 'http://localhost:8545', // Local Ethereum fork
433
+ },
434
+ },
435
+ };
218
436
 
219
- ### **Tag-Based Releases**
437
+ // Production Configuration
438
+ const prodConfig = {
439
+ mode: [SDK_MODES.CORE, SDK_MODES.NATIVE],
440
+ core: {
441
+ apiBaseUrl: 'https://api.agglayer.com',
442
+ apiTimeout: 30000,
443
+ },
444
+ native: {
445
+ defaultNetwork: 1, // Ethereum Mainnet
446
+ customRpcUrls: {
447
+ 1: process.env.ETHEREUM_RPC_URL,
448
+ 137: process.env.POLYGON_RPC_URL,
449
+ },
450
+ },
451
+ };
220
452
 
221
- ```bash
222
- # Create and push a tag to trigger release
223
- git tag v1.0.0-beta.1
224
- git push origin v1.0.0-beta.1
453
+ // Use environment-appropriate config
454
+ const config = process.env.NODE_ENV === 'production' ? prodConfig : devConfig;
455
+ const sdk = new AggLayerSDK(config);
225
456
  ```
226
457
 
227
- ### **Manual Releases**
458
+ ### Built-in Chain Registry
228
459
 
229
- 1. Go to GitHub Actions "Tag Release"
230
- 2. Choose release type and channel
231
- 3. Click "Run workflow"
460
+ The SDK includes a comprehensive registry of popular networks:
232
461
 
233
- ### **Release Types**
462
+ - **Ethereum Mainnet** (Chain ID: 1)
463
+ - **Katana** (Chain ID: 747474)
464
+ - **Sepolia Testnet** (Chain ID: 11155111)
465
+ <!-- - **Bokuto Testnet** (Chain ID: 2442) -->
234
466
 
235
- - **Stable**: `v1.0.0` `latest` channel
236
- - **Beta**: `v1.0.0-beta.1` → `beta` channel
237
- - **Alpha**: `v1.0.0-alpha.1` → `alpha` channel
238
- - **Dev**: `v1.0.0-dev.1` → `dev` channel
467
+ Additional networks can be added via the `chains` configuration option.
239
468
 
240
- ## 🔧 Development
469
+ ## 🔧 Architecture & Design Principles
241
470
 
242
- ### Prerequisites
471
+ The SDK employs a **modular microservice architecture** with strict separation of concerns:
243
472
 
244
- - Node.js 18+
245
- - npm or bun
473
+ ### Core Module (`SDK_MODES.CORE`)
246
474
 
247
- ### Setup
475
+ Core module primarily supports the features based on ARC API
248
476
 
249
- ```bash
250
- # Clone the repository
251
- git clone https://github.com/agglayer/sdk.git
252
- cd sdk
477
+ - **Chain Registry**: Comprehensive chain management
478
+ - **Route Discovery**: Intelligently find routes for bridging, across agglayer bridge and other aggregators
479
+ - **Transaction Orchestration**: Prepare unsigned executable transactions based on routes
480
+ - **Transactions Activity and History**: Track status of transactions to perform aadditional functions like claim or view history of transactions.
253
481
 
254
- # Install dependencies
255
- npm install
482
+ ### Native Module (`SDK_MODES.NATIVE`)
256
483
 
257
- # Build the project
258
- npm run build
259
- ```
484
+ Interact with blockchain and agglayer bridge directly, this does not involve any additional APIs(except for proof generation)
260
485
 
261
- ### Available Scripts
486
+ - **ERC20 Token Operations**: Standards-compliant token interactions(getBalance, getAllowance, buildApprove, etc)
487
+ - **Bridge Infrastructure**: Cross-chain asset transfer protocols (like bridgeTo, claimAsset, etc via ERC20 interface)
262
488
 
263
- | Script | Description |
264
- | ----------------------- | ----------------------------------- |
265
- | `npm run build` | Build the library for production |
266
- | `npm run dev` | Build in watch mode for development |
267
- | `npm run test` | Run test suite |
268
- | `npm run test:coverage` | Run tests with coverage report |
269
- | `npm run test:watch` | Run tests in watch mode |
270
- | `npm run lint` | Run ESLint |
271
- | `npm run lint:fix` | Fix ESLint issues automatically |
272
- | `npm run format` | Format code with Prettier |
273
- | `npm run format:check` | Check code formatting |
274
- | `npm run typecheck` | Type check with TypeScript |
489
+ ### Key Design Principles
275
490
 
276
- ### Testing
491
+ - **Type-First Development**: 100% TypeScript with strict mode enabled
492
+ - **Flexible Configuration**: Zero-config defaults with progressive customization
493
+ - **Immutable Data Structures**: Predictable state management
494
+ - **Error-First Callbacks**: Comprehensive error handling patterns
495
+ - **Smart Defaults**: Intelligent fallbacks that work out-of-the-box
496
+ - **Modular Loading**: Tree-shakeable imports for optimized bundles
277
497
 
278
- ```bash
279
- # Run all tests
280
- npm run test
498
+ ## � Release Channels & Versioning
499
+
500
+ The SDK follows semantic versioning with multiple release channels for different stability requirements:
501
+
502
+ | Channel | Description | Stability | Installation | Use Case |
503
+ | -------- | -------------------------- | ------------------- | --------------------------------- | ------------------------------- |
504
+ | `latest` | Stable production releases | ✅ Production Ready | `npm install @agglayer/sdk` | Production applications |
505
+ | `beta` | Release candidates | ⚠️ Testing | `npm install @agglayer/sdk@beta` | Pre-production testing |
506
+ | `alpha` | Early feature previews | 🚧 Experimental | `npm install @agglayer/sdk@alpha` | Feature development |
507
+ | `dev` | Internal use | 🔧 Development | `npm install @agglayer/sdk@dev` | SDK development & bleeding edge |
508
+
509
+ ### Release Strategy
510
+
511
+ - **Stable releases** (`v1.0.0`, `v2.0.0`): Thoroughly tested, API-stable versions
512
+ - **Beta releases** (`v1.0.0-beta.1`): Feature-complete candidates with minimal changes expected
513
+ - **Alpha releases** (`v1.0.0-alpha.1`): Early access to new features, API may change
514
+ - **Dev releases** (`v1.0.0-dev.1`): Internal use
515
+
516
+ ## Quick Reference
517
+
518
+ ### Common Configuration Patterns
519
+
520
+ ```typescript
521
+ // Development with testnet
522
+ const devSdk = new AggLayerSDK({
523
+ mode: [SDK_MODES.CORE, SDK_MODES.NATIVE],
524
+ core: {
525
+ apiBaseUrl: 'https://api-testnet.agglayer.com',
526
+ },
527
+ native: {
528
+ defaultNetwork: 11155111, // Sepolia testnet
529
+ },
530
+ });
281
531
 
282
- # Run tests with coverage
283
- npm run test:coverage
532
+ // Production with custom timeouts
533
+ const prodSdk = new AggLayerSDK({
534
+ core: {
535
+ apiTimeout: 60000, // 60 second timeout
536
+ },
537
+ });
284
538
 
285
- # Run tests in watch mode
286
- npm run test:watch
539
+ // Multi-chain setup
540
+ const multiChainSdk = new AggLayerSDK({
541
+ mode: [SDK_MODES.NATIVE],
542
+ native: {
543
+ defaultNetwork: 1,
544
+ customRpcUrls: {
545
+ 1: 'https://ethereum-mainnet.infura.io/v3/YOUR_KEY',
546
+ 137: 'https://polygon-mainnet.infura.io/v3/YOUR_KEY',
547
+ 42161: 'https://arbitrum-mainnet.infura.io/v3/YOUR_KEY',
548
+ },
549
+ },
550
+ });
287
551
  ```
288
552
 
289
- ## 🎯 Key Features
553
+ ## 🔧 Development & Contributing
290
554
 
291
- ### Type Safety
555
+ ### Prerequisites
556
+
557
+ - **Node.js** 18+ or **Bun** 1.0+
558
+ - **TypeScript** 4.9+
559
+ - **Git** for version control
292
560
 
293
- - Full TypeScript support with strict configuration
294
- - Comprehensive type definitions for all operations
295
- - IntelliSense support for better developer experience
561
+ ### Local Development Setup
562
+
563
+ ```bash
564
+ # Clone the repository
565
+ git clone https://github.com/agglayer/sdk.git
566
+ cd sdk
296
567
 
297
- ### Modular Design
568
+ # Install dependencies (npm, yarn, or bun)
569
+ npm install
570
+ # or
571
+ bun install
298
572
 
299
- - **Core Module**: ARC API integration for route discovery and transaction building
300
- - **Native Module**: Direct blockchain interactions for ERC20 and bridge operations
301
- - Flexible configuration allowing module-specific usage
573
+ # Build the project
574
+ npm run build
302
575
 
303
- ### Multi-Chain Support
576
+ # Start development mode with hot reload
577
+ npm run dev
578
+ ```
304
579
 
305
- - Built-in support for major EVM chains
306
- - Custom chain configuration
307
- - Custom RPC URL support
308
- - Chain registry for easy network management
580
+ ### Available Development Scripts
309
581
 
310
- ### Raw Wei Handling
582
+ | Script | Description | Usage |
583
+ | ----------------------- | ------------------------------------------ | ------------------------------------- |
584
+ | `npm run build` | Production build with optimizations | CI/CD and release preparation |
585
+ | `npm run dev` | Development build with watch mode | Local development with hot reload |
586
+ | `npm run typecheck` | TypeScript type checking without emit | Validate types before commits |
587
+ | `npm run test` | Run complete test suite | Continuous testing during development |
588
+ | `npm run test:run` | Single test run without watch | CI/CD pipeline testing |
589
+ | `npm run test:coverage` | Generate test coverage reports | Quality assurance metrics |
590
+ | `npm run test:watch` | Interactive test runner with file watching | TDD development workflow |
591
+ | `npm run lint` | ESLint code quality analysis | Code style enforcement |
592
+ | `npm run lint:fix` | Auto-fix ESLint issues | Automated code style corrections |
593
+ | `npm run format` | Prettier code formatting | Consistent code style across codebase |
594
+ | `npm run format:check` | Validate code formatting | CI/CD formatting verification |
595
+ | `npm run clean` | Remove build artifacts | Clean slate rebuilds |
311
596
 
312
- - All token amounts returned as unformatted Wei strings
313
- - No automatic decimal conversion for precision control
314
- - Consistent number formatting across all operations
597
+ ## 🚨 Error Handling & Debugging
315
598
 
316
- ### Lightweight & Efficient
599
+ ### Comprehensive Error Types
317
600
 
318
- - Minimal dependencies (only viem for blockchain interactions)
319
- - Tree-shakeable modules
320
- - Optimized bundle size
601
+ The SDK provides detailed error information for all failure scenarios:
321
602
 
322
- ## 🤝 Contributing
603
+ ```typescript
604
+ try {
605
+ const routes = await core.getRoutes({
606
+ fromChainId: 1,
607
+ toChainId: 137,
608
+ fromTokenAddress: '0xinvalid',
609
+ toTokenAddress: '0x...',
610
+ amount: '1000000000000000000',
611
+ fromAddress: '0x...',
612
+ });
613
+ } catch (error) {
614
+ if (error instanceof ValidationError) {
615
+ console.error('Input validation failed:', error.message);
616
+ console.error('Field:', error.field);
617
+ console.error('Value:', error.value);
618
+ } else if (error instanceof NetworkError) {
619
+ console.error('Network request failed:', error.message);
620
+ console.error('Status:', error.status);
621
+ console.error('Endpoint:', error.url);
622
+ } else if (error instanceof ContractError) {
623
+ console.error('Contract interaction failed:', error.message);
624
+ console.error('Contract:', error.address);
625
+ console.error('Function:', error.functionName);
626
+ }
627
+ }
628
+ ```
323
629
 
324
- We welcome contributions! Please follow these steps:
630
+ ## 📈 Roadmap & Future Development
325
631
 
326
- 1. **Fork the repository**
327
- 2. **Create a feature branch**: `git checkout -b feature/your-feature-name`
328
- 3. **Make your changes** following our coding standards
329
- 4. **Run tests**: `npm run test`
330
- 5. **Run linting**: `npm run lint`
331
- 6. **Format code**: `npm run format`
332
- 7. **Submit a pull request**
632
+ ### Upcoming Features
333
633
 
334
- ### Code Quality Standards
634
+ - User input validations
635
+ - Runtime api response validation using zod
636
+ - WebSocket support for real-time updates of transactions and their status
335
637
 
336
- - **TypeScript**: Strict type checking enabled
337
- - **ESLint**: Enforced code quality rules
338
- - **Prettier**: Consistent code formatting
339
- - **Vitest**: Comprehensive test coverage
340
- - **Husky**: Pre-commit hooks for quality assurance
638
+ ---
341
639
 
342
- ## 📄 License
640
+ <div align="center">
343
641
 
344
- ISC License - see [LICENSE](LICENSE) file for details.
642
+ **Built with ❤️ by the AggLayer Team**
345
643
 
346
- ## 🔗 Links
644
+ [⭐ Star us on GitHub](https://github.com/agglayer/sdk) • [🐛 Report Issues](https://github.com/agglayer/sdk/issues)
347
645
 
348
- - [GitHub Repository](https://github.com/agglayer/sdk)
349
- - [NPM Package](https://www.npmjs.com/package/@agglayer/sdk)
350
- - [Documentation](https://docs.agglayer.com)
351
- - [Issues](https://github.com/agglayer/sdk/issues)
646
+ </div>