@agglayer/sdk 1.0.0-beta.19 → 1.0.0-beta.8
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 +199 -494
- package/dist/index.d.mts +26 -136
- package/dist/index.d.ts +26 -136
- package/dist/index.js +90 -317
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -316
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,644 +3,349 @@
|
|
|
3
3
|
[](https://opensource.org/licenses/ISC)
|
|
4
4
|
[](https://www.typescriptlang.org/)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
|
-
[](https://bun.sh/)
|
|
7
7
|
|
|
8
|
-
A comprehensive TypeScript SDK for interacting with
|
|
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.
|
|
9
9
|
|
|
10
10
|
## 🚀 Quick Start
|
|
11
11
|
|
|
12
12
|
### Installation
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
#
|
|
15
|
+
# Install latest stable version
|
|
16
16
|
npm install @agglayer/sdk
|
|
17
17
|
|
|
18
|
-
#
|
|
18
|
+
# Install beta version (for testing)
|
|
19
19
|
npm install @agglayer/sdk@beta
|
|
20
|
+
|
|
21
|
+
# Install alpha version (experimental)
|
|
22
|
+
npm install @agglayer/sdk@alpha
|
|
20
23
|
```
|
|
21
24
|
|
|
22
25
|
### Basic Usage
|
|
23
26
|
|
|
24
27
|
```typescript
|
|
25
|
-
import { AggLayerSDK
|
|
28
|
+
import { AggLayerSDK } from '@agglayer/sdk';
|
|
26
29
|
|
|
27
|
-
//
|
|
28
|
-
// No configuration needed - uses intelligent defaults
|
|
30
|
+
// Initialize SDK with default Core module
|
|
29
31
|
const sdk = new AggLayerSDK();
|
|
32
|
+
```
|
|
30
33
|
|
|
31
|
-
|
|
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
|
-
});
|
|
34
|
+
## 📋 Release Channels
|
|
42
35
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
|
|
43
|
+
## 🏗️ Architecture
|
|
44
|
+
|
|
45
|
+
The SDK is built with a modular architecture supporting two main modules:
|
|
46
|
+
|
|
47
|
+
### Core Module
|
|
48
|
+
|
|
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
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
### Native Module
|
|
49
55
|
|
|
50
|
-
|
|
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
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
## 📖 Usage Examples
|
|
53
62
|
|
|
54
|
-
|
|
63
|
+
### Core Module - API Operations
|
|
55
64
|
|
|
56
65
|
```typescript
|
|
66
|
+
// Get Core client
|
|
57
67
|
const core = sdk.getCore();
|
|
58
68
|
|
|
59
|
-
// Retrieve
|
|
69
|
+
// Retrieve all supported chains
|
|
60
70
|
const chains = await core.getAllChains();
|
|
61
|
-
console.log(
|
|
71
|
+
console.log('Supported chains:', chains);
|
|
62
72
|
|
|
63
|
-
// Get
|
|
73
|
+
// Get chain metadata for specific networks
|
|
64
74
|
const chainData = await core.getChainMetadataByChainIds([1, 137, 11155111]);
|
|
65
75
|
console.log('Chain metadata:', chainData);
|
|
66
76
|
|
|
67
|
-
//
|
|
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
|
|
77
|
+
// Find bridging routes
|
|
80
78
|
const routes = await core.getRoutes({
|
|
81
|
-
fromChainId: 1,
|
|
82
|
-
toChainId: 137,
|
|
79
|
+
fromChainId: 1,
|
|
80
|
+
toChainId: 137,
|
|
83
81
|
fromTokenAddress: '0xA0b86a33E6441b8c4C8C0e4b8c4C8C0e4b8c4C8C0',
|
|
84
82
|
toTokenAddress: '0xB0b86a33E6441b8c4C8C0e4b8c4C8C0e4b8c4C8C0',
|
|
85
83
|
amount: '1000000000000000000', // 1 token in wei
|
|
86
|
-
fromAddress: '
|
|
87
|
-
slippage: 0.5, // 0.5% slippage tolerance
|
|
84
|
+
fromAddress: '0x1234567890123456789012345678901234567890',
|
|
88
85
|
});
|
|
89
86
|
|
|
90
|
-
//
|
|
91
|
-
const
|
|
92
|
-
|
|
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
|
|
87
|
+
// Build transaction from route steps
|
|
88
|
+
const transaction = await core.buildTransaction({
|
|
89
|
+
steps: routes.steps,
|
|
90
|
+
fromAddress: '0x1234567890123456789012345678901234567890',
|
|
110
91
|
});
|
|
111
|
-
|
|
112
|
-
console.log(`Retrieved ${transactions.transactions.length} transactions`);
|
|
113
92
|
```
|
|
114
93
|
|
|
115
94
|
### Native Module - Blockchain Operations
|
|
116
95
|
|
|
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
|
-
|
|
122
96
|
```typescript
|
|
97
|
+
// Get Native client
|
|
123
98
|
const native = sdk.getNative();
|
|
124
99
|
|
|
125
|
-
|
|
126
|
-
// Get native token balance (ETH, MATIC, etc.)
|
|
100
|
+
// Get native token balance
|
|
127
101
|
const nativeBalance = await native.getNativeBalance(
|
|
128
|
-
'
|
|
129
|
-
|
|
102
|
+
'0x1234567890123456789012345678901234567890',
|
|
103
|
+
11155111 // Sepolia
|
|
130
104
|
);
|
|
131
|
-
console.log(
|
|
105
|
+
console.log('Native balance (wei):', nativeBalance);
|
|
132
106
|
|
|
133
|
-
//
|
|
134
|
-
const
|
|
135
|
-
|
|
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',
|
|
107
|
+
// Create ERC20 instance
|
|
108
|
+
const erc20 = native.erc20(
|
|
109
|
+
'0x1234567890123456789012345678901234567890', // USDC on Sepolia
|
|
146
110
|
11155111
|
|
147
111
|
);
|
|
148
112
|
|
|
149
|
-
//
|
|
150
|
-
const
|
|
151
|
-
'
|
|
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
|
|
113
|
+
// Get ERC20 token balance
|
|
114
|
+
const tokenBalance = await erc20.getBalance(
|
|
115
|
+
'0xabcdefabcdefabcdefabcdefabcdefabcdefabcd'
|
|
163
116
|
);
|
|
117
|
+
console.log('Token balance (wei):', tokenBalance);
|
|
164
118
|
|
|
165
|
-
// Build transaction
|
|
166
|
-
const transferTx = await
|
|
167
|
-
'
|
|
168
|
-
'
|
|
169
|
-
'
|
|
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
|
|
170
124
|
);
|
|
171
125
|
|
|
172
|
-
// Build
|
|
173
|
-
const
|
|
174
|
-
'
|
|
175
|
-
'
|
|
176
|
-
'
|
|
177
|
-
'0xFromAddress12345678901234567890123456789012345' // spender
|
|
126
|
+
// Build approval transaction
|
|
127
|
+
const approvalTx = await erc20.buildApprove(
|
|
128
|
+
'0x2222222222222222222222222222222222222222', // spender
|
|
129
|
+
'1000000000', // amount in wei
|
|
130
|
+
'0x1111111111111111111111111111111111111111' // from address
|
|
178
131
|
);
|
|
179
132
|
```
|
|
180
133
|
|
|
181
|
-
|
|
134
|
+
### Bridge Operations
|
|
182
135
|
|
|
183
136
|
```typescript
|
|
184
|
-
//
|
|
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
|
|
137
|
+
// Create bridge instance
|
|
197
138
|
const bridge = native.bridge(
|
|
198
|
-
'
|
|
139
|
+
'0x3333333333333333333333333333333333333333', // bridge contract
|
|
199
140
|
11155111 // Sepolia
|
|
200
141
|
);
|
|
201
142
|
|
|
202
|
-
// Build bridge
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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',
|
|
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',
|
|
232
150
|
});
|
|
233
151
|
```
|
|
234
152
|
|
|
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
|
-
|
|
258
153
|
## ⚙️ Configuration
|
|
259
154
|
|
|
260
|
-
### SDK Configuration
|
|
261
|
-
|
|
262
|
-
The SDK provides comprehensive configuration capabilities for both modules with sensible defaults and extensive customization options.
|
|
263
|
-
|
|
264
|
-
#### Complete Configuration Example
|
|
155
|
+
### SDK Configuration
|
|
265
156
|
|
|
266
157
|
```typescript
|
|
267
158
|
import { AggLayerSDK, SDK_MODES } from '@agglayer/sdk';
|
|
268
159
|
|
|
269
160
|
const sdk = new AggLayerSDK({
|
|
270
|
-
|
|
271
|
-
mode: [SDK_MODES.CORE, SDK_MODES.NATIVE],
|
|
272
|
-
|
|
273
|
-
// Core Module Configuration
|
|
161
|
+
mode: [SDK_MODES.CORE, SDK_MODES.NATIVE], // Enable both modules
|
|
274
162
|
core: {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
apiTimeout: 30000, // Default: 30000 (30 seconds)
|
|
278
|
-
// Implementation pending for websocket
|
|
279
|
-
// websocketBaseUrl: 'wss://ws.agglayer.com', // Optional: For transactions history
|
|
163
|
+
apiBaseUrl: 'https://api.agglayer.com',
|
|
164
|
+
apiTimeout: 30000, // 30 seconds
|
|
280
165
|
},
|
|
281
|
-
|
|
282
|
-
// Native Module Configuration
|
|
283
166
|
native: {
|
|
284
|
-
// Default
|
|
285
|
-
defaultNetwork: 1, // Default: 1 (Ethereum)
|
|
286
|
-
|
|
287
|
-
// Custom chain configurations
|
|
167
|
+
defaultNetwork: 11155111, // Default chain ID
|
|
288
168
|
chains: [
|
|
289
169
|
{
|
|
290
|
-
|
|
291
|
-
networkId: 1,
|
|
170
|
+
id: 1,
|
|
292
171
|
name: 'Ethereum Mainnet',
|
|
293
|
-
rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/your-
|
|
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,
|
|
172
|
+
rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/your-key',
|
|
173
|
+
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
|
|
306
174
|
},
|
|
307
175
|
{
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
nativeCurrency: {
|
|
313
|
-
name: 'MATIC',
|
|
314
|
-
symbol: 'MATIC',
|
|
315
|
-
decimals: 18,
|
|
316
|
-
},
|
|
317
|
-
bridgeAddress: '0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe',
|
|
318
|
-
isTestnet: false,
|
|
176
|
+
id: 137,
|
|
177
|
+
name: 'Polygon',
|
|
178
|
+
rpcUrl: 'https://polygon-rpc.com',
|
|
179
|
+
nativeCurrency: { name: 'MATIC', symbol: 'MATIC', decimals: 18 },
|
|
319
180
|
},
|
|
320
181
|
],
|
|
321
|
-
|
|
322
|
-
// Override RPC URLs for existing chains
|
|
323
182
|
customRpcUrls: {
|
|
324
|
-
1: 'https://your-
|
|
325
|
-
137: 'https://your-
|
|
326
|
-
11155111: 'https://sepolia.infura.io/v3/your-project-id',
|
|
183
|
+
1: 'https://your-custom-eth-rpc.com',
|
|
184
|
+
137: 'https://your-custom-polygon-rpc.com',
|
|
327
185
|
},
|
|
328
186
|
},
|
|
329
187
|
});
|
|
330
188
|
```
|
|
331
189
|
|
|
332
|
-
|
|
190
|
+
### Module-Specific Usage
|
|
333
191
|
|
|
334
192
|
```typescript
|
|
335
|
-
|
|
336
|
-
|
|
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({
|
|
193
|
+
// Core-only configuration
|
|
194
|
+
const coreOnlySdk = new AggLayerSDK({
|
|
391
195
|
mode: [SDK_MODES.CORE],
|
|
392
196
|
core: {
|
|
393
197
|
apiBaseUrl: 'https://api.agglayer.com',
|
|
394
|
-
apiTimeout: 45000, // Increased timeout for complex operations
|
|
395
|
-
// websocketBaseUrl: 'wss://ws.agglayer.com'
|
|
396
198
|
},
|
|
199
|
+
native: {} as any, // Required but unused
|
|
397
200
|
});
|
|
398
201
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
#### Native-Only Setup (Blockchain Operations)
|
|
403
|
-
|
|
404
|
-
```typescript
|
|
405
|
-
const nativeOnlySDK = new AggLayerSDK({
|
|
202
|
+
// Native-only configuration
|
|
203
|
+
const nativeOnlySdk = new AggLayerSDK({
|
|
406
204
|
mode: [SDK_MODES.NATIVE],
|
|
205
|
+
core: {} as any, // Required but unused
|
|
407
206
|
native: {
|
|
408
|
-
defaultNetwork:
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
},
|
|
207
|
+
defaultNetwork: 11155111,
|
|
208
|
+
chains: [
|
|
209
|
+
/* your chains */
|
|
210
|
+
],
|
|
413
211
|
},
|
|
414
212
|
});
|
|
415
|
-
|
|
416
|
-
const native = nativeOnlySDK.getNative();
|
|
417
213
|
```
|
|
418
214
|
|
|
419
|
-
|
|
215
|
+
## 🚀 Release Process
|
|
420
216
|
|
|
421
|
-
|
|
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
|
-
};
|
|
217
|
+
The SDK uses a tag-based release workflow for all releases:
|
|
436
218
|
|
|
437
|
-
|
|
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
|
-
};
|
|
219
|
+
### **Tag-Based Releases**
|
|
452
220
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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
|
|
456
225
|
```
|
|
457
226
|
|
|
458
|
-
###
|
|
227
|
+
### **Manual Releases**
|
|
459
228
|
|
|
460
|
-
|
|
229
|
+
1. Go to GitHub Actions → "Tag Release"
|
|
230
|
+
2. Choose release type and channel
|
|
231
|
+
3. Click "Run workflow"
|
|
461
232
|
|
|
462
|
-
|
|
463
|
-
- **Katana** (Chain ID: 747474)
|
|
464
|
-
- **Sepolia Testnet** (Chain ID: 11155111)
|
|
465
|
-
<!-- - **Bokuto Testnet** (Chain ID: 2442) -->
|
|
233
|
+
### **Release Types**
|
|
466
234
|
|
|
467
|
-
|
|
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
|
|
468
239
|
|
|
469
|
-
## 🔧
|
|
240
|
+
## 🔧 Development
|
|
470
241
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
### Core Module (`SDK_MODES.CORE`)
|
|
474
|
-
|
|
475
|
-
Core module primarily supports the features based on ARC API
|
|
476
|
-
|
|
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.
|
|
481
|
-
|
|
482
|
-
### Native Module (`SDK_MODES.NATIVE`)
|
|
483
|
-
|
|
484
|
-
Interact with blockchain and agglayer bridge directly, this does not involve any additional APIs(except for proof generation)
|
|
485
|
-
|
|
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)
|
|
488
|
-
|
|
489
|
-
### Key Design Principles
|
|
242
|
+
### Prerequisites
|
|
490
243
|
|
|
491
|
-
-
|
|
492
|
-
-
|
|
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
|
|
244
|
+
- Node.js 18+
|
|
245
|
+
- npm or bun
|
|
497
246
|
|
|
498
|
-
|
|
247
|
+
### Setup
|
|
499
248
|
|
|
500
|
-
|
|
249
|
+
```bash
|
|
250
|
+
# Clone the repository
|
|
251
|
+
git clone https://github.com/agglayer/sdk.git
|
|
252
|
+
cd sdk
|
|
501
253
|
|
|
502
|
-
|
|
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 |
|
|
254
|
+
# Install dependencies
|
|
255
|
+
npm install
|
|
508
256
|
|
|
509
|
-
|
|
257
|
+
# Build the project
|
|
258
|
+
npm run build
|
|
259
|
+
```
|
|
510
260
|
|
|
511
|
-
|
|
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
|
|
261
|
+
### Available Scripts
|
|
515
262
|
|
|
516
|
-
|
|
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 |
|
|
517
275
|
|
|
518
|
-
###
|
|
276
|
+
### Testing
|
|
519
277
|
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
|
|
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
|
-
});
|
|
278
|
+
```bash
|
|
279
|
+
# Run all tests
|
|
280
|
+
npm run test
|
|
531
281
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
core: {
|
|
535
|
-
apiTimeout: 60000, // 60 second timeout
|
|
536
|
-
},
|
|
537
|
-
});
|
|
282
|
+
# Run tests with coverage
|
|
283
|
+
npm run test:coverage
|
|
538
284
|
|
|
539
|
-
|
|
540
|
-
|
|
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
|
-
});
|
|
285
|
+
# Run tests in watch mode
|
|
286
|
+
npm run test:watch
|
|
551
287
|
```
|
|
552
288
|
|
|
553
|
-
##
|
|
289
|
+
## 🎯 Key Features
|
|
554
290
|
|
|
555
|
-
###
|
|
556
|
-
|
|
557
|
-
- **Node.js** 18+ or **Bun** 1.0+
|
|
558
|
-
- **TypeScript** 4.9+
|
|
559
|
-
- **Git** for version control
|
|
291
|
+
### Type Safety
|
|
560
292
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
# Clone the repository
|
|
565
|
-
git clone https://github.com/agglayer/sdk.git
|
|
566
|
-
cd sdk
|
|
293
|
+
- Full TypeScript support with strict configuration
|
|
294
|
+
- Comprehensive type definitions for all operations
|
|
295
|
+
- IntelliSense support for better developer experience
|
|
567
296
|
|
|
568
|
-
|
|
569
|
-
npm install
|
|
570
|
-
# or
|
|
571
|
-
bun install
|
|
297
|
+
### Modular Design
|
|
572
298
|
|
|
573
|
-
|
|
574
|
-
|
|
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
|
|
575
302
|
|
|
576
|
-
|
|
577
|
-
npm run dev
|
|
578
|
-
```
|
|
303
|
+
### Multi-Chain Support
|
|
579
304
|
|
|
580
|
-
|
|
305
|
+
- Built-in support for major EVM chains
|
|
306
|
+
- Custom chain configuration
|
|
307
|
+
- Custom RPC URL support
|
|
308
|
+
- Chain registry for easy network management
|
|
581
309
|
|
|
582
|
-
|
|
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 |
|
|
310
|
+
### Raw Wei Handling
|
|
596
311
|
|
|
597
|
-
|
|
312
|
+
- All token amounts returned as unformatted Wei strings
|
|
313
|
+
- No automatic decimal conversion for precision control
|
|
314
|
+
- Consistent number formatting across all operations
|
|
598
315
|
|
|
599
|
-
###
|
|
316
|
+
### Lightweight & Efficient
|
|
600
317
|
|
|
601
|
-
|
|
318
|
+
- Minimal dependencies (only viem for blockchain interactions)
|
|
319
|
+
- Tree-shakeable modules
|
|
320
|
+
- Optimized bundle size
|
|
602
321
|
|
|
603
|
-
|
|
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
|
-
```
|
|
322
|
+
## 🤝 Contributing
|
|
629
323
|
|
|
630
|
-
|
|
324
|
+
We welcome contributions! Please follow these steps:
|
|
631
325
|
|
|
632
|
-
|
|
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**
|
|
633
333
|
|
|
634
|
-
|
|
635
|
-
- Runtime api response validation using zod
|
|
636
|
-
- WebSocket support for real-time updates of transactions and their status
|
|
334
|
+
### Code Quality Standards
|
|
637
335
|
|
|
638
|
-
|
|
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
|
|
639
341
|
|
|
640
|
-
|
|
342
|
+
## 📄 License
|
|
641
343
|
|
|
642
|
-
|
|
344
|
+
ISC License - see [LICENSE](LICENSE) file for details.
|
|
643
345
|
|
|
644
|
-
|
|
346
|
+
## 🔗 Links
|
|
645
347
|
|
|
646
|
-
|
|
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)
|