@reserve-protocol/dtf-rebalance-lib 2.4.0 → 2.4.2
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 +11 -9
- package/dist/start-rebalance.js +3 -2
- 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
|
};
|
|
@@ -378,7 +380,7 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
|
|
|
378
380
|
// {USD} = {wholeTok} * {USD/wholeTok}
|
|
379
381
|
const tokenDeficitValue = deficitAmount.mul(prices[i]);
|
|
380
382
|
// $1 minimum
|
|
381
|
-
if (tokenDeficitValue.gte(numbers_1.ONE)) {
|
|
383
|
+
if (round == AuctionRound.EJECT || tokenDeficitValue.gte(numbers_1.ONE)) {
|
|
382
384
|
deficitTokens.push(token);
|
|
383
385
|
deficitTokenSizes.push(tokenDeficitValue.toNumber());
|
|
384
386
|
}
|
|
@@ -389,7 +391,7 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
|
|
|
389
391
|
// {USD} = {wholeTok} * {USD/wholeTok}
|
|
390
392
|
const tokenSurplusValue = surplusAmount.mul(prices[i]);
|
|
391
393
|
// $1 minimum
|
|
392
|
-
if (tokenSurplusValue.gte(numbers_1.ONE)) {
|
|
394
|
+
if (round == AuctionRound.EJECT || tokenSurplusValue.gte(numbers_1.ONE)) {
|
|
393
395
|
surplusTokens.push(token);
|
|
394
396
|
surplusTokenSizes.push(tokenSurplusValue.toNumber());
|
|
395
397
|
}
|
package/dist/start-rebalance.js
CHANGED
|
@@ -68,10 +68,11 @@ const getStartRebalance = (_supply, tokens, _assets, decimals, _targetBasket, _p
|
|
|
68
68
|
else if (weightControl) {
|
|
69
69
|
// NATIVE case
|
|
70
70
|
// {wholeTok/wholeShare} = {wholeTok/wholeShare} / {1}
|
|
71
|
+
const lowWeight = spotWeight.mul(numbers_1.ONE.sub(priceError[i]));
|
|
71
72
|
const highWeight = spotWeight.div(numbers_1.ONE.sub(priceError[i]));
|
|
72
73
|
// D27{tok/share} = {wholeTok/wholeShare} * D27{tok/share}{wholeShare/wholeTok} / {BU/share}
|
|
73
74
|
newWeights.push({
|
|
74
|
-
low: 1n,
|
|
75
|
+
low: deferWeights ? 1n : (0, numbers_1.bn)(lowWeight.mul(limitMultiplier)),
|
|
75
76
|
spot: (0, numbers_1.bn)(spotWeight.mul(limitMultiplier)),
|
|
76
77
|
high: deferWeights ? numbers_1.D27n * numbers_1.D27n : (0, numbers_1.bn)(highWeight.mul(limitMultiplier)),
|
|
77
78
|
});
|
|
@@ -106,7 +107,7 @@ const getStartRebalance = (_supply, tokens, _assets, decimals, _targetBasket, _p
|
|
|
106
107
|
throw new Error("basketError >= 1");
|
|
107
108
|
}
|
|
108
109
|
const newLimits = {
|
|
109
|
-
low:
|
|
110
|
+
low: 1n,
|
|
110
111
|
spot: (0, numbers_1.bn)("1e18"),
|
|
111
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)),
|
|
112
113
|
};
|