@reserve-protocol/dtf-rebalance-lib 0.0.16 → 0.0.17

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.
@@ -185,25 +185,28 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
185
185
  // make it an eject auction if there is 1 bps or more of value to eject
186
186
  if (portionBeingEjected.gte(1e-4)) {
187
187
  round = AuctionRound.EJECT;
188
- rebalanceTarget = progression.add(portionBeingEjected.mul(1.2)); // set rebalanceTarget to 20% more than needed to ensure ejection completes
189
- if (rebalanceTarget.gte(numbers_1.ONE)) {
190
- rebalanceTarget = initialProgression.add(numbers_1.ONE.sub(initialProgression).mul(finalStageAt));
188
+ if (relativeProgression.lt(finalStageAt.sub(0.02))) {
189
+ rebalanceTarget = progression.add(portionBeingEjected.mul(1.1)); // set rebalanceTarget to 10% more than needed to ensure ejection completes
190
+ // do not finish trading yet
191
+ if (rebalanceTarget.gte(numbers_1.ONE)) {
192
+ rebalanceTarget = initialProgression.add(numbers_1.ONE.sub(initialProgression).mul(finalStageAt));
193
+ }
191
194
  }
192
195
  }
193
196
  else if (relativeProgression.lt(finalStageAt.sub(0.02))) {
194
197
  // wiggle room to prevent having to re-run an auction at the same stage after price movement
195
198
  round = AuctionRound.PROGRESS;
196
199
  rebalanceTarget = initialProgression.add(numbers_1.ONE.sub(initialProgression).mul(finalStageAt));
197
- if (rebalanceTarget.gt(numbers_1.ONE)) {
198
- throw new Error('something has gone very wrong');
200
+ if (rebalanceTarget.eq(numbers_1.ONE)) {
201
+ round = AuctionRound.FINAL;
199
202
  }
200
203
  }
204
+ if (rebalanceTarget.gt(numbers_1.ONE)) {
205
+ throw new Error('something has gone very wrong');
206
+ }
201
207
  if (rebalanceTarget.lt(progression)) {
202
208
  rebalanceTarget = numbers_1.ONE;
203
209
  }
204
- else if (rebalanceTarget.eq(numbers_1.ONE)) {
205
- round = AuctionRound.FINAL;
206
- }
207
210
  if (logging) {
208
211
  console.log('rebalanceTarget', rebalanceTarget.toString());
209
212
  }
@@ -219,6 +222,12 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
219
222
  spot: (0, numbers_1.bn)(spotLimit.mul(numbers_1.D18d)),
220
223
  high: (0, numbers_1.bn)(spotLimit.add(spotLimit.mul(delta)).mul(numbers_1.D18d)),
221
224
  };
225
+ if (round == AuctionRound.EJECT && rebalanceTarget.eq(numbers_1.ONE)) {
226
+ // if ejecting to completion, aim 10% higher (if possible)
227
+ newLimits.low = (0, numbers_1.bn)(spotLimit.mul(1.1).mul(numbers_1.D18d));
228
+ newLimits.spot = (0, numbers_1.bn)(spotLimit.mul(1.1).mul(numbers_1.D18d));
229
+ newLimits.high = (0, numbers_1.bn)(spotLimit.mul(1.1).mul(numbers_1.D18d));
230
+ }
222
231
  // low
223
232
  if (newLimits.low < rebalance.limits.low) {
224
233
  newLimits.low = rebalance.limits.low;
@@ -272,6 +281,12 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
272
281
  .mul(decimalScale[i])
273
282
  .div(numbers_1.D18d)),
274
283
  };
284
+ if (round == AuctionRound.EJECT && rebalanceTarget.eq(numbers_1.ONE)) {
285
+ // if ejecting to completion, aim 10% higher
286
+ newWeightsD27.low = newWeightsD27.low * 11n / 10n;
287
+ newWeightsD27.spot = newWeightsD27.spot * 11n / 10n;
288
+ newWeightsD27.high = newWeightsD27.high * 11n / 10n;
289
+ }
275
290
  if (newWeightsD27.low < weightRange.low) {
276
291
  newWeightsD27.low = weightRange.low;
277
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reserve-protocol/dtf-rebalance-lib",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "Rebalancing library for DTFs in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -282,24 +282,30 @@ export const getOpenAuction = (
282
282
  if (portionBeingEjected.gte(1e-4)) {
283
283
  round = AuctionRound.EJECT
284
284
 
285
- rebalanceTarget = progression.add(portionBeingEjected.mul(1.2)) // set rebalanceTarget to 20% more than needed to ensure ejection completes
286
- if (rebalanceTarget.gte(ONE)) {
287
- rebalanceTarget = initialProgression.add(ONE.sub(initialProgression).mul(finalStageAt))
288
- }
285
+ if (relativeProgression.lt(finalStageAt.sub(0.02))) {
286
+ rebalanceTarget = progression.add(portionBeingEjected.mul(1.1)) // set rebalanceTarget to 10% more than needed to ensure ejection completes
287
+
288
+ // do not finish trading yet
289
+ if (rebalanceTarget.gte(ONE)) {
290
+ rebalanceTarget = initialProgression.add(ONE.sub(initialProgression).mul(finalStageAt))
291
+ }
292
+ }
289
293
  } else if (relativeProgression.lt(finalStageAt.sub(0.02))) {
290
294
  // wiggle room to prevent having to re-run an auction at the same stage after price movement
291
295
  round = AuctionRound.PROGRESS
292
296
 
293
297
  rebalanceTarget = initialProgression.add(ONE.sub(initialProgression).mul(finalStageAt))
294
- if (rebalanceTarget.gt(ONE)) {
295
- throw new Error('something has gone very wrong')
298
+ if (rebalanceTarget.eq(ONE)) {
299
+ round = AuctionRound.FINAL
296
300
  }
297
301
  }
302
+
303
+ if (rebalanceTarget.gt(ONE)) {
304
+ throw new Error('something has gone very wrong')
305
+ }
298
306
 
299
307
  if (rebalanceTarget.lt(progression)) {
300
308
  rebalanceTarget = ONE
301
- } else if (rebalanceTarget.eq(ONE)) {
302
- round = AuctionRound.FINAL
303
309
  }
304
310
 
305
311
  if (logging) {
@@ -316,7 +322,6 @@ export const getOpenAuction = (
316
322
  // {wholeBU/wholeShare} = {USD/wholeShare} / {USD/wholeBU}
317
323
  const spotLimit = shareValue.div(buValue)
318
324
 
319
-
320
325
  // D18{BU/share} = {wholeBU/wholeShare} * D18 * {1}
321
326
  const newLimits = {
322
327
  low: bn(spotLimit.sub(spotLimit.mul(delta)).mul(D18d)),
@@ -324,6 +329,13 @@ export const getOpenAuction = (
324
329
  high: bn(spotLimit.add(spotLimit.mul(delta)).mul(D18d)),
325
330
  }
326
331
 
332
+ if (round == AuctionRound.EJECT && rebalanceTarget.eq(ONE)) {
333
+ // if ejecting to completion, aim 10% higher (if possible)
334
+ newLimits.low = bn(spotLimit.mul(1.1).mul(D18d))
335
+ newLimits.spot = bn(spotLimit.mul(1.1).mul(D18d))
336
+ newLimits.high = bn(spotLimit.mul(1.1).mul(D18d))
337
+ }
338
+
327
339
  // low
328
340
  if (newLimits.low < rebalance.limits.low) {
329
341
  newLimits.low = rebalance.limits.low
@@ -390,6 +402,13 @@ export const getOpenAuction = (
390
402
  ),
391
403
  }
392
404
 
405
+ if (round == AuctionRound.EJECT && rebalanceTarget.eq(ONE)) {
406
+ // if ejecting to completion, aim 10% higher
407
+ newWeightsD27.low = newWeightsD27.low * 11n / 10n
408
+ newWeightsD27.spot = newWeightsD27.spot * 11n / 10n
409
+ newWeightsD27.high = newWeightsD27.high * 11n / 10n
410
+ }
411
+
393
412
  if (newWeightsD27.low < weightRange.low) {
394
413
  newWeightsD27.low = weightRange.low
395
414
  } else if (newWeightsD27.low > weightRange.high) {