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

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