@reserve-protocol/dtf-rebalance-lib 0.2.7 → 0.2.8

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.
@@ -147,40 +147,38 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
147
147
  .reduce((a, b) => a.add(b), numbers_1.ZERO)
148
148
  .div(shareValue);
149
149
  // ================================================================
150
+ // calculate progressions
150
151
  // {wholeBU/wholeShare} = D18{BU/share} / D18
151
152
  const prevSpotLimit = new decimal_js_light_1.default(rebalance.limits.spot.toString()).div(numbers_1.D18d);
152
- // calculate progressions
153
- // {1} = {USD/wholeBU} / {USD/wholeBU}
153
+ // {wholeTok/wholeBU} = {wholeTok/wholeBU} * {wholeBU/wholeShare}
154
+ const expectedBalances = weightRanges.map((weightRange) => weightRange.spot.mul(prevSpotLimit));
155
+ // {1} = {USD/wholeShare} / {USD/wholeShare}
154
156
  let progression = folio
155
157
  .map((actualBalance, i) => {
156
158
  if (!rebalance.inRebalance[i]) {
157
159
  return numbers_1.ZERO;
158
160
  }
159
- // {wholeTok/wholeBU} = {wholeTok/wholeShare} / {wholeBU/wholeShare}
160
- const actualInBU = actualBalance.div(prevSpotLimit);
161
- // {wholeTok/wholeBU}
162
- const balanceInBasket = weightRanges[i].spot.gt(actualInBU) ? actualInBU : weightRanges[i].spot;
163
- // {USD/wholeBU} = {wholeTok/wholeBU} * {USD/wholeTok}
161
+ // {wholeTok/wholeShare}
162
+ const balanceInBasket = expectedBalances[i].gt(actualBalance) ? actualBalance : expectedBalances[i];
163
+ // {USD/wholeShare} = {wholeTok/wholeShare} * {USD/wholeTok}
164
164
  return balanceInBasket.mul(prices[i]);
165
165
  })
166
166
  .reduce((a, b) => a.add(b))
167
- .div(buValue);
168
- // {1} = {USD/wholeBU} / {USD/wholeBU}
167
+ .div(shareValue);
168
+ // {1} = {USD/wholeShare} / {USD/wholeShare}
169
169
  const initialProgression = initialFolio
170
170
  .map((initialBalance, i) => {
171
171
  // make sure to include tokens that were already ejected
172
172
  if (!rebalance.inRebalance[i] && rebalance.weights[i].spot > 0n) {
173
173
  return numbers_1.ZERO;
174
174
  }
175
- // {wholeTok/wholeBU} = {wholeTok/wholeShare} / {wholeBU/wholeShare}
176
- const initialInBU = initialBalance.div(prevSpotLimit);
177
- // {wholeTok/wholeBU}
178
- const balanceInBasket = weightRanges[i].spot.gt(initialInBU) ? initialInBU : weightRanges[i].spot;
179
- // {USD/wholeBU} = {wholeTok/wholeBU} * {USD/wholeTok}
175
+ // {wholeTok/wholeShare}
176
+ const balanceInBasket = expectedBalances[i].gt(initialBalance) ? initialBalance : expectedBalances[i];
177
+ // {USD/wholeShare} = {wholeTok/wholeShare} * {USD/wholeTok}
180
178
  return balanceInBasket.mul(prices[i]);
181
179
  })
182
180
  .reduce((a, b) => a.add(b))
183
- .div(buValue);
181
+ .div(shareValue);
184
182
  if (progression < initialProgression) {
185
183
  progression = initialProgression; // don't go backwards
186
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reserve-protocol/dtf-rebalance-lib",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Rebalancing library for DTFs in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",