@reserve-protocol/dtf-rebalance-lib 0.2.3 → 0.2.4

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.
@@ -393,14 +393,22 @@ const getOpenAuction = (rebalance, _supply, _initialFolio = [], _targetBasket =
393
393
  const buyUpTo = weightRanges[i].low.mul(actualLimits.low);
394
394
  const sellDownTo = weightRanges[i].high.mul(actualLimits.high);
395
395
  if (folio[i].lt(buyUpTo)) {
396
- deficitTokens.push(token);
397
- // {USD} += {wholeTok/wholeShare} * {USD/wholeTok} * {wholeShare}
398
- deficitValue = deficitValue.add(buyUpTo.sub(folio[i]).mul(prices[i]).mul(supply));
396
+ // {USD} = {wholeTok/wholeShare} * {USD/wholeTok} * {wholeShare}
397
+ const tokenDeficitValue = deficitValue.add(buyUpTo.sub(folio[i]).mul(prices[i]).mul(supply));
398
+ // $1 minimum
399
+ if (tokenDeficitValue.gte(numbers_1.ONE)) {
400
+ deficitValue = tokenDeficitValue;
401
+ deficitTokens.push(token);
402
+ }
399
403
  }
400
404
  else if (folio[i].gt(sellDownTo)) {
401
- surplusTokens.push(token);
402
- // {USD} += {wholeTok/wholeShare} * {USD/wholeTok} * {wholeShare}
403
- surplusValue = surplusValue.add(folio[i].sub(sellDownTo).mul(prices[i]).mul(supply));
405
+ // {USD} = {wholeTok/wholeShare} * {USD/wholeTok} * {wholeShare}
406
+ const tokenSurplusValue = sellDownTo.sub(folio[i]).mul(prices[i]).mul(supply);
407
+ // $1 minimum
408
+ if (tokenSurplusValue.gte(numbers_1.ONE)) {
409
+ surplusValue = surplusValue.add(tokenSurplusValue);
410
+ surplusTokens.push(token);
411
+ }
404
412
  }
405
413
  });
406
414
  // {USD}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reserve-protocol/dtf-rebalance-lib",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Rebalancing library for DTFs in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",