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

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.
@@ -132,7 +132,7 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
132
132
  throw new Error("buValue and shareValue are too different, something probably went wrong");
133
133
  }
134
134
  // ================================================================
135
- // calculate rebalanceTarget
135
+ // calculate portionBeingEjected
136
136
  const ejectionIndices = [];
137
137
  for (let i = 0; i < rebalance.weights.length; i++) {
138
138
  if (rebalance.inRebalance[i] && rebalance.weights[i].spot == 0n) {
@@ -146,16 +146,20 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
146
146
  })
147
147
  .reduce((a, b) => a.add(b), numbers_1.ZERO)
148
148
  .div(shareValue);
149
+ // ================================================================
150
+ // calculate progressions
151
+ // {wholeBU/wholeShare} = D18{BU/share} / D18
152
+ 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));
149
155
  // {1} = {USD/wholeShare} / {USD/wholeShare}
150
156
  let progression = folio
151
157
  .map((actualBalance, i) => {
152
158
  if (!rebalance.inRebalance[i]) {
153
159
  return numbers_1.ZERO;
154
160
  }
155
- // {wholeTok/wholeShare} = {USD/wholeShare} * {1} / {USD/wholeTok}
156
- const balanceExpected = shareValue.mul(targetBasket[i]).div(prices[i]);
157
- // {wholeTok/wholeShare} = {wholeTok/wholeBU} * {wholeBU/wholeShare}
158
- const balanceInBasket = balanceExpected.gt(actualBalance) ? actualBalance : balanceExpected;
161
+ // {wholeTok/wholeShare}
162
+ const balanceInBasket = expectedBalances[i].gt(actualBalance) ? actualBalance : expectedBalances[i];
159
163
  // {USD/wholeShare} = {wholeTok/wholeShare} * {USD/wholeTok}
160
164
  return balanceInBasket.mul(prices[i]);
161
165
  })
@@ -168,10 +172,8 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
168
172
  if (!rebalance.inRebalance[i] && rebalance.weights[i].spot > 0n) {
169
173
  return numbers_1.ZERO;
170
174
  }
171
- // {wholeTok/wholeShare} = {USD/wholeShare} * {1} / {USD/wholeTok}
172
- const balanceExpected = shareValue.mul(targetBasket[i]).div(prices[i]);
173
- // {wholeTok/wholeShare} = {wholeTok/wholeBU} * {wholeBU/wholeShare}
174
- const balanceInBasket = balanceExpected.gt(initialBalance) ? initialBalance : balanceExpected;
175
+ // {wholeTok/wholeShare}
176
+ const balanceInBasket = expectedBalances[i].gt(initialBalance) ? initialBalance : expectedBalances[i];
175
177
  // {USD/wholeShare} = {wholeTok/wholeShare} * {USD/wholeTok}
176
178
  return balanceInBasket.mul(prices[i]);
177
179
  })
@@ -210,7 +212,7 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
210
212
  // if the ejections are everything that's left, keep the finalStageAt targeting from above
211
213
  if (progression.add(portionBeingEjected).lt(numbers_1.ONE)) {
212
214
  // else: get rid of all the dust
213
- let ejectionTarget = progression.add(portionBeingEjected.mul(1.02)); // buy 2% extra
215
+ let ejectionTarget = progression.add(portionBeingEjected.mul(1.05)); // buy 5% extra
214
216
  if (ejectionTarget.gt(numbers_1.ONE)) {
215
217
  ejectionTarget = numbers_1.ONE;
216
218
  }
@@ -242,11 +244,6 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
242
244
  };
243
245
  // hold some surpluses aside if ejecting
244
246
  if (round == AuctionRound.EJECT) {
245
- // buy 0.1% more
246
- newLimits.low += newLimits.low / 1000n;
247
- // aim 1% higher in the future
248
- newLimits.spot += newLimits.spot / 100n;
249
- // leave 10% room to increase low in the future if ejection leaves dust behind
250
247
  newLimits.high += newLimits.high / 10n;
251
248
  }
252
249
  // low
@@ -299,11 +296,6 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
299
296
  };
300
297
  // hold some surpluses aside if ejecting
301
298
  if (round == AuctionRound.EJECT) {
302
- // buy 0.1% more
303
- newWeightsD27.low += newWeightsD27.low / 1000n;
304
- // aim 1% higher in the future
305
- newWeightsD27.spot += newWeightsD27.spot / 100n;
306
- // leave 10% room to increase low in the future if ejection leaves dust behind
307
299
  newWeightsD27.high += newWeightsD27.high / 10n;
308
300
  }
309
301
  if (newWeightsD27.low < weightRange.low) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reserve-protocol/dtf-rebalance-lib",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Rebalancing library for DTFs in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",