@cetusprotocol/dlmm-sdk 0.0.2 → 0.0.3

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.
@@ -14,11 +14,11 @@ import {
14
14
  import { printTransaction, toDecimalsAmount } from '@cetusprotocol/common-sdk'
15
15
  import { BinUtils } from '../src/utils/binUtils'
16
16
 
17
- const pool_id = '0x833a468857db452508351dbbe5f9859ed557014bf0a23e4c8eba5dfa0c0741f0'
17
+ const pool_id = '0x2ebd6828bc7a952f6e3a884800f70c3ad658964fa9a103bea953835d73873e68'
18
18
  const position_id = '0xf5139870fbc926d1ca1afdc536b4ab457a9c2a696440d10955572f04b95d9e29'
19
19
 
20
20
  describe('dlmm add liquidity spot', () => {
21
- const sdk = CetusDlmmSDK.createSDK({ env: 'testnet', full_rpc_url: 'https://rpc-testnet.suiscan.xyz:443' })
21
+ const sdk = CetusDlmmSDK.createSDK({ env: 'mainnet' })
22
22
  let send_key_pair: Ed25519Keypair
23
23
  let account: string
24
24
  let pool: DlmmPool
@@ -55,17 +55,17 @@ describe('dlmm add liquidity spot', () => {
55
55
  )
56
56
 
57
57
  const calculateOption: CalculateAddLiquidityOption = {
58
+ pool_id,
58
59
  amount_a,
59
60
  amount_b,
60
61
  active_id,
61
62
  bin_step,
62
63
  lower_bin_id,
63
64
  upper_bin_id,
64
- amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
65
- amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
65
+ active_bin_of_pool: amounts_in_active_bin,
66
66
  strategy_type: StrategyType.Spot,
67
67
  }
68
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
68
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
69
69
  // console.log('🚀 ~ test ~ bin_infos:', bin_infos)
70
70
 
71
71
  const addOption: OpenAndAddLiquidityWithPriceOption = {
@@ -78,19 +78,18 @@ describe('dlmm add liquidity spot', () => {
78
78
  lower_price,
79
79
  upper_price,
80
80
  bin_step,
81
- amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
82
- amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
81
+ active_bin_of_pool: amounts_in_active_bin,
83
82
  strategy_type: StrategyType.Spot,
84
83
  decimals_a: 6,
85
84
  decimals_b: 6,
86
85
  max_price_slippage: 0.01,
87
86
  active_id,
88
87
  }
89
- const tx = sdk.Position.addLiquidityWithPricePayload(addOption)
88
+ const tx = await sdk.Position.addLiquidityWithPricePayload(addOption)
90
89
 
91
90
  printTransaction(tx)
92
91
 
93
- const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
92
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, true)
94
93
  console.log('🚀 ~ test ~ res:', res)
95
94
  })
96
95
 
@@ -99,8 +98,8 @@ describe('dlmm add liquidity spot', () => {
99
98
  console.log('🚀 ~ beforeEach ~ pool:', pool)
100
99
  const { active_id, bin_step } = pool
101
100
  const amount_a = '10000000'
102
- const amount_b = '0'
103
- const lower_bin_id = active_id
101
+ const amount_b = '20000000'
102
+ const lower_bin_id = active_id - 10
104
103
  const upper_bin_id = active_id + 10
105
104
 
106
105
  const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
@@ -112,17 +111,17 @@ describe('dlmm add liquidity spot', () => {
112
111
  )
113
112
 
114
113
  const calculateOption: CalculateAddLiquidityOption = {
114
+ pool_id,
115
115
  amount_a,
116
116
  amount_b,
117
117
  active_id,
118
118
  bin_step,
119
119
  lower_bin_id,
120
120
  upper_bin_id,
121
- amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
122
- amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
121
+ active_bin_of_pool: amounts_in_active_bin,
123
122
  strategy_type: StrategyType.Spot,
124
123
  }
125
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
124
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
126
125
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
127
126
 
128
127
  const addOption: OpenAndAddLiquidityOption = {
@@ -140,7 +139,7 @@ describe('dlmm add liquidity spot', () => {
140
139
  }
141
140
  const tx = sdk.Position.addLiquidityPayload(addOption)
142
141
  tx.setGasBudget(10000000000)
143
- printTransaction(tx)
142
+ // printTransaction(tx)
144
143
 
145
144
  const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
146
145
  console.log('🚀 ~ test ~ res:', res)
@@ -167,17 +166,17 @@ describe('dlmm add liquidity spot', () => {
167
166
  const amount_b = '0'
168
167
 
169
168
  const calculateOption: CalculateAddLiquidityOption = {
169
+ pool_id,
170
170
  amount_a,
171
171
  amount_b,
172
172
  active_id,
173
173
  bin_step,
174
174
  lower_bin_id,
175
175
  upper_bin_id,
176
- amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
177
- amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
176
+ active_bin_of_pool: amounts_in_active_bin,
178
177
  strategy_type: StrategyType.Spot,
179
178
  }
180
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
179
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
181
180
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
182
181
 
183
182
  const addOption: AddLiquidityOption = {
@@ -225,17 +224,17 @@ describe('dlmm add liquidity spot', () => {
225
224
  const coin_amount = toDecimalsAmount(1, 9)
226
225
 
227
226
  const calculateOption: CalculateAddLiquidityAutoFillOption = {
227
+ pool_id,
228
228
  coin_amount,
229
- fix_amount_a: false,
229
+ fix_amount_a: true,
230
230
  active_id,
231
231
  bin_step,
232
232
  lower_bin_id,
233
233
  upper_bin_id,
234
- amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
235
- amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
234
+ active_bin_of_pool: amounts_in_active_bin,
236
235
  strategy_type: StrategyType.Spot,
237
236
  }
238
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
237
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
239
238
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
240
239
 
241
240
  const addOption: AddLiquidityOption = {
@@ -256,6 +255,59 @@ describe('dlmm add liquidity spot', () => {
256
255
  tx.setGasBudget(10000000000)
257
256
  printTransaction(tx)
258
257
 
258
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
259
+ console.log('🚀 ~ test ~ res:', res)
260
+ })
261
+
262
+ test('4 spot strategy fix coin a open add liquidity', async () => {
263
+ pool = await sdk.Pool.getPool(pool_id)
264
+ const { active_id, bin_step, bin_manager, coin_type_a, coin_type_b } = pool
265
+ console.log('🚀 ~ pool:', pool)
266
+
267
+ const lower_bin_id = active_id
268
+ const upper_bin_id = active_id
269
+
270
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
271
+ bin_manager.bin_manager_handle,
272
+ lower_bin_id,
273
+ upper_bin_id,
274
+ active_id,
275
+ bin_step
276
+ )
277
+
278
+ const coin_amount = toDecimalsAmount(1, 6)
279
+
280
+ const calculateOption: CalculateAddLiquidityAutoFillOption = {
281
+ pool_id,
282
+ coin_amount,
283
+ fix_amount_a: true,
284
+ active_id,
285
+ bin_step,
286
+ lower_bin_id,
287
+ upper_bin_id,
288
+ active_bin_of_pool: amounts_in_active_bin,
289
+ strategy_type: StrategyType.Spot,
290
+ }
291
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
292
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
293
+
294
+ const addOption: OpenAndAddLiquidityOption = {
295
+ pool_id,
296
+ bin_infos: bin_infos,
297
+ coin_type_a,
298
+ coin_type_b,
299
+ active_id,
300
+ use_bin_infos: false,
301
+ strategy_type: StrategyType.Spot,
302
+ max_price_slippage: 0.01,
303
+ bin_step,
304
+ lower_bin_id,
305
+ upper_bin_id,
306
+ }
307
+ const tx = sdk.Position.addLiquidityPayload(addOption)
308
+ tx.setGasBudget(10000000000)
309
+ printTransaction(tx)
310
+
259
311
  const res = await sdk.FullClient.executeTx(send_key_pair, tx, true)
260
312
  console.log('🚀 ~ test ~ res:', res)
261
313
  })
@@ -3,9 +3,13 @@ import type { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
3
3
  import { buildTestAccount } from '@cetusprotocol/test-utils'
4
4
  import { CetusDlmmSDK } from '../src/sdk'
5
5
  import { parseCurrentRewardPeriodEmission, parseRewardPeriodEmission } from '../src/utils/parseData'
6
+ import { Transaction } from '@mysten/sui/transactions'
7
+ import { CoinAssist, printTransaction } from '@cetusprotocol/common-sdk'
8
+ import { toB64, toBase64 } from '@mysten/sui/utils'
9
+ import BN from 'bn.js'
6
10
 
7
11
  describe('config', () => {
8
- const sdk = CetusDlmmSDK.createSDK({ env: 'testnet' })
12
+ const sdk = CetusDlmmSDK.createSDK({ env: 'mainnet' })
9
13
  let send_key_pair: Ed25519Keypair
10
14
  let account: string
11
15
 
@@ -20,6 +24,24 @@ describe('config', () => {
20
24
  console.log('🚀 ~ test ~ res:', res)
21
25
  })
22
26
 
27
+ test('build rawBytes', async () => {
28
+ const tx = new Transaction()
29
+
30
+ const zeroCoin = CoinAssist.buildCoinWithBalance(
31
+ BigInt(100),
32
+ '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',
33
+ tx
34
+ )
35
+ tx.transferObjects([zeroCoin], tx.pure.address(account))
36
+ tx.setSender(account)
37
+
38
+ printTransaction(tx)
39
+ // build rawBytes
40
+ const data = await tx.build({ client: sdk.FullClient })
41
+ const rawBytes = toBase64(data)
42
+ console.log('rawBytes: ', rawBytes)
43
+ })
44
+
23
45
  test('getBinStepConfigList', async () => {
24
46
  const res = await sdk.Config.getBinStepConfigList('0xc00e4dbc372948b2b72ae5554c7296b39e107a92821baff08aa640aba0b07aed')
25
47
  console.log('🚀 ~ test ~ res:', res)
@@ -6,7 +6,7 @@ import { BinUtils } from '../src/utils/binUtils'
6
6
  import { StrategyType } from '../src/types/dlmm'
7
7
  import { asIntN, asUintN, d, printTransaction } from '@cetusprotocol/common-sdk'
8
8
  import { Transaction } from '@mysten/sui/transactions'
9
- import { FeeUtils } from '../src/utils'
9
+ import { buildPoolKey, FeeUtils } from '../src/utils'
10
10
  import { FEE_PRECISION, MAX_FEE_RATE } from '../src/types/constants'
11
11
 
12
12
  describe('pool', () => {
@@ -70,6 +70,16 @@ describe('pool', () => {
70
70
  console.log('🚀 ~ test ~ bin_info:', bin_info)
71
71
  })
72
72
 
73
+ test('getPoolAddress', async () => {
74
+ const address = await sdk.Pool.getPoolAddress(
75
+ '14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdt::USDT',
76
+ '0000000000000000000000000000000000000000000000000000000000000002::sui::SUI',
77
+ 25,
78
+ 10000
79
+ )
80
+ console.log('🚀 ~ test ~ address:', address)
81
+ })
82
+
73
83
  test('getVariableFee', async () => {
74
84
  const pool = await sdk.Pool.getPool('0xe7e85914ab054a8d0d6d8f5f3e52445d17153da1efba857fed986f2d79e43412')
75
85
  console.log('🚀 ~ test ~ pool:', JSON.stringify(pool, null, 2))
@@ -83,7 +93,7 @@ describe('pool', () => {
83
93
 
84
94
  test('1 getPoolBinInfo', async () => {
85
95
  const bin_info = await sdk.Pool.getPoolBinInfo({
86
- pool_id: '0xffd4260d625f99349542badf632037c824ad919425ee227de1745b19edc05133',
96
+ pool_id: '0x2805cdfa9a58d112d1a8ce238cd77dbb40b1fe89d9e64f1625dee8ce378450bf',
87
97
  coin_type_a: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdt::USDT',
88
98
  coin_type_b: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdc::USDC',
89
99
  })
@@ -30,8 +30,8 @@ describe('dlmm position', () => {
30
30
  })
31
31
 
32
32
  test('get position', async () => {
33
- const pool = await sdk.Pool.getPool('0x6055e7eb872d7db12a6267fe43310326189aaf2cc1ba5ad4228f1c2c3b3998c2')
34
- const res = await sdk.Position.getPosition('0xf3385e599ca649880233194e34b1910991c997f5f72f4888c831df79c6c65d17')
33
+ const pool = await sdk.Pool.getPool('0x9ec24e51ba5083a800538622ef42343de80f62e9b3f2a507ed409ca0155cff35')
34
+ const res = await sdk.Position.getPosition('0xe7b049747668f198137adbbba21c5e03ab56266bf5273413a1713e097f7482ae')
35
35
  console.log('🚀 ~ test ~ res:', res)
36
36
 
37
37
  const active_bin = await sdk.Pool.getBinInfo(pool.bin_manager.bin_manager_handle, pool.active_id, pool.bin_step)