@reserve-protocol/dtf-rebalance-lib 0.2.17 → 0.2.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 +12 -6
- package/package.json +1 -1
package/dist/open-auction.js
CHANGED
@@ -148,10 +148,14 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
148
148
|
.div(shareValue);
|
149
149
|
// ================================================================
|
150
150
|
// calculate progressions
|
151
|
+
// {wholeBU/wholeShare} = {USD/wholeShare} / {USD/wholeBU}
|
152
|
+
const spotLimit = shareValue.div(buValue);
|
151
153
|
// {wholeBU/wholeShare} = D18{BU/share} / D18
|
152
154
|
const prevSpotLimit = new utils_1.Decimal(rebalance.limits.spot.toString()).div(numbers_1.D18d);
|
155
|
+
const maxSpotLimit = spotLimit.gt(prevSpotLimit) ? spotLimit : prevSpotLimit;
|
153
156
|
// {wholeTok/wholeShare} = {wholeTok/wholeBU} * {wholeBU/wholeShare}
|
154
|
-
const expectedBalances = weightRanges.map((weightRange) => weightRange.spot.mul(
|
157
|
+
const expectedBalances = weightRanges.map((weightRange) => weightRange.spot.mul(maxSpotLimit));
|
158
|
+
// absolute scale
|
155
159
|
// {1} = {USD/wholeShare} / {USD/wholeShare}
|
156
160
|
let progression = folio
|
157
161
|
.map((actualBalance, i) => {
|
@@ -165,6 +169,7 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
165
169
|
})
|
166
170
|
.reduce((a, b) => a.add(b))
|
167
171
|
.div(shareValue);
|
172
|
+
// absolute scale
|
168
173
|
// {1} = {USD/wholeShare} / {USD/wholeShare}
|
169
174
|
const initialProgression = initialFolio
|
170
175
|
.map((initialBalance, i) => {
|
@@ -188,7 +193,7 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
188
193
|
let relativeProgression = initialProgression.eq(numbers_1.ONE)
|
189
194
|
? numbers_1.ONE
|
190
195
|
: progression.sub(initialProgression).div(numbers_1.ONE.sub(initialProgression));
|
191
|
-
let rebalanceTarget = numbers_1.ONE;
|
196
|
+
let rebalanceTarget = numbers_1.ONE; // absolute scale
|
192
197
|
let round = AuctionRound.FINAL;
|
193
198
|
if (debug) {
|
194
199
|
console.log("initialProgression", initialProgression.toString());
|
@@ -209,6 +214,8 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
209
214
|
}
|
210
215
|
}
|
211
216
|
// EJECT
|
217
|
+
// TODO maybe increase threshold to nonzero value, taking into account price
|
218
|
+
// currently will get stuck trying to eject tiny dust over and over
|
212
219
|
if (portionBeingEjected.gt(0)) {
|
213
220
|
round = AuctionRound.EJECT;
|
214
221
|
// if the ejections are everything that's left, keep the finalStageAt targeting from above
|
@@ -236,8 +243,6 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
236
243
|
const delta = numbers_1.ONE.sub(rebalanceTarget);
|
237
244
|
// ================================================================
|
238
245
|
// get new limits, constrained by extremes
|
239
|
-
// {wholeBU/wholeShare} = {USD/wholeShare} / {USD/wholeBU}
|
240
|
-
const spotLimit = shareValue.div(buValue);
|
241
246
|
// D18{BU/share} = {wholeBU/wholeShare} * D18 * {1}
|
242
247
|
const newLimits = {
|
243
248
|
low: (0, numbers_1.bn)(spotLimit.sub(spotLimit.mul(delta)).mul(numbers_1.D18d)),
|
@@ -287,7 +292,7 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
287
292
|
// D27{tok/BU} = {wholeTok/wholeBU} * D27 * {tok/wholeTok} / {BU/wholeBU}
|
288
293
|
const newWeightsD27 = {
|
289
294
|
low: (0, numbers_1.bn)(idealWeight
|
290
|
-
.mul(
|
295
|
+
.mul(numbers_1.ONE.sub(delta).div(actualLimits.low.div(actualLimits.spot))) // add remaining delta into weight
|
291
296
|
.mul(numbers_1.D9d)
|
292
297
|
.mul(decimalScale[i])),
|
293
298
|
spot: (0, numbers_1.bn)(idealWeight.mul(numbers_1.D9d).mul(decimalScale[i])),
|
@@ -420,7 +425,8 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
420
425
|
const returnWeights = [];
|
421
426
|
const returnPrices = [];
|
422
427
|
for (let i = 0; i < rebalance.tokens.length; i++) {
|
423
|
-
if (rebalance.inRebalance[i]
|
428
|
+
if (rebalance.inRebalance[i] &&
|
429
|
+
(surplusTokens.includes(rebalance.tokens[i]) || deficitTokens.includes(rebalance.tokens[i]))) {
|
424
430
|
returnTokens.push(rebalance.tokens[i]);
|
425
431
|
returnWeights.push(newWeights[i]);
|
426
432
|
returnPrices.push(newPrices[i]);
|