@reserve-protocol/dtf-rebalance-lib 0.0.16 → 0.0.18
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.
- package/dist/open-auction.js +23 -8
- package/package.json +1 -1
- package/src/open-auction.ts +30 -9
package/dist/open-auction.js
CHANGED
@@ -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
|
-
|
189
|
-
|
190
|
-
|
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.
|
198
|
-
|
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
|
+
// aim 1% higher if executed permissonlessly
|
227
|
+
newLimits.spot += newLimits.spot * 1n / 100n;
|
228
|
+
// leave 10% room to increase low in the future if ejection leaves dust behind
|
229
|
+
newLimits.high += newLimits.high * 10n / 100n;
|
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
|
+
// aim 1% higher if executed permissonlessly
|
286
|
+
newWeightsD27.spot += newWeightsD27.spot * 1n / 100n;
|
287
|
+
// leave 10% room to increase low in the future if ejection leaves dust behind
|
288
|
+
newWeightsD27.high += newWeightsD27.high * 10n / 100n;
|
289
|
+
}
|
275
290
|
if (newWeightsD27.low < weightRange.low) {
|
276
291
|
newWeightsD27.low = weightRange.low;
|
277
292
|
}
|
package/package.json
CHANGED
package/src/open-auction.ts
CHANGED
@@ -282,24 +282,30 @@ export const getOpenAuction = (
|
|
282
282
|
if (portionBeingEjected.gte(1e-4)) {
|
283
283
|
round = AuctionRound.EJECT
|
284
284
|
|
285
|
-
|
286
|
-
|
287
|
-
|
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.
|
295
|
-
|
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,14 @@ 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
|
+
// aim 1% higher if executed permissonlessly
|
334
|
+
newLimits.spot += newLimits.spot * 1n / 100n
|
335
|
+
|
336
|
+
// leave 10% room to increase low in the future if ejection leaves dust behind
|
337
|
+
newLimits.high += newLimits.high * 10n / 100n
|
338
|
+
}
|
339
|
+
|
327
340
|
// low
|
328
341
|
if (newLimits.low < rebalance.limits.low) {
|
329
342
|
newLimits.low = rebalance.limits.low
|
@@ -390,6 +403,14 @@ export const getOpenAuction = (
|
|
390
403
|
),
|
391
404
|
}
|
392
405
|
|
406
|
+
if (round == AuctionRound.EJECT && rebalanceTarget.eq(ONE)) {
|
407
|
+
// aim 1% higher if executed permissonlessly
|
408
|
+
newWeightsD27.spot += newWeightsD27.spot * 1n / 100n
|
409
|
+
|
410
|
+
// leave 10% room to increase low in the future if ejection leaves dust behind
|
411
|
+
newWeightsD27.high += newWeightsD27.high * 10n / 100n
|
412
|
+
}
|
413
|
+
|
393
414
|
if (newWeightsD27.low < weightRange.low) {
|
394
415
|
newWeightsD27.low = weightRange.low
|
395
416
|
} else if (newWeightsD27.low > weightRange.high) {
|