@cetusprotocol/dlmm-sdk 0.0.3 → 0.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/dlmm-sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "SDK for cetus dlmm",
5
5
  "typings": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -19,7 +19,7 @@ export const dlmmMainnet: SdkOptions = {
19
19
  },
20
20
  dlmm_router: {
21
21
  package_id: '0xc65d59c4aa7c9d53836bdbbb2a1418b02be6a351a767c64d6e4b7e96d26356d2',
22
- published_at: '0xda28da84b5b1fef0ca053a2373e80ddb3a75f45e891e825fb06c2a53f838067d',
22
+ published_at: '0x8d389fa25cb08ebc5e520bc520ed394eed9e62b56b7868acb398bf298b8a76f3',
23
23
  version: 1,
24
24
  },
25
25
  }
@@ -192,8 +192,8 @@ export class StrategyUtils {
192
192
  bin_step,
193
193
  lower_bin_id: min_bin_id,
194
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,
195
+ total_amount_a: info.amount_a,
196
+ total_amount_b: info.amount_b,
197
197
  active_bin_of_pool,
198
198
  })
199
199
 
@@ -61,9 +61,22 @@ export class WeightUtils {
61
61
 
62
62
  const diff_weight = d(DEFAULT_MAX_WEIGHT).sub(d(DEFAULT_MIN_WEIGHT)).floor()
63
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)
64
+ const left_end_bin_id = active_id > upper_bin_id ? upper_bin_id : active_id
65
+ const right_start_bin_id = active_id < lower_bin_id ? lower_bin_id : active_id
66
+
67
+ const diff_min_weight =
68
+ active_id > lower_bin_id
69
+ ? left_end_bin_id === lower_bin_id
70
+ ? d(0)
71
+ : diff_weight.div(d(left_end_bin_id - lower_bin_id)).floor()
72
+ : d(0)
73
+
74
+ const diff_max_weight =
75
+ upper_bin_id > active_id
76
+ ? right_start_bin_id === upper_bin_id
77
+ ? d(0)
78
+ : diff_weight.div(d(upper_bin_id - right_start_bin_id)).floor()
79
+ : d(0)
67
80
 
68
81
  let bin_id = lower_bin_id
69
82
  let weights: Decimal[] = []
@@ -72,7 +85,7 @@ export class WeightUtils {
72
85
  while (bin_id <= upper_bin_id) {
73
86
  let weight: Decimal = d(0)
74
87
  if (bin_id < active_id) {
75
- const delta_bin = active_id - bin_id
88
+ const delta_bin = left_end_bin_id - bin_id
76
89
  if (strategy_type === StrategyType.Spot) {
77
90
  weight = d(1)
78
91
  } else if (strategy_type === StrategyType.BidAsk) {
@@ -81,7 +94,7 @@ export class WeightUtils {
81
94
  weight = d(base_weight).sub(diff_min_weight.mul(delta_bin)).floor()
82
95
  }
83
96
  } else if (bin_id > active_id) {
84
- const delta_bin = bin_id - active_id
97
+ const delta_bin = bin_id - right_start_bin_id
85
98
  if (strategy_type === StrategyType.Spot) {
86
99
  weight = d(1)
87
100
  } else if (strategy_type === StrategyType.BidAsk) {
package/tests/bin.test.ts CHANGED
@@ -57,21 +57,36 @@ describe('dlmm bin', () => {
57
57
  })
58
58
 
59
59
  test('calculateAddLiquidityInfo', async () => {
60
- const calculateOption: CalculateAddLiquidityOption = {
61
- amount_a: '100000000',
62
- amount_b: '100000000',
63
- active_id: 0,
64
- bin_step: 2,
65
- lower_bin_id: 0,
66
- upper_bin_id: 70,
67
- amount_a_in_active_bin: '0',
68
- amount_b_in_active_bin: '0',
69
- strategy_type: StrategyType.Spot,
60
+ // const calculateOption: CalculateAddLiquidityOption = {
61
+ // amount_a: '100000000',
62
+ // amount_b: '100000000',
63
+ // active_id: 0,
64
+ // bin_step: 2,
65
+ // lower_bin_id: 0,
66
+ // upper_bin_id: 70,
67
+ // amount_a_in_active_bin: '0',
68
+ // amount_b_in_active_bin: '0',
69
+ // strategy_type: StrategyType.Spot,
70
+ // }
71
+ // const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
72
+ // console.log('🚀 ~ test ~ split_bin_infos:', bin_infos.bins.length)
73
+ // const split_bin_infos = BinUtils.splitBinLiquidityInfo(bin_infos, 0, 70)
74
+ // console.log('🚀 ~ test ~ split_bin_infos:', split_bin_infos.length)
75
+
76
+ const calculateOption = {
77
+ active_bin_of_pool: undefined,
78
+ active_id: 2290,
79
+ pool_id: '0x556d4a393ce033ba4ee77980b70b63ca7b824752583e51103c15e4038cc96e44',
80
+ amount_a: '0',
81
+ amount_b: '1000000000',
82
+ bin_step: 25,
83
+ lower_bin_id: 2273,
84
+ strategy_type: 0,
85
+ upper_bin_id: 2273
70
86
  }
71
- const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
72
- console.log('🚀 ~ test ~ split_bin_infos:', bin_infos.bins.length)
73
- const split_bin_infos = BinUtils.splitBinLiquidityInfo(bin_infos, 0, 70)
74
- console.log('🚀 ~ test ~ split_bin_infos:', split_bin_infos.length)
87
+
88
+ const bin_infos = await sdk.Position.calculateAddLiquidityInfo(calculateOption)
89
+ console.log("🚀 ~ bin_infos:", JSON.stringify(bin_infos, null, 2))
75
90
  })
76
91
 
77
92
  test('findMinMaxBinId', async () => {