@reserve-protocol/dtf-rebalance-lib 2.3.3 → 2.4.0
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 +0 -7
- package/dist/start-rebalance.js +18 -16
- package/package.json +1 -1
package/dist/open-auction.js
CHANGED
|
@@ -392,13 +392,6 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
|
|
|
392
392
|
if (tokenSurplusValue.gte(numbers_1.ONE)) {
|
|
393
393
|
surplusTokens.push(token);
|
|
394
394
|
surplusTokenSizes.push(tokenSurplusValue.toNumber());
|
|
395
|
-
if (debug && newWeights[i].spot === 0n) {
|
|
396
|
-
console.log(` EJECTING ${token}:`);
|
|
397
|
-
console.log(` assets[${i}]: ${_assets[i].toString()}`);
|
|
398
|
-
console.log(` sellDownTo: ${sellDownTo.toString()}`);
|
|
399
|
-
console.log(` surplusAmount: ${surplusAmount.toString()}`);
|
|
400
|
-
console.log(` surplusValue: ${tokenSurplusValue.toString()}`);
|
|
401
|
-
}
|
|
402
395
|
}
|
|
403
396
|
}
|
|
404
397
|
});
|
package/dist/start-rebalance.js
CHANGED
|
@@ -58,31 +58,33 @@ 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
|
-
const lowWeight = spotWeight.mul(numbers_1.ONE.sub(priceError[i]));
|
|
74
71
|
const highWeight = spotWeight.div(numbers_1.ONE.sub(priceError[i]));
|
|
75
72
|
// D27{tok/share} = {wholeTok/wholeShare} * D27{tok/share}{wholeShare/wholeTok} / {BU/share}
|
|
76
73
|
newWeights.push({
|
|
77
|
-
low:
|
|
74
|
+
low: 1n,
|
|
78
75
|
spot: (0, numbers_1.bn)(spotWeight.mul(limitMultiplier)),
|
|
79
|
-
high: (0, numbers_1.bn)(highWeight.mul(limitMultiplier)),
|
|
76
|
+
high: deferWeights ? numbers_1.D27n * numbers_1.D27n : (0, numbers_1.bn)(highWeight.mul(limitMultiplier)),
|
|
77
|
+
});
|
|
78
|
+
// 1e54 MAX_WEIGHT
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// TRACKING case
|
|
82
|
+
// D27{tok/BU} = {wholeTok/wholeShare} * D27{tok/share}{wholeShare/wholeTok} / {BU/share}
|
|
83
|
+
newWeights.push({
|
|
84
|
+
low: (0, numbers_1.bn)(spotWeight.mul(limitMultiplier)),
|
|
85
|
+
spot: (0, numbers_1.bn)(spotWeight.mul(limitMultiplier)),
|
|
86
|
+
high: (0, numbers_1.bn)(spotWeight.mul(limitMultiplier)),
|
|
80
87
|
});
|
|
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
88
|
}
|
|
87
89
|
// === newPrices ===
|
|
88
90
|
// D27{wholeTok/tok} = D27 / {tok/wholeTok}
|
|
@@ -104,7 +106,7 @@ const getStartRebalance = (_supply, tokens, _assets, decimals, _targetBasket, _p
|
|
|
104
106
|
throw new Error("basketError >= 1");
|
|
105
107
|
}
|
|
106
108
|
const newLimits = {
|
|
107
|
-
low: weightControl ? (0, numbers_1.bn)("1e18") :
|
|
109
|
+
low: weightControl ? (0, numbers_1.bn)("1e18") : 1n,
|
|
108
110
|
spot: (0, numbers_1.bn)("1e18"),
|
|
109
111
|
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
112
|
};
|