@reserve-protocol/dtf-rebalance-lib 2.1.0 → 2.1.2

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/dist/utils.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare const Decimal: typeof DecimalLight;
12
12
  */
13
13
  export declare const getBasketDistribution: (_bals: bigint[], _prices: number[], decimals: bigint[]) => bigint[];
14
14
  /**
15
- * Calculate basket deviation basket on balances and current weights
15
+ * Calculate how accurately balances reflect weights
16
16
  *
17
17
  * @param supply {share} Current total supply
18
18
  * @param _bals {tok} Current balances
@@ -22,4 +22,4 @@ export declare const getBasketDistribution: (_bals: bigint[], _prices: number[],
22
22
  * @param limits Current limits from getRebalance.limits
23
23
  * @returns {1} Basket deviation
24
24
  */
25
- export declare const getBasketDeviation: (supply: bigint, _bals: bigint[], _prices: number[], decimals: bigint[], weights: WeightRange[], limits: RebalanceLimits) => number;
25
+ export declare const getBasketAccuracy: (supply: bigint, _bals: bigint[], _prices: number[], decimals: bigint[], weights: WeightRange[], limits: RebalanceLimits) => number;
package/dist/utils.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getBasketDeviation = exports.getBasketDistribution = exports.Decimal = void 0;
6
+ exports.getBasketAccuracy = exports.getBasketDistribution = exports.Decimal = void 0;
7
7
  const decimal_js_light_1 = __importDefault(require("decimal.js-light"));
8
8
  const numbers_1 = require("./numbers");
9
9
  // Create a local Decimal constructor with custom precision
@@ -30,7 +30,7 @@ const getBasketDistribution = (_bals, _prices, decimals) => {
30
30
  };
31
31
  exports.getBasketDistribution = getBasketDistribution;
32
32
  /**
33
- * Calculate basket deviation basket on balances and current weights
33
+ * Calculate how accurately balances reflect weights
34
34
  *
35
35
  * @param supply {share} Current total supply
36
36
  * @param _bals {tok} Current balances
@@ -40,7 +40,7 @@ exports.getBasketDistribution = getBasketDistribution;
40
40
  * @param limits Current limits from getRebalance.limits
41
41
  * @returns {1} Basket deviation
42
42
  */
43
- const getBasketDeviation = (supply, _bals, _prices, decimals, weights, limits) => {
43
+ const getBasketAccuracy = (supply, _bals, _prices, decimals, weights, limits) => {
44
44
  const decimalScale = decimals.map((d) => new exports.Decimal(`1e${d}`));
45
45
  // {USD/wholeTok} = {USD/wholeTok}
46
46
  const prices = _prices.map((a) => new exports.Decimal(a.toString()));
@@ -54,9 +54,9 @@ const getBasketDeviation = (supply, _bals, _prices, decimals, weights, limits) =
54
54
  // {USD} = {tok} * {USD/wholeTok} / {tok/wholeTok}
55
55
  surplusValue = surplusValue.add(new exports.Decimal((_bals[i] - expectedBal).toString()).mul(prices[i]).div(decimalScale[i]));
56
56
  // {USD} = {tok} * {USD/wholeTok} / {tok/wholeTok}
57
- totalValue = totalValue.add(new exports.Decimal(_bals[i].toString()).mul(prices[i])).div(decimalScale[i]);
57
+ totalValue = totalValue.add(new exports.Decimal(_bals[i].toString()).mul(prices[i]).div(decimalScale[i]));
58
58
  }
59
59
  }
60
- return surplusValue.div(totalValue).toNumber();
60
+ return totalValue.sub(surplusValue).div(totalValue).toNumber();
61
61
  };
62
- exports.getBasketDeviation = getBasketDeviation;
62
+ exports.getBasketAccuracy = getBasketAccuracy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reserve-protocol/dtf-rebalance-lib",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "Rebalancing library for DTFs in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",