@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.
@@ -1,8 +1,83 @@
1
1
  import { d } from '@cetusprotocol/common-sdk'
2
- import { BinAmount, BinLiquidityInfo, StrategyType } from '../types/dlmm'
2
+ import { BinAmount, BinLiquidityInfo, StrategyType, WeightsInfo } from '../types/dlmm'
3
3
  import { WeightUtils } from './weightUtils'
4
+ import { BinUtils, SCALE_OFFSET } from './binUtils'
5
+ import { safeAmount, safeMulAmount } from './parseData'
6
+ import Decimal from 'decimal.js'
4
7
 
5
8
  export class StrategyUtils {
9
+ static toAmountsByWeights(weights_info: WeightsInfo): BinLiquidityInfo {
10
+ const {
11
+ total_weight_a,
12
+ total_weight_b,
13
+ weights,
14
+ weight_per_prices,
15
+ total_amount_a,
16
+ total_amount_b,
17
+ active_weight_a,
18
+ active_weight_b,
19
+ lower_bin_id,
20
+ upper_bin_id,
21
+ active_id,
22
+ bin_step,
23
+ } = weights_info
24
+
25
+ const ky = total_weight_b.isZero()
26
+ ? d(0)
27
+ : d(total_amount_b)
28
+ .mul(d(2).pow(SCALE_OFFSET * 2))
29
+ .div(total_weight_b)
30
+ .floor()
31
+
32
+ const kx = total_weight_a.isZero()
33
+ ? d(0)
34
+ : d(total_amount_a)
35
+ .mul(d(2).pow(SCALE_OFFSET * 2))
36
+ .div(total_weight_a)
37
+ .floor()
38
+
39
+ const amount_a_in_active_id = safeAmount(kx.mul(active_weight_a).div(d(2).pow(SCALE_OFFSET * 2)))
40
+ const amount_b_in_active_id = safeAmount(ky.mul(active_weight_b).div(d(2).pow(SCALE_OFFSET * 2)))
41
+
42
+ const bin_count = upper_bin_id - lower_bin_id + 1
43
+ let bin_id = lower_bin_id
44
+ let idx = 0
45
+ const bin_amounts: BinAmount[] = []
46
+ while (idx < bin_count) {
47
+ let amount_a_in_bin = d(0)
48
+ let amount_b_in_bin = d(0)
49
+
50
+ const qPrice = BinUtils.getQPriceFromId(bin_id, bin_step)
51
+
52
+ if (bin_id < active_id) {
53
+ amount_b_in_bin = safeAmount(ky.mul(weights[idx]).div(d(2).pow(SCALE_OFFSET)))
54
+ } else if (bin_id > active_id) {
55
+ amount_a_in_bin = safeAmount(kx.mul(weight_per_prices[idx]).div(d(2).pow(SCALE_OFFSET * 2)))
56
+ } else {
57
+ amount_a_in_bin = amount_a_in_active_id
58
+ amount_b_in_bin = amount_b_in_active_id
59
+ }
60
+ const liquidity = BinUtils.getLiquidity(amount_a_in_bin.toString(), amount_b_in_bin.toString(), qPrice)
61
+
62
+ bin_amounts.push({
63
+ bin_id,
64
+ amount_a: amount_a_in_bin.toString(),
65
+ amount_b: amount_b_in_bin.toString(),
66
+ price_per_lamport: BinUtils.getPricePerLamportFromBinId(bin_id, bin_step),
67
+ liquidity,
68
+ })
69
+ bin_id += 1
70
+ idx += 1
71
+ }
72
+
73
+ const info: BinLiquidityInfo = {
74
+ bins: bin_amounts,
75
+ amount_a: total_amount_a.toString(),
76
+ amount_b: total_amount_b.toString(),
77
+ }
78
+ return info
79
+ }
80
+
6
81
  /**
7
82
  * Given a strategy type and amounts of X and Y, returns the distribution of liquidity.
8
83
  * @param active_id The bin id of the active bin.
@@ -23,61 +98,32 @@ export class StrategyUtils {
23
98
  max_bin_id: number,
24
99
  amount_a: string,
25
100
  amount_b: string,
26
- amount_a_in_active_bin: string,
27
- amount_b_in_active_bin: string,
28
- strategy_type: StrategyType
101
+ strategy_type: StrategyType,
102
+ active_bin_of_pool?: BinAmount
29
103
  ): BinLiquidityInfo {
30
- switch (strategy_type) {
31
- case StrategyType.Spot: {
32
- let weights = WeightUtils.toWeightSpotBalanced(min_bin_id, max_bin_id)
33
- return WeightUtils.toAmountBothSide(
34
- active_id,
35
- bin_step,
36
- amount_a,
37
- amount_b,
38
- amount_a_in_active_bin,
39
- amount_b_in_active_bin,
40
- weights
41
- )
42
- }
43
- case StrategyType.Curve: {
44
- let weights = WeightUtils.toWeightCurve(min_bin_id, max_bin_id, active_id)
45
- return WeightUtils.toAmountBothSide(
46
- active_id,
47
- bin_step,
48
- amount_a,
49
- amount_b,
50
- amount_a_in_active_bin,
51
- amount_b_in_active_bin,
52
- weights
53
- )
54
- }
55
- case StrategyType.BidAsk: {
56
- let weights = WeightUtils.toWeightBidAsk(min_bin_id, max_bin_id, active_id)
57
- return WeightUtils.toAmountBothSide(
58
- active_id,
59
- bin_step,
60
- amount_a,
61
- amount_b,
62
- amount_a_in_active_bin,
63
- amount_b_in_active_bin,
64
- weights
65
- )
66
- }
67
- }
104
+ const weights = WeightUtils.toWeight({
105
+ strategy_type,
106
+ active_id,
107
+ bin_step,
108
+ lower_bin_id: min_bin_id,
109
+ upper_bin_id: max_bin_id,
110
+ total_amount_a: amount_a,
111
+ total_amount_b: amount_b,
112
+ active_bin_of_pool,
113
+ })
114
+
115
+ return this.toAmountsByWeights(weights)
68
116
  }
69
117
 
70
- // only apply for
71
118
  static autoFillCoinByStrategy(
72
119
  active_id: number,
73
120
  bin_step: number,
74
121
  amount: string,
75
122
  fix_amount_a: boolean,
76
- amount_a_in_active_bin: string,
77
- amount_b_in_active_bin: string,
78
123
  min_bin_id: number,
79
124
  max_bin_id: number,
80
- strategy_type: StrategyType
125
+ strategy_type: StrategyType,
126
+ active_bin_of_pool?: BinAmount
81
127
  ): BinLiquidityInfo {
82
128
  switch (strategy_type) {
83
129
  case StrategyType.Spot: {
@@ -87,8 +133,8 @@ export class StrategyUtils {
87
133
  bin_step,
88
134
  amount,
89
135
  fix_amount_a,
90
- amount_a_in_active_bin,
91
- amount_b_in_active_bin,
136
+ active_bin_of_pool?.amount_a || '0',
137
+ active_bin_of_pool?.amount_b || '0',
92
138
  weights
93
139
  )
94
140
  }
@@ -99,8 +145,8 @@ export class StrategyUtils {
99
145
  bin_step,
100
146
  amount,
101
147
  fix_amount_a,
102
- amount_a_in_active_bin,
103
- amount_b_in_active_bin,
148
+ active_bin_of_pool?.amount_a || '0',
149
+ active_bin_of_pool?.amount_b || '0',
104
150
  weights
105
151
  )
106
152
  }
@@ -111,11 +157,46 @@ export class StrategyUtils {
111
157
  bin_step,
112
158
  amount,
113
159
  fix_amount_a,
114
- amount_a_in_active_bin,
115
- amount_b_in_active_bin,
160
+ active_bin_of_pool?.amount_a || '0',
161
+ active_bin_of_pool?.amount_b || '0',
116
162
  weights
117
163
  )
118
164
  }
119
165
  }
120
166
  }
167
+
168
+ // only apply for
169
+ static autoFillCoinByStrategyV2(
170
+ active_id: number,
171
+ bin_step: number,
172
+ amount: string,
173
+ fix_amount_a: boolean,
174
+ min_bin_id: number,
175
+ max_bin_id: number,
176
+ strategy_type: StrategyType,
177
+ active_bin_of_pool?: BinAmount
178
+ ): BinLiquidityInfo {
179
+ const info = this.autoFillCoinByStrategy(
180
+ active_id,
181
+ bin_step,
182
+ amount,
183
+ fix_amount_a,
184
+ min_bin_id,
185
+ max_bin_id,
186
+ strategy_type,
187
+ active_bin_of_pool
188
+ )
189
+ const weights = WeightUtils.toWeight({
190
+ strategy_type,
191
+ active_id,
192
+ bin_step,
193
+ lower_bin_id: min_bin_id,
194
+ upper_bin_id: max_bin_id,
195
+ total_amount_a: fix_amount_a ? amount : info.amount_a,
196
+ total_amount_b: fix_amount_a ? info.amount_b : amount,
197
+ active_bin_of_pool,
198
+ })
199
+
200
+ return this.toAmountsByWeights(weights)
201
+ }
121
202
  }
@@ -1,12 +1,127 @@
1
- import { d, DETAILS_KEYS } from '@cetusprotocol/common-sdk'
2
- import { BinAmount, BinLiquidityInfo, BinWeight, StrategyType } from '../types/dlmm'
1
+ import { d } from '@cetusprotocol/common-sdk'
2
+ import { BinLiquidityInfo, BinWeight, StrategyType, WeightsInfo, WeightsOptions } from '../types/dlmm'
3
3
  import Decimal from 'decimal.js'
4
- import { DlmmErrorCode, handleError } from '../errors/errors'
5
4
  import { DEFAULT_MAX_WEIGHT, DEFAULT_MIN_WEIGHT } from '../types/constants'
6
- import { BinUtils } from './binUtils'
5
+ import { BinUtils, SCALE_OFFSET } from './binUtils'
7
6
  import { safeMulAmount } from './parseData'
8
7
 
9
8
  export class WeightUtils {
9
+ static toWeight(options: WeightsOptions): WeightsInfo {
10
+ console.log('🚀 ~ WeightUtils ~ toWeight ~ options:', options)
11
+
12
+ const { strategy_type, active_id, bin_step, lower_bin_id, upper_bin_id, total_amount_a, total_amount_b, active_bin_of_pool } = options
13
+ const single_side = active_id < lower_bin_id || active_id > upper_bin_id
14
+ const active_bin_price = BinUtils.getQPriceFromId(active_id, bin_step)
15
+
16
+ let active_weight_a = d(0)
17
+ let active_weight_b = d(0)
18
+
19
+ let base_weight = d(DEFAULT_MIN_WEIGHT)
20
+ if (strategy_type === StrategyType.BidAsk) {
21
+ base_weight = d(DEFAULT_MIN_WEIGHT)
22
+ } else if (strategy_type === StrategyType.Curve) {
23
+ base_weight = d(DEFAULT_MAX_WEIGHT)
24
+ } else if (strategy_type === StrategyType.Spot) {
25
+ base_weight = d(1)
26
+ }
27
+
28
+ if (!single_side && active_bin_of_pool) {
29
+ const weights = this.calculateActiveWeights(active_bin_of_pool.amount_a, active_bin_of_pool.amount_b, active_bin_price, base_weight)
30
+ active_weight_a = weights.active_weight_a
31
+ active_weight_b = weights.active_weight_b
32
+ }
33
+
34
+ if (active_id === lower_bin_id && d(total_amount_b).isZero()) {
35
+ active_weight_a = d(base_weight)
36
+ .mul(d(2).pow(SCALE_OFFSET * 2))
37
+ .div(d(active_bin_price))
38
+ .floor()
39
+ active_weight_b = d(0)
40
+ }
41
+ if (active_id === upper_bin_id && d(total_amount_a).isZero()) {
42
+ active_weight_b = d(base_weight).mul(d(2).pow(SCALE_OFFSET)).floor()
43
+ active_weight_a = d(0)
44
+ }
45
+
46
+ if (active_id > lower_bin_id && active_id < upper_bin_id) {
47
+ if (d(total_amount_a).isZero()) {
48
+ active_weight_b = d(base_weight).mul(d(2).pow(SCALE_OFFSET)).floor()
49
+ active_weight_a = d(0)
50
+ }
51
+ if (d(total_amount_b).isZero()) {
52
+ active_weight_a = d(base_weight)
53
+ .mul(d(2).pow(SCALE_OFFSET * 2))
54
+ .div(d(active_bin_price))
55
+ .floor()
56
+ active_weight_b = d(0)
57
+ }
58
+ }
59
+ let total_weight_a = single_side ? d(0) : active_weight_a
60
+ let total_weight_b = single_side ? d(0) : active_weight_b
61
+
62
+ const diff_weight = d(DEFAULT_MAX_WEIGHT).sub(d(DEFAULT_MIN_WEIGHT)).floor()
63
+
64
+ const diff_min_weight = active_id > lower_bin_id ? diff_weight.div(d(active_id - lower_bin_id)).floor() : d(0)
65
+
66
+ const diff_max_weight = upper_bin_id > active_id ? diff_weight.div(d(upper_bin_id - active_id)).floor() : d(0)
67
+
68
+ let bin_id = lower_bin_id
69
+ let weights: Decimal[] = []
70
+ let weight_per_prices: Decimal[] = []
71
+
72
+ while (bin_id <= upper_bin_id) {
73
+ let weight: Decimal = d(0)
74
+ if (bin_id < active_id) {
75
+ const delta_bin = active_id - bin_id
76
+ if (strategy_type === StrategyType.Spot) {
77
+ weight = d(1)
78
+ } else if (strategy_type === StrategyType.BidAsk) {
79
+ weight = d(base_weight).add(diff_min_weight.mul(delta_bin)).floor()
80
+ } else if (strategy_type === StrategyType.Curve) {
81
+ weight = d(base_weight).sub(diff_min_weight.mul(delta_bin)).floor()
82
+ }
83
+ } else if (bin_id > active_id) {
84
+ const delta_bin = bin_id - active_id
85
+ if (strategy_type === StrategyType.Spot) {
86
+ weight = d(1)
87
+ } else if (strategy_type === StrategyType.BidAsk) {
88
+ weight = d(base_weight).add(diff_max_weight.mul(delta_bin)).floor()
89
+ } else if (strategy_type === StrategyType.Curve) {
90
+ weight = d(base_weight).sub(diff_max_weight.mul(delta_bin)).floor()
91
+ }
92
+ } else {
93
+ weight = base_weight
94
+ }
95
+ weights.push(weight)
96
+
97
+ if (bin_id < active_id) {
98
+ total_weight_b = total_weight_b.add(weight.mul(d(2).pow(SCALE_OFFSET))).floor()
99
+ weight_per_prices.push(d(0))
100
+ } else if (bin_id > active_id) {
101
+ const weight_per_price = weight
102
+ .mul(d(2).pow(SCALE_OFFSET * 2))
103
+ .div(BinUtils.getQPriceFromId(bin_id, bin_step))
104
+ .floor()
105
+ weight_per_prices.push(weight_per_price)
106
+ total_weight_a = total_weight_a.add(weight_per_price).floor()
107
+ } else {
108
+ weight_per_prices.push(d(0))
109
+ }
110
+
111
+ bin_id += 1
112
+ }
113
+
114
+ return {
115
+ ...options,
116
+ total_weight_a,
117
+ total_weight_b,
118
+ active_weight_a,
119
+ active_weight_b,
120
+ weights,
121
+ weight_per_prices,
122
+ }
123
+ }
124
+
10
125
  static toWeightSpotBalanced(min_bin_id: number, max_bin_id: number): BinWeight[] {
11
126
  let distributions = []
12
127
  for (let i = min_bin_id; i <= max_bin_id; i++) {
@@ -446,9 +561,9 @@ export class WeightUtils {
446
561
  let k = d(0)
447
562
 
448
563
  if (fix_amount_a) {
449
- k = totalWeightA.isZero() ? new Decimal(1) : new Decimal(amount).div(totalWeightA)
564
+ k = totalWeightA.isZero() ? new Decimal(0) : new Decimal(amount).div(totalWeightA)
450
565
  } else {
451
- k = totalWeightB.isZero() ? new Decimal(1) : new Decimal(amount).div(totalWeightB)
566
+ k = totalWeightB.isZero() ? new Decimal(0) : new Decimal(amount).div(totalWeightB)
452
567
  }
453
568
  const other_amount = safeMulAmount(k, fix_amount_a ? totalWeightB : totalWeightA).toString()
454
569
 
@@ -463,6 +578,52 @@ export class WeightUtils {
463
578
  )
464
579
  }
465
580
 
581
+ static calculateActiveWeights(
582
+ amount_a_in_active_id: string,
583
+ amount_b_in_active_id: string,
584
+ active_bin_price: string,
585
+ base_weight: Decimal
586
+ ): { active_weight_a: Decimal; active_weight_b: Decimal } {
587
+ const p0 = d(active_bin_price)
588
+ const amountA = d(amount_a_in_active_id)
589
+ const amountB = d(amount_b_in_active_id)
590
+
591
+ let active_weight_a: Decimal = d(0)
592
+ let active_weight_b: Decimal = d(0)
593
+
594
+ if (amountA.isZero() && amountB.isZero()) {
595
+ active_weight_a = d(base_weight)
596
+ .mul(d(2).pow(SCALE_OFFSET * 2))
597
+ .div(p0.mul(2))
598
+ .floor()
599
+ active_weight_b = d(base_weight).mul(d(2).pow(SCALE_OFFSET)).div(2).floor()
600
+ } else {
601
+ // Calculate wx0
602
+ if (amountA.isZero()) {
603
+ active_weight_a = d(0)
604
+ } else {
605
+ const m = amountB.mul(d(2).pow(SCALE_OFFSET)).div(amountA)
606
+ active_weight_a = d(base_weight)
607
+ .mul(d(2).pow(SCALE_OFFSET * 2))
608
+ .div(p0.add(m))
609
+ .floor()
610
+ }
611
+
612
+ // Calculate wy0
613
+ if (amountB.isZero()) {
614
+ active_weight_b = d(0)
615
+ } else {
616
+ const m = d(2).pow(SCALE_OFFSET).add(p0.mul(amountA).div(amountB)).floor()
617
+ active_weight_b = d(base_weight)
618
+ .mul(d(2).pow(SCALE_OFFSET * 2))
619
+ .div(m)
620
+ .floor()
621
+ }
622
+ }
623
+
624
+ return { active_weight_a, active_weight_b }
625
+ }
626
+
466
627
  static calculateTotalWeights(
467
628
  bin_step: number,
468
629
  distributions: BinWeight[],
@@ -12,8 +12,8 @@ import {
12
12
  } from '../src/types/dlmm'
13
13
  import { printTransaction } from '@cetusprotocol/common-sdk'
14
14
 
15
- const pool_id = '0x56d2a3270238f1347fa6fb94836da8afd2415c49ab7bb843996fe5c6a807dc5a'
16
- const position_id = '0x081a3fda4c7df0fc86ff7f69809434ac096911eb7b5e81865cdd1bf8858214fa'
15
+ const pool_id = '0x6ae0b7d9fe4f3ed5ea187c357a4c6c5a192a199d899a58d1f559a6501082f3bf'
16
+ const position_id = '0x85f39912b4eca99e076a925749552fe7a4b2dc882005e21070ba3f2e43b11f3d'
17
17
 
18
18
  describe('dlmm add liquidity bid ask', () => {
19
19
  const sdk = CetusDlmmSDK.createSDK({ env: 'testnet', full_rpc_url: 'https://rpc-testnet.suiscan.xyz' })
@@ -45,17 +45,17 @@ describe('dlmm add liquidity bid ask', () => {
45
45
  )
46
46
 
47
47
  const calculateOption: CalculateAddLiquidityOption = {
48
+ pool_id,
48
49
  amount_a,
49
50
  amount_b,
50
51
  active_id,
51
52
  bin_step,
52
53
  lower_bin_id,
53
54
  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',
55
+ active_bin_of_pool: amounts_in_active_bin,
56
56
  strategy_type: StrategyType.BidAsk,
57
57
  }
58
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
58
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
59
59
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
60
60
 
61
61
  const addOption: OpenAndAddLiquidityOption = {
@@ -66,10 +66,14 @@ describe('dlmm add liquidity bid ask', () => {
66
66
  lower_bin_id,
67
67
  upper_bin_id,
68
68
  active_id,
69
+ use_bin_infos: false,
70
+ strategy_type: StrategyType.BidAsk,
71
+ max_price_slippage: 0.01,
72
+ bin_step,
69
73
  }
70
74
  const tx = sdk.Position.addLiquidityPayload(addOption)
71
75
 
72
- printTransaction(tx)
76
+ // printTransaction(tx)
73
77
 
74
78
  const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
75
79
  console.log('🚀 ~ test ~ res:', res)
@@ -92,21 +96,21 @@ describe('dlmm add liquidity bid ask', () => {
92
96
  bin_step
93
97
  )
94
98
 
95
- const amount_a = '1000000'
96
- const amount_b = '1200000'
99
+ const amount_a = '100000000'
100
+ const amount_b = '120000000'
97
101
 
98
102
  const calculateOption: CalculateAddLiquidityOption = {
103
+ pool_id,
99
104
  amount_a,
100
105
  amount_b,
101
106
  active_id,
102
107
  bin_step,
103
108
  lower_bin_id,
104
109
  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',
110
+ active_bin_of_pool: amounts_in_active_bin,
107
111
  strategy_type: StrategyType.BidAsk,
108
112
  }
109
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
113
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
110
114
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
111
115
 
112
116
  const addOption: AddLiquidityOption = {
@@ -118,6 +122,10 @@ describe('dlmm add liquidity bid ask', () => {
118
122
  position_id,
119
123
  collect_fee: true,
120
124
  reward_coins: [],
125
+ strategy_type: StrategyType.BidAsk,
126
+ use_bin_infos: false,
127
+ max_price_slippage: 0.01,
128
+ bin_step,
121
129
  }
122
130
  const tx = sdk.Position.addLiquidityPayload(addOption)
123
131
 
@@ -147,17 +155,17 @@ describe('dlmm add liquidity bid ask', () => {
147
155
  const coin_amount = '2000000'
148
156
 
149
157
  const calculateOption: CalculateAddLiquidityAutoFillOption = {
158
+ pool_id,
150
159
  coin_amount,
151
160
  fix_amount_a: true,
152
161
  active_id,
153
162
  bin_step,
154
163
  lower_bin_id,
155
164
  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',
165
+ active_bin_of_pool: amounts_in_active_bin,
158
166
  strategy_type: StrategyType.BidAsk,
159
167
  }
160
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
168
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
161
169
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
162
170
 
163
171
  const addOption: AddLiquidityOption = {
@@ -169,6 +177,10 @@ describe('dlmm add liquidity bid ask', () => {
169
177
  position_id,
170
178
  collect_fee: true,
171
179
  reward_coins: [],
180
+ strategy_type: StrategyType.BidAsk,
181
+ use_bin_infos: false,
182
+ max_price_slippage: 0.01,
183
+ bin_step,
172
184
  }
173
185
  const tx = sdk.Position.addLiquidityPayload(addOption)
174
186
 
@@ -12,7 +12,7 @@ import {
12
12
  } from '../src/types/dlmm'
13
13
  import { printTransaction } from '@cetusprotocol/common-sdk'
14
14
 
15
- const pool_id = '0x5156119a3cc1143ac65c24f3e7e0b339b74ea057ff5e3a1532b407a749193394'
15
+ const pool_id = '0x6ae0b7d9fe4f3ed5ea187c357a4c6c5a192a199d899a58d1f559a6501082f3bf'
16
16
  const position_id = '0xbf3a7a03dbb80e37c44b3dac20cf675b69e5c1ca866538853522ccec934ef554'
17
17
 
18
18
  describe('dlmm add liquidity curve', () => {
@@ -33,8 +33,8 @@ describe('dlmm add liquidity curve', () => {
33
33
  const { active_id, bin_step } = pool
34
34
  const amount_a = '10000000'
35
35
  const amount_b = '10000000'
36
- const lower_bin_id = active_id - 100
37
- const upper_bin_id = active_id + 1300
36
+ const lower_bin_id = active_id - 10
37
+ const upper_bin_id = active_id + 10
38
38
 
39
39
  const amounts_in_active_bin = await sdk.Position.getActiveBinIfInRange(
40
40
  pool.bin_manager.bin_manager_handle,
@@ -45,17 +45,17 @@ describe('dlmm add liquidity curve', () => {
45
45
  )
46
46
 
47
47
  const calculateOption: CalculateAddLiquidityOption = {
48
+ pool_id,
48
49
  amount_a,
49
50
  amount_b,
50
51
  active_id,
51
52
  bin_step,
52
53
  lower_bin_id,
53
54
  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',
55
+ active_bin_of_pool: amounts_in_active_bin,
56
56
  strategy_type: StrategyType.Curve,
57
57
  }
58
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
58
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
59
59
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
60
60
 
61
61
  const addOption: OpenAndAddLiquidityOption = {
@@ -75,7 +75,7 @@ describe('dlmm add liquidity curve', () => {
75
75
  tx.setGasBudget(10000000000)
76
76
  printTransaction(tx)
77
77
 
78
- const res = await sdk.FullClient.executeTx(send_key_pair, tx, true)
78
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
79
79
  console.log('🚀 ~ test ~ res:', res)
80
80
  })
81
81
 
@@ -97,17 +97,17 @@ describe('dlmm add liquidity curve', () => {
97
97
  )
98
98
 
99
99
  const calculateOption: CalculateAddLiquidityOption = {
100
+ pool_id,
100
101
  amount_a,
101
102
  amount_b,
102
103
  active_id,
103
104
  bin_step,
104
105
  lower_bin_id,
105
106
  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',
107
+ active_bin_of_pool: amounts_in_active_bin,
108
108
  strategy_type: StrategyType.Curve,
109
109
  }
110
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
110
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
111
111
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
112
112
 
113
113
  const addOption: OpenAndAddLiquidityOption = {
@@ -152,17 +152,17 @@ describe('dlmm add liquidity curve', () => {
152
152
  const amount_b = '1200000'
153
153
 
154
154
  const calculateOption: CalculateAddLiquidityOption = {
155
+ pool_id,
155
156
  amount_a,
156
157
  amount_b,
157
158
  active_id,
158
159
  bin_step,
159
160
  lower_bin_id,
160
161
  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',
162
+ active_bin_of_pool: amounts_in_active_bin,
163
163
  strategy_type: StrategyType.Curve,
164
164
  }
165
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
165
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
166
166
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
167
167
 
168
168
  const addOption: AddLiquidityOption = {
@@ -207,17 +207,17 @@ describe('dlmm add liquidity curve', () => {
207
207
  const coin_amount = '2000000'
208
208
 
209
209
  const calculateOption: CalculateAddLiquidityAutoFillOption = {
210
+ pool_id,
210
211
  coin_amount,
211
212
  fix_amount_a: true,
212
213
  active_id,
213
214
  bin_step,
214
215
  lower_bin_id,
215
216
  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',
217
+ active_bin_of_pool: amounts_in_active_bin,
218
218
  strategy_type: StrategyType.Curve,
219
219
  }
220
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
220
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
221
221
  console.log('🚀 ~ test ~ bin_infos:', bin_infos)
222
222
 
223
223
  const addOption: AddLiquidityOption = {