@reserve-protocol/dtf-rebalance-lib 0.0.15 → 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,19 +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.gt(numbers_1.ONE)) {
190
- rebalanceTarget = numbers_1.ONE;
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
+ }
207
+ if (rebalanceTarget.lt(progression)) {
208
+ rebalanceTarget = numbers_1.ONE;
209
+ }
201
210
  if (logging) {
202
211
  console.log('rebalanceTarget', rebalanceTarget.toString());
203
212
  }
@@ -213,6 +222,12 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
213
222
  spot: (0, numbers_1.bn)(spotLimit.mul(numbers_1.D18d)),
214
223
  high: (0, numbers_1.bn)(spotLimit.add(spotLimit.mul(delta)).mul(numbers_1.D18d)),
215
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
+ }
216
231
  // low
217
232
  if (newLimits.low < rebalance.limits.low) {
218
233
  newLimits.low = rebalance.limits.low;
@@ -266,6 +281,12 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
266
281
  .mul(decimalScale[i])
267
282
  .div(numbers_1.D18d)),
268
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
+ }
269
290
  if (newWeightsD27.low < weightRange.low) {
270
291
  newWeightsD27.low = weightRange.low;
271
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reserve-protocol/dtf-rebalance-lib",
3
- "version": "0.0.15",
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",
@@ -281,21 +281,33 @@ export const getOpenAuction = (
281
281
  // make it an eject auction if there is 1 bps or more of value to eject
282
282
  if (portionBeingEjected.gte(1e-4)) {
283
283
  round = AuctionRound.EJECT
284
-
285
- rebalanceTarget = progression.add(portionBeingEjected.mul(1.2)) // set rebalanceTarget to 20% more than needed to ensure ejection completes
286
- if (rebalanceTarget.gt(ONE)) {
287
- rebalanceTarget = ONE
284
+
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
+ }
288
292
  }
289
293
  } else if (relativeProgression.lt(finalStageAt.sub(0.02))) {
290
- // wiggle room to prevent having to re-run an auction at the same stage after price movement
291
- round = AuctionRound.PROGRESS
292
-
293
- rebalanceTarget = initialProgression.add(ONE.sub(initialProgression).mul(finalStageAt))
294
- if (rebalanceTarget.gt(ONE)) {
295
- throw new Error('something has gone very wrong')
296
- }
294
+ // wiggle room to prevent having to re-run an auction at the same stage after price movement
295
+ round = AuctionRound.PROGRESS
296
+
297
+ rebalanceTarget = initialProgression.add(ONE.sub(initialProgression).mul(finalStageAt))
298
+ if (rebalanceTarget.eq(ONE)) {
299
+ round = AuctionRound.FINAL
300
+ }
301
+ }
302
+
303
+ if (rebalanceTarget.gt(ONE)) {
304
+ throw new Error('something has gone very wrong')
297
305
  }
298
306
 
307
+ if (rebalanceTarget.lt(progression)) {
308
+ rebalanceTarget = ONE
309
+ }
310
+
299
311
  if (logging) {
300
312
  console.log('rebalanceTarget', rebalanceTarget.toString())
301
313
  }
@@ -310,7 +322,6 @@ export const getOpenAuction = (
310
322
  // {wholeBU/wholeShare} = {USD/wholeShare} / {USD/wholeBU}
311
323
  const spotLimit = shareValue.div(buValue)
312
324
 
313
-
314
325
  // D18{BU/share} = {wholeBU/wholeShare} * D18 * {1}
315
326
  const newLimits = {
316
327
  low: bn(spotLimit.sub(spotLimit.mul(delta)).mul(D18d)),
@@ -318,6 +329,13 @@ export const getOpenAuction = (
318
329
  high: bn(spotLimit.add(spotLimit.mul(delta)).mul(D18d)),
319
330
  }
320
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
+
321
339
  // low
322
340
  if (newLimits.low < rebalance.limits.low) {
323
341
  newLimits.low = rebalance.limits.low
@@ -384,6 +402,13 @@ export const getOpenAuction = (
384
402
  ),
385
403
  }
386
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
+
387
412
  if (newWeightsD27.low < weightRange.low) {
388
413
  newWeightsD27.low = weightRange.low
389
414
  } else if (newWeightsD27.low > weightRange.high) {