@sodax/sdk 1.0.0-rc.3 β†’ 1.0.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,48 +1,65 @@
1
1
  # Sodax SDK
2
2
 
3
- The Sodax SDK provides a comprehensive interface for interacting with the Sodax protocol, enabling cross-chain swaps and money market operations.
3
+ The Sodax SDK provides a comprehensive interface for interacting with the Sodax protocol, enabling cross-chain swaps, money market, cross-chain bridging, migration and staking SODA token.
4
4
 
5
- ## Features
5
+ ## Table of Contents
6
6
 
7
- ### Swaps (Solver / Intents) [πŸ“–](./docs/SOLVER.md)
8
- - EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon, Sonic, HyperEVM❌, Lightlink) βœ…
7
+ ### Features
8
+
9
+ - [Swaps (Solver / Intents)](./docs/SWAPS.md) - Cross-chain intent-based swaps
10
+ - EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon, Sonic, HyperEVM, Lightlink) βœ…
9
11
  - Sui βœ…
10
12
  - Stellar βœ…
11
13
  - ICON βœ…
12
14
  - Solana βœ…
13
15
  - Injective βœ…
14
-
15
- ### Lend and Borrow (Money Market) [πŸ“–](./docs/MONEY_MARKET.md)
16
+ - [Money Market](./docs/MONEY_MARKET.md) - Cross-chain lending and borrowing
16
17
  - EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon, Sonic, HyperEVM, Lightlink) βœ…
17
18
  - Sui βœ…
18
19
  - Stellar βœ…
19
20
  - ICON βœ…
20
21
  - Solana βœ…
21
22
  - Injective βœ…
22
-
23
- ### Cross-chain bridging (Bridge) [πŸ“–](./docs/BRIDGE.md)
23
+ - [Bridge](./docs/BRIDGE.md) - Cross-chain token bridging
24
24
  - EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon, Sonic, HyperEVM, Lightlink) βœ…
25
25
  - Sui βœ…
26
26
  - Stellar βœ…
27
27
  - ICON βœ…
28
28
  - Solana βœ…
29
29
  - Injective βœ…
30
-
31
- ### Migration [πŸ“–](./docs/MIGRATION.md)
32
- - Legacy bnUSD <> New bnUSD:
33
- - ICX <> SODA
34
- - BALN <> SODA
35
-
36
- ### Staking SODA [πŸ“–](./docs/STAKING.md)
37
- - EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon, Sonic, HyperEVM❌, Lightlink) βœ…
30
+ - [Migration](./docs/MIGRATION.md) - Token migration (ICX, bnUSD, BALN)
31
+ - [Staking](./docs/STAKING.md) - SODA token staking
32
+ - EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon, Sonic, HyperEVM, Lightlink) βœ…
38
33
  - Sui βœ…
39
34
  - Stellar βœ…
40
35
  - ICON βœ…
41
36
  - Solana βœ…
42
37
  - Injective βœ…
43
38
 
44
- ## Installation
45
-
39
+ ### API Endpoints
40
+
41
+ - [Intent Solver API Endpoints](./docs/SOLVER_API_ENDPOINTS.md) - Solver API endpoint documentation
42
+ - [Relayer API Endpoints](./docs/RELAYER_API_ENDPOINTS.md) - Relayer API endpoint documentation
43
+
44
+ ### Guides
45
+
46
+ - [Configure SDK](./docs/CONFIGURE_SDK.md) - Comprehensive guide for configuring the SDK
47
+ - [Monetize SDK](./docs/MONETIZE_SDK.md) - Configure fees and monetize your SDK integration
48
+ - [Make a Swap](./docs/HOW_TO_MAKE_A_SWAP.md) - Step by step guide on how to make a swap
49
+ - [Create a Spoke Provider](./docs/HOW_TO_CREATE_A_SPOKE_PROVIDER.md) - Comprehensive guide for creating spoke providers
50
+ - [Estimate Gas for Raw Transactions](./docs/ESTIMATE_GAS.md) - Estimate transaction gas for raw transaction payloads.
51
+ - [Wallet Providers](./docs/WALLET_PROVIDERS.md) - Wallet provider interfaces and implementation guide
52
+ - [Stellar Trustline Requirements](./docs/STELLAR_TRUSTLINE.md) - Guide for handling Stellar trustlines across all operations
53
+
54
+ ### Miscellaneous
55
+
56
+ - [Intent Relay API](./docs/INTENT_RELAY_API.md) - Intent relay API internally used to relay cross-chain messages.
57
+ - [Backend API](./docs/BACKEND_API.md) - Sodax Backend API offering access to Intent, Swap, and Money Market data.
58
+
59
+ ## Development
60
+
61
+ ### Installation
62
+
46
63
  ```bash
47
64
  # Using npm
48
65
  npm install @sodax/sdk
@@ -66,7 +83,7 @@ Package can be locally installed by following this steps:
66
83
  Instead of version define absolute path to your SDK repository `"file:<sdk-repository-path>"` (e.g. `"file:/Users/dev/.../operation-liquidity-layer/packages/sdk"`).
67
84
  Full example: `"@sodax/sdk": "file:/Users/dev/operation-liquidity-layer/sdk-new/packages/sdk"`.
68
85
 
69
- ## Local Development
86
+ ### Local Development
70
87
 
71
88
  How to setup local development
72
89
 
@@ -77,357 +94,11 @@ How to setup local development
77
94
  1. Do not forget to export TS files in same folder `index.ts`.
78
95
  2. Always import files using `.js` postfix.
79
96
 
80
- ## Intent Solver Endpoints
81
-
82
- Current Intent Solver API endpoints:
83
- - **Production (mainnet)**: "https://sodax-solver-staging.iconblockchain.xyz"
84
- - **Staging** (mainnet): "https://sodax-solver-staging.iconblockchain.xyz"
85
-
86
- **Note** Staging endpoint contains features to be potentially released and is subject to frequent change!
87
-
88
- ## Relayer API Endpoints
89
-
90
- Current Relayer API endpoints:
91
- - **Production (mainnet)**: "https://xcall-relay.nw.iconblockchain.xyz"
92
- - **Staging** (mainnet): "https://testnet-xcall-relay.nw.iconblockchain.xyz"
93
-
94
- **Note** Staging endpoint contains features to be potentially released and is subject to frequent change!
95
-
96
- ## Usage
97
-
98
- The Sodax SDK is initialized by creating a new `Sodax` instance with your desired configuration. The SDK supports both Swaps (for intent-based solver swaps) and Money Market (for cross-chain lending and borrowing) services.
99
-
100
- Both Swaps (Solver) and Money Market configuration and optional. You can always choose to use just a specific feature.
101
-
102
- ### Basic Configuration
103
-
104
- ```typescript
105
- import { Sodax } from '@sodax/sdk';
106
-
107
- // Initialize Sodax using default Sonic mainnet configurations (no fees)
108
- const sodax = new Sodax();
109
-
110
- // If you want dynamic (backend API based - contains latest tokens) configuration,
111
- // make sure to initialize the instance before usage!
112
- // By default, configuration from the specific SDK version you are using is used
113
- await sodax.initialize();
114
-
115
- // Use default config but put fee on swaps (solver intent swaps)
116
- const partnerFeePercentage = {
117
- address: '0x0000000000000000000000000000000000000000', // address to receive fee
118
- percentage: 100, // 100 = 1%, 10000 = 100%
119
- };
120
-
121
- const sodaxWithSwapFees = new Sodax({
122
- swap: { partnerFee: partnerFeePercentage },
123
- });
124
-
125
- // Use default config with fee on money market (borrows)
126
- const sodaxWithMoneyMarketFees = new Sodax({
127
- moneyMarket: { partnerFee: partnerFeePercentage },
128
- });
129
-
130
- // Or use default config with fees on both swaps and money market
131
- const sodaxWithFees = new Sodax({
132
- swap: { partnerFee: partnerFeePercentage },
133
- moneyMarket: { partnerFee: partnerFeePercentage },
134
- });
135
- ```
136
-
137
- ### Custom Configuration
138
-
139
- Sodax SDK can be customized for partner fee, swaps or money market configuration.
140
-
141
- ```typescript
142
- import {
143
- Sodax,
144
- PartnerFee,
145
- SolverConfigParams,
146
- MoneyMarketConfigParams,
147
- EvmHubProviderConfig,
148
- getSolverConfig,
149
- getMoneyMarketConfig,
150
- getHubChainConfig,
151
- SONIC_MAINNET_CHAIN_ID,
152
- } from '@sodax/sdk';
153
-
154
- // Partner fee can be defined as a percentage or a definite token amount.
155
- // Fee is optional, you can leave it empty/undefined.
156
- const partnerFeePercentage = {
157
- address: '0x0000000000000000000000000000000000000000', // address to receive fee
158
- percentage: 100, // 100 = 1%, 10000 = 100%
159
- } satisfies PartnerFee;
160
-
161
- const partnerFeeAmount = {
162
- address: '0x0000000000000000000000000000000000000000', // address to receive fee
163
- amount: 1000n, // definite amount denominated in token decimal precision
164
- } satisfies PartnerFee;
165
-
166
- // Solver config is optional and is required only if you want to use intent based swaps.
167
- // You can either use custom solver config or the default one (based on hub chain id - defaults to Sonic chain as hub)
168
-
169
- // Example of custom solver config
170
- const customSolverConfig = {
171
- intentsContract: '0x6382D6ccD780758C5e8A6123c33ee8F4472F96ef',
172
- solverApiEndpoint: 'https://sodax-solver-staging.iconblockchain.xyz',
173
- partnerFee: partnerFeePercentage, // or partnerFeeAmount
174
- } satisfies SolverConfigParams;
175
-
176
- // Pre-defined default solver config per hub chain id (Sonic hub is the default)
177
- const solverConfig: SolverConfigParams = getSolverConfig(SONIC_MAINNET_CHAIN_ID);
178
-
179
- // Example of custom money market config
180
- const customMoneyMarketConfig = {
181
- lendingPool: '0x553434896D39F867761859D0FE7189d2Af70514E',
182
- uiPoolDataProvider: '0xC04d746C38f1E51C8b3A3E2730250bbAC2F271bf',
183
- poolAddressesProvider: '0x036aDe0aBAA4c82445Cb7597f2d6d6130C118c7b',
184
- bnUSD: '0x94dC79ce9C515ba4AE4D195da8E6AB86c69BFc38',
185
- bnUSDVault: '0xE801CA34E19aBCbFeA12025378D19c4FBE250131',
186
- } satisfies MoneyMarketConfigParams;
187
-
188
- // Pre-defined default money market config per hub chain id (Sonic hub is the default)
189
- const moneyMarketConfig = getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID);
190
-
191
- // Example of custom hub config
192
- const hubConfig = {
193
- hubRpcUrl: 'https://rpc.soniclabs.com',
194
- chainConfig: getHubChainConfig(SONIC_MAINNET_CHAIN_ID),
195
- } satisfies EvmHubProviderConfig;
196
-
197
- // Initialize Sodax using custom/default configurations
198
- const sodax = new Sodax({
199
- swap: solverConfig,
200
- moneyMarket: moneyMarketConfig,
201
- hubProviderConfig: hubConfig,
202
- });
203
-
204
- // Initialize with dynamic configuration (recommended for latest tokens/chains)
205
- await sodax.initialize();
206
- ```
207
-
208
- ### Using SDK Config and Constants
209
-
210
- SDK includes predefined configurations of supported chains, tokens and other relevant information for the client to consume. All configurations are accessible through the `config` property of the Sodax instance (`sodax.config`), or through service-specific properties for convenience.
211
-
212
- **NOTE**: You should generally only use spoke chains configuration to retrieve all supported chains and then invoke per spoke chain based configurations. If you are using hub configurations you should know what you are doing.
213
-
214
- **IMPORTANT**: If you want dynamic (backend API based - contains latest tokens) configuration, make sure to initialize the instance before usage:
215
- ```typescript
216
- await sodax.initialize();
217
- ```
218
- By default, configuration from the specific SDK version you are using is used.
219
-
220
- #### General Configuration (sodax.config)
221
-
222
- ```typescript
223
- import { Sodax, type SpokeChainId, type HubChainId } from "@sodax/sdk";
224
-
225
- const sodax = new Sodax();
226
- await sodax.initialize(); // Initialize for dynamic config (optional but recommended)
227
-
228
- // All supported hub chains (Sonic mainnet and testnet)
229
- const hubChains: HubChainId[] = sodax.config.getSupportedHubChains();
230
-
231
- // All supported spoke chains
232
- const spokeChains: SpokeChainId[] = sodax.config.getSupportedSpokeChains();
233
-
234
- // Get all chains configuration
235
- const chains = sodax.config.getChains();
236
-
237
- // Get hub assets configuration
238
- const hubAssets = sodax.config.getHubAssets();
239
-
240
- // Get hub vaults configuration
241
- const hubVaults = sodax.config.getHubVaults();
242
-
243
- // Get money market reserve assets
244
- const moneyMarketReserves = sodax.config.getMoneyMarketReserveAssets();
245
-
246
- // Check if a token is valid for a given chain
247
- const isValid = sodax.config.isValidOriginalAssetAddress(chainId, tokenAddress);
248
-
249
- // Get hub asset info for a given chain and original asset
250
- const hubAssetInfo = sodax.config.getHubAssetInfo(chainId, tokenAddress);
251
- ```
252
-
253
- #### Swap Configuration (sodax.swap)
254
-
255
- ```typescript
256
- import { Sodax, type SpokeChainId, type Token } from "@sodax/sdk";
257
-
258
- const sodax = new Sodax();
259
- await sodax.initialize(); // Initialize for dynamic config (optional but recommended)
260
-
261
- // Get supported swap tokens for a specific chain
262
- const supportedSwapTokens: readonly Token[] = sodax.swap.getSupportedSwapTokensByChainId(chainId);
263
-
264
- // Get all supported swap tokens per chain
265
- const allSwapTokens: Record<SpokeChainId, readonly Token[]> = sodax.swap.getSupportedSwapTokens();
266
-
267
- // Alternative: Access through config service
268
- const swapTokensFromConfig: readonly Token[] = sodax.config.getSupportedSwapTokensByChainId(chainId);
269
- const allSwapTokensFromConfig = sodax.config.getSupportedSwapTokens();
270
- ```
271
-
272
- #### Money Market Configuration (sodax.moneyMarket)
273
-
274
- ```typescript
275
- import { Sodax, type SpokeChainId, type Token, type Address } from "@sodax/sdk";
276
-
277
- const sodax = new Sodax();
278
- await sodax.initialize(); // Initialize for dynamic config (optional but recommended)
279
-
280
- // Get supported money market tokens for a specific chain
281
- const supportedMoneyMarketTokens: readonly Token[] = sodax.moneyMarket.getSupportedTokensByChainId(chainId);
282
-
283
- // Get all supported money market tokens
284
- const allMoneyMarketTokens = sodax.moneyMarket.getSupportedTokens();
285
-
286
- // Get supported money market reserves
287
- const reserves: readonly Address[] = sodax.moneyMarket.getSupportedReserves();
288
-
289
- // Alternative: Access through config service
290
- const moneyMarketTokensFromConfig: readonly Token[] = sodax.config.getSupportedMoneyMarketTokensByChainId(chainId);
291
- const allMoneyMarketTokensFromConfig = sodax.config.getSupportedMoneyMarketTokens();
292
- ```
293
-
294
- Please refer to [SDK constants.ts](https://github.com/icon-project/sodax-frontend/blob/main/packages/sdk/src/constants.ts) for additional static constants and configurations.
295
-
296
- ### Wallet Providers
297
-
298
- Sodax SDK does not force the usage of a specific wallet or library, but requires client to provide implementation of `IWalletProvider` interfaces (e.g. for EVM chains `IEvmWalletProvider` has to be implemented).
299
-
300
- As part of Sodax suite, Wallet SDK is also going to be provided as one example wallet provider implementation. You are free to choose between using our Wallet SDK or implementing your own wallet connectivity for each chain.
301
-
302
- - Supported Wallet Provider Interface (`IWalletProvider`)
303
- - `IEvmWalletProvider`: EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon) βœ…
304
- - `ISuiWalletProvider`: Sui βœ…
305
- - `IIconWalletProvider`: ICON βœ…
306
- - `IStellarWalletProvider`: Stellar βœ…
307
- - `ISolanaWalletProvider`: Solana βœ…
308
- - `IInjectiveWalletProvider`: Injective βœ…
309
-
310
- ### Initialising Spoke Provider
311
-
312
- Spoke provider is a main instance used to interact with Sodax features because it contains all the relevant information we need to successfully execute features. You should generally establish SpokeProvider instances for each chain (e.g. evm, sui, etc..) user connects wallet to.
313
-
314
- Spoke is simply a chain you are connecting to and SpokeProvider is a container of relevant wallet provider and chain configuration.
315
-
316
- **IMPORTANT**: Sonic Spoke Provider must be instantiated as `SonicSpokeProvider` instance even though it is of `EVM` chain type. This is due to the fact that Sonic chain is a hub chain of Sodax and needs special handling under the hood.
317
-
318
- EVM Provider example:
319
-
320
- ```typescript
321
- import { EvmProvider, EvmHubProvider, EvmSpokeProvider, AVALANCHE_MAINNET_CHAIN_ID, SONIC_MAINNET_CHAIN_ID } from "@sodax/sdk"
322
-
323
- const evmWalletProvider: IEvmWalletProvider = // injected by Wallet SDK or your own implementation
324
-
325
- // spoke provider represents connection to a specific chain, should be instantiated for each supported chain when user connects wallet
326
- const bscSpokeProvider: EvmSpokeProvider = new EvmSpokeProvider(
327
- evmWalletProvider, // user connected wallet
328
- spokeChainConfig[BSC_MAINNET_CHAIN_ID], // connected chain config
329
- );
330
- ```
331
-
332
- ### Estimate Gas for Raw Transactions
333
-
334
- The `estimateGas` function allows you to estimate the gas cost for raw transactions before executing them. This is particularly useful for all Sodax operations (swaps, money market operations, approvals) to provide users with accurate gas estimates.
335
-
336
- The function is available on all service classes:
337
- - `SwapService.estimateGas()` - for solver/intent operations (reachable through `sodax.swap`)
338
- - `MoneyMarketService.estimateGas()` - for money market operations (reachable through `sodax.moneyMarket`)
339
- - `SpokeService.estimateGas()` - for general spoke chain operations
340
-
341
- ```typescript
342
- import {
343
- SwapService,
344
- MoneyMarketService,
345
- SpokeService,
346
- MoneyMarketSupplyParams
347
- } from "@sodax/sdk";
348
-
349
- // Example: Estimate gas for a solver swap transaction
350
- const createIntentResult = await sodax.swap.createIntent(
351
- createIntentParams,
352
- bscSpokeProvider,
353
- partnerFeeAmount,
354
- true, // true = get raw transaction
355
- );
356
-
357
- if (createIntentResult.ok) {
358
- const [rawTx, intent] = createIntentResult.value;
359
-
360
- // Estimate gas for the raw transaction
361
- const gasEstimate = await SwapService.estimateGas(rawTx, bscSpokeProvider);
362
-
363
- if (gasEstimate.ok) {
364
- console.log('Estimated gas for swap:', gasEstimate.value);
365
- } else {
366
- console.error('Failed to estimate gas for swap:', gasEstimate.error);
367
- }
368
- }
369
-
370
- // Example: Estimate gas for a money market supply transaction
371
- const supplyResult = await sodax.moneyMarket.createSupplyIntent(
372
- supplyParams,
373
- bscSpokeProvider,
374
- true, // true = get raw transaction
375
- );
376
-
377
- if (supplyResult.ok) {
378
- const rawTx = supplyResult.value;
379
-
380
- // Estimate gas for the raw transaction
381
- const gasEstimate = await MoneyMarketService.estimateGas(rawTx, bscSpokeProvider);
382
-
383
- if (gasEstimate.ok) {
384
- console.log('Estimated gas for supply:', gasEstimate.value);
385
- } else {
386
- console.error('Failed to estimate gas for supply:', gasEstimate.error);
387
- }
388
- }
389
-
390
- // Example: Estimate gas for an approval transaction
391
- const approveResult = await sodax.swap.approve(
392
- tokenAddress,
393
- amount,
394
- bscSpokeProvider,
395
- true // true = get raw transaction
396
- );
397
-
398
- if (approveResult.ok) {
399
- const rawTx = approveResult.value;
400
-
401
- // Estimate gas for the approval transaction
402
- const gasEstimate = await SpokeService.estimateGas(rawTx, bscSpokeProvider);
403
-
404
- if (gasEstimate.ok) {
405
- console.log('Estimated gas for approval:', gasEstimate.value);
406
- } else {
407
- console.error('Failed to estimate gas for approval:', gasEstimate.error);
408
- }
409
- }
410
- ```
411
-
412
- ### Accessing Sodax Features
413
-
414
- Sodax feature set currently contain:
415
- - Swap (Solver): used for intent based swaps. Please find documentation for Swaps part of the SDK in [SWAPS.md](./docs/SWAPS.md)
416
- - Money Market: used for lending and borowing. Please find documentation for Money Market part of the SDK in [MONEY_MARKET.md](./docs/MONEY_MARKET.md)
417
- - Bridge: provides functionality to bridge tokens between different blockchain chains [BRIDGE.md](./docs/BRIDGE.md)
418
- - Staking: provides functionality to stake SODA tokens from different blockchain chains [STAKING.md](./docs/STAKING.md)
419
-
420
- ## Intent Relay API
421
-
422
- Intent relay is internally used to relay transaction information from one chain to another.
423
- Sodax SDK abstracts the heavy lifting of using the relay, but you can find documentation for Intent Relay API in [INTENT_RELAY_API.md](./docs/INTENT_RELAY_API.md) in case you want to explore it.
424
-
425
-
426
97
  ## Contributing
427
98
 
428
99
  We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
429
100
 
430
- ## Development
101
+ ## Development Commands
431
102
 
432
103
  ```bash
433
104
  # Install dependencies