@reserve-protocol/dtf-rebalance-lib 2.6.2 → 2.6.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.
@@ -90,11 +90,23 @@ const getStartRebalance = (_supply, tokens, _assets, decimals, _targetBasket, _p
90
90
  // === newPrices ===
91
91
  // D27{wholeTok/tok} = D27 / {tok/wholeTok}
92
92
  const priceMultiplier = numbers_1.D27d.div(new utils_1.Decimal(`1e${decimals[i]}`));
93
+ // D27{nanoUSD/tok} = {USD/wholeTok} * {1} * D27{wholeTok/tok} * {nanoUSD/USD}
94
+ const low = (0, numbers_1.bn)(prices[i].mul(numbers_1.ONE.sub(priceError[i])).mul(priceMultiplier).mul(numbers_1.D9d));
95
+ let high = (0, numbers_1.bn)(prices[i].div(numbers_1.ONE.sub(priceError[i])).mul(priceMultiplier).mul(numbers_1.D9d));
96
+ // check if prices are valid
97
+ if (low < 0n || low > high || high > numbers_1.D18n * numbers_1.D27n) {
98
+ throw new Error(`invalid prices for token ${tokens[i]}: low: ${low}, high: ${high}`);
99
+ }
100
+ // constrain price range if too large, but not by more than 10%
101
+ if (high > low * 110n) {
102
+ throw new Error(`invalid price range for token ${tokens[i]}: low: ${low}, high: ${high}`);
103
+ }
104
+ if (high > low * 100n) {
105
+ high = low * 100n;
106
+ }
93
107
  newPrices.push({
94
- // D27{nanoUSD/tok} = {USD/wholeTok} * {1} * D27{wholeTok/tok} * {nanoUSD/USD}
95
- low: (0, numbers_1.bn)(prices[i].mul(numbers_1.ONE.sub(priceError[i])).mul(priceMultiplier).mul(numbers_1.D9d)),
96
- // D27{nanoUSD/tok} = {USD/wholeTok} / {1} * D27{wholeTok/tok} * {nanoUSD/USD}
97
- high: (0, numbers_1.bn)(prices[i].div(numbers_1.ONE.sub(priceError[i])).mul(priceMultiplier).mul(numbers_1.D9d)),
108
+ low: low,
109
+ high: high,
98
110
  });
99
111
  }
100
112
  // ================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reserve-protocol/dtf-rebalance-lib",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
4
4
  "description": "Rebalancing library for DTFs in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",