@sodax/sdk 0.0.1-rc.8 → 1.0.0-beta
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/LICENSE +1 -1
- package/README.md +51 -220
- package/dist/index.cjs +16822 -8321
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8687 -4617
- package/dist/index.d.ts +8687 -4617
- package/dist/index.mjs +16694 -8273
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -29
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,29 +1,64 @@
|
|
|
1
1
|
# Sodax SDK
|
|
2
2
|
|
|
3
|
-
The Sodax SDK provides a comprehensive interface for interacting with the Sodax protocol, enabling cross-chain swaps
|
|
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
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
###
|
|
8
|
-
|
|
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
|
-
- Solana
|
|
13
|
-
- Injective
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
14
|
+
- Solana ✅
|
|
15
|
+
- Injective ✅
|
|
16
|
+
- [Money Market](./docs/MONEY_MARKET.md) - Cross-chain lending and borrowing
|
|
17
|
+
- EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon, Sonic, HyperEVM, Lightlink) ✅
|
|
18
|
+
- Sui ✅
|
|
19
|
+
- Stellar ✅
|
|
20
|
+
- ICON ✅
|
|
21
|
+
- Solana ✅
|
|
22
|
+
- Injective ✅
|
|
23
|
+
- [Bridge](./docs/BRIDGE.md) - Cross-chain token bridging
|
|
24
|
+
- EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon, Sonic, HyperEVM, Lightlink) ✅
|
|
18
25
|
- Sui ✅
|
|
19
26
|
- Stellar ✅
|
|
20
27
|
- ICON ✅
|
|
21
|
-
- Solana
|
|
22
|
-
- Injective
|
|
23
|
-
|
|
28
|
+
- Solana ✅
|
|
29
|
+
- Injective ✅
|
|
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) ✅
|
|
33
|
+
- Sui ✅
|
|
34
|
+
- Stellar ✅
|
|
35
|
+
- ICON ✅
|
|
36
|
+
- Solana ✅
|
|
37
|
+
- Injective ✅
|
|
38
|
+
|
|
39
|
+
### API Endpoints
|
|
24
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
|
|
25
43
|
|
|
26
|
-
|
|
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
|
|
27
62
|
|
|
28
63
|
```bash
|
|
29
64
|
# Using npm
|
|
@@ -48,7 +83,7 @@ Package can be locally installed by following this steps:
|
|
|
48
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"`).
|
|
49
84
|
Full example: `"@sodax/sdk": "file:/Users/dev/operation-liquidity-layer/sdk-new/packages/sdk"`.
|
|
50
85
|
|
|
51
|
-
|
|
86
|
+
### Local Development
|
|
52
87
|
|
|
53
88
|
How to setup local development
|
|
54
89
|
|
|
@@ -59,215 +94,11 @@ How to setup local development
|
|
|
59
94
|
1. Do not forget to export TS files in same folder `index.ts`.
|
|
60
95
|
2. Always import files using `.js` postfix.
|
|
61
96
|
|
|
62
|
-
## Intent Solver Endpoints
|
|
63
|
-
|
|
64
|
-
Current Intent Solver API endpoints:
|
|
65
|
-
- **Production (mainnet)**: "TODO"
|
|
66
|
-
- **Staging** (mainnet): "https://staging-new-world.iconblockchain.xyz"
|
|
67
|
-
|
|
68
|
-
**Note** Staging endpoint contains features to be potentially released and is subject to frequent change!
|
|
69
|
-
|
|
70
|
-
## Relayer API Endpoints
|
|
71
|
-
|
|
72
|
-
Current Relayer API endpoints:
|
|
73
|
-
- **Production (mainnet)**: "https://xcall-relay.nw.iconblockchain.xyz"
|
|
74
|
-
- **Staging** (mainnet): "https://testnet-xcall-relay.nw.iconblockchain.xyz"
|
|
75
|
-
|
|
76
|
-
**Note** Staging endpoint contains features to be potentially released and is subject to frequent change!
|
|
77
|
-
|
|
78
|
-
## Usage
|
|
79
|
-
|
|
80
|
-
The Sodax SDK is initialized by creating a new `Sodax` instance with your desired configuration. The SDK supports both Solver (for intent-based swaps) and Money Market (for cross-chain lending and borrowing) services.
|
|
81
|
-
|
|
82
|
-
Both Solver and Money Market configuration and optional. You can always choose to use just a specific feature.
|
|
83
|
-
|
|
84
|
-
### Basic Configuration
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
// Initialize Sodax using default Sonic mainnet configurations (no fees)
|
|
88
|
-
const sodax = new Sodax();
|
|
89
|
-
|
|
90
|
-
// Use default config but put fee on solver (intent swaps)
|
|
91
|
-
const sodaxWithSolverFees = new Sodax({
|
|
92
|
-
solver: { partnerFee: partnerFeePercentage },
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Use default config with fee on money market (borrows)
|
|
96
|
-
const sodaxWithMoneyMarketFees = new Sodax({
|
|
97
|
-
moneyMarket: { partnerFee: partnerFeePercentage },
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// or use default config with fees on both solver and money market
|
|
101
|
-
const sodaxWithFees = new Sodax({
|
|
102
|
-
solver: { partnerFee: partnerFeePercentage },
|
|
103
|
-
moneyMarket: { partnerFee: partnerFeePercentage },
|
|
104
|
-
});
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Custom Configuration
|
|
108
|
-
|
|
109
|
-
Sodax SDK can be customized for partner fee, solver or money market configuration.
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
import {
|
|
113
|
-
Sodax,
|
|
114
|
-
PartnerFee,
|
|
115
|
-
SolverConfigParams,
|
|
116
|
-
getSolverConfig,
|
|
117
|
-
getMoneyMarketConfig,
|
|
118
|
-
} from '@sodax/sdk';
|
|
119
|
-
|
|
120
|
-
// Partner fee can be defined as a percentage or a definite token amount.
|
|
121
|
-
// Fee is optional, you can leave it empty/undefined.
|
|
122
|
-
const partnerFeePercentage = {
|
|
123
|
-
address: '0x0000000000000000000000000000000000000000', // address to receive fee too
|
|
124
|
-
percentage: 100, // 100 = 1%, 10000 = 100%
|
|
125
|
-
} satisfies PartnerFee;
|
|
126
|
-
|
|
127
|
-
const partnerFeeAmount = {
|
|
128
|
-
address: '0x0000000000000000000000000000000000000000', // address to receive fee too
|
|
129
|
-
amount: 1000n, // definite amount denominated in token decimal precision
|
|
130
|
-
} satisfies PartnerFee;
|
|
131
|
-
|
|
132
|
-
// Solver config is optional and is required only if you want to use intent based swaps.
|
|
133
|
-
// You can either use custom solver config or the default one (based on hub chain id - defaults to Sonic chain as hub)
|
|
134
|
-
|
|
135
|
-
// example of custom solver config
|
|
136
|
-
const customSolverConfig = {
|
|
137
|
-
intentsContract: '0x6382D6ccD780758C5e8A6123c33ee8F4472F96ef',
|
|
138
|
-
solverApiEndpoint: 'https://staging-new-world.iconblockchain.xyz',
|
|
139
|
-
partnerFee: partnerFeePercentage, // or partnerFeeAmount
|
|
140
|
-
} satisfies SolverConfigParams;
|
|
141
|
-
|
|
142
|
-
// pre-defined default solver config per hub chain id (Sonic hub is the default)
|
|
143
|
-
const solverConfig: SolverConfigParams = getSolverConfig(SONIC_MAINNET_CHAIN_ID);
|
|
144
|
-
|
|
145
|
-
// example of custom money market config
|
|
146
|
-
const customMoneyMarketConfig = {
|
|
147
|
-
lendingPool: '0x553434896D39F867761859D0FE7189d2Af70514E',
|
|
148
|
-
uiPoolDataProvider: '0xC04d746C38f1E51C8b3A3E2730250bbAC2F271bf',
|
|
149
|
-
poolAddressesProvider: '0x036aDe0aBAA4c82445Cb7597f2d6d6130C118c7b',
|
|
150
|
-
bnUSD: '0x94dC79ce9C515ba4AE4D195da8E6AB86c69BFc38',
|
|
151
|
-
bnUSDVault: '0xE801CA34E19aBCbFeA12025378D19c4FBE250131',
|
|
152
|
-
} satisfies MoneyMarketConfig;
|
|
153
|
-
|
|
154
|
-
// pre-defined default money market config per hub chain id (Sonic hub is the default)
|
|
155
|
-
const moneyMarketConfig = getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID);
|
|
156
|
-
|
|
157
|
-
// example of custom hub config
|
|
158
|
-
const hubConfig = {
|
|
159
|
-
hubRpcUrl: 'https://rpc.soniclabs.com',
|
|
160
|
-
chainConfig: getHubChainConfig(SONIC_MAINNET_CHAIN_ID),
|
|
161
|
-
} satisfies EvmHubProviderConfig;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
// Initialize Sodax using custom/default configurations
|
|
165
|
-
const sodax = new Sodax({
|
|
166
|
-
solver: solverConfig,
|
|
167
|
-
moneyMarket: moneyMarketConfig,
|
|
168
|
-
hubProviderConfig: hubConfig,
|
|
169
|
-
});
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Using SDK Config and Constants
|
|
173
|
-
|
|
174
|
-
SDK includes predefined configurations of supported chains, tokens and other relevant information for the client to consume.
|
|
175
|
-
|
|
176
|
-
**NOTE** you should generally only use `spokeChains` 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.
|
|
177
|
-
|
|
178
|
-
Please refer to [SDK constants.ts](https://github.com/icon-project/sodax-frontend/blob/main/packages/sdk/src/constants.ts) for more.
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
import {
|
|
182
|
-
getHubChainConfig,
|
|
183
|
-
supportedHubAssets,
|
|
184
|
-
supportedHubChains,
|
|
185
|
-
supportedSpokeChains,
|
|
186
|
-
spokeChainConfig,
|
|
187
|
-
getSupportedSolverTokens,
|
|
188
|
-
moneyMarketReserveAssets,
|
|
189
|
-
} from "@sodax/sdk";
|
|
190
|
-
|
|
191
|
-
const hubChainConfig = getHubChainConfig(SONIC_MAINNET_CHAIN_ID);
|
|
192
|
-
|
|
193
|
-
// all supported hub chains (Sonic mainnet and testnet)
|
|
194
|
-
export const hubChains: HubChainId[] = supportedHubChains;
|
|
195
|
-
|
|
196
|
-
// all supported spoke chains
|
|
197
|
-
export const spokeChains: SpokeChainId[] = supportedSpokeChains;
|
|
198
|
-
|
|
199
|
-
// all hub assets (original asset addresses mapped to "Abstracted evm addresses")
|
|
200
|
-
export const hubAssets: Set<Address> = supportedHubAssets;
|
|
201
|
-
|
|
202
|
-
// all money market reserve addresses on hub chain (sonic)
|
|
203
|
-
export const moneyMarketReserves = moneyMarketReserveAssets;
|
|
204
|
-
|
|
205
|
-
// record mapping spoke chain Id to spoke chain configs
|
|
206
|
-
export spokeChainConfigRecord : Record<SpokeChainId, SpokeChainConfig> = spokeChainConfig;
|
|
207
|
-
|
|
208
|
-
// using spoke chain id to retrieve supported tokens for solver (intent swaps)
|
|
209
|
-
const supportedSolverTokens: readonly Token[] = getSupportedSolverTokens(spokeChainId);
|
|
210
|
-
|
|
211
|
-
// using spoke chain id to retrieve supported tokens address (on spoke chain = original address) for money market
|
|
212
|
-
const supportedMoneyMarketTokens: readonly Token[] = getSupportedMoneyMarketTokens(spokeChainId)
|
|
213
|
-
|
|
214
|
-
// checkout constants.ts for all configs available
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### Wallet Providers
|
|
218
|
-
|
|
219
|
-
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).
|
|
220
|
-
|
|
221
|
-
As part of Sodax suite, xWagmi SDK is also going to be provided as one example wallet provider implementation. You are free to choose between using our xWagmi SDK or implementing your own wallet connectivity for each chain.
|
|
222
|
-
|
|
223
|
-
- Supported Wallet Provider Interface (`IWalletProvider`)
|
|
224
|
-
- `IEvmWalletProvider`: EVM (Arbitrum, Avalanche, Base, BSC, Optimism, Polygon) ✅
|
|
225
|
-
- `ISuiWalletProvider`: Sui ✅
|
|
226
|
-
- `IIconWalletProvider`: ICON ✅
|
|
227
|
-
- `IStellarWalletProvider`: Stellar ✅
|
|
228
|
-
- Solana ❌ Coming soon
|
|
229
|
-
- Injective ❌ Coming soon
|
|
230
|
-
- Havah ❌ Coming soon
|
|
231
|
-
|
|
232
|
-
### Initialising Spoke Provider
|
|
233
|
-
|
|
234
|
-
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.
|
|
235
|
-
|
|
236
|
-
Spoke is simply a chain you are connecting to and SpokeProvider is a container of relevant wallet provider and chain configuration.
|
|
237
|
-
|
|
238
|
-
**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.
|
|
239
|
-
|
|
240
|
-
EVM Provider example:
|
|
241
|
-
|
|
242
|
-
```typescript
|
|
243
|
-
import { EvmProvider, EvmHubProvider, EvmSpokeProvider, AVALANCHE_MAINNET_CHAIN_ID, SONIC_MAINNET_CHAIN_ID } from "@sodax/sdk"
|
|
244
|
-
|
|
245
|
-
const evmWalletProvider: IEvmWalletProvider = // injected by xWagmi SDK or your own implementation
|
|
246
|
-
|
|
247
|
-
// spoke provider represents connection to a specific chain, should be instantiated for each supported chain when user connects wallet
|
|
248
|
-
const bscSpokeProvider: EvmSpokeProvider = new EvmSpokeProvider(
|
|
249
|
-
evmWalletProvider, // user connected wallet
|
|
250
|
-
spokeChainConfig[BSC_MAINNET_CHAIN_ID] as EvmSpokeChainConfig, // connected chain config
|
|
251
|
-
);
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
### Accessing Sodax Features
|
|
255
|
-
|
|
256
|
-
Sodax feature set currently contain:
|
|
257
|
-
- Solver: used for intent based swaps. Please find documentation for Solver part of the SDK in [SOLVER.md](./docs/SOLVER.md)
|
|
258
|
-
- Money Market: used for lending and borowing. Please find documentation for Solver part of the SDK in [MONEY_MARKET.md](./docs/MONEY_MARKET.md)
|
|
259
|
-
|
|
260
|
-
## Intent Relay API
|
|
261
|
-
|
|
262
|
-
Intent relay is internally used to relay transaction information from one chain to another.
|
|
263
|
-
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.
|
|
264
|
-
|
|
265
|
-
|
|
266
97
|
## Contributing
|
|
267
98
|
|
|
268
99
|
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
269
100
|
|
|
270
|
-
## Development
|
|
101
|
+
## Development Commands
|
|
271
102
|
|
|
272
103
|
```bash
|
|
273
104
|
# Install dependencies
|