@reserve-protocol/dtf-rebalance-lib 0.2.6 → 0.2.7
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 -13
- package/package.json +1 -1
package/dist/open-auction.js
CHANGED
@@ -147,38 +147,40 @@ 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
|
151
150
|
// {wholeBU/wholeShare} = D18{BU/share} / D18
|
152
151
|
const prevSpotLimit = new decimal_js_light_1.default(rebalance.limits.spot.toString()).div(numbers_1.D18d);
|
153
|
-
//
|
154
|
-
|
155
|
-
// {1} = {USD/wholeShare} / {USD/wholeShare}
|
152
|
+
// calculate progressions
|
153
|
+
// {1} = {USD/wholeBU} / {USD/wholeBU}
|
156
154
|
let progression = folio
|
157
155
|
.map((actualBalance, i) => {
|
158
156
|
if (!rebalance.inRebalance[i]) {
|
159
157
|
return numbers_1.ZERO;
|
160
158
|
}
|
161
|
-
// {wholeTok/wholeShare}
|
162
|
-
const
|
163
|
-
// {
|
159
|
+
// {wholeTok/wholeBU} = {wholeTok/wholeShare} / {wholeBU/wholeShare}
|
160
|
+
const actualInBU = actualBalance.div(prevSpotLimit);
|
161
|
+
// {wholeTok/wholeBU}
|
162
|
+
const balanceInBasket = weightRanges[i].spot.gt(actualInBU) ? actualInBU : weightRanges[i].spot;
|
163
|
+
// {USD/wholeBU} = {wholeTok/wholeBU} * {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(buValue);
|
168
|
+
// {1} = {USD/wholeBU} / {USD/wholeBU}
|
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/wholeShare}
|
176
|
-
const
|
177
|
-
// {
|
175
|
+
// {wholeTok/wholeBU} = {wholeTok/wholeShare} / {wholeBU/wholeShare}
|
176
|
+
const initialInBU = initialBalance.div(prevSpotLimit);
|
177
|
+
// {wholeTok/wholeBU}
|
178
|
+
const balanceInBasket = weightRanges[i].spot.gt(initialInBU) ? initialInBU : weightRanges[i].spot;
|
179
|
+
// {USD/wholeBU} = {wholeTok/wholeBU} * {USD/wholeTok}
|
178
180
|
return balanceInBasket.mul(prices[i]);
|
179
181
|
})
|
180
182
|
.reduce((a, b) => a.add(b))
|
181
|
-
.div(
|
183
|
+
.div(buValue);
|
182
184
|
if (progression < initialProgression) {
|
183
185
|
progression = initialProgression; // don't go backwards
|
184
186
|
}
|