@cetusprotocol/dlmm-sdk 0.0.0-experimental-20250925173459

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.
Files changed (47) hide show
  1. package/.turbo/turbo-build.log +10444 -0
  2. package/README.md +654 -0
  3. package/dist/index.d.mts +1050 -0
  4. package/dist/index.d.ts +1050 -0
  5. package/dist/index.js +13 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +13 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +35 -0
  10. package/src/config/index.ts +2 -0
  11. package/src/config/mainnet.ts +25 -0
  12. package/src/config/testnet.ts +30 -0
  13. package/src/errors/errors.ts +40 -0
  14. package/src/index.ts +8 -0
  15. package/src/modules/configModule.ts +184 -0
  16. package/src/modules/index.ts +1 -0
  17. package/src/modules/partnerModule.ts +302 -0
  18. package/src/modules/poolModule.ts +578 -0
  19. package/src/modules/positionModule.ts +882 -0
  20. package/src/modules/rewardModule.ts +174 -0
  21. package/src/modules/swapModule.ts +129 -0
  22. package/src/sdk.ts +88 -0
  23. package/src/types/constants.ts +23 -0
  24. package/src/types/dlmm.ts +445 -0
  25. package/src/types/ilm.ts +33 -0
  26. package/src/types/index.ts +3 -0
  27. package/src/utils/binUtils.ts +552 -0
  28. package/src/utils/feeUtils.ts +92 -0
  29. package/src/utils/ilmUtils.ts +187 -0
  30. package/src/utils/index.ts +6 -0
  31. package/src/utils/parseData.ts +519 -0
  32. package/src/utils/strategyUtils.ts +121 -0
  33. package/src/utils/weightUtils.ts +510 -0
  34. package/tests/add_liquidity_bidask.test.ts +180 -0
  35. package/tests/add_liquidity_curve.test.ts +244 -0
  36. package/tests/add_liquidity_spot.test.ts +262 -0
  37. package/tests/bin.test.ts +80 -0
  38. package/tests/config.test.ts +73 -0
  39. package/tests/ilm.test.ts +31 -0
  40. package/tests/partner.test.ts +74 -0
  41. package/tests/pool.test.ts +174 -0
  42. package/tests/position.test.ts +76 -0
  43. package/tests/remove_liquidity.test.ts +137 -0
  44. package/tests/swap.test.ts +96 -0
  45. package/tests/tsconfig.json +26 -0
  46. package/tsconfig.json +5 -0
  47. package/tsup.config.ts +9 -0
@@ -0,0 +1,180 @@
1
+ // buildTestAccount
2
+ import type { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
3
+ import { buildTestAccount } from '@cetusprotocol/test-utils'
4
+ import { CetusDlmmSDK } from '../src/sdk'
5
+ import {
6
+ AddLiquidityOption,
7
+ CalculateAddLiquidityAutoFillOption,
8
+ CalculateAddLiquidityOption,
9
+ DlmmPool,
10
+ OpenAndAddLiquidityOption,
11
+ StrategyType,
12
+ } from '../src/types/dlmm'
13
+ import { printTransaction } from '@cetusprotocol/common-sdk'
14
+
15
+ const pool_id = '0x56d2a3270238f1347fa6fb94836da8afd2415c49ab7bb843996fe5c6a807dc5a'
16
+ const position_id = '0x081a3fda4c7df0fc86ff7f69809434ac096911eb7b5e81865cdd1bf8858214fa'
17
+
18
+ describe('dlmm add liquidity bid ask', () => {
19
+ const sdk = CetusDlmmSDK.createSDK({ env: 'testnet', full_rpc_url: 'https://rpc-testnet.suiscan.xyz' })
20
+ let send_key_pair: Ed25519Keypair
21
+ let account: string
22
+ let pool: DlmmPool
23
+
24
+ beforeEach(async () => {
25
+ send_key_pair = buildTestAccount()
26
+ account = send_key_pair.getPublicKey().toSuiAddress()
27
+ sdk.setSenderAddress(account)
28
+ })
29
+
30
+ test('1 bid ask both amounts open and add liquidity', async () => {
31
+ pool = await sdk.Pool.getPool(pool_id)
32
+ console.log('🚀 ~ beforeEach ~ pool:', pool)
33
+ const { active_id, bin_step } = pool
34
+ const amount_a = '1000000'
35
+ const amount_b = '1200000'
36
+ const lower_bin_id = -10
37
+ const upper_bin_id = 10
38
+
39
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
40
+ pool.bin_manager.bin_manager_handle,
41
+ lower_bin_id,
42
+ upper_bin_id,
43
+ active_id,
44
+ bin_step
45
+ )
46
+
47
+ const calculateOption: CalculateAddLiquidityOption = {
48
+ amount_a,
49
+ amount_b,
50
+ active_id,
51
+ bin_step,
52
+ lower_bin_id,
53
+ upper_bin_id,
54
+ amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
55
+ amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
56
+ strategy_type: StrategyType.BidAsk,
57
+ }
58
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
59
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
60
+
61
+ const addOption: OpenAndAddLiquidityOption = {
62
+ pool_id,
63
+ bin_infos: bin_infos,
64
+ coin_type_a: pool.coin_type_a,
65
+ coin_type_b: pool.coin_type_b,
66
+ lower_bin_id,
67
+ upper_bin_id,
68
+ active_id,
69
+ }
70
+ const tx = sdk.Position.addLiquidityPayload(addOption)
71
+
72
+ printTransaction(tx)
73
+
74
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
75
+ console.log('🚀 ~ test ~ res:', res)
76
+ })
77
+
78
+ test('2 bid ask strategy both amounts add liquidity', async () => {
79
+ pool = await sdk.Pool.getPool(pool_id)
80
+ const { active_id, bin_step, bin_manager, coin_type_a, coin_type_b } = pool
81
+ console.log('🚀 ~ pool:', pool)
82
+
83
+ const position = await sdk.Position.getPosition(position_id)
84
+ const { lower_bin_id, upper_bin_id } = position
85
+ console.log('🚀 ~ position:', position)
86
+
87
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
88
+ bin_manager.bin_manager_handle,
89
+ lower_bin_id,
90
+ upper_bin_id,
91
+ active_id,
92
+ bin_step
93
+ )
94
+
95
+ const amount_a = '1000000'
96
+ const amount_b = '1200000'
97
+
98
+ const calculateOption: CalculateAddLiquidityOption = {
99
+ amount_a,
100
+ amount_b,
101
+ active_id,
102
+ bin_step,
103
+ lower_bin_id,
104
+ upper_bin_id,
105
+ amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
106
+ amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
107
+ strategy_type: StrategyType.BidAsk,
108
+ }
109
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
110
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
111
+
112
+ const addOption: AddLiquidityOption = {
113
+ pool_id,
114
+ bin_infos: bin_infos,
115
+ coin_type_a,
116
+ coin_type_b,
117
+ active_id,
118
+ position_id,
119
+ collect_fee: true,
120
+ reward_coins: [],
121
+ }
122
+ const tx = sdk.Position.addLiquidityPayload(addOption)
123
+
124
+ printTransaction(tx)
125
+
126
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
127
+ console.log('🚀 ~ test ~ res:', res)
128
+ })
129
+
130
+ test('3 bid ask strategy fix coin a add liquidity', async () => {
131
+ pool = await sdk.Pool.getPool(pool_id)
132
+ const { active_id, bin_step, bin_manager, coin_type_a, coin_type_b } = pool
133
+ console.log('🚀 ~ pool:', pool)
134
+
135
+ const position = await sdk.Position.getPosition(position_id)
136
+ const { lower_bin_id, upper_bin_id } = position
137
+ console.log('🚀 ~ position:', position)
138
+
139
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
140
+ bin_manager.bin_manager_handle,
141
+ lower_bin_id,
142
+ upper_bin_id,
143
+ active_id,
144
+ bin_step
145
+ )
146
+
147
+ const coin_amount = '2000000'
148
+
149
+ const calculateOption: CalculateAddLiquidityAutoFillOption = {
150
+ coin_amount,
151
+ fix_amount_a: true,
152
+ active_id,
153
+ bin_step,
154
+ lower_bin_id,
155
+ upper_bin_id,
156
+ amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
157
+ amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
158
+ strategy_type: StrategyType.BidAsk,
159
+ }
160
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
161
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
162
+
163
+ const addOption: AddLiquidityOption = {
164
+ pool_id,
165
+ bin_infos: bin_infos,
166
+ coin_type_a,
167
+ coin_type_b,
168
+ active_id,
169
+ position_id,
170
+ collect_fee: true,
171
+ reward_coins: [],
172
+ }
173
+ const tx = sdk.Position.addLiquidityPayload(addOption)
174
+
175
+ printTransaction(tx)
176
+
177
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
178
+ console.log('🚀 ~ test ~ res:', res)
179
+ })
180
+ })
@@ -0,0 +1,244 @@
1
+ // buildTestAccount
2
+ import type { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
3
+ import { buildTestAccount } from '@cetusprotocol/test-utils'
4
+ import { CetusDlmmSDK } from '../src/sdk'
5
+ import {
6
+ AddLiquidityOption,
7
+ CalculateAddLiquidityAutoFillOption,
8
+ CalculateAddLiquidityOption,
9
+ DlmmPool,
10
+ OpenAndAddLiquidityOption,
11
+ StrategyType,
12
+ } from '../src/types/dlmm'
13
+ import { printTransaction } from '@cetusprotocol/common-sdk'
14
+
15
+ const pool_id = '0x5156119a3cc1143ac65c24f3e7e0b339b74ea057ff5e3a1532b407a749193394'
16
+ const position_id = '0xbf3a7a03dbb80e37c44b3dac20cf675b69e5c1ca866538853522ccec934ef554'
17
+
18
+ describe('dlmm add liquidity curve', () => {
19
+ const sdk = CetusDlmmSDK.createSDK({ env: 'testnet', full_rpc_url: 'https://rpc-testnet.suiscan.xyz' })
20
+ let send_key_pair: Ed25519Keypair
21
+ let account: string
22
+ let pool: DlmmPool
23
+
24
+ beforeEach(async () => {
25
+ send_key_pair = buildTestAccount()
26
+ account = send_key_pair.getPublicKey().toSuiAddress()
27
+ sdk.setSenderAddress(account)
28
+ })
29
+
30
+ test('0 curve both amounts open multiple positions and add liquidity', async () => {
31
+ pool = await sdk.Pool.getPool(pool_id)
32
+ console.log('🚀 ~ beforeEach ~ pool:', pool)
33
+ const { active_id, bin_step } = pool
34
+ const amount_a = '10000000'
35
+ const amount_b = '10000000'
36
+ const lower_bin_id = active_id - 100
37
+ const upper_bin_id = active_id + 1300
38
+
39
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
40
+ pool.bin_manager.bin_manager_handle,
41
+ lower_bin_id,
42
+ upper_bin_id,
43
+ active_id,
44
+ bin_step
45
+ )
46
+
47
+ const calculateOption: CalculateAddLiquidityOption = {
48
+ amount_a,
49
+ amount_b,
50
+ active_id,
51
+ bin_step,
52
+ lower_bin_id,
53
+ upper_bin_id,
54
+ amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
55
+ amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
56
+ strategy_type: StrategyType.Curve,
57
+ }
58
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
59
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
60
+
61
+ const addOption: OpenAndAddLiquidityOption = {
62
+ pool_id,
63
+ bin_infos: bin_infos,
64
+ coin_type_a: pool.coin_type_a,
65
+ coin_type_b: pool.coin_type_b,
66
+ lower_bin_id,
67
+ upper_bin_id,
68
+ active_id,
69
+ strategy_type: StrategyType.Curve,
70
+ max_price_slippage: 0.001,
71
+ bin_step,
72
+ use_bin_infos: false,
73
+ }
74
+ const tx = sdk.Position.addLiquidityPayload(addOption)
75
+ tx.setGasBudget(10000000000)
76
+ printTransaction(tx)
77
+
78
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, true)
79
+ console.log('🚀 ~ test ~ res:', res)
80
+ })
81
+
82
+ test('1 curve both amounts open and add liquidity', async () => {
83
+ pool = await sdk.Pool.getPool(pool_id)
84
+ console.log('🚀 ~ beforeEach ~ pool:', pool)
85
+ const { active_id, bin_step } = pool
86
+ const amount_a = '1000000'
87
+ const amount_b = '1200000'
88
+ const lower_bin_id = -10
89
+ const upper_bin_id = 10
90
+
91
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
92
+ pool.bin_manager.bin_manager_handle,
93
+ lower_bin_id,
94
+ upper_bin_id,
95
+ active_id,
96
+ bin_step
97
+ )
98
+
99
+ const calculateOption: CalculateAddLiquidityOption = {
100
+ amount_a,
101
+ amount_b,
102
+ active_id,
103
+ bin_step,
104
+ lower_bin_id,
105
+ upper_bin_id,
106
+ amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
107
+ amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
108
+ strategy_type: StrategyType.Curve,
109
+ }
110
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
111
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
112
+
113
+ const addOption: OpenAndAddLiquidityOption = {
114
+ pool_id,
115
+ bin_infos: bin_infos,
116
+ coin_type_a: pool.coin_type_a,
117
+ coin_type_b: pool.coin_type_b,
118
+ lower_bin_id,
119
+ upper_bin_id,
120
+ active_id,
121
+ strategy_type: StrategyType.Curve,
122
+ max_price_slippage: 0.001,
123
+ bin_step,
124
+ use_bin_infos: false,
125
+ }
126
+ const tx = sdk.Position.addLiquidityPayload(addOption)
127
+
128
+ printTransaction(tx)
129
+
130
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
131
+ console.log('🚀 ~ test ~ res:', res)
132
+ })
133
+
134
+ test('2 curve strategy both amounts add liquidity', async () => {
135
+ pool = await sdk.Pool.getPool(pool_id)
136
+ const { active_id, bin_step, bin_manager, coin_type_a, coin_type_b } = pool
137
+ console.log('🚀 ~ pool:', pool)
138
+
139
+ const position = await sdk.Position.getPosition(position_id)
140
+ const { lower_bin_id, upper_bin_id } = position
141
+ console.log('🚀 ~ position:', position)
142
+
143
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
144
+ bin_manager.bin_manager_handle,
145
+ lower_bin_id,
146
+ upper_bin_id,
147
+ active_id,
148
+ bin_step
149
+ )
150
+
151
+ const amount_a = '1000000'
152
+ const amount_b = '1200000'
153
+
154
+ const calculateOption: CalculateAddLiquidityOption = {
155
+ amount_a,
156
+ amount_b,
157
+ active_id,
158
+ bin_step,
159
+ lower_bin_id,
160
+ upper_bin_id,
161
+ amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
162
+ amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
163
+ strategy_type: StrategyType.Curve,
164
+ }
165
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
166
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
167
+
168
+ const addOption: AddLiquidityOption = {
169
+ pool_id,
170
+ bin_infos: bin_infos,
171
+ coin_type_a,
172
+ coin_type_b,
173
+ active_id,
174
+ position_id,
175
+ collect_fee: true,
176
+ reward_coins: [],
177
+ strategy_type: StrategyType.Curve,
178
+ max_price_slippage: 0.001,
179
+ bin_step,
180
+ use_bin_infos: false,
181
+ }
182
+ const tx = sdk.Position.addLiquidityPayload(addOption)
183
+
184
+ printTransaction(tx)
185
+
186
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
187
+ console.log('🚀 ~ test ~ res:', res)
188
+ })
189
+
190
+ test('3 curve strategy fix coin a add liquidity', async () => {
191
+ pool = await sdk.Pool.getPool(pool_id)
192
+ const { active_id, bin_step, bin_manager, coin_type_a, coin_type_b } = pool
193
+ console.log('🚀 ~ pool:', pool)
194
+
195
+ const position = await sdk.Position.getPosition(position_id)
196
+ const { lower_bin_id, upper_bin_id } = position
197
+ console.log('🚀 ~ position:', position)
198
+
199
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
200
+ bin_manager.bin_manager_handle,
201
+ lower_bin_id,
202
+ upper_bin_id,
203
+ active_id,
204
+ bin_step
205
+ )
206
+
207
+ const coin_amount = '2000000'
208
+
209
+ const calculateOption: CalculateAddLiquidityAutoFillOption = {
210
+ coin_amount,
211
+ fix_amount_a: true,
212
+ active_id,
213
+ bin_step,
214
+ lower_bin_id,
215
+ upper_bin_id,
216
+ amount_a_in_active_bin: amounts_in_active_bin?.amount_a || '0',
217
+ amount_b_in_active_bin: amounts_in_active_bin?.amount_b || '0',
218
+ strategy_type: StrategyType.Curve,
219
+ }
220
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
221
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
222
+
223
+ const addOption: AddLiquidityOption = {
224
+ pool_id,
225
+ bin_infos: bin_infos,
226
+ coin_type_a,
227
+ coin_type_b,
228
+ active_id,
229
+ position_id,
230
+ collect_fee: true,
231
+ reward_coins: [],
232
+ strategy_type: StrategyType.Curve,
233
+ max_price_slippage: 0.001,
234
+ bin_step,
235
+ use_bin_infos: false,
236
+ }
237
+ const tx = sdk.Position.addLiquidityPayload(addOption)
238
+
239
+ printTransaction(tx)
240
+
241
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
242
+ console.log('🚀 ~ test ~ res:', res)
243
+ })
244
+ })
@@ -0,0 +1,262 @@
1
+ // buildTestAccount
2
+ import type { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
3
+ import { buildTestAccount } from '@cetusprotocol/test-utils'
4
+ import { CetusDlmmSDK } from '../src/sdk'
5
+ import {
6
+ AddLiquidityOption,
7
+ CalculateAddLiquidityAutoFillOption,
8
+ CalculateAddLiquidityOption,
9
+ DlmmPool,
10
+ OpenAndAddLiquidityOption,
11
+ OpenAndAddLiquidityWithPriceOption,
12
+ StrategyType,
13
+ } from '../src/types/dlmm'
14
+ import { printTransaction, toDecimalsAmount } from '@cetusprotocol/common-sdk'
15
+ import { BinUtils } from '../src/utils/binUtils'
16
+
17
+ const pool_id = '0x833a468857db452508351dbbe5f9859ed557014bf0a23e4c8eba5dfa0c0741f0'
18
+ const position_id = '0xf5139870fbc926d1ca1afdc536b4ab457a9c2a696440d10955572f04b95d9e29'
19
+
20
+ describe('dlmm add liquidity spot', () => {
21
+ const sdk = CetusDlmmSDK.createSDK({ env: 'testnet', full_rpc_url: 'https://rpc-testnet.suiscan.xyz:443' })
22
+ let send_key_pair: Ed25519Keypair
23
+ let account: string
24
+ let pool: DlmmPool
25
+
26
+ beforeEach(async () => {
27
+ send_key_pair = buildTestAccount()
28
+ account = send_key_pair.getPublicKey().toSuiAddress()
29
+ sdk.setSenderAddress(account)
30
+ })
31
+
32
+ test('0 spot both amounts open and add liquidity with price', async () => {
33
+ pool = await sdk.Pool.getPool(pool_id)
34
+ console.log('🚀 ~ beforeEach ~ pool:', pool)
35
+ const { active_id, bin_step } = pool
36
+ const amount_a = '1000000'
37
+ const amount_b = '1200000'
38
+
39
+ const lower_price = '0.99'
40
+ const upper_price = '1.01'
41
+ const price = BinUtils.getPriceFromBinId(active_id, bin_step, 6, 6)
42
+
43
+ const lower_bin_id = BinUtils.getBinIdFromPrice(lower_price, bin_step, true, 6, 6)
44
+ const upper_bin_id = BinUtils.getBinIdFromPrice(upper_price, bin_step, true, 6, 6)
45
+
46
+ console.log('🚀 ~ test ~ lower_bin_id:', lower_bin_id)
47
+ console.log('🚀 ~ test ~ upper_bin_id:', upper_bin_id)
48
+
49
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
50
+ pool.bin_manager.bin_manager_handle,
51
+ lower_bin_id,
52
+ upper_bin_id,
53
+ active_id,
54
+ bin_step
55
+ )
56
+
57
+ const calculateOption: CalculateAddLiquidityOption = {
58
+ amount_a,
59
+ amount_b,
60
+ active_id,
61
+ bin_step,
62
+ lower_bin_id,
63
+ 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',
66
+ strategy_type: StrategyType.Spot,
67
+ }
68
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
69
+ // console.log('🚀 ~ test ~ bin_infos:', bin_infos)
70
+
71
+ const addOption: OpenAndAddLiquidityWithPriceOption = {
72
+ pool_id,
73
+ bin_infos: bin_infos,
74
+ coin_type_a: pool.coin_type_a,
75
+ coin_type_b: pool.coin_type_b,
76
+ price_base_coin: 'coin_a',
77
+ price: price.toString(),
78
+ lower_price,
79
+ upper_price,
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',
83
+ strategy_type: StrategyType.Spot,
84
+ decimals_a: 6,
85
+ decimals_b: 6,
86
+ max_price_slippage: 0.01,
87
+ active_id,
88
+ }
89
+ const tx = sdk.Position.addLiquidityWithPricePayload(addOption)
90
+
91
+ printTransaction(tx)
92
+
93
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
94
+ console.log('🚀 ~ test ~ res:', res)
95
+ })
96
+
97
+ test('1 spot both amounts open and add liquidity', async () => {
98
+ pool = await sdk.Pool.getPool(pool_id)
99
+ console.log('🚀 ~ beforeEach ~ pool:', pool)
100
+ const { active_id, bin_step } = pool
101
+ const amount_a = '10000000'
102
+ const amount_b = '0'
103
+ const lower_bin_id = active_id
104
+ const upper_bin_id = active_id + 10
105
+
106
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
107
+ pool.bin_manager.bin_manager_handle,
108
+ lower_bin_id,
109
+ upper_bin_id,
110
+ active_id,
111
+ bin_step
112
+ )
113
+
114
+ const calculateOption: CalculateAddLiquidityOption = {
115
+ amount_a,
116
+ amount_b,
117
+ active_id,
118
+ bin_step,
119
+ lower_bin_id,
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',
123
+ strategy_type: StrategyType.Spot,
124
+ }
125
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
126
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
127
+
128
+ const addOption: OpenAndAddLiquidityOption = {
129
+ pool_id,
130
+ bin_infos: bin_infos,
131
+ coin_type_a: pool.coin_type_a,
132
+ coin_type_b: pool.coin_type_b,
133
+ lower_bin_id,
134
+ upper_bin_id,
135
+ active_id,
136
+ strategy_type: StrategyType.Spot,
137
+ use_bin_infos: false,
138
+ max_price_slippage: 0.01,
139
+ bin_step,
140
+ }
141
+ const tx = sdk.Position.addLiquidityPayload(addOption)
142
+ tx.setGasBudget(10000000000)
143
+ printTransaction(tx)
144
+
145
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
146
+ console.log('🚀 ~ test ~ res:', res)
147
+ })
148
+
149
+ test('2 spot strategy both amounts add liquidity', async () => {
150
+ pool = await sdk.Pool.getPool(pool_id)
151
+ const { active_id, bin_step, bin_manager, coin_type_a, coin_type_b } = pool
152
+ console.log('🚀 ~ pool:', pool)
153
+
154
+ const position = await sdk.Position.getPosition(position_id)
155
+ const { lower_bin_id, upper_bin_id } = position
156
+ console.log('🚀 ~ position:', position)
157
+
158
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
159
+ bin_manager.bin_manager_handle,
160
+ lower_bin_id,
161
+ upper_bin_id,
162
+ active_id,
163
+ bin_step
164
+ )
165
+
166
+ const amount_a = '1000000'
167
+ const amount_b = '0'
168
+
169
+ const calculateOption: CalculateAddLiquidityOption = {
170
+ amount_a,
171
+ amount_b,
172
+ active_id,
173
+ bin_step,
174
+ lower_bin_id,
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',
178
+ strategy_type: StrategyType.Spot,
179
+ }
180
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
181
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
182
+
183
+ const addOption: AddLiquidityOption = {
184
+ pool_id,
185
+ bin_infos: bin_infos,
186
+ coin_type_a,
187
+ coin_type_b,
188
+ active_id,
189
+ position_id,
190
+ collect_fee: true,
191
+ reward_coins: [],
192
+ strategy_type: StrategyType.Spot,
193
+ use_bin_infos: false,
194
+ max_price_slippage: 0.01,
195
+ bin_step,
196
+ }
197
+ const tx = sdk.Position.addLiquidityPayload(addOption)
198
+
199
+ printTransaction(tx)
200
+
201
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
202
+ console.log('🚀 ~ test ~ res:', res)
203
+ })
204
+
205
+ test('3 spot strategy fix coin a add liquidity', async () => {
206
+ pool = await sdk.Pool.getPool(pool_id)
207
+ const { active_id, bin_step, bin_manager, coin_type_a, coin_type_b } = pool
208
+ console.log('🚀 ~ pool:', pool)
209
+
210
+ const position = await sdk.Position.getPosition(position_id)
211
+ const { lower_bin_id, upper_bin_id } = position
212
+ console.log('🚀 ~ position:', position)
213
+
214
+ // const lower_bin_id = active_id + 1
215
+ // const upper_bin_id = active_id + 1
216
+
217
+ const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
218
+ bin_manager.bin_manager_handle,
219
+ lower_bin_id,
220
+ upper_bin_id,
221
+ active_id,
222
+ bin_step
223
+ )
224
+
225
+ const coin_amount = toDecimalsAmount(1, 9)
226
+
227
+ const calculateOption: CalculateAddLiquidityAutoFillOption = {
228
+ coin_amount,
229
+ fix_amount_a: false,
230
+ active_id,
231
+ bin_step,
232
+ lower_bin_id,
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',
236
+ strategy_type: StrategyType.Spot,
237
+ }
238
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
239
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
240
+
241
+ const addOption: AddLiquidityOption = {
242
+ pool_id,
243
+ bin_infos: bin_infos,
244
+ coin_type_a,
245
+ coin_type_b,
246
+ active_id,
247
+ position_id,
248
+ collect_fee: false,
249
+ reward_coins: [],
250
+ use_bin_infos: false,
251
+ strategy_type: StrategyType.Spot,
252
+ max_price_slippage: 0.01,
253
+ bin_step,
254
+ }
255
+ const tx = sdk.Position.addLiquidityPayload(addOption)
256
+ tx.setGasBudget(10000000000)
257
+ printTransaction(tx)
258
+
259
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, true)
260
+ console.log('🚀 ~ test ~ res:', res)
261
+ })
262
+ })