@xchainjs/xchain-thorchain-query 0.4.6 → 0.4.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/lib/index.esm.js CHANGED
@@ -543,6 +543,25 @@ class Midgard {
543
543
  throw Error(`Midgard not responding`);
544
544
  });
545
545
  }
546
+ /**
547
+ * Function to return member details based on valid liquidity position
548
+ * @param address - query can also be multiple addresses should be separated by comma
549
+ * @returns - object type of Member Detail
550
+ */
551
+ getSavers(address) {
552
+ return __awaiter(this, void 0, void 0, function* () {
553
+ for (const api of this.midgardApis) {
554
+ try {
555
+ const saverDetails = (yield api.getSaverDetail(address)).data;
556
+ return saverDetails;
557
+ }
558
+ catch (e) {
559
+ //console.error(e)
560
+ }
561
+ }
562
+ throw Error(`Midgard not responding`);
563
+ });
564
+ }
546
565
  /**
547
566
  * Function to return pool statistics for a particular asset
548
567
  * @param asset - asset string to query its pool stats
@@ -1411,6 +1430,7 @@ class ThorchainQuery {
1411
1430
  outboundDelayBlocks: 0,
1412
1431
  streamingSlipBasisPoints: 0,
1413
1432
  streamingSwapBlocks: 0,
1433
+ streamingSwapSeconds: 0,
1414
1434
  totalSwapSeconds: 0,
1415
1435
  warning: '',
1416
1436
  },
@@ -1438,7 +1458,7 @@ class ThorchainQuery {
1438
1458
  },
1439
1459
  slipBasisPoints: swapQuote.slippage_bps,
1440
1460
  netOutput: new CryptoAmount(baseAmount(swapQuote.expected_amount_out), destinationAsset),
1441
- netOutputStreaming: new CryptoAmount(baseAmount(swapQuote.expected_amount_out), destinationAsset),
1461
+ netOutputStreaming: new CryptoAmount(baseAmount(swapQuote.expected_amount_out_streaming), destinationAsset),
1442
1462
  outboundDelaySeconds: swapQuote.outbound_delay_seconds,
1443
1463
  inboundConfirmationSeconds: swapQuote.inbound_confirmation_seconds,
1444
1464
  recommendedMinAmountIn: swapQuote.recommended_min_amount_in,
@@ -1446,6 +1466,7 @@ class ThorchainQuery {
1446
1466
  outboundDelayBlocks: swapQuote.outbound_delay_blocks,
1447
1467
  streamingSlipBasisPoints: swapQuote.streaming_slippage_bps,
1448
1468
  streamingSwapBlocks: swapQuote.streaming_swap_blocks ? swapQuote.streaming_swap_blocks : 0,
1469
+ streamingSwapSeconds: swapQuote.streaming_swap_seconds ? swapQuote.streaming_swap_seconds : 0,
1449
1470
  totalSwapSeconds: swapQuote.total_swap_seconds ? swapQuote.total_swap_seconds : 0,
1450
1471
  canSwap: !swapQuote.memo || errors.length > 0 ? false : true,
1451
1472
  errors,
@@ -2054,11 +2075,53 @@ class ThorchainQuery {
2054
2075
  percentageGrowth: saverGrowth.assetAmount.amount().toNumber(),
2055
2076
  ageInYears: saversAge,
2056
2077
  ageInDays: saversAge * 365,
2078
+ asset: params.asset,
2057
2079
  errors,
2058
2080
  };
2059
2081
  return saversPos;
2060
2082
  });
2061
2083
  }
2084
+ getSaverPositions(params) {
2085
+ return __awaiter(this, void 0, void 0, function* () {
2086
+ const addresses = new Set();
2087
+ params.forEach((param) => addresses.add(param.address));
2088
+ const addressesString = Array.from(addresses).join(',');
2089
+ const saversDetail = yield this.thorchainCache.midgard.getSavers(addressesString);
2090
+ const pools = yield this.thorchainCache.getPools();
2091
+ const inboundDetails = yield this.thorchainCache.getInboundDetails();
2092
+ const errors = [];
2093
+ const saversPositions = [];
2094
+ saversDetail.pools.forEach((saver) => {
2095
+ const asset = assetFromString(saver.pool);
2096
+ if (asset) {
2097
+ const outboundFee = calcOutboundFee(asset, inboundDetails[asset.chain]);
2098
+ const convertToBaseEight = getBaseAmountWithDiffDecimals(outboundFee, 8);
2099
+ if (Number(saver === null || saver === void 0 ? void 0 : saver.assetRedeem) < convertToBaseEight.toNumber())
2100
+ errors.push(`Unlikely to withdraw balance as outbound fee is greater than redeemable amount`);
2101
+ const liquidityPool = pools[`${asset.chain}.${asset.ticker}`];
2102
+ const depositAmount = new CryptoAmount(baseAmount(saver.assetAdded).minus(saver.assetWithdrawn), asset);
2103
+ const ownerUnits = Number(saver === null || saver === void 0 ? void 0 : saver.saverUnits);
2104
+ const saverUnits = Number(liquidityPool.pool.saversUnits);
2105
+ const assetDepth = Number(liquidityPool.pool.saversDepth);
2106
+ const redeemableValue = (ownerUnits / saverUnits) * assetDepth;
2107
+ const redeemableAssetAmount = new CryptoAmount(baseAmount(redeemableValue), asset);
2108
+ const saverGrowth = redeemableAssetAmount.minus(depositAmount).div(depositAmount).times(100);
2109
+ const saversAge = (Date.now() / 1000 - Number(saver.dateLastAdded)) / (365 * 86400);
2110
+ saversPositions.push({
2111
+ depositValue: depositAmount,
2112
+ redeemableValue: redeemableAssetAmount,
2113
+ lastAddHeight: -1,
2114
+ percentageGrowth: saverGrowth.assetAmount.amount().toNumber(),
2115
+ ageInYears: saversAge,
2116
+ ageInDays: saversAge * 365,
2117
+ asset,
2118
+ errors,
2119
+ });
2120
+ }
2121
+ });
2122
+ return saversPositions;
2123
+ });
2124
+ }
2062
2125
  getAddSaversEstimateErrors(addAmount) {
2063
2126
  return __awaiter(this, void 0, void 0, function* () {
2064
2127
  const errors = [];