@cetusprotocol/sui-clmm-sdk 1.0.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/.turbo/turbo-build.log +11100 -0
- package/README.md +108 -0
- package/dist/index.d.mts +2251 -0
- package/dist/index.d.ts +2251 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -0
- package/docs/add_liquidity.md +145 -0
- package/docs/close_position.md +57 -0
- package/docs/collect_fees.md +37 -0
- package/docs/create_clmm_pool.md +228 -0
- package/docs/error_code.md +69 -0
- package/docs/get_clmm_pools.md +92 -0
- package/docs/get_positions.md +70 -0
- package/docs/get_reward.md +53 -0
- package/docs/get_ticks.md +39 -0
- package/docs/migrate_to_version_6.0.md +143 -0
- package/docs/open_position.md +224 -0
- package/docs/partner_swap.md +60 -0
- package/docs/pre_swap.md +136 -0
- package/docs/remove_liquidity.md +124 -0
- package/docs/swap.md +153 -0
- package/docs/utils.md +85 -0
- package/package.json +37 -0
- package/src/config/index.ts +2 -0
- package/src/config/mainnet.ts +41 -0
- package/src/config/testnet.ts +40 -0
- package/src/errors/errors.ts +93 -0
- package/src/errors/index.ts +1 -0
- package/src/index.ts +10 -0
- package/src/math/apr.ts +167 -0
- package/src/math/index.ts +1 -0
- package/src/modules/configModule.ts +540 -0
- package/src/modules/index.ts +5 -0
- package/src/modules/poolModule.ts +1066 -0
- package/src/modules/positionModule.ts +932 -0
- package/src/modules/rewarderModule.ts +430 -0
- package/src/modules/swapModule.ts +389 -0
- package/src/sdk.ts +131 -0
- package/src/types/clmm_type.ts +1002 -0
- package/src/types/clmmpool.ts +366 -0
- package/src/types/config_type.ts +241 -0
- package/src/types/index.ts +8 -0
- package/src/types/sui.ts +124 -0
- package/src/types/token_type.ts +189 -0
- package/src/utils/common.ts +426 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/positionUtils.ts +434 -0
- package/src/utils/swapUtils.ts +499 -0
- package/tests/add_liquidity.test.ts +121 -0
- package/tests/add_liquidity_fix_token.test.ts +182 -0
- package/tests/apr.test.ts +71 -0
- package/tests/cetus_config.test.ts +26 -0
- package/tests/collect_fees.test.ts +11 -0
- package/tests/pool.test.ts +267 -0
- package/tests/position.test.ts +145 -0
- package/tests/remove_liquidity.test.ts +119 -0
- package/tests/rewarder.test.ts +60 -0
- package/tests/sdk_config.test.ts +49 -0
- package/tests/swap.test.ts +254 -0
- package/tests/tsconfig.json +26 -0
- package/tsconfig.json +5 -0
- package/tsup.config.ts +10 -0
|
@@ -0,0 +1,1002 @@
|
|
|
1
|
+
import BN from 'bn.js'
|
|
2
|
+
import { CoinPairType, NFT, Percentage, SuiAddressType, SuiObjectIdType } from '@cetusprotocol/common-sdk'
|
|
3
|
+
import { TickData } from './clmmpool'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Enumerates the possible status values of a position within a liquidity mining module.
|
|
7
|
+
*/
|
|
8
|
+
export enum ClmmPositionStatus {
|
|
9
|
+
/**
|
|
10
|
+
* The position has been deleted or removed.
|
|
11
|
+
*/
|
|
12
|
+
'Deleted' = 'Deleted',
|
|
13
|
+
/**
|
|
14
|
+
* The position exists and is active.
|
|
15
|
+
*/
|
|
16
|
+
'Exists' = 'Exists',
|
|
17
|
+
/**
|
|
18
|
+
* The position does not exist or is not active.
|
|
19
|
+
*/
|
|
20
|
+
'NotExists' = 'NotExists',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The Cetus clmmpool's position NFT.
|
|
25
|
+
*/
|
|
26
|
+
export type Position = {
|
|
27
|
+
/**
|
|
28
|
+
* The unique identifier of the position object.
|
|
29
|
+
*/
|
|
30
|
+
pos_object_id: SuiObjectIdType
|
|
31
|
+
/**
|
|
32
|
+
* The owner of the position.
|
|
33
|
+
*/
|
|
34
|
+
owner: SuiObjectIdType
|
|
35
|
+
/**
|
|
36
|
+
* The liquidity pool associated with the position.
|
|
37
|
+
*/
|
|
38
|
+
pool: SuiObjectIdType
|
|
39
|
+
/**
|
|
40
|
+
* The type of position represented by an address.
|
|
41
|
+
*/
|
|
42
|
+
type: SuiAddressType
|
|
43
|
+
/**
|
|
44
|
+
* The index of the position.
|
|
45
|
+
*/
|
|
46
|
+
index: number
|
|
47
|
+
/**
|
|
48
|
+
* The amount of liquidity held by the position.
|
|
49
|
+
*/
|
|
50
|
+
liquidity: string
|
|
51
|
+
/**
|
|
52
|
+
* The lower tick index of the position range.
|
|
53
|
+
*/
|
|
54
|
+
tick_lower_index: number
|
|
55
|
+
/**
|
|
56
|
+
* The upper tick index of the position range.
|
|
57
|
+
*/
|
|
58
|
+
tick_upper_index: number
|
|
59
|
+
/**
|
|
60
|
+
* The status of the position within the liquidity mining module.
|
|
61
|
+
*/
|
|
62
|
+
position_status: ClmmPositionStatus
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The address type of the first coin in the position.
|
|
66
|
+
*/
|
|
67
|
+
coin_type_a: SuiAddressType
|
|
68
|
+
/**
|
|
69
|
+
* The address type of the second coin in the position.
|
|
70
|
+
*/
|
|
71
|
+
coin_type_b: SuiAddressType
|
|
72
|
+
} & NFT &
|
|
73
|
+
PositionReward
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Represents reward information associated with a liquidity mining position.
|
|
77
|
+
*/
|
|
78
|
+
export type PositionReward = {
|
|
79
|
+
/**
|
|
80
|
+
* The unique identifier of the position object.
|
|
81
|
+
*/
|
|
82
|
+
pos_object_id: SuiObjectIdType
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The amount of liquidity held by the position.
|
|
86
|
+
*/
|
|
87
|
+
liquidity: string
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The lower tick index of the position range.
|
|
91
|
+
*/
|
|
92
|
+
tick_lower_index: number
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The upper tick index of the position range.
|
|
96
|
+
*/
|
|
97
|
+
tick_upper_index: number
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The accumulated fee growth inside the first coin of the position.
|
|
101
|
+
*/
|
|
102
|
+
fee_growth_inside_a: string
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The accumulated fee owned in the first coin of the position.
|
|
106
|
+
*/
|
|
107
|
+
fee_owned_a: string
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The accumulated fee growth inside the second coin of the position.
|
|
111
|
+
*/
|
|
112
|
+
fee_growth_inside_b: string
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The accumulated fee owned in the second coin of the position.
|
|
116
|
+
*/
|
|
117
|
+
fee_owned_b: string
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The amount of reward owned in the first reward category.
|
|
121
|
+
*/
|
|
122
|
+
reward_amount_owned_0: string
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The amount of reward owned in the second reward category.
|
|
126
|
+
*/
|
|
127
|
+
reward_amount_owned_1: string
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The amount of reward owned in the third reward category.
|
|
131
|
+
*/
|
|
132
|
+
reward_amount_owned_2: string
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The accumulated reward growth inside the first reward category.
|
|
136
|
+
*/
|
|
137
|
+
reward_growth_inside_0: string
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The accumulated reward growth inside the second reward category.
|
|
141
|
+
*/
|
|
142
|
+
reward_growth_inside_1: string
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The accumulated reward growth inside the third reward category.
|
|
146
|
+
*/
|
|
147
|
+
reward_growth_inside_2: string
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Represents immutable properties of a liquidity pool.
|
|
152
|
+
*/
|
|
153
|
+
export type PoolImmutables = {
|
|
154
|
+
/**
|
|
155
|
+
* The address of the liquidity pool.
|
|
156
|
+
*/
|
|
157
|
+
id: string
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The tick spacing value used in the pool.
|
|
161
|
+
*/
|
|
162
|
+
tick_spacing: string
|
|
163
|
+
} & CoinPairType
|
|
164
|
+
/**
|
|
165
|
+
* "Pool" is the core module of Clmm protocol, which defines the trading pairs of "clmmpool".
|
|
166
|
+
*/
|
|
167
|
+
export type Pool = {
|
|
168
|
+
/**
|
|
169
|
+
* Represents the type or category of a liquidity pool.
|
|
170
|
+
*/
|
|
171
|
+
pool_type: string
|
|
172
|
+
/**
|
|
173
|
+
* The amount of coin a.
|
|
174
|
+
*/
|
|
175
|
+
coin_amount_a: number
|
|
176
|
+
/**
|
|
177
|
+
* The amount of coin b.
|
|
178
|
+
*/
|
|
179
|
+
coin_amount_b: number
|
|
180
|
+
/**
|
|
181
|
+
* The current sqrt price
|
|
182
|
+
*/
|
|
183
|
+
current_sqrt_price: number
|
|
184
|
+
/**
|
|
185
|
+
* The current tick index
|
|
186
|
+
*/
|
|
187
|
+
current_tick_index: number
|
|
188
|
+
/**
|
|
189
|
+
* The global fee growth of coin a as Q64.64
|
|
190
|
+
*/
|
|
191
|
+
fee_growth_global_b: number
|
|
192
|
+
/**
|
|
193
|
+
* The global fee growth of coin b as Q64.64
|
|
194
|
+
*/
|
|
195
|
+
fee_growth_global_a: number
|
|
196
|
+
/**
|
|
197
|
+
* The amounts of coin a owned to protocol
|
|
198
|
+
*/
|
|
199
|
+
fee_protocol_coin_a: number
|
|
200
|
+
/**
|
|
201
|
+
* The amounts of coin b owned to protocol
|
|
202
|
+
*/
|
|
203
|
+
fee_protocol_coin_b: number
|
|
204
|
+
/**
|
|
205
|
+
* The numerator of fee rate, the denominator is 1_000_000.
|
|
206
|
+
*/
|
|
207
|
+
fee_rate: number
|
|
208
|
+
/**
|
|
209
|
+
* is the pool pause
|
|
210
|
+
*/
|
|
211
|
+
is_pause: boolean
|
|
212
|
+
/**
|
|
213
|
+
* The liquidity of current tick index
|
|
214
|
+
*/
|
|
215
|
+
liquidity: number
|
|
216
|
+
/**
|
|
217
|
+
* The pool index
|
|
218
|
+
*/
|
|
219
|
+
index: number
|
|
220
|
+
/**
|
|
221
|
+
* The positions manager
|
|
222
|
+
*/
|
|
223
|
+
position_manager: {
|
|
224
|
+
positions_handle: string
|
|
225
|
+
size: number
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The rewarder manager
|
|
229
|
+
*/
|
|
230
|
+
rewarder_infos: Array<Rewarder>
|
|
231
|
+
rewarder_last_updated_time: string
|
|
232
|
+
/**
|
|
233
|
+
* The tick manager handle
|
|
234
|
+
*/
|
|
235
|
+
ticks_handle: string
|
|
236
|
+
/**
|
|
237
|
+
* The url for pool and position
|
|
238
|
+
*/
|
|
239
|
+
uri: string
|
|
240
|
+
/**
|
|
241
|
+
* The name for pool
|
|
242
|
+
*/
|
|
243
|
+
name: string
|
|
244
|
+
} & PoolImmutables
|
|
245
|
+
|
|
246
|
+
export type Rewarder = {
|
|
247
|
+
/**
|
|
248
|
+
* The coin address where rewards will be distributed.
|
|
249
|
+
*/
|
|
250
|
+
coin_type: string
|
|
251
|
+
/**
|
|
252
|
+
* The rate of emissions in coins per second.
|
|
253
|
+
*/
|
|
254
|
+
emissions_per_second: number
|
|
255
|
+
/**
|
|
256
|
+
* The global growth factor influencing reward emissions.
|
|
257
|
+
*/
|
|
258
|
+
growth_global: number
|
|
259
|
+
/**
|
|
260
|
+
* The total emissions in coins that occur every day.
|
|
261
|
+
*/
|
|
262
|
+
emissions_every_day: number
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Configuration settings for the Cryptocurrency Liquidity Mining Module (CLMM).
|
|
266
|
+
*/
|
|
267
|
+
export type ClmmConfig = {
|
|
268
|
+
/**
|
|
269
|
+
* Identifier of the pools for liquidity mining.
|
|
270
|
+
*/
|
|
271
|
+
pools_id: SuiObjectIdType
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Identifier of the global configuration for the module.
|
|
275
|
+
*/
|
|
276
|
+
global_config_id: SuiObjectIdType
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Identifier of the administrative capacity for the module.
|
|
280
|
+
*/
|
|
281
|
+
admin_cap_id: SuiObjectIdType
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Identifier of the global vault for the module.
|
|
285
|
+
*/
|
|
286
|
+
global_vault_id: SuiObjectIdType
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Optional identifier of partners for the liquidity mining module.
|
|
290
|
+
*/
|
|
291
|
+
partners_id?: SuiObjectIdType
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Represents an event to create a liquidity mining partner.
|
|
296
|
+
*/
|
|
297
|
+
export type CreatePartnerEvent = {
|
|
298
|
+
/**
|
|
299
|
+
* The name of the liquidity mining partner.
|
|
300
|
+
*/
|
|
301
|
+
name: string
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* The recipient's address for the partner.
|
|
305
|
+
*/
|
|
306
|
+
recipient: SuiAddressType
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Identifier of the partner.
|
|
310
|
+
*/
|
|
311
|
+
partner_id: SuiObjectIdType
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Identifier of the partner's capacity.
|
|
315
|
+
*/
|
|
316
|
+
partner_cap_id: SuiObjectIdType
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The fee rate associated with the partner.
|
|
320
|
+
*/
|
|
321
|
+
fee_rate: string
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The starting epoch of the partnership.
|
|
325
|
+
*/
|
|
326
|
+
start_epoch: string
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* The ending epoch of the partnership.
|
|
330
|
+
*/
|
|
331
|
+
end_epoch: string
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Represents parameters for creating a liquidity pool.
|
|
336
|
+
*/
|
|
337
|
+
export type CreatePoolParams = {
|
|
338
|
+
/**
|
|
339
|
+
* The tick spacing value used for the pool.
|
|
340
|
+
*/
|
|
341
|
+
tick_spacing: number
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The initial square root price value for the pool.
|
|
345
|
+
*/
|
|
346
|
+
initialize_sqrt_price: string
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* The Uniform Resource Identifier (URI) associated with the pool.
|
|
350
|
+
*/
|
|
351
|
+
uri: string
|
|
352
|
+
} & CoinPairType
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Represents parameters for adding liquidity to a created liquidity pool.
|
|
356
|
+
* Extends the CreatePoolParams type.
|
|
357
|
+
*/
|
|
358
|
+
export type CreatePoolAddLiquidityParams = CreatePoolParams & {
|
|
359
|
+
/**
|
|
360
|
+
* The amount of the first coin to be added as liquidity.
|
|
361
|
+
* Can be a number or a string.
|
|
362
|
+
*/
|
|
363
|
+
amount_a: number | string
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The amount of the second coin to be added as liquidity.
|
|
367
|
+
* Can be a number or a string.
|
|
368
|
+
*/
|
|
369
|
+
amount_b: number | string
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Indicates whether the amount of the first coin is fixed.
|
|
373
|
+
*/
|
|
374
|
+
fix_amount_a: boolean
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* The lower tick index for liquidity provision.
|
|
378
|
+
*/
|
|
379
|
+
tick_lower: number
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* The upper tick index for liquidity provision.
|
|
383
|
+
*/
|
|
384
|
+
tick_upper: number
|
|
385
|
+
|
|
386
|
+
metadata_a: SuiObjectIdType
|
|
387
|
+
metadata_b: SuiObjectIdType
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export type FetchParams = {
|
|
391
|
+
pool_id: SuiObjectIdType
|
|
392
|
+
} & CoinPairType
|
|
393
|
+
|
|
394
|
+
type CommonParams = {
|
|
395
|
+
/**
|
|
396
|
+
* The object id about which pool you want to operation.
|
|
397
|
+
*/
|
|
398
|
+
pool_id: SuiObjectIdType
|
|
399
|
+
/**
|
|
400
|
+
* The object id about position.
|
|
401
|
+
*/
|
|
402
|
+
pos_id: SuiObjectIdType
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export type AddLiquidityFixTokenParams = {
|
|
406
|
+
/**
|
|
407
|
+
* If fixed amount A, you must set amount_a, amount_b will be auto calculated by ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts().
|
|
408
|
+
*/
|
|
409
|
+
amount_a: number | string
|
|
410
|
+
/**
|
|
411
|
+
* If fixed amount B, you must set amount_b, amount_a will be auto calculated by ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts().
|
|
412
|
+
*/
|
|
413
|
+
amount_b: number | string
|
|
414
|
+
/**
|
|
415
|
+
* Price slippage point.
|
|
416
|
+
*/
|
|
417
|
+
slippage: number
|
|
418
|
+
/**
|
|
419
|
+
* true means fixed coinA amount, false means fixed coinB amount
|
|
420
|
+
*/
|
|
421
|
+
fix_amount_a: boolean
|
|
422
|
+
/**
|
|
423
|
+
* control whether or not to create a new position or add liquidity on existed position.
|
|
424
|
+
*/
|
|
425
|
+
is_open: boolean
|
|
426
|
+
} & AddLiquidityCommonParams
|
|
427
|
+
|
|
428
|
+
export type AddLiquidityParams = {
|
|
429
|
+
/**
|
|
430
|
+
* The actual change in liquidity that has been added.
|
|
431
|
+
*/
|
|
432
|
+
delta_liquidity: string
|
|
433
|
+
/**
|
|
434
|
+
* The max limit about used coin a amount
|
|
435
|
+
*/
|
|
436
|
+
max_amount_a: number | string
|
|
437
|
+
/**
|
|
438
|
+
* The max limit about used coin b amount.
|
|
439
|
+
*/
|
|
440
|
+
max_amount_b: number | string
|
|
441
|
+
} & AddLiquidityCommonParams
|
|
442
|
+
|
|
443
|
+
export type AddLiquidityCommonParams = {
|
|
444
|
+
/**
|
|
445
|
+
* Represents the index of the lower tick boundary.
|
|
446
|
+
*/
|
|
447
|
+
tick_lower: string | number
|
|
448
|
+
/**
|
|
449
|
+
* Represents the index of the upper tick boundary.
|
|
450
|
+
*/
|
|
451
|
+
tick_upper: string | number
|
|
452
|
+
/**
|
|
453
|
+
* If you already has one position, you can select collect fees while adding liquidity.
|
|
454
|
+
*/
|
|
455
|
+
collect_fee: boolean
|
|
456
|
+
/**
|
|
457
|
+
* If these not empty, it will collect rewarder in this position, if you already open the position.
|
|
458
|
+
*/
|
|
459
|
+
rewarder_coin_types: SuiAddressType[]
|
|
460
|
+
} & CoinPairType &
|
|
461
|
+
CommonParams
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Parameters for opening a position within a liquidity pool.
|
|
465
|
+
* Extends the CoinPairType type.
|
|
466
|
+
*/
|
|
467
|
+
export type OpenPositionParams = CoinPairType & {
|
|
468
|
+
/**
|
|
469
|
+
* The lower tick index for the position.
|
|
470
|
+
*/
|
|
471
|
+
tick_lower: string
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* The upper tick index for the position.
|
|
475
|
+
*/
|
|
476
|
+
tick_upper: string
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* The object identifier of the liquidity pool.
|
|
480
|
+
*/
|
|
481
|
+
pool_id: SuiObjectIdType
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Parameters for opening a position within a liquidity pool using full range.
|
|
486
|
+
*/
|
|
487
|
+
export type FullRangeParams = {
|
|
488
|
+
is_full_range: true
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export type CustomRangeParams = {
|
|
492
|
+
is_full_range: false
|
|
493
|
+
min_price: string
|
|
494
|
+
max_price: string
|
|
495
|
+
coin_decimals_a: number
|
|
496
|
+
coin_decimals_b: number
|
|
497
|
+
price_base_coin: 'coin_a' | 'coin_b'
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export type CreatePoolCustomRangeParams = {
|
|
501
|
+
is_full_range: false
|
|
502
|
+
min_price: string
|
|
503
|
+
max_price: string
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export type CalculateAddLiquidityWithPriceParams = {
|
|
507
|
+
pool_id: SuiObjectIdType
|
|
508
|
+
liquidity: string
|
|
509
|
+
slippage: number
|
|
510
|
+
refresh_pool_price?: boolean
|
|
511
|
+
add_mode_params: FullRangeParams | CustomRangeParams
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export type CalculateAddLiquidityFixCoinWithPriceParams = {
|
|
515
|
+
pool_id: SuiObjectIdType
|
|
516
|
+
coin_amount: string
|
|
517
|
+
fix_amount_a: boolean
|
|
518
|
+
slippage: number
|
|
519
|
+
refresh_pool_price?: boolean
|
|
520
|
+
add_mode_params: FullRangeParams | CustomRangeParams
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export type CalculateAddLiquidityResult = {
|
|
524
|
+
coin_amount_a: string
|
|
525
|
+
coin_amount_b: string
|
|
526
|
+
coin_amount_limit_a: string
|
|
527
|
+
coin_amount_limit_b: string
|
|
528
|
+
liquidity: string
|
|
529
|
+
tick_lower: number
|
|
530
|
+
tick_upper: number
|
|
531
|
+
fix_amount_a?: boolean
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export type CalculateCreatePoolWithPriceParams = {
|
|
535
|
+
tick_spacing: number
|
|
536
|
+
current_price: string
|
|
537
|
+
coin_amount: string
|
|
538
|
+
fix_amount_a: boolean
|
|
539
|
+
slippage: number
|
|
540
|
+
coin_decimals_a: number
|
|
541
|
+
coin_decimals_b: number
|
|
542
|
+
price_base_coin: 'coin_a' | 'coin_b'
|
|
543
|
+
add_mode_params: FullRangeParams | CreatePoolCustomRangeParams
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export type CalculateCreatePoolResult = {
|
|
547
|
+
coin_amount_a: string
|
|
548
|
+
coin_amount_b: string
|
|
549
|
+
coin_amount_limit_a: string
|
|
550
|
+
coin_amount_limit_b: string
|
|
551
|
+
liquidity: string
|
|
552
|
+
tick_lower: number
|
|
553
|
+
tick_upper: number
|
|
554
|
+
initialize_sqrt_price: string
|
|
555
|
+
fix_amount_a: boolean
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export type CreatePoolAddLiquidityWithPriceParams = {
|
|
559
|
+
tick_spacing: number
|
|
560
|
+
uri?: string
|
|
561
|
+
calculate_result: CalculateCreatePoolResult
|
|
562
|
+
add_mode_params: FullRangeParams | CreatePoolCustomRangeParams
|
|
563
|
+
} & CoinPairType
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Parameters for adding liquidity to a liquidity pool using price range.
|
|
567
|
+
*/
|
|
568
|
+
export type AddLiquidityWithPriceRangeParams = {
|
|
569
|
+
/**
|
|
570
|
+
* The object identifier of the liquidity pool.
|
|
571
|
+
*/
|
|
572
|
+
pool_id: SuiObjectIdType
|
|
573
|
+
/**
|
|
574
|
+
* The result of calculateAddLiquidityResultWithPrice.
|
|
575
|
+
*/
|
|
576
|
+
calculate_result: CalculateAddLiquidityResult
|
|
577
|
+
/**
|
|
578
|
+
* The parameters of full range or custom range.
|
|
579
|
+
*/
|
|
580
|
+
add_mode_params: FullRangeParams | CustomRangeParams
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Parameters for opening a position within a liquidity pool using price range.
|
|
585
|
+
* Extends the CoinPairType type.
|
|
586
|
+
*/
|
|
587
|
+
export type OpenPositionWithPriceParams = {
|
|
588
|
+
/**
|
|
589
|
+
* The object identifier of the liquidity pool.
|
|
590
|
+
*/
|
|
591
|
+
pool_id: SuiObjectIdType
|
|
592
|
+
} & (FullRangeParams | CustomRangeParams)
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Parameters for removing liquidity from a pool.
|
|
596
|
+
* Extends the CoinPairType and CommonParams types.
|
|
597
|
+
*/
|
|
598
|
+
export type RemoveLiquidityParams = CoinPairType &
|
|
599
|
+
CommonParams & {
|
|
600
|
+
/**
|
|
601
|
+
* The change in liquidity amount to be removed.
|
|
602
|
+
*/
|
|
603
|
+
delta_liquidity: string
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* The minimum amount of the first coin to be received.
|
|
607
|
+
*/
|
|
608
|
+
min_amount_a: string
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* The minimum amount of the second coin to be received.
|
|
612
|
+
*/
|
|
613
|
+
min_amount_b: string
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Indicates whether to collect fees during the removal.
|
|
617
|
+
*/
|
|
618
|
+
collect_fee: boolean
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Coin types associated with rewarder contracts.
|
|
622
|
+
*/
|
|
623
|
+
rewarder_coin_types: string[]
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Parameters for closing a position within a liquidity pool.
|
|
628
|
+
* Extends the CoinPairType, CommonParams, and CommonParams types.
|
|
629
|
+
*/
|
|
630
|
+
export type ClosePositionParams = CoinPairType &
|
|
631
|
+
CommonParams & {
|
|
632
|
+
/**
|
|
633
|
+
* Coin types associated with rewarder contracts.
|
|
634
|
+
*/
|
|
635
|
+
rewarder_coin_types: SuiAddressType[]
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* The minimum amount of the first coin to be received.
|
|
639
|
+
*/
|
|
640
|
+
min_amount_a: string
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* The minimum amount of the second coin to be received.
|
|
644
|
+
*/
|
|
645
|
+
min_amount_b: string
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Indicates whether to collect fees during the closing.
|
|
649
|
+
*/
|
|
650
|
+
collect_fee: boolean
|
|
651
|
+
} & CoinPairType &
|
|
652
|
+
CommonParams
|
|
653
|
+
/**
|
|
654
|
+
* Represents parameters for collecting fees.
|
|
655
|
+
*/
|
|
656
|
+
export type CollectFeeParams = CommonParams & CoinPairType
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Represents parameters for collecting rewarder fees.
|
|
660
|
+
*/
|
|
661
|
+
export type CollectRewarderParams = {
|
|
662
|
+
/**
|
|
663
|
+
* The identifier of the pool.
|
|
664
|
+
*/
|
|
665
|
+
pool_id: SuiObjectIdType
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* The identifier of the position.
|
|
669
|
+
*/
|
|
670
|
+
pos_id: SuiObjectIdType
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Specifies if the fee should be collected.
|
|
674
|
+
*/
|
|
675
|
+
collect_fee: boolean
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* An array of rewarder coin types.
|
|
679
|
+
*/
|
|
680
|
+
rewarder_coin_types: SuiAddressType[]
|
|
681
|
+
} & CoinPairType
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Represents the amount owned by a rewarder.
|
|
685
|
+
*/
|
|
686
|
+
export type RewarderAmountOwned = {
|
|
687
|
+
/**
|
|
688
|
+
* The amount owed.
|
|
689
|
+
*/
|
|
690
|
+
amount_owned: string
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* The address of the coin.
|
|
694
|
+
*/
|
|
695
|
+
coin_type: string
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export type PositionTransactionInfo = {
|
|
699
|
+
index: string
|
|
700
|
+
tx_digest: string
|
|
701
|
+
package_id: string
|
|
702
|
+
transaction_module: string
|
|
703
|
+
sender: string
|
|
704
|
+
type: string
|
|
705
|
+
timestamp_ms: string
|
|
706
|
+
parsed_json: any
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
export type PoolTransactionInfo = {
|
|
710
|
+
index: string
|
|
711
|
+
tx: string
|
|
712
|
+
sender: string
|
|
713
|
+
type: string
|
|
714
|
+
block_time: string
|
|
715
|
+
parsed_json: any
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
export const poolFilterEvenTypes = ['RemoveLiquidityEvent', 'SwapEvent', 'AddLiquidityEvent']
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* @category CollectFeesQuote
|
|
722
|
+
*/
|
|
723
|
+
export type CollectFeesQuote = {
|
|
724
|
+
position_id: string
|
|
725
|
+
fee_owned_a: string
|
|
726
|
+
fee_owned_b: string
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
export type FetchPosRewardParams = {
|
|
730
|
+
pool_id: string
|
|
731
|
+
position_id: string
|
|
732
|
+
rewarder_types: string[]
|
|
733
|
+
} & CoinPairType
|
|
734
|
+
|
|
735
|
+
export type FetchPosFeeParams = {
|
|
736
|
+
pool_id: string
|
|
737
|
+
position_id: string
|
|
738
|
+
} & CoinPairType
|
|
739
|
+
|
|
740
|
+
export type PosRewarderResult = {
|
|
741
|
+
pool_id: string
|
|
742
|
+
position_id: string
|
|
743
|
+
rewarder_amounts: RewarderAmountOwned[]
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* If changes in liquidity are required before the swap, then this parameter should be passed.
|
|
748
|
+
*/
|
|
749
|
+
export type PreSwapLpChangeParams = {
|
|
750
|
+
/**
|
|
751
|
+
* Unique identifier for the liquidity pool involved in the transaction.
|
|
752
|
+
*/
|
|
753
|
+
pool_id: string
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Lower bound of the liquidity range. In AMM models, like Uniswap V3, liquidity is provided within specific price ranges. This represents the lower limit of that range.
|
|
757
|
+
*/
|
|
758
|
+
tick_lower: number
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Upper bound of the liquidity range, corresponding to the lower bound. This defines the upper limit of the range where liquidity is provided.
|
|
762
|
+
*/
|
|
763
|
+
tick_upper: number
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* The change in liquidity, which can be a large number and is thus represented as a string. It can be positive or negative, indicating an increase or decrease in liquidity.
|
|
767
|
+
*/
|
|
768
|
+
delta_liquidity: number
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* A boolean value indicating whether the 'delta_liquidity' represents an increase (true) or decrease (false) in liquidity.
|
|
772
|
+
*/
|
|
773
|
+
is_increase: boolean
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Represents parameters for a pre-swap operation with multiple pools.
|
|
777
|
+
*/
|
|
778
|
+
export type PreSwapWithMultiPoolParams = {
|
|
779
|
+
/**
|
|
780
|
+
* An array of pool addresses for the pre-swap.
|
|
781
|
+
*/
|
|
782
|
+
pool_ids: string[]
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Specifies if the swap is from token A to token B.
|
|
786
|
+
*/
|
|
787
|
+
a2b: boolean
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Specifies if the swap amount is specified in token A.
|
|
791
|
+
*/
|
|
792
|
+
by_amount_in: boolean
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* The swap amount.
|
|
796
|
+
*/
|
|
797
|
+
amount: string
|
|
798
|
+
} & CoinPairType
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Represents parameters for a pre-swap operation.
|
|
802
|
+
*/
|
|
803
|
+
export type PreSwapParams = {
|
|
804
|
+
/**
|
|
805
|
+
* The pool information for the pre-swap.
|
|
806
|
+
*/
|
|
807
|
+
pool: Pool
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* The current square root price.
|
|
811
|
+
*/
|
|
812
|
+
current_sqrt_price: number
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* The number of decimal places for token A.
|
|
816
|
+
*/
|
|
817
|
+
decimals_a: number
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* The number of decimal places for token B.
|
|
821
|
+
*/
|
|
822
|
+
decimals_b: number
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Specifies if the swap is from token A to token B.
|
|
826
|
+
*/
|
|
827
|
+
a2b: boolean
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Specifies if the swap amount is specified in token A.
|
|
831
|
+
*/
|
|
832
|
+
by_amount_in: boolean
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* The swap amount.
|
|
836
|
+
*/
|
|
837
|
+
amount: string
|
|
838
|
+
} & CoinPairType
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Represents parameters for a transitional pre-swap operation with multiple pools.
|
|
842
|
+
*/
|
|
843
|
+
export type TransPreSwapWithMultiPoolParams = {
|
|
844
|
+
/**
|
|
845
|
+
* The address of the pool for the transitional pre-swap.
|
|
846
|
+
*/
|
|
847
|
+
pool_address: string
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Specifies if the swap is from token A to token B.
|
|
851
|
+
*/
|
|
852
|
+
a2b: boolean
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Specifies if the swap amount is specified in token A.
|
|
856
|
+
*/
|
|
857
|
+
by_amount_in: boolean
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* The swap amount.
|
|
861
|
+
*/
|
|
862
|
+
amount: string
|
|
863
|
+
} & CoinPairType
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* Represents parameters for calculating rates in a swap.
|
|
867
|
+
*/
|
|
868
|
+
export type CalculateRatesParams = {
|
|
869
|
+
/**
|
|
870
|
+
* The number of decimal places for token A.
|
|
871
|
+
*/
|
|
872
|
+
decimals_a: number
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* The number of decimal places for token B.
|
|
876
|
+
*/
|
|
877
|
+
decimals_b: number
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Specifies if the swap is from token A to token B.
|
|
881
|
+
*/
|
|
882
|
+
a2b: boolean
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Specifies if the swap amount is specified in token A.
|
|
886
|
+
*/
|
|
887
|
+
by_amount_in: boolean
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* The amount to swap.
|
|
891
|
+
*/
|
|
892
|
+
amount: BN
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* An array of tick data for swap ticks.
|
|
896
|
+
*/
|
|
897
|
+
swap_ticks: Array<TickData>
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* The current pool information.
|
|
901
|
+
*/
|
|
902
|
+
current_pool: Pool
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Represents the result of calculating rates in a swap.
|
|
907
|
+
*/
|
|
908
|
+
export type CalculateRatesResult = {
|
|
909
|
+
/**
|
|
910
|
+
* The estimated amount in token A.
|
|
911
|
+
*/
|
|
912
|
+
estimated_amount_in: BN
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* The estimated amount in token B.
|
|
916
|
+
*/
|
|
917
|
+
estimated_amount_out: BN
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* The estimated ending square root price.
|
|
921
|
+
*/
|
|
922
|
+
estimated_end_sqrt_price: BN
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* The estimated fee amount.
|
|
926
|
+
*/
|
|
927
|
+
estimated_fee_amount: BN
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* Indicates if the estimated amount exceeds the limit.
|
|
931
|
+
*/
|
|
932
|
+
is_exceed: boolean
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* The extra compute limit.
|
|
936
|
+
*/
|
|
937
|
+
extra_compute_limit: number
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Specifies if the swap is from token A to token B.
|
|
941
|
+
*/
|
|
942
|
+
a2b: boolean
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Specifies if the swap amount is specified in token A.
|
|
946
|
+
*/
|
|
947
|
+
by_amount_in: boolean
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* The amount to swap.
|
|
951
|
+
*/
|
|
952
|
+
amount: BN
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* The price impact percentage.
|
|
956
|
+
*/
|
|
957
|
+
price_impact_pct: number
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Represents parameters for a swap operation.
|
|
962
|
+
*/
|
|
963
|
+
export type SwapParams = {
|
|
964
|
+
/**
|
|
965
|
+
* The identifier of the pool.
|
|
966
|
+
*/
|
|
967
|
+
pool_id: SuiObjectIdType
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Specifies if the swap is from token A to token B.
|
|
971
|
+
*/
|
|
972
|
+
a2b: boolean
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Specifies if the swap amount is specified in token A.
|
|
976
|
+
*/
|
|
977
|
+
by_amount_in: boolean
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* The swap amount.
|
|
981
|
+
*/
|
|
982
|
+
amount: string
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* The amount limit for the swap.
|
|
986
|
+
*/
|
|
987
|
+
amount_limit: string
|
|
988
|
+
|
|
989
|
+
/**
|
|
990
|
+
* The optional swap partner.
|
|
991
|
+
*/
|
|
992
|
+
swap_partner?: string
|
|
993
|
+
} & CoinPairType
|
|
994
|
+
|
|
995
|
+
export type SwapGasEstimateArg = {
|
|
996
|
+
by_amount_in: boolean
|
|
997
|
+
slippage: Percentage
|
|
998
|
+
decimals_a: number
|
|
999
|
+
decimals_b: number
|
|
1000
|
+
swap_ticks: Array<TickData>
|
|
1001
|
+
current_pool: Pool
|
|
1002
|
+
}
|