@reserve-protocol/dtf-rebalance-lib 0.2.7 → 0.2.8
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 +13 -15
- package/package.json +1 -1
package/dist/open-auction.js
CHANGED
@@ -147,40 +147,38 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
|
|
147
147
|
.reduce((a, b) => a.add(b), numbers_1.ZERO)
|
148
148
|
.div(shareValue);
|
149
149
|
// ================================================================
|
150
|
+
// calculate progressions
|
150
151
|
// {wholeBU/wholeShare} = D18{BU/share} / D18
|
151
152
|
const prevSpotLimit = new decimal_js_light_1.default(rebalance.limits.spot.toString()).div(numbers_1.D18d);
|
152
|
-
//
|
153
|
-
|
153
|
+
// {wholeTok/wholeBU} = {wholeTok/wholeBU} * {wholeBU/wholeShare}
|
154
|
+
const expectedBalances = weightRanges.map((weightRange) => weightRange.spot.mul(prevSpotLimit));
|
155
|
+
// {1} = {USD/wholeShare} / {USD/wholeShare}
|
154
156
|
let progression = folio
|
155
157
|
.map((actualBalance, i) => {
|
156
158
|
if (!rebalance.inRebalance[i]) {
|
157
159
|
return numbers_1.ZERO;
|
158
160
|
}
|
159
|
-
// {wholeTok/
|
160
|
-
const
|
161
|
-
// {wholeTok/
|
162
|
-
const balanceInBasket = weightRanges[i].spot.gt(actualInBU) ? actualInBU : weightRanges[i].spot;
|
163
|
-
// {USD/wholeBU} = {wholeTok/wholeBU} * {USD/wholeTok}
|
161
|
+
// {wholeTok/wholeShare}
|
162
|
+
const balanceInBasket = expectedBalances[i].gt(actualBalance) ? actualBalance : expectedBalances[i];
|
163
|
+
// {USD/wholeShare} = {wholeTok/wholeShare} * {USD/wholeTok}
|
164
164
|
return balanceInBasket.mul(prices[i]);
|
165
165
|
})
|
166
166
|
.reduce((a, b) => a.add(b))
|
167
|
-
.div(
|
168
|
-
// {1} = {USD/
|
167
|
+
.div(shareValue);
|
168
|
+
// {1} = {USD/wholeShare} / {USD/wholeShare}
|
169
169
|
const initialProgression = initialFolio
|
170
170
|
.map((initialBalance, i) => {
|
171
171
|
// make sure to include tokens that were already ejected
|
172
172
|
if (!rebalance.inRebalance[i] && rebalance.weights[i].spot > 0n) {
|
173
173
|
return numbers_1.ZERO;
|
174
174
|
}
|
175
|
-
// {wholeTok/
|
176
|
-
const
|
177
|
-
// {wholeTok/
|
178
|
-
const balanceInBasket = weightRanges[i].spot.gt(initialInBU) ? initialInBU : weightRanges[i].spot;
|
179
|
-
// {USD/wholeBU} = {wholeTok/wholeBU} * {USD/wholeTok}
|
175
|
+
// {wholeTok/wholeShare}
|
176
|
+
const balanceInBasket = expectedBalances[i].gt(initialBalance) ? initialBalance : expectedBalances[i];
|
177
|
+
// {USD/wholeShare} = {wholeTok/wholeShare} * {USD/wholeTok}
|
180
178
|
return balanceInBasket.mul(prices[i]);
|
181
179
|
})
|
182
180
|
.reduce((a, b) => a.add(b))
|
183
|
-
.div(
|
181
|
+
.div(shareValue);
|
184
182
|
if (progression < initialProgression) {
|
185
183
|
progression = initialProgression; // don't go backwards
|
186
184
|
}
|