@reserve-protocol/dtf-rebalance-lib 2.3.4 → 2.4.1
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 +9 -7
- package/dist/start-rebalance.js +18 -15
- package/package.json +1 -1
package/dist/open-auction.js
CHANGED
|
@@ -154,9 +154,9 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
|
|
|
154
154
|
// ================================================================
|
|
155
155
|
// calculate progressions
|
|
156
156
|
// {wholeBU/wholeShare} = {USD/wholeShare} / {USD/wholeBU}
|
|
157
|
-
const
|
|
157
|
+
const idealSpotLimit = shareValue.div(buValue);
|
|
158
158
|
// {wholeTok/wholeShare} = {wholeTok/wholeBU} * {wholeBU/wholeShare}
|
|
159
|
-
const expectedBalances = weightRanges.map((weightRange) => weightRange.spot.mul(
|
|
159
|
+
const expectedBalances = weightRanges.map((weightRange) => weightRange.spot.mul(idealSpotLimit));
|
|
160
160
|
// absoluteProgression
|
|
161
161
|
// {1} = {USD/wholeShare} / {USD/wholeShare}
|
|
162
162
|
let progression = folio
|
|
@@ -230,12 +230,14 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
|
|
|
230
230
|
const delta = numbers_1.ONE.sub(target);
|
|
231
231
|
// ================================================================
|
|
232
232
|
// get new limits, constrained by extremes
|
|
233
|
+
const idealLowLimit = idealSpotLimit.mul(numbers_1.ONE.sub(delta));
|
|
234
|
+
const idealHighLimit = idealSpotLimit.mul(numbers_1.ONE.add(delta));
|
|
233
235
|
// D18{BU/share} = {wholeBU/wholeShare} * D18 * {1}
|
|
234
236
|
const newLimits = {
|
|
235
|
-
low: (0, numbers_1.bn)(
|
|
236
|
-
spot: (0, numbers_1.bn)(
|
|
237
|
+
low: (0, numbers_1.bn)(idealLowLimit.mul(numbers_1.D18d)),
|
|
238
|
+
spot: (0, numbers_1.bn)(idealSpotLimit.mul(numbers_1.D18d)),
|
|
237
239
|
// hold non-eject surpluses aside if ejecting
|
|
238
|
-
high: round == AuctionRound.EJECT ? rebalance.limits.high : (0, numbers_1.bn)(
|
|
240
|
+
high: round == AuctionRound.EJECT ? rebalance.limits.high : (0, numbers_1.bn)(idealHighLimit.mul(numbers_1.D18d)),
|
|
239
241
|
};
|
|
240
242
|
// low
|
|
241
243
|
if (newLimits.low < rebalance.limits.low) {
|
|
@@ -276,7 +278,7 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
|
|
|
276
278
|
// D27{tok/BU} = {wholeTok/wholeBU} * D27 * {tok/wholeTok} / {BU/wholeBU}
|
|
277
279
|
const newWeightsD27 = {
|
|
278
280
|
low: (0, numbers_1.bn)(idealWeight
|
|
279
|
-
.mul(
|
|
281
|
+
.mul(idealLowLimit.div(actualLimits.low)) // add the portion of `delta` we failed to propagate through to the low limit
|
|
280
282
|
.mul(numbers_1.D9d)
|
|
281
283
|
.mul(decimalScale[i])),
|
|
282
284
|
spot: (0, numbers_1.bn)(idealWeight.mul(numbers_1.D9d).mul(decimalScale[i])),
|
|
@@ -285,7 +287,7 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
|
|
|
285
287
|
round == AuctionRound.EJECT
|
|
286
288
|
? weightRange.high
|
|
287
289
|
: (0, numbers_1.bn)(idealWeight
|
|
288
|
-
.mul(
|
|
290
|
+
.mul(idealHighLimit.div(actualLimits.high)) // add the portion of `delta` we failed to propagate through to the high limit
|
|
289
291
|
.mul(numbers_1.D9d)
|
|
290
292
|
.mul(decimalScale[i])),
|
|
291
293
|
};
|
package/dist/start-rebalance.js
CHANGED
|
@@ -58,31 +58,34 @@ const getStartRebalance = (_supply, tokens, _assets, decimals, _targetBasket, _p
|
|
|
58
58
|
const spotWeight = targetBasket[i].mul(dtfValue).div(prices[i]).div(supply);
|
|
59
59
|
// D27{tok/share}{wholeShare/wholeTok} = D27 * {tok/wholeTok} / {share/wholeShare}
|
|
60
60
|
const limitMultiplier = numbers_1.D27d.mul(new utils_1.Decimal(`1e${decimals[i]}`)).div(numbers_1.D18d);
|
|
61
|
-
if (
|
|
62
|
-
// TRACKING case
|
|
63
|
-
// D27{tok/BU} = {wholeTok/wholeShare} * D27{tok/share}{wholeShare/wholeTok} / {BU/share}
|
|
61
|
+
if (spotWeight.eq(numbers_1.ZERO)) {
|
|
64
62
|
newWeights.push({
|
|
65
|
-
low:
|
|
66
|
-
spot:
|
|
67
|
-
high:
|
|
63
|
+
low: 0n,
|
|
64
|
+
spot: 0n,
|
|
65
|
+
high: 0n,
|
|
68
66
|
});
|
|
69
67
|
}
|
|
70
|
-
else {
|
|
68
|
+
else if (weightControl) {
|
|
71
69
|
// NATIVE case
|
|
72
70
|
// {wholeTok/wholeShare} = {wholeTok/wholeShare} / {1}
|
|
73
71
|
const lowWeight = spotWeight.mul(numbers_1.ONE.sub(priceError[i]));
|
|
74
72
|
const highWeight = spotWeight.div(numbers_1.ONE.sub(priceError[i]));
|
|
75
73
|
// D27{tok/share} = {wholeTok/wholeShare} * D27{tok/share}{wholeShare/wholeTok} / {BU/share}
|
|
76
74
|
newWeights.push({
|
|
77
|
-
low: (0, numbers_1.bn)(lowWeight.mul(limitMultiplier)),
|
|
75
|
+
low: deferWeights ? 1n : (0, numbers_1.bn)(lowWeight.mul(limitMultiplier)),
|
|
78
76
|
spot: (0, numbers_1.bn)(spotWeight.mul(limitMultiplier)),
|
|
79
|
-
high: (0, numbers_1.bn)(highWeight.mul(limitMultiplier)),
|
|
77
|
+
high: deferWeights ? numbers_1.D27n * numbers_1.D27n : (0, numbers_1.bn)(highWeight.mul(limitMultiplier)),
|
|
78
|
+
});
|
|
79
|
+
// 1e54 MAX_WEIGHT
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// TRACKING case
|
|
83
|
+
// D27{tok/BU} = {wholeTok/wholeShare} * D27{tok/share}{wholeShare/wholeTok} / {BU/share}
|
|
84
|
+
newWeights.push({
|
|
85
|
+
low: (0, numbers_1.bn)(spotWeight.mul(limitMultiplier)),
|
|
86
|
+
spot: (0, numbers_1.bn)(spotWeight.mul(limitMultiplier)),
|
|
87
|
+
high: (0, numbers_1.bn)(spotWeight.mul(limitMultiplier)),
|
|
80
88
|
});
|
|
81
|
-
// deferWeights case
|
|
82
|
-
if (deferWeights && newWeights[i].low > 0n) {
|
|
83
|
-
newWeights[i].low = 1n;
|
|
84
|
-
newWeights[i].high = numbers_1.D27n * numbers_1.D27n; // 1e54 MAX_WEIGHT
|
|
85
|
-
}
|
|
86
89
|
}
|
|
87
90
|
// === newPrices ===
|
|
88
91
|
// D27{wholeTok/tok} = D27 / {tok/wholeTok}
|
|
@@ -104,7 +107,7 @@ const getStartRebalance = (_supply, tokens, _assets, decimals, _targetBasket, _p
|
|
|
104
107
|
throw new Error("basketError >= 1");
|
|
105
108
|
}
|
|
106
109
|
const newLimits = {
|
|
107
|
-
low:
|
|
110
|
+
low: 1n,
|
|
108
111
|
spot: (0, numbers_1.bn)("1e18"),
|
|
109
112
|
high: weightControl ? (0, numbers_1.bn)("1e18") : (0, numbers_1.bn)(numbers_1.ONE.div(numbers_1.ONE.sub(basketError)).mul(numbers_1.D18d)),
|
|
110
113
|
};
|