@cetusprotocol/dlmm-sdk 0.0.4 → 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.4",
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: '0xab76281e46956e18ce7ae3ab876da0b769e21afca90d2dc00b74bb9161720d28',
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
 
@@ -64,9 +64,19 @@ export class WeightUtils {
64
64
  const left_end_bin_id = active_id > upper_bin_id ? upper_bin_id : active_id
65
65
  const right_start_bin_id = active_id < lower_bin_id ? lower_bin_id : active_id
66
66
 
67
- const diff_min_weight = active_id > lower_bin_id ? diff_weight.div(d(left_end_bin_id - lower_bin_id)).floor() : d(0)
68
-
69
- const diff_max_weight = upper_bin_id > active_id ? diff_weight.div(d(upper_bin_id - right_start_bin_id)).floor() : d(0)
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)
70
80
 
71
81
  let bin_id = lower_bin_id
72
82
  let weights: Decimal[] = []
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 () => {