@reserve-protocol/dtf-rebalance-lib 0.1.4 → 0.1.5
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 +7 -19
- package/dist/start-rebalance.js +4 -4
- package/package.json +1 -1
package/dist/open-auction.js
CHANGED
@@ -108,11 +108,13 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
108
108
|
.reduce((a, b) => a.add(b));
|
109
109
|
// {USD/wholeBU} = {wholeTok/wholeBU} * {USD/wholeTok}
|
110
110
|
const buValue = weightRanges.map((weightRange, i) => weightRange.spot.mul(prices[i])).reduce((a, b) => a.add(b));
|
111
|
+
const buPriceChange = buValue.sub(shareValue).abs().div(shareValue);
|
112
|
+
console.log(` 🧺 ${buPriceChange.mul(100).toFixed(2)}% price change`);
|
111
113
|
if (debug) {
|
112
114
|
console.log("shareValue", shareValue.toString());
|
113
115
|
console.log("buValue", buValue.toString());
|
114
116
|
}
|
115
|
-
if (buValue.div(shareValue).gt(10) || shareValue.div(buValue).gt(
|
117
|
+
if (buValue.div(shareValue).gt(10) || shareValue.div(buValue).gt(10)) {
|
116
118
|
throw new Error("buValue and shareValue are too different");
|
117
119
|
}
|
118
120
|
// ================================================================
|
@@ -174,7 +176,7 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
174
176
|
if (progression.lt(0.99) && relativeProgression.lt(finalStageAt.sub(0.02))) {
|
175
177
|
round = AuctionRound.PROGRESS;
|
176
178
|
rebalanceTarget = initialProgression.add(numbers_1.ONE.sub(initialProgression).mul(finalStageAt));
|
177
|
-
if (
|
179
|
+
if (rebalanceTarget.gte(0.99)) {
|
178
180
|
rebalanceTarget = numbers_1.ONE;
|
179
181
|
}
|
180
182
|
if (rebalanceTarget.eq(numbers_1.ONE)) {
|
@@ -219,18 +221,11 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
219
221
|
if (round == AuctionRound.EJECT) {
|
220
222
|
// buy 0.1% more
|
221
223
|
newLimits.low += newLimits.low / 1000n;
|
222
|
-
// aim 1% higher
|
224
|
+
// aim 1% higher in the future
|
223
225
|
newLimits.spot += newLimits.spot / 100n;
|
224
226
|
// leave 10% room to increase low in the future if ejection leaves dust behind
|
225
227
|
newLimits.high += newLimits.high / 10n;
|
226
228
|
}
|
227
|
-
else if (round == AuctionRound.FINAL && progression.gt(0.999)) {
|
228
|
-
// if it's the final round and we're within 0.1%, buy 10% more than we need to
|
229
|
-
const delta = (0, numbers_1.bn)(numbers_1.ONE.sub(progression).mul(numbers_1.D18d).div(10));
|
230
|
-
newLimits.low += (newLimits.low * delta) / 10n ** 18n;
|
231
|
-
newLimits.spot += (newLimits.spot * delta) / 10n ** 18n;
|
232
|
-
newLimits.high += (newLimits.high * delta) / 10n ** 18n;
|
233
|
-
}
|
234
229
|
// low
|
235
230
|
if (newLimits.low < rebalance.limits.low) {
|
236
231
|
newLimits.low = rebalance.limits.low;
|
@@ -285,18 +280,11 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
285
280
|
if (round == AuctionRound.EJECT) {
|
286
281
|
// buy 0.1% more
|
287
282
|
newWeightsD27.low += newWeightsD27.low / 1000n;
|
288
|
-
// aim 1% higher
|
283
|
+
// aim 1% higher in the future
|
289
284
|
newWeightsD27.spot += newWeightsD27.spot / 100n;
|
290
285
|
// leave 10% room to increase low in the future if ejection leaves dust behind
|
291
286
|
newWeightsD27.high += newWeightsD27.high / 10n;
|
292
287
|
}
|
293
|
-
else if (round == AuctionRound.FINAL && progression.gt(0.999)) {
|
294
|
-
// if it's the final round and we're within 0.1%, buy 10% more than we need to
|
295
|
-
const delta = (0, numbers_1.bn)(numbers_1.ONE.sub(progression).mul(numbers_1.D18d).div(10));
|
296
|
-
newWeightsD27.low += (newWeightsD27.low * delta) / 10n ** 18n;
|
297
|
-
newWeightsD27.spot += (newWeightsD27.spot * delta) / 10n ** 18n;
|
298
|
-
newWeightsD27.high += (newWeightsD27.high * delta) / 10n ** 18n;
|
299
|
-
}
|
300
288
|
if (newWeightsD27.low < weightRange.low) {
|
301
289
|
newWeightsD27.low = weightRange.low;
|
302
290
|
}
|
@@ -327,7 +315,7 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
327
315
|
// revert if price out of bounds
|
328
316
|
const spotPrice = (0, numbers_1.bn)(prices[i].mul(numbers_1.D27d).div(decimalScale[i]));
|
329
317
|
if (spotPrice < initialPrice.low || spotPrice > initialPrice.high) {
|
330
|
-
throw new Error(
|
318
|
+
throw new Error(`spot price ${spotPrice.toString()} out of bounds relative to initial range [${initialPrice.low.toString()}, ${initialPrice.high.toString()}]! auction launcher MUST closeRebalance to prevent loss!`);
|
331
319
|
}
|
332
320
|
if (rebalance.priceControl == types_1.PriceControl.NONE) {
|
333
321
|
return initialPrice;
|
package/dist/start-rebalance.js
CHANGED
@@ -75,8 +75,8 @@ const getStartRebalance = (_supply, tokens, _folio, decimals, _targetBasket, _pr
|
|
75
75
|
else {
|
76
76
|
// NATIVE case
|
77
77
|
// {wholeTok/wholeShare} = {wholeTok/wholeShare} / {1}
|
78
|
-
const lowWeight = spotWeight.mul(numbers_1.ONE.
|
79
|
-
const highWeight = spotWeight.
|
78
|
+
const lowWeight = spotWeight.mul(numbers_1.ONE.sub(priceError[i]));
|
79
|
+
const highWeight = spotWeight.div(numbers_1.ONE.sub(priceError[i]));
|
80
80
|
// D27{tok/share} = {wholeTok/wholeShare} * D27{tok/share}{wholeShare/wholeTok} / {BU/share}
|
81
81
|
newWeights.push({
|
82
82
|
low: (0, numbers_1.bn)(lowWeight.mul(limitMultiplier)),
|
@@ -106,8 +106,8 @@ const getStartRebalance = (_supply, tokens, _folio, decimals, _targetBasket, _pr
|
|
106
106
|
throw new Error("totalPortion > 1");
|
107
107
|
}
|
108
108
|
// D18{BU/share} = {1} * D18 * {BU/share}
|
109
|
-
newLimits.low = (0, numbers_1.bn)(numbers_1.ONE.
|
110
|
-
newLimits.high = (0, numbers_1.bn)(numbers_1.ONE.
|
109
|
+
newLimits.low = (0, numbers_1.bn)(numbers_1.ONE.sub(totalPortion).mul(numbers_1.D18d));
|
110
|
+
newLimits.high = (0, numbers_1.bn)(numbers_1.ONE.div(numbers_1.ONE.sub(totalPortion)).mul(numbers_1.D18d));
|
111
111
|
}
|
112
112
|
if (debug) {
|
113
113
|
console.log("newWeights", newWeights);
|