@reserve-protocol/dtf-rebalance-lib 2.0.1 → 2.0.3
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 -17
- package/package.json +1 -1
package/dist/open-auction.js
CHANGED
|
@@ -375,14 +375,6 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
|
|
|
375
375
|
}
|
|
376
376
|
// ================================================================
|
|
377
377
|
// calculate metrics
|
|
378
|
-
// {wholeTok/wholeBU} = D27{tok/BU} * {BU/wholeBU} / {tok/wholeTok} / D27
|
|
379
|
-
weightRanges = newWeights.map((range, i) => {
|
|
380
|
-
return {
|
|
381
|
-
low: new utils_1.Decimal(range.low.toString()).div(decimalScale[i]).div(numbers_1.D9d),
|
|
382
|
-
spot: new utils_1.Decimal(range.spot.toString()).div(decimalScale[i]).div(numbers_1.D9d),
|
|
383
|
-
high: new utils_1.Decimal(range.high.toString()).div(decimalScale[i]).div(numbers_1.D9d),
|
|
384
|
-
};
|
|
385
|
-
});
|
|
386
378
|
// basket
|
|
387
379
|
const auctionTokens = [];
|
|
388
380
|
const auctionWeights = []; // D27{tok/BU}
|
|
@@ -399,21 +391,25 @@ const getOpenAuction = (rebalance, _supply, _initialSupply, _initialAssets = [],
|
|
|
399
391
|
auctionTokens.push(token);
|
|
400
392
|
auctionWeights.push(newWeights[i]);
|
|
401
393
|
auctionPrices.push(newPrices[i]);
|
|
402
|
-
// {
|
|
403
|
-
const buyUpTo =
|
|
404
|
-
const sellDownTo =
|
|
405
|
-
if (
|
|
406
|
-
// {
|
|
407
|
-
const
|
|
394
|
+
// {tok} = D27{tok/BU} * D18{BU/share} * {share} / D18 / D27
|
|
395
|
+
const buyUpTo = (newWeights[i].low * newLimits.low * _supply) / numbers_1.D18n / numbers_1.D27n;
|
|
396
|
+
const sellDownTo = (newWeights[i].high * newLimits.high * _supply + (numbers_1.D18n * numbers_1.D27n - 1n)) / numbers_1.D18n / numbers_1.D27n;
|
|
397
|
+
if (_assets[i] < buyUpTo) {
|
|
398
|
+
// {wholeTok} = {tok} / {tok/wholeTok}
|
|
399
|
+
const deficitAmount = new utils_1.Decimal((buyUpTo - _assets[i]).toString()).div(decimalScale[i]);
|
|
400
|
+
// {USD} = {wholeTok} * {USD/wholeTok}
|
|
401
|
+
const tokenDeficitValue = deficitAmount.mul(prices[i]);
|
|
408
402
|
// $1 minimum
|
|
409
403
|
if (tokenDeficitValue.gte(numbers_1.ONE)) {
|
|
410
404
|
deficitTokens.push(token);
|
|
411
405
|
deficitTokenSizes.push(tokenDeficitValue.toNumber());
|
|
412
406
|
}
|
|
413
407
|
}
|
|
414
|
-
else if (
|
|
415
|
-
// {
|
|
416
|
-
const
|
|
408
|
+
else if (_assets[i] > sellDownTo) {
|
|
409
|
+
// {wholeTok} = {tok} / {tok/wholeTok}
|
|
410
|
+
const surplusAmount = new utils_1.Decimal((_assets[i] - sellDownTo).toString()).div(decimalScale[i]);
|
|
411
|
+
// {USD} = {wholeTok} * {USD/wholeTok}
|
|
412
|
+
const tokenSurplusValue = surplusAmount.mul(prices[i]);
|
|
417
413
|
// $1 minimum
|
|
418
414
|
if (tokenSurplusValue.gte(numbers_1.ONE)) {
|
|
419
415
|
surplusTokens.push(token);
|