Skip to content

Commit 1fa059e

Browse files
committed
2.4.1
1 parent 4884db6 commit 1fa059e

File tree

4 files changed

+266
-326
lines changed

4 files changed

+266
-326
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reserve-protocol/dtf-rebalance-lib",
3-
"version": "2.4.0",
3+
"version": "2.4.1",
44
"description": "Rebalancing library for DTFs in typescript",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

src/open-auction.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ export const getOpenAuction = (
263263
// calculate progressions
264264

265265
// {wholeBU/wholeShare} = {USD/wholeShare} / {USD/wholeBU}
266-
const spotLimit = shareValue.div(buValue);
266+
const idealSpotLimit = shareValue.div(buValue);
267267

268268
// {wholeTok/wholeShare} = {wholeTok/wholeBU} * {wholeBU/wholeShare}
269-
const expectedBalances = weightRanges.map((weightRange) => weightRange.spot.mul(spotLimit));
269+
const expectedBalances = weightRanges.map((weightRange) => weightRange.spot.mul(idealSpotLimit));
270270

271271
// absoluteProgression
272272
// {1} = {USD/wholeShare} / {USD/wholeShare}
@@ -361,13 +361,16 @@ export const getOpenAuction = (
361361

362362
// get new limits, constrained by extremes
363363

364+
const idealLowLimit = idealSpotLimit.mul(ONE.sub(delta));
365+
const idealHighLimit = idealSpotLimit.mul(ONE.add(delta));
366+
364367
// D18{BU/share} = {wholeBU/wholeShare} * D18 * {1}
365368
const newLimits = {
366-
low: bn(spotLimit.sub(spotLimit.mul(delta)).mul(D18d)),
367-
spot: bn(spotLimit.mul(D18d)),
369+
low: bn(idealLowLimit.mul(D18d)),
370+
spot: bn(idealSpotLimit.mul(D18d)),
368371

369372
// hold non-eject surpluses aside if ejecting
370-
high: round == AuctionRound.EJECT ? rebalance.limits.high : bn(spotLimit.add(spotLimit.mul(delta)).mul(D18d)),
373+
high: round == AuctionRound.EJECT ? rebalance.limits.high : bn(idealHighLimit.mul(D18d)),
371374
};
372375

373376
// low
@@ -418,7 +421,7 @@ export const getOpenAuction = (
418421
const newWeightsD27 = {
419422
low: bn(
420423
idealWeight
421-
.mul(ONE.sub(delta).div(actualLimits.low.div(actualLimits.spot))) // add remaining delta into weight
424+
.mul(idealLowLimit.div(actualLimits.low)) // add the portion of `delta` we failed to propagate through to the low limit
422425
.mul(D9d)
423426
.mul(decimalScale[i]),
424427
),
@@ -430,7 +433,7 @@ export const getOpenAuction = (
430433
? weightRange.high
431434
: bn(
432435
idealWeight
433-
.mul(ONE.add(delta).div(actualLimits.high.div(actualLimits.spot))) // add remaining delta into weight
436+
.mul(idealHighLimit.div(actualLimits.high)) // add the portion of `delta` we failed to propagate through to the high limit
434437
.mul(D9d)
435438
.mul(decimalScale[i]),
436439
),

src/start-rebalance.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@ export const getStartRebalance = (
117117
// NATIVE case
118118

119119
// {wholeTok/wholeShare} = {wholeTok/wholeShare} / {1}
120+
const lowWeight = spotWeight.mul(ONE.sub(priceError[i]));
120121
const highWeight = spotWeight.div(ONE.sub(priceError[i]));
121122

122123
// D27{tok/share} = {wholeTok/wholeShare} * D27{tok/share}{wholeShare/wholeTok} / {BU/share}
123124
newWeights.push({
124-
low: 1n,
125+
low: deferWeights ? 1n : bn(lowWeight.mul(limitMultiplier)),
125126
spot: bn(spotWeight.mul(limitMultiplier)),
126127
high: deferWeights ? D27n * D27n : bn(highWeight.mul(limitMultiplier)),
127128
});
@@ -164,7 +165,7 @@ export const getStartRebalance = (
164165
}
165166

166167
const newLimits: RebalanceLimits = {
167-
low: weightControl ? bn("1e18") : 1n,
168+
low: 1n,
168169
spot: bn("1e18"),
169170
high: weightControl ? bn("1e18") : bn(ONE.div(ONE.sub(basketError)).mul(D18d)),
170171
};

0 commit comments

Comments
 (0)