@cetusprotocol/dlmm-sdk 0.0.3 → 0.0.4

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.4",
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: '0xab76281e46956e18ce7ae3ab876da0b769e21afca90d2dc00b74bb9161720d28',
23
23
  version: 1,
24
24
  },
25
25
  }
@@ -61,9 +61,12 @@ 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)
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
65
66
 
66
- const diff_max_weight = upper_bin_id > active_id ? diff_weight.div(d(upper_bin_id - active_id)).floor() : d(0)
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
70
 
68
71
  let bin_id = lower_bin_id
69
72
  let weights: Decimal[] = []
@@ -72,7 +75,7 @@ export class WeightUtils {
72
75
  while (bin_id <= upper_bin_id) {
73
76
  let weight: Decimal = d(0)
74
77
  if (bin_id < active_id) {
75
- const delta_bin = active_id - bin_id
78
+ const delta_bin = left_end_bin_id - bin_id
76
79
  if (strategy_type === StrategyType.Spot) {
77
80
  weight = d(1)
78
81
  } else if (strategy_type === StrategyType.BidAsk) {
@@ -81,7 +84,7 @@ export class WeightUtils {
81
84
  weight = d(base_weight).sub(diff_min_weight.mul(delta_bin)).floor()
82
85
  }
83
86
  } else if (bin_id > active_id) {
84
- const delta_bin = bin_id - active_id
87
+ const delta_bin = bin_id - right_start_bin_id
85
88
  if (strategy_type === StrategyType.Spot) {
86
89
  weight = d(1)
87
90
  } else if (strategy_type === StrategyType.BidAsk) {