@reserve-protocol/dtf-rebalance-lib 0.1.7 → 0.2.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 +15 -2
- package/package.json +1 -1
package/dist/open-auction.js
CHANGED
@@ -56,6 +56,9 @@ exports.getTargetBasket = getTargetBasket;
|
|
56
56
|
* @param _finalStageAt {1} The % rebalanced from the initial Folio to determine when is the final stage of the rebalance
|
57
57
|
*/
|
58
58
|
const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket = [], _folio, _decimals, _prices, _priceError, _finalStageAt, debug) => {
|
59
|
+
if (debug === undefined) {
|
60
|
+
debug = true;
|
61
|
+
}
|
59
62
|
if (debug) {
|
60
63
|
console.log("getOpenAuction", rebalance, _supply, _initialFolio, _targetBasket, _folio, _decimals, _prices, _priceError, _finalStageAt);
|
61
64
|
}
|
@@ -160,7 +163,7 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
160
163
|
progression = initialProgression; // don't go backwards
|
161
164
|
}
|
162
165
|
// {1} = {1} / {1}
|
163
|
-
|
166
|
+
let relativeProgression = initialProgression.eq(numbers_1.ONE)
|
164
167
|
? numbers_1.ONE
|
165
168
|
: progression.sub(initialProgression).div(numbers_1.ONE.sub(initialProgression));
|
166
169
|
let rebalanceTarget = numbers_1.ONE;
|
@@ -352,7 +355,7 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
352
355
|
// ================================================================
|
353
356
|
// calculate metrics
|
354
357
|
// {USD} = {1} * {USD/wholeShare} * {wholeShare}
|
355
|
-
|
358
|
+
let valueBeingTraded = rebalanceTarget.sub(progression).mul(shareValue).mul(supply);
|
356
359
|
const surplusTokens = [];
|
357
360
|
const deficitTokens = [];
|
358
361
|
// update Decimal weightRanges
|
@@ -365,6 +368,9 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
365
368
|
};
|
366
369
|
});
|
367
370
|
rebalance.tokens.forEach((token, i) => {
|
371
|
+
if (!rebalance.inRebalance[i]) {
|
372
|
+
return;
|
373
|
+
}
|
368
374
|
// {wholeTok/wholeShare} = {wholeTok/wholeBU} * {wholeBU/wholeShare}
|
369
375
|
const buyUpTo = weightRanges[i].low.mul(actualLimits.low);
|
370
376
|
const sellDownTo = weightRanges[i].high.mul(actualLimits.high);
|
@@ -375,6 +381,13 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
375
381
|
surplusTokens.push(token);
|
376
382
|
}
|
377
383
|
});
|
384
|
+
// completed if no surpluses or deficits
|
385
|
+
if (deficitTokens.length == 0 || surplusTokens.length == 0) {
|
386
|
+
rebalanceTarget = numbers_1.ONE;
|
387
|
+
relativeProgression = numbers_1.ONE;
|
388
|
+
progression = numbers_1.ONE;
|
389
|
+
valueBeingTraded = numbers_1.ZERO;
|
390
|
+
}
|
378
391
|
// ================================================================
|
379
392
|
// only return tokens that are in the rebalance
|
380
393
|
const returnTokens = [];
|