@reserve-protocol/dtf-rebalance-lib 2.2.0 → 2.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.
@@ -151,6 +151,16 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
151
151
  })
152
152
  .reduce((a, b) => a.add(b), numbers_1.ZERO)
153
153
  .div(shareValue);
154
+ if (debug && ejectionIndices.length > 0) {
155
+ console.log(" Ejection calculation:");
156
+ console.log(" ejectionIndices:", ejectionIndices);
157
+ ejectionIndices.forEach(i => {
158
+ console.log(` Token ${i}: assets=${_assets[i].toString()}, decimals=${_decimals[i].toString()}`);
159
+ console.log(` Token ${i}: folio=${folio[i].toString()}, price=${prices[i].toString()}, value=${folio[i].mul(prices[i]).toString()}`);
160
+ });
161
+ console.log(" shareValue:", shareValue.toString());
162
+ console.log(" Total folio value:", folio.map((f, i) => f.mul(prices[i])).reduce((a, b) => a.add(b)).toString());
163
+ }
154
164
  // ================================================================
155
165
  // calculate progressions
156
166
  // {wholeBU/wholeShare} = {USD/wholeShare} / {USD/wholeBU}
@@ -221,16 +231,17 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
221
231
  // EJECT -- used later to adjust weights.high and limits.high
222
232
  if (portionBeingEjected.gt(1e-5)) {
223
233
  round = AuctionRound.EJECT;
224
- // if the ejections are everything that's left, keep the finalStageAt targeting from above
225
- if (progression.add(portionBeingEjected).lt(numbers_1.ONE)) {
226
- // else: get rid of all the dust
227
- let ejectionTarget = progression.add(portionBeingEjected.mul(1.1)); // buy up to 10% extra
228
- if (ejectionTarget.gt(numbers_1.ONE)) {
229
- ejectionTarget = numbers_1.ONE;
230
- }
231
- if (ejectionTarget.gt(target)) {
232
- target = ejectionTarget;
233
- }
234
+ // if the ejections are mostly what's left, target JUST the ejection if that puts us at <100%
235
+ let ejectionTarget = progression.add(portionBeingEjected.mul(1.1)); // buy up to 10% extra
236
+ if (ejectionTarget.lt(numbers_1.ONE)) {
237
+ target = ejectionTarget;
238
+ }
239
+ if (debug) {
240
+ console.log(" EJECT round detected:");
241
+ console.log(" portionBeingEjected:", portionBeingEjected.toString());
242
+ console.log(" progression:", progression.toString());
243
+ console.log(" ejectionTarget:", ejectionTarget.toString());
244
+ console.log(" target:", target.toString());
234
245
  }
235
246
  }
236
247
  if (target.lte(numbers_1.ZERO) || target.lt(initialProgression) || target.gt(numbers_1.ONE)) {
@@ -411,6 +422,13 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
411
422
  if (tokenSurplusValue.gte(numbers_1.ONE)) {
412
423
  surplusTokens.push(token);
413
424
  surplusTokenSizes.push(tokenSurplusValue.toNumber());
425
+ if (debug && newWeights[i].spot === 0n) {
426
+ console.log(` EJECTING ${token}:`);
427
+ console.log(` assets[${i}]: ${_assets[i].toString()}`);
428
+ console.log(` sellDownTo: ${sellDownTo.toString()}`);
429
+ console.log(` surplusAmount: ${surplusAmount.toString()}`);
430
+ console.log(` surplusValue: ${tokenSurplusValue.toString()}`);
431
+ }
414
432
  }
415
433
  }
416
434
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reserve-protocol/dtf-rebalance-lib",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Rebalancing library for DTFs in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",