haedal-vault-sdk 1.5.0 → 1.7.0
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 +209 -6
- package/dist/index.d.ts +390 -116
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -42,39 +42,111 @@ sdk.senderAddress = '0x..'
|
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## Function Description
|
|
45
|
+
|
|
46
|
+
### Vaults Module vs VaultsV2 Module
|
|
47
|
+
|
|
48
|
+
The SDK provides two coexisting vault modules, each designed for different types of liquidity pools:
|
|
49
|
+
|
|
50
|
+
- **Vaults Module** (`sdk.Vaults`): Specialized module for CLMM (Constant Liquidity Market Maker) pools
|
|
51
|
+
- **VaultsV2 Module** (`sdk.VaultsV2`): Specialized module for DLMM (Dynamic Liquidity Market Maker) pools
|
|
52
|
+
|
|
53
|
+
Both modules coexist and serve different purposes:
|
|
54
|
+
- **Vaults** is specifically designed for CLMM pool management
|
|
55
|
+
- **VaultsV2** is specifically designed for DLMM pool management
|
|
56
|
+
|
|
57
|
+
The modules maintain consistent method signatures and usage patterns, making it easy to use the appropriate module based on your pool type. The main differences are:
|
|
58
|
+
|
|
59
|
+
1. **Pool Types**: Vaults supports CLMM pools, VaultsV2 supports DLMM pools
|
|
60
|
+
2. **Target Use Cases**: Each module is optimized for its respective pool type
|
|
61
|
+
3. **Data Structures**: Each module provides data structures tailored to their specific pool types
|
|
62
|
+
|
|
45
63
|
### 1. Queries
|
|
46
64
|
#### 1. Get Pool List
|
|
47
65
|
Retrieves a list of all available vaults pools.
|
|
66
|
+
|
|
67
|
+
**Vaults Module:**
|
|
48
68
|
```typescript
|
|
49
69
|
const poolList = await sdk.Vaults.getPoolList()
|
|
50
70
|
```
|
|
51
71
|
|
|
72
|
+
**VaultsV2 Module:**
|
|
73
|
+
```typescript
|
|
74
|
+
const poolList = await sdk.VaultsV2.getPoolList()
|
|
75
|
+
```
|
|
76
|
+
|
|
52
77
|
#### 2. Get Specific Pool Details
|
|
53
78
|
Fetches details of a specific pool using its poolId.
|
|
79
|
+
|
|
80
|
+
**Vaults Module:**
|
|
54
81
|
```typescript
|
|
55
82
|
const poolId="0x..."
|
|
56
83
|
const pool = await sdk.Vaults.getPool(poolId)
|
|
57
84
|
```
|
|
58
85
|
|
|
59
|
-
|
|
60
|
-
|
|
86
|
+
**VaultsV2 Module:**
|
|
87
|
+
```typescript
|
|
88
|
+
const poolId="0x..."
|
|
89
|
+
const pool = await sdk.VaultsV2.getPool(poolId)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### 3. Querying LP Holdings
|
|
93
|
+
To query the LP (Liquidity Provider) token balance for a specific address in a particular pool.
|
|
94
|
+
|
|
95
|
+
**Vaults Module:**
|
|
61
96
|
```typescript
|
|
62
97
|
const poolId="0x..." // The ID of the pool
|
|
63
98
|
const address="0x..." // The address of the wallet
|
|
64
99
|
const res = await sdk.Vaults.getOwnerVaultsBalance(address, poolId)
|
|
65
100
|
```
|
|
66
101
|
|
|
67
|
-
|
|
68
|
-
|
|
102
|
+
**VaultsV2 Module:**
|
|
103
|
+
```typescript
|
|
104
|
+
const poolId="0x..." // The ID of the pool
|
|
105
|
+
const address="0x..." // The address of the wallet
|
|
106
|
+
const res = await sdk.VaultsV2.getOwnerVaultsBalance(address, poolId)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### 4. Get Specific CLMM Pool Details
|
|
110
|
+
Fetches details of a specific CLMM pool using its poolId.
|
|
69
111
|
```typescript
|
|
70
112
|
const clmm_pool_id="0x..."
|
|
71
|
-
|
|
113
|
+
const res = await sdk.CetusClmmSDK.Pool.getPool(clmm_pool_id)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### 5. Get Specific DLMM Pool Details
|
|
117
|
+
Fetches details of a specific DLMM pool using its poolId.
|
|
118
|
+
```typescript
|
|
119
|
+
const dlmm_pool_id="0x..."
|
|
120
|
+
const res = await sdk.CetusDlmmSDK.Pool.getPool(dlmm_pool_id)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### 6. VaultsV2 Additional Query Methods
|
|
124
|
+
|
|
125
|
+
**Get Multiple Pools by IDs:**
|
|
126
|
+
```typescript
|
|
127
|
+
const poolIds = ["0x...", "0x..."]
|
|
128
|
+
const pools = await sdk.VaultsV2.getAssignPoolList(poolIds)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Get Market List:**
|
|
132
|
+
```typescript
|
|
133
|
+
const marketsTableId = "0x..."
|
|
134
|
+
const markets = await sdk.VaultsV2.getMarketList(marketsTableId)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Get Market Position List:**
|
|
138
|
+
```typescript
|
|
139
|
+
const positionTableId = "0x..."
|
|
140
|
+
const positions = await sdk.VaultsV2.getMarketPositionList(positionTableId)
|
|
72
141
|
```
|
|
73
142
|
|
|
74
143
|
### 2. Deposit
|
|
75
144
|
Deposits can be made using different modes. Below are examples of various deposit types.
|
|
145
|
+
|
|
76
146
|
#### 1. Mode: FixedOneSide
|
|
77
147
|
In this mode, one asset's amount is fixed, and the other is calculated automatically.
|
|
148
|
+
|
|
149
|
+
**Vaults Module:**
|
|
78
150
|
```typescript
|
|
79
151
|
const poolId="0x..."
|
|
80
152
|
|
|
@@ -93,8 +165,30 @@ const tx = await sdk.Vaults.buildDepositPayload({
|
|
|
93
165
|
amount_b: result.deposit_amount_b,
|
|
94
166
|
})
|
|
95
167
|
```
|
|
168
|
+
|
|
169
|
+
**VaultsV2 Module:**
|
|
170
|
+
```typescript
|
|
171
|
+
const poolId="0x..."
|
|
172
|
+
|
|
173
|
+
// Pre-calculate deposit amounts based on the fixed asset
|
|
174
|
+
const result = await sdk.VaultsV2.preCalculateDepositAmount( {
|
|
175
|
+
mode: 'FixedOneSide',
|
|
176
|
+
fixed_amount: toDecimalsAmount(1, 6).toString(),// // Fixed amount
|
|
177
|
+
fixed_coin_a: true,// // Determines which asset is fixed
|
|
178
|
+
pool_id: poolId,
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
// Build the deposit transaction payload
|
|
182
|
+
const tx = await sdk.VaultsV2.buildDepositPayload({
|
|
183
|
+
pool_id: poolId,
|
|
184
|
+
amount_a: result.deposit_amount_a,
|
|
185
|
+
amount_b: result.deposit_amount_b,
|
|
186
|
+
})
|
|
187
|
+
```
|
|
96
188
|
#### 2. Mode: FlexibleBoth
|
|
97
189
|
Allows specifying amounts for both assets, and the system calculates the corresponding LP tokens.
|
|
190
|
+
|
|
191
|
+
**Vaults Module:**
|
|
98
192
|
```typescript
|
|
99
193
|
const poolId="0x..."
|
|
100
194
|
|
|
@@ -113,8 +207,29 @@ const tx = await sdk.Vaults.buildDepositPayload({
|
|
|
113
207
|
})
|
|
114
208
|
```
|
|
115
209
|
|
|
210
|
+
**VaultsV2 Module:**
|
|
211
|
+
```typescript
|
|
212
|
+
const poolId="0x..."
|
|
213
|
+
|
|
214
|
+
const result = await sdk.VaultsV2.preCalculateDepositAmount({
|
|
215
|
+
mode: 'FlexibleBoth',
|
|
216
|
+
coin_amount_a: toDecimalsAmount(1, 6).toString(), // User-defined deposit amount for asset A
|
|
217
|
+
coin_amount_b: toDecimalsAmount(1, 9).toString(), // User-defined deposit amount for asset B
|
|
218
|
+
pool_id: poolId,
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
// Build the deposit transaction payload
|
|
222
|
+
const tx = await sdk.VaultsV2.buildDepositPayload({
|
|
223
|
+
pool_id: poolId,
|
|
224
|
+
amount_a: result.deposit_amount_a,
|
|
225
|
+
amount_b: result.deposit_amount_b,
|
|
226
|
+
})
|
|
227
|
+
```
|
|
228
|
+
|
|
116
229
|
#### 3. Mode: OnlyCoinA or OnlyCoinB
|
|
117
230
|
These modes allow depositing only one type of asset.
|
|
231
|
+
|
|
232
|
+
**Vaults Module:**
|
|
118
233
|
```typescript
|
|
119
234
|
const poolId="0x..."
|
|
120
235
|
|
|
@@ -131,11 +246,30 @@ const tx = await sdk.Vaults.buildDepositPayload({
|
|
|
131
246
|
})
|
|
132
247
|
```
|
|
133
248
|
|
|
249
|
+
**VaultsV2 Module:**
|
|
250
|
+
```typescript
|
|
251
|
+
const poolId="0x..."
|
|
252
|
+
|
|
253
|
+
const result = await sdk.VaultsV2.preCalculateDepositAmount( {
|
|
254
|
+
mode: 'OnlyCoinA',
|
|
255
|
+
coin_amount_a: toDecimalsAmount(1, 6).toString(), // Deposit only asset A
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
// Build the deposit transaction payload
|
|
259
|
+
const tx = await sdk.VaultsV2.buildDepositPayload({
|
|
260
|
+
pool_id: poolId,
|
|
261
|
+
amount_a: result.deposit_amount_a,
|
|
262
|
+
amount_b: result.deposit_amount_b,
|
|
263
|
+
})
|
|
264
|
+
```
|
|
265
|
+
|
|
134
266
|
### 3. Withdrawal
|
|
135
267
|
Withdrawals can be performed in different modes, similar to deposits.
|
|
136
268
|
|
|
137
269
|
#### 1. Mode: FixedOneSide (Withdraw by LP token amount)
|
|
138
270
|
Withdraws assets based on a specified LP token amount.
|
|
271
|
+
|
|
272
|
+
**Vaults Module:**
|
|
139
273
|
```typescript
|
|
140
274
|
const poolId="0x..."
|
|
141
275
|
|
|
@@ -147,14 +281,27 @@ const tx = await sdk.Vaults.buildWithdrawPayload({
|
|
|
147
281
|
})
|
|
148
282
|
```
|
|
149
283
|
|
|
284
|
+
**VaultsV2 Module:**
|
|
285
|
+
```typescript
|
|
286
|
+
const poolId="0x..."
|
|
287
|
+
|
|
288
|
+
// Build the withdrawal transaction payload
|
|
289
|
+
const tx = await sdk.VaultsV2.buildWithdrawPayload({
|
|
290
|
+
pool_id: poolId,
|
|
291
|
+
burn_lp_amount: result.burn_lp_amount,
|
|
292
|
+
mode: result.mode,
|
|
293
|
+
})
|
|
294
|
+
```
|
|
295
|
+
|
|
150
296
|
|
|
151
297
|
#### 2. Mode: OnlyCoinA or OnlyCoinB (Withdraw by LP token amount)
|
|
152
298
|
In this mode, the user specifies the amount of a single coin (either Coin A or Coin B) they wish to receive.
|
|
153
299
|
Example for OnlyCoinA:
|
|
300
|
+
|
|
301
|
+
**Vaults Module:**
|
|
154
302
|
```typescript
|
|
155
303
|
const poolId="0x..."
|
|
156
304
|
|
|
157
|
-
|
|
158
305
|
// Build the withdrawal transaction payload
|
|
159
306
|
const tx = await sdk.Vaults.buildWithdrawPayload({
|
|
160
307
|
pool_id: poolId,
|
|
@@ -164,5 +311,61 @@ const tx = await sdk.Vaults.buildWithdrawPayload({
|
|
|
164
311
|
});
|
|
165
312
|
```
|
|
166
313
|
|
|
314
|
+
**VaultsV2 Module:**
|
|
315
|
+
```typescript
|
|
316
|
+
const poolId="0x..."
|
|
167
317
|
|
|
318
|
+
// Build the withdrawal transaction payload
|
|
319
|
+
const tx = await sdk.VaultsV2.buildWithdrawPayload({
|
|
320
|
+
pool_id: poolId,
|
|
321
|
+
burn_lp_amount: result.burn_lp_amount, // Amount of LP tokens to burn
|
|
322
|
+
mode: result.mode, // Withdrawal mode ('OnlyCoinA')
|
|
323
|
+
slippage: "0.001" // Slippage tolerance when swapping the counterpart asset during the withdrawal
|
|
324
|
+
});
|
|
325
|
+
```
|
|
168
326
|
|
|
327
|
+
## Module Comparison Summary
|
|
328
|
+
|
|
329
|
+
### Vaults Module (sdk.Vaults)
|
|
330
|
+
- **Purpose**: Specialized vault module for CLMM pools
|
|
331
|
+
- **Pool Support**: CLMM (Constant Liquidity Market Maker) pools only
|
|
332
|
+
- **Key Features**: CLMM-optimized vault operations, fee collection, reward management
|
|
333
|
+
- **Use Case**: Liquidity provision and management in CLMM pools
|
|
334
|
+
|
|
335
|
+
### VaultsV2 Module (sdk.VaultsV2)
|
|
336
|
+
- **Purpose**: Specialized vault module for DLMM pools
|
|
337
|
+
- **Pool Support**: DLMM (Dynamic Liquidity Market Maker) pools only
|
|
338
|
+
- **Key Features**:
|
|
339
|
+
- DLMM-optimized vault operations
|
|
340
|
+
- DLMM market and position management
|
|
341
|
+
- DLMM-specific data structures
|
|
342
|
+
- Advanced query methods for DLMM markets and positions
|
|
343
|
+
- **Use Case**: Liquidity provision and management in DLMM pools
|
|
344
|
+
|
|
345
|
+
### Method Compatibility
|
|
346
|
+
Both modules maintain consistent method signatures for core operations:
|
|
347
|
+
- `getPoolList()` - Get list of available pools
|
|
348
|
+
- `getPool(poolId)` - Get specific pool details
|
|
349
|
+
- `getOwnerVaultsBalance(address, poolId)` - Query LP holdings
|
|
350
|
+
- `preCalculateDepositAmount()` - Calculate deposit amounts
|
|
351
|
+
- `buildDepositPayload()` - Build deposit transactions
|
|
352
|
+
- `preCalculateWithdrawAmount()` - Calculate withdrawal amounts
|
|
353
|
+
- `buildWithdrawPayload()` - Build withdrawal transactions
|
|
354
|
+
|
|
355
|
+
### Module Selection Guide
|
|
356
|
+
Choose the appropriate module based on your pool type:
|
|
357
|
+
|
|
358
|
+
**For CLMM Pools:**
|
|
359
|
+
- Use `sdk.Vaults` for all CLMM pool operations
|
|
360
|
+
- Optimized for constant liquidity market maker pools
|
|
361
|
+
- Provides traditional vault functionality
|
|
362
|
+
|
|
363
|
+
**For DLMM Pools:**
|
|
364
|
+
- Use `sdk.VaultsV2` for all DLMM pool operations
|
|
365
|
+
- Optimized for dynamic liquidity market maker pools
|
|
366
|
+
- Provides advanced DLMM-specific features
|
|
367
|
+
|
|
368
|
+
**Key Points:**
|
|
369
|
+
- Both modules can be used simultaneously in the same application
|
|
370
|
+
- Method signatures are consistent between modules for easy switching
|
|
371
|
+
- Choose the module that matches your target pool type
|