@agglayer/sdk 1.0.0-beta.16 → 1.0.0-beta.18
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 +494 -199
- package/dist/index.d.mts +67 -9
- package/dist/index.d.ts +67 -9
- package/dist/index.js +236 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +235 -105
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,349 +3,644 @@
|
|
|
3
3
|
[](https://opensource.org/licenses/ISC)
|
|
4
4
|
[](https://www.typescriptlang.org/)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
|
-
[](https://www.npmjs.com/package/@agglayer/sdk)
|
|
7
7
|
|
|
8
|
-
A comprehensive TypeScript SDK for interacting with AggLayer
|
|
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
|
-
#
|
|
15
|
+
# Production (stable) - NOT YET AVAILABLE
|
|
16
16
|
npm install @agglayer/sdk
|
|
17
17
|
|
|
18
|
-
#
|
|
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
|
-
//
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
// Access modules
|
|
44
|
+
const core = sdk.getCore();
|
|
45
|
+
const native = sdkWithConfig.getNative();
|
|
46
|
+
```
|
|
53
47
|
|
|
54
|
-
|
|
48
|
+
## Usage Examples
|
|
55
49
|
|
|
56
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
61
|
+
console.log(`Found ${chains.chains.length} supported chains`);
|
|
72
62
|
|
|
73
|
-
// Get chain metadata
|
|
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
|
-
//
|
|
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: '
|
|
86
|
+
fromAddress: '0x2254E4D1B41F2Dd3969a79b994E6ee8C3C6F2C71',
|
|
87
|
+
slippage: 0.5, // 0.5% slippage tolerance
|
|
85
88
|
});
|
|
86
89
|
|
|
87
|
-
//
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
125
|
+
const chainDetails = getNetwork(1);
|
|
126
|
+
// Get native token balance (ETH, MATIC, etc.)
|
|
101
127
|
const nativeBalance = await native.getNativeBalance(
|
|
102
|
-
'
|
|
103
|
-
|
|
128
|
+
'0xFromAddress12345678901234567890123456789012345',
|
|
129
|
+
1
|
|
104
130
|
);
|
|
105
|
-
console.log(
|
|
131
|
+
console.log(`ETH balance: ${nativeBalance} wei`);
|
|
106
132
|
|
|
107
|
-
//
|
|
108
|
-
const
|
|
109
|
-
|
|
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
|
-
//
|
|
114
|
-
const
|
|
115
|
-
'
|
|
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
|
|
120
|
-
const transferTx = await
|
|
121
|
-
'
|
|
122
|
-
'
|
|
123
|
-
'
|
|
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
|
|
127
|
-
const
|
|
128
|
-
'
|
|
129
|
-
'
|
|
130
|
-
'
|
|
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
|
-
|
|
181
|
+
#### Cross-Chain Bridge Operations
|
|
135
182
|
|
|
136
183
|
```typescript
|
|
137
|
-
//
|
|
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
|
-
'
|
|
198
|
+
'0x528e26b25a34a4A5d0dbDa1d57D318153d2ED582', // bridge contract
|
|
140
199
|
11155111 // Sepolia
|
|
141
200
|
);
|
|
142
201
|
|
|
143
|
-
// Build bridge transaction
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
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
|
-
|
|
164
|
-
|
|
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
|
-
|
|
284
|
+
// Default network for operations
|
|
285
|
+
defaultNetwork: 1, // Default: 1 (Ethereum)
|
|
286
|
+
|
|
287
|
+
// Custom chain configurations
|
|
168
288
|
chains: [
|
|
169
289
|
{
|
|
170
|
-
|
|
290
|
+
chainId: 1,
|
|
291
|
+
networkId: 1,
|
|
171
292
|
name: 'Ethereum Mainnet',
|
|
172
|
-
rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/your-key',
|
|
173
|
-
nativeCurrency: {
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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-
|
|
184
|
-
137: 'https://your-
|
|
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
|
-
|
|
332
|
+
#### Core Module Configuration
|
|
191
333
|
|
|
192
334
|
```typescript
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
203
|
-
|
|
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:
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
419
|
+
#### Environment-Specific Configurations
|
|
216
420
|
|
|
217
|
-
|
|
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
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
###
|
|
458
|
+
### Built-in Chain Registry
|
|
228
459
|
|
|
229
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
## 🔧
|
|
469
|
+
## 🔧 Architecture & Design Principles
|
|
241
470
|
|
|
242
|
-
|
|
471
|
+
The SDK employs a **modular microservice architecture** with strict separation of concerns:
|
|
243
472
|
|
|
244
|
-
|
|
245
|
-
- npm or bun
|
|
473
|
+
### Core Module (`SDK_MODES.CORE`)
|
|
246
474
|
|
|
247
|
-
|
|
475
|
+
Core module primarily supports the features based on ARC API
|
|
248
476
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
255
|
-
npm install
|
|
482
|
+
### Native Module (`SDK_MODES.NATIVE`)
|
|
256
483
|
|
|
257
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
283
|
-
|
|
532
|
+
// Production with custom timeouts
|
|
533
|
+
const prodSdk = new AggLayerSDK({
|
|
534
|
+
core: {
|
|
535
|
+
apiTimeout: 60000, // 60 second timeout
|
|
536
|
+
},
|
|
537
|
+
});
|
|
284
538
|
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
##
|
|
553
|
+
## 🔧 Development & Contributing
|
|
290
554
|
|
|
291
|
-
###
|
|
555
|
+
### Prerequisites
|
|
556
|
+
|
|
557
|
+
- **Node.js** 18+ or **Bun** 1.0+
|
|
558
|
+
- **TypeScript** 4.9+
|
|
559
|
+
- **Git** for version control
|
|
292
560
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
568
|
+
# Install dependencies (npm, yarn, or bun)
|
|
569
|
+
npm install
|
|
570
|
+
# or
|
|
571
|
+
bun install
|
|
298
572
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
- Flexible configuration allowing module-specific usage
|
|
573
|
+
# Build the project
|
|
574
|
+
npm run build
|
|
302
575
|
|
|
303
|
-
|
|
576
|
+
# Start development mode with hot reload
|
|
577
|
+
npm run dev
|
|
578
|
+
```
|
|
304
579
|
|
|
305
|
-
|
|
306
|
-
- Custom chain configuration
|
|
307
|
-
- Custom RPC URL support
|
|
308
|
-
- Chain registry for easy network management
|
|
580
|
+
### Available Development Scripts
|
|
309
581
|
|
|
310
|
-
|
|
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
|
-
|
|
313
|
-
- No automatic decimal conversion for precision control
|
|
314
|
-
- Consistent number formatting across all operations
|
|
597
|
+
## 🚨 Error Handling & Debugging
|
|
315
598
|
|
|
316
|
-
###
|
|
599
|
+
### Comprehensive Error Types
|
|
317
600
|
|
|
318
|
-
|
|
319
|
-
- Tree-shakeable modules
|
|
320
|
-
- Optimized bundle size
|
|
601
|
+
The SDK provides detailed error information for all failure scenarios:
|
|
321
602
|
|
|
322
|
-
|
|
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
|
-
|
|
630
|
+
## 📈 Roadmap & Future Development
|
|
325
631
|
|
|
326
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
640
|
+
<div align="center">
|
|
343
641
|
|
|
344
|
-
|
|
642
|
+
**Built with ❤️ by the AggLayer Team**
|
|
345
643
|
|
|
346
|
-
|
|
644
|
+
[⭐ Star us on GitHub](https://github.com/agglayer/sdk) • [🐛 Report Issues](https://github.com/agglayer/sdk/issues)
|
|
347
645
|
|
|
348
|
-
|
|
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>
|