@cetusprotocol/dlmm-sdk 0.0.1
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 +10423 -0
- package/README.md +646 -0
- package/dist/index.d.mts +1015 -0
- package/dist/index.d.ts +1015 -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/package.json +35 -0
- package/src/config/index.ts +2 -0
- package/src/config/mainnet.ts +25 -0
- package/src/config/testnet.ts +30 -0
- package/src/errors/errors.ts +40 -0
- package/src/index.ts +8 -0
- package/src/modules/configModule.ts +184 -0
- package/src/modules/index.ts +1 -0
- package/src/modules/partnerModule.ts +302 -0
- package/src/modules/poolModule.ts +578 -0
- package/src/modules/positionModule.ts +888 -0
- package/src/modules/rewardModule.ts +175 -0
- package/src/modules/swapModule.ts +129 -0
- package/src/sdk.ts +88 -0
- package/src/types/constants.ts +23 -0
- package/src/types/dlmm.ts +445 -0
- package/src/types/index.ts +2 -0
- package/src/utils/binUtils.ts +552 -0
- package/src/utils/feeUtils.ts +92 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/parseData.ts +519 -0
- package/src/utils/strategyUtils.ts +121 -0
- package/src/utils/weightUtils.ts +510 -0
- package/tests/add_liquidity_bidask.test.ts +180 -0
- package/tests/add_liquidity_curve.test.ts +244 -0
- package/tests/add_liquidity_spot.test.ts +262 -0
- package/tests/bin.test.ts +80 -0
- package/tests/config.test.ts +51 -0
- package/tests/partner.test.ts +74 -0
- package/tests/pool.test.ts +174 -0
- package/tests/position.test.ts +76 -0
- package/tests/remove_liquidity.test.ts +137 -0
- package/tests/swap.test.ts +96 -0
- package/tests/tsconfig.json +26 -0
- package/tsconfig.json +5 -0
- package/tsup.config.ts +9 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import type { CoinPairType, TableHandle } from '@cetusprotocol/common-sdk'
|
|
2
|
+
import { TransactionObjectArgument } from '@mysten/sui/transactions'
|
|
3
|
+
export type DlmmConfigs = {
|
|
4
|
+
registry_id: string
|
|
5
|
+
pools_id: string
|
|
6
|
+
partners_id: string
|
|
7
|
+
global_config_id: string
|
|
8
|
+
versioned_id: string
|
|
9
|
+
admin_cap_id: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type BinStepConfig = {
|
|
13
|
+
bin_step: number
|
|
14
|
+
base_factor: number
|
|
15
|
+
filter_period: number
|
|
16
|
+
decay_period: number
|
|
17
|
+
reduction_factor: number
|
|
18
|
+
variable_fee_control: string
|
|
19
|
+
max_volatility_accumulator: string
|
|
20
|
+
protocol_fee_rate: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type BinManager = {
|
|
24
|
+
bin_step: number
|
|
25
|
+
bin_manager_handle: string
|
|
26
|
+
size: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type VariableParameters = {
|
|
30
|
+
volatility_accumulator: string
|
|
31
|
+
volatility_reference: string
|
|
32
|
+
index_reference: number
|
|
33
|
+
last_update_timestamp: string
|
|
34
|
+
bin_step_config: BinStepConfig
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type Reward = {
|
|
38
|
+
reward_coin: string
|
|
39
|
+
emissions_per_second: string
|
|
40
|
+
emissions_per_day: string
|
|
41
|
+
period_emission_rates: TableHandle
|
|
42
|
+
}
|
|
43
|
+
export type RewardManager = {
|
|
44
|
+
is_public: boolean
|
|
45
|
+
vault: TableHandle
|
|
46
|
+
rewards: Reward[]
|
|
47
|
+
emergency_reward_pause: boolean
|
|
48
|
+
last_updated_time: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type PositionManager = {
|
|
52
|
+
bin_step: number
|
|
53
|
+
position_index: number
|
|
54
|
+
position_handle: string
|
|
55
|
+
size: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type DlmmBasePool = {
|
|
59
|
+
id: string
|
|
60
|
+
bin_step: number
|
|
61
|
+
} & CoinPairType
|
|
62
|
+
|
|
63
|
+
export type PoolPermissions = {
|
|
64
|
+
disable_add: boolean
|
|
65
|
+
disable_remove: boolean
|
|
66
|
+
disable_swap: boolean
|
|
67
|
+
disable_collect_fee: boolean
|
|
68
|
+
disable_collect_reward: boolean
|
|
69
|
+
disable_add_reward: boolean
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type DlmmPool = {
|
|
73
|
+
pool_type: string
|
|
74
|
+
index: number
|
|
75
|
+
bin_manager: BinManager
|
|
76
|
+
variable_parameters: VariableParameters
|
|
77
|
+
active_id: number
|
|
78
|
+
permissions: PoolPermissions
|
|
79
|
+
balance_a: string
|
|
80
|
+
balance_b: string
|
|
81
|
+
base_fee_rate: string
|
|
82
|
+
protocol_fee_a: string
|
|
83
|
+
protocol_fee_b: string
|
|
84
|
+
url: string
|
|
85
|
+
reward_manager: RewardManager
|
|
86
|
+
position_manager: PositionManager
|
|
87
|
+
} & DlmmBasePool
|
|
88
|
+
|
|
89
|
+
export type DlmmPosition = {
|
|
90
|
+
id: string
|
|
91
|
+
pool_id: string
|
|
92
|
+
index: number
|
|
93
|
+
description: string
|
|
94
|
+
uri: string
|
|
95
|
+
liquidity_shares: string[]
|
|
96
|
+
lower_bin_id: number
|
|
97
|
+
upper_bin_id: number
|
|
98
|
+
name: string
|
|
99
|
+
} & CoinPairType
|
|
100
|
+
|
|
101
|
+
export type BinWeight = {
|
|
102
|
+
bin_id: number
|
|
103
|
+
weight: number
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type BinAmount = {
|
|
107
|
+
bin_id: number
|
|
108
|
+
amount_a: string
|
|
109
|
+
amount_b: string
|
|
110
|
+
liquidity?: string
|
|
111
|
+
price_per_lamport: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type BinLiquidityInfo = {
|
|
115
|
+
bins: BinAmount[]
|
|
116
|
+
amount_a: string
|
|
117
|
+
amount_b: string
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export enum StrategyType {
|
|
121
|
+
Spot,
|
|
122
|
+
Curve,
|
|
123
|
+
BidAsk,
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type ClosePositionOption = {
|
|
127
|
+
pool_id: string
|
|
128
|
+
position_id: string
|
|
129
|
+
reward_coins: string[]
|
|
130
|
+
} & CoinPairType
|
|
131
|
+
|
|
132
|
+
export type BaseCreatePoolOption = {
|
|
133
|
+
bin_step: number
|
|
134
|
+
base_factor: number
|
|
135
|
+
url?: string
|
|
136
|
+
} & CoinPairType
|
|
137
|
+
|
|
138
|
+
export type BaseCreatePoolAndAddOption = {
|
|
139
|
+
bin_infos: BinLiquidityInfo
|
|
140
|
+
strategy_type: StrategyType
|
|
141
|
+
use_bin_infos?: boolean
|
|
142
|
+
} & BaseCreatePoolOption
|
|
143
|
+
|
|
144
|
+
export type CreatePoolAndAddOption = {
|
|
145
|
+
active_id: number
|
|
146
|
+
lower_bin_id: number
|
|
147
|
+
upper_bin_id: number
|
|
148
|
+
} & BaseCreatePoolAndAddOption
|
|
149
|
+
|
|
150
|
+
export type CreatePoolOption = {
|
|
151
|
+
active_id: number
|
|
152
|
+
} & BaseCreatePoolOption
|
|
153
|
+
|
|
154
|
+
export type CreatePoolAndAddWithPriceOption = {
|
|
155
|
+
price_base_coin: 'coin_a' | 'coin_b'
|
|
156
|
+
price: string
|
|
157
|
+
lower_price: string
|
|
158
|
+
upper_price: string
|
|
159
|
+
strategy_type: StrategyType
|
|
160
|
+
decimals_a: number
|
|
161
|
+
decimals_b: number
|
|
162
|
+
} & BaseCreatePoolAndAddOption
|
|
163
|
+
|
|
164
|
+
export type BaseAddLiquidityOption = {
|
|
165
|
+
pool_id: string | TransactionObjectArgument
|
|
166
|
+
bin_infos: BinLiquidityInfo
|
|
167
|
+
strategy_type: StrategyType
|
|
168
|
+
max_price_slippage: number
|
|
169
|
+
active_id: number
|
|
170
|
+
bin_step: number
|
|
171
|
+
/**
|
|
172
|
+
* Controls whether to use pre-calculated bin_infos or let the contract calculate based on strategy_type.
|
|
173
|
+
* - true: Use bin_infos to add liquidity to each bin
|
|
174
|
+
* - false: Pass strategy_type to contract for automatic liquidity distribution calculation
|
|
175
|
+
*/
|
|
176
|
+
use_bin_infos?: boolean
|
|
177
|
+
} & CoinPairType
|
|
178
|
+
|
|
179
|
+
export type BaseCalculateAddLiquidityOption = {
|
|
180
|
+
active_id: number
|
|
181
|
+
bin_step: number
|
|
182
|
+
lower_bin_id: number
|
|
183
|
+
upper_bin_id: number
|
|
184
|
+
amount_a_in_active_bin: string
|
|
185
|
+
amount_b_in_active_bin: string
|
|
186
|
+
strategy_type: StrategyType
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export type CalculateAddLiquidityOption = {
|
|
190
|
+
amount_a: string
|
|
191
|
+
amount_b: string
|
|
192
|
+
} & BaseCalculateAddLiquidityOption
|
|
193
|
+
|
|
194
|
+
export type CalculateAddLiquidityAutoFillOption = {
|
|
195
|
+
coin_amount: string
|
|
196
|
+
fix_amount_a: boolean
|
|
197
|
+
} & BaseCalculateAddLiquidityOption
|
|
198
|
+
|
|
199
|
+
export type AddLiquidityOption = BaseAddLiquidityOption & {
|
|
200
|
+
position_id: string
|
|
201
|
+
collect_fee: boolean
|
|
202
|
+
reward_coins: string[]
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export type OpenAndAddLiquidityOption = BaseAddLiquidityOption & {
|
|
206
|
+
lower_bin_id: number
|
|
207
|
+
upper_bin_id: number
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export type OpenAndAddLiquidityWithPriceOption = BaseAddLiquidityOption & {
|
|
211
|
+
price_base_coin: 'coin_a' | 'coin_b'
|
|
212
|
+
price: string
|
|
213
|
+
lower_price: string
|
|
214
|
+
upper_price: string
|
|
215
|
+
amount_a_in_active_bin: string
|
|
216
|
+
amount_b_in_active_bin: string
|
|
217
|
+
strategy_type: StrategyType
|
|
218
|
+
decimals_a: number
|
|
219
|
+
decimals_b: number
|
|
220
|
+
max_price_slippage: number
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export type OpenPositionOption = {
|
|
224
|
+
pool_id: string
|
|
225
|
+
lower_bin_id: number
|
|
226
|
+
upper_bin_id: number
|
|
227
|
+
} & CoinPairType
|
|
228
|
+
|
|
229
|
+
export type CalculateRemoveLiquidityBothOption = {
|
|
230
|
+
bins: BinAmount[]
|
|
231
|
+
active_id: number
|
|
232
|
+
fix_amount_a: boolean
|
|
233
|
+
coin_amount: string
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export type CalculateRemoveLiquidityOnlyOption = {
|
|
237
|
+
bins: BinAmount[]
|
|
238
|
+
active_id: number
|
|
239
|
+
is_only_a: boolean
|
|
240
|
+
coin_amount: string
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export type RemoveLiquidityOption = {
|
|
244
|
+
pool_id: string
|
|
245
|
+
position_id: string
|
|
246
|
+
active_id: number
|
|
247
|
+
bin_step: number
|
|
248
|
+
bin_infos: BinLiquidityInfo
|
|
249
|
+
slippage: number
|
|
250
|
+
reward_coins: string[]
|
|
251
|
+
collect_fee: boolean
|
|
252
|
+
remove_percent?: number
|
|
253
|
+
} & CoinPairType
|
|
254
|
+
|
|
255
|
+
export type CollectRewardOption = {
|
|
256
|
+
pool_id: string
|
|
257
|
+
position_id: string
|
|
258
|
+
reward_coins: string[]
|
|
259
|
+
} & CoinPairType
|
|
260
|
+
|
|
261
|
+
export type CollectFeeOption = {
|
|
262
|
+
pool_id: string
|
|
263
|
+
position_id: string
|
|
264
|
+
} & CoinPairType
|
|
265
|
+
|
|
266
|
+
export type CollectRewardAndFeeOption = {
|
|
267
|
+
pool_id: string
|
|
268
|
+
position_id: string
|
|
269
|
+
reward_coins: string[]
|
|
270
|
+
} & CoinPairType
|
|
271
|
+
|
|
272
|
+
export type BinSwap = {
|
|
273
|
+
bin_id: number
|
|
274
|
+
in_amount: string
|
|
275
|
+
out_amount: string
|
|
276
|
+
fee: string
|
|
277
|
+
var_fee_rate: string
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export type PreSwapQuote = {
|
|
281
|
+
pool_id: string
|
|
282
|
+
a2b: boolean
|
|
283
|
+
in_amount: string
|
|
284
|
+
out_amount: string
|
|
285
|
+
ref_fee_amount: string
|
|
286
|
+
fee_amount: string
|
|
287
|
+
partner: string
|
|
288
|
+
from_coin_type: string
|
|
289
|
+
to_coin_type: string
|
|
290
|
+
bin_swaps: BinSwap[]
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export type PreSwapOption = {
|
|
294
|
+
pool_id: string
|
|
295
|
+
a2b: boolean
|
|
296
|
+
by_amount_in: boolean
|
|
297
|
+
in_amount: string
|
|
298
|
+
} & CoinPairType
|
|
299
|
+
|
|
300
|
+
export type SwapOption = {
|
|
301
|
+
quote_obj: PreSwapQuote
|
|
302
|
+
by_amount_in: boolean
|
|
303
|
+
partner?: string
|
|
304
|
+
slippage: number
|
|
305
|
+
} & CoinPairType
|
|
306
|
+
|
|
307
|
+
export type PositionFee = {
|
|
308
|
+
position_id: string
|
|
309
|
+
fee_owned_a: string
|
|
310
|
+
fee_owned_b: string
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export type RewardInfo = {
|
|
314
|
+
coin_type: string
|
|
315
|
+
reward_owned: string
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export type PositionReward = {
|
|
319
|
+
position_id: string
|
|
320
|
+
rewards: RewardInfo[]
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export type CreatePartnerOption = {
|
|
324
|
+
name: string
|
|
325
|
+
ref_fee_rate: number
|
|
326
|
+
start_time: number
|
|
327
|
+
end_time: number
|
|
328
|
+
recipient: string
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export type UpdateRefFeeRateOption = {
|
|
332
|
+
partner_id: string
|
|
333
|
+
ref_fee_rate: number
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export type UpdateTimeRangeOption = {
|
|
337
|
+
partner_id: string
|
|
338
|
+
start_time: number
|
|
339
|
+
end_time: number
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export type ClaimRefFeeOption = {
|
|
343
|
+
partner_id: string
|
|
344
|
+
partner_cap_id?: string
|
|
345
|
+
fee_coin_types: string[]
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export type Partner = {
|
|
349
|
+
id: string
|
|
350
|
+
name: string
|
|
351
|
+
ref_fee_rate: number
|
|
352
|
+
start_time: number
|
|
353
|
+
end_time: number
|
|
354
|
+
balances: TableHandle
|
|
355
|
+
type: string
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export type PoolTransactionInfo = {
|
|
359
|
+
index: string
|
|
360
|
+
tx: string
|
|
361
|
+
sender: string
|
|
362
|
+
type: string
|
|
363
|
+
block_time: string
|
|
364
|
+
parsed_json: any
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export type AddRewardOption = {
|
|
368
|
+
pool_id: string
|
|
369
|
+
reward_coin_type: string
|
|
370
|
+
reward_amount: string
|
|
371
|
+
// Optional start time in seconds for the reward
|
|
372
|
+
start_time_seconds?: number
|
|
373
|
+
// Mandatory end time in seconds for the reward
|
|
374
|
+
end_time_seconds: number
|
|
375
|
+
} & CoinPairType
|
|
376
|
+
|
|
377
|
+
export type InitRewardOption = {
|
|
378
|
+
pool_id: string
|
|
379
|
+
reward_coin_types: string[]
|
|
380
|
+
} & CoinPairType
|
|
381
|
+
|
|
382
|
+
export type RewardWhiteListOption = {
|
|
383
|
+
reward_coin_types: string[]
|
|
384
|
+
type: 'add' | 'remove'
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export type RewardAccessOption = {
|
|
388
|
+
pool_id: string
|
|
389
|
+
type: 'to_public' | 'to_private'
|
|
390
|
+
} & CoinPairType
|
|
391
|
+
|
|
392
|
+
export type ValidateActiveIdSlippageOption = {
|
|
393
|
+
pool_id: string | TransactionObjectArgument
|
|
394
|
+
active_id: number
|
|
395
|
+
bin_step: number
|
|
396
|
+
max_price_slippage: number
|
|
397
|
+
} & CoinPairType
|
|
398
|
+
|
|
399
|
+
export type DlmmGlobalConfig = {
|
|
400
|
+
id: string
|
|
401
|
+
acl: TableHandle
|
|
402
|
+
allowed_list: TableHandle
|
|
403
|
+
denied_list: TableHandle
|
|
404
|
+
bin_steps: TableHandle
|
|
405
|
+
reward_white_list: string[]
|
|
406
|
+
blocked_position: TableHandle
|
|
407
|
+
blocked_user: TableHandle
|
|
408
|
+
min_reward_duration: number
|
|
409
|
+
non_manager_initialize_reward_cap: number
|
|
410
|
+
reward_public: boolean
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export type UpdatePositionFeeAndRewardsOption = {
|
|
414
|
+
pool_id: string
|
|
415
|
+
position_id: string
|
|
416
|
+
} & CoinPairType
|
|
417
|
+
|
|
418
|
+
export type RewardPeriodEmission = {
|
|
419
|
+
emissions_per_second: string
|
|
420
|
+
emissions_per_day: string
|
|
421
|
+
emissions_per: string
|
|
422
|
+
time: string
|
|
423
|
+
visualized_time: string
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export type RewardPeriodEmissionFormat = {
|
|
427
|
+
emissions_per_second: string
|
|
428
|
+
emissions_per_day: string
|
|
429
|
+
time: string
|
|
430
|
+
visualized_time: string
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export type GetPoolBinInfoOption = {
|
|
434
|
+
pool_id: string
|
|
435
|
+
} & CoinPairType
|
|
436
|
+
|
|
437
|
+
export type GetTotalFeeRateOption = {
|
|
438
|
+
pool_id: string
|
|
439
|
+
} & CoinPairType
|
|
440
|
+
|
|
441
|
+
export type FeeRate = {
|
|
442
|
+
base_fee_rate: string
|
|
443
|
+
var_fee_rate: string
|
|
444
|
+
total_fee_rate: string
|
|
445
|
+
}
|