@xchainjs/xchain-thorchain-query 0.1.11 → 0.1.13

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
@@ -1,11 +1,19 @@
1
- import { assetToBase, formatAssetAmountCurrency, baseToAsset, eqAsset, assetToString, assetFromString, baseAmount, AssetRuneNative, Chain, AssetAtom, AssetAVAX, AssetETH, AssetBNB, AssetDOGE, AssetLTC, AssetBCH, AssetBTC, AvalancheChain, DOGEChain, LTCChain, BCHChain, CosmosChain, THORChain, ETHChain, BTCChain, BNBChain, assetFromStringEx, isAssetRuneNative, getContractAddressFromAsset, assetAmount } from '@xchainjs/xchain-util';
1
+ import { BNBChain, AssetBNB } from '@xchainjs/xchain-binance';
2
+ import { BTCChain, AssetBTC } from '@xchainjs/xchain-bitcoin';
3
+ import { GAIAChain, AssetATOM } from '@xchainjs/xchain-cosmos';
4
+ import { AssetRuneNative, THORChain, isAssetRuneNative } from '@xchainjs/xchain-thorchain';
5
+ import { assetToBase, formatAssetAmountCurrency, baseToAsset, eqAsset, assetToString, assetFromString, baseAmount, assetFromStringEx, getContractAddressFromAsset, assetAmount } from '@xchainjs/xchain-util';
2
6
  import { BigNumber } from 'bignumber.js';
3
7
  import { Network } from '@xchainjs/xchain-client';
4
8
  import { MidgardApi, Configuration } from '@xchainjs/xchain-midgard';
5
9
  import axios from 'axios';
6
10
  import axiosRetry from 'axios-retry';
11
+ import { AVAXChain, AssetAVAX } from '@xchainjs/xchain-avax';
12
+ import { AssetBCH, BCHChain } from '@xchainjs/xchain-bitcoincash';
13
+ import { DOGEChain, AssetDOGE } from '@xchainjs/xchain-doge';
14
+ import { ETHChain, AssetETH } from '@xchainjs/xchain-ethereum';
15
+ import { LTCChain, AssetLTC } from '@xchainjs/xchain-litecoin';
7
16
  import { TransactionsApi, Configuration as Configuration$1, QueueApi, NetworkApi, PoolsApi, LiquidityProvidersApi, SaversApi, QuoteApi } from '@xchainjs/xchain-thornode';
8
- import { baseAmount as baseAmount$1, AssetRuneNative as AssetRuneNative$1 } from '@xchainjs/xchain-util/lib';
9
17
 
10
18
  /*! *****************************************************************************
11
19
  Copyright (c) Microsoft Corporation.
@@ -546,19 +554,19 @@ const calcNetworkFee = (asset, inbound) => {
546
554
  if (asset.synth)
547
555
  return new CryptoAmount(baseAmount(2000000), AssetRuneNative);
548
556
  switch (asset.chain) {
549
- case Chain.Bitcoin:
557
+ case BTCChain:
550
558
  return new CryptoAmount(baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetBTC);
551
- case Chain.BitcoinCash:
559
+ case BTCChain:
552
560
  return new CryptoAmount(baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetBCH);
553
- case Chain.Litecoin:
561
+ case LTCChain:
554
562
  return new CryptoAmount(baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetLTC);
555
- case Chain.Doge:
563
+ case DOGEChain:
556
564
  // NOTE: UTXO chains estimate fees with a 250 byte size
557
565
  return new CryptoAmount(baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetDOGE);
558
- case Chain.Binance:
566
+ case BNBChain:
559
567
  //flat fee
560
568
  return new CryptoAmount(baseAmount(inbound.gasRate), AssetBNB);
561
- case Chain.Ethereum:
569
+ case ETHChain:
562
570
  const gasRateinETHGwei = inbound.gasRate;
563
571
  const gasRateinETHWei = baseAmount(gasRateinETHGwei.multipliedBy(Math.pow(10, 9)), 18);
564
572
  if (eqAsset(asset, AssetETH)) {
@@ -567,7 +575,7 @@ const calcNetworkFee = (asset, inbound) => {
567
575
  else {
568
576
  return new CryptoAmount(gasRateinETHWei.times(70000), AssetETH);
569
577
  }
570
- case Chain.Avalanche:
578
+ case AVAXChain:
571
579
  const gasRateinAVAXGwei = inbound.gasRate;
572
580
  const gasRateinAVAXWei = baseAmount(gasRateinAVAXGwei.multipliedBy(Math.pow(10, 9)), 18);
573
581
  if (eqAsset(asset, AssetAVAX)) {
@@ -576,9 +584,9 @@ const calcNetworkFee = (asset, inbound) => {
576
584
  else {
577
585
  return new CryptoAmount(gasRateinAVAXWei.times(70000), AssetAVAX);
578
586
  }
579
- case Chain.Cosmos:
580
- return new CryptoAmount(baseAmount(inbound.gasRate), AssetAtom);
581
- case Chain.THORChain:
587
+ case GAIAChain:
588
+ return new CryptoAmount(baseAmount(inbound.gasRate), AssetATOM);
589
+ case THORChain:
582
590
  return new CryptoAmount(baseAmount(2000000), AssetRuneNative);
583
591
  }
584
592
  throw new Error(`could not calculate inbound fee for ${asset.chain}`);
@@ -596,25 +604,25 @@ const calcOutboundFee = (asset, inbound) => {
596
604
  if (asset.synth)
597
605
  return new CryptoAmount(baseAmount(2000000), AssetRuneNative);
598
606
  switch (asset.chain) {
599
- case Chain.Bitcoin:
607
+ case BTCChain:
600
608
  return new CryptoAmount(baseAmount(inbound.outboundFee), AssetBTC);
601
- case Chain.BitcoinCash:
609
+ case BCHChain:
602
610
  return new CryptoAmount(baseAmount(inbound.outboundFee), AssetBCH);
603
- case Chain.Litecoin:
611
+ case LTCChain:
604
612
  return new CryptoAmount(baseAmount(inbound.outboundFee), AssetLTC);
605
- case Chain.Doge:
613
+ case DOGEChain:
606
614
  // NOTE: UTXO chains estimate fees with a 250 byte size
607
615
  return new CryptoAmount(baseAmount(inbound.outboundFee), AssetDOGE);
608
- case Chain.Binance:
616
+ case BNBChain:
609
617
  //flat fee
610
618
  return new CryptoAmount(baseAmount(inbound.outboundFee), AssetBNB);
611
- case Chain.Ethereum:
619
+ case ETHChain:
612
620
  return new CryptoAmount(baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), AssetETH);
613
- case Chain.Avalanche:
621
+ case AVAXChain:
614
622
  return new CryptoAmount(baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), AssetAVAX);
615
- case Chain.Cosmos:
616
- return new CryptoAmount(baseAmount(inbound.outboundFee), AssetAtom);
617
- case Chain.THORChain:
623
+ case GAIAChain:
624
+ return new CryptoAmount(baseAmount(inbound.outboundFee), AssetATOM);
625
+ case THORChain:
618
626
  return new CryptoAmount(baseAmount(2000000), AssetRuneNative);
619
627
  }
620
628
  throw new Error(`could not calculate outbound fee for ${asset.chain}`);
@@ -634,15 +642,15 @@ const getChainAsset = (chain) => {
634
642
  return AssetETH;
635
643
  case THORChain:
636
644
  return AssetRuneNative;
637
- case CosmosChain:
638
- return AssetAtom;
645
+ case GAIAChain:
646
+ return AssetATOM;
639
647
  case BCHChain:
640
648
  return AssetBCH;
641
649
  case LTCChain:
642
650
  return AssetLTC;
643
651
  case DOGEChain:
644
652
  return AssetDOGE;
645
- case AvalancheChain:
653
+ case AVAXChain:
646
654
  return AssetAVAX;
647
655
  default:
648
656
  throw Error('Unknown chain');
@@ -655,6 +663,8 @@ const getChainAsset = (chain) => {
655
663
  */
656
664
  const getChain = (chain) => {
657
665
  switch (chain) {
666
+ case 'AVAX':
667
+ return AVAXChain;
658
668
  case 'BNB':
659
669
  return BNBChain;
660
670
  case 'BTC':
@@ -664,7 +674,7 @@ const getChain = (chain) => {
664
674
  case 'THOR':
665
675
  return THORChain;
666
676
  case 'GAIA':
667
- return CosmosChain;
677
+ return GAIAChain;
668
678
  case 'BCH':
669
679
  return BCHChain;
670
680
  case 'LTC':
@@ -1123,7 +1133,7 @@ class ThorchainCache {
1123
1133
  }
1124
1134
  // add mock THORCHAIN inbound details
1125
1135
  const details = {
1126
- chain: Chain.THORChain,
1136
+ chain: THORChain,
1127
1137
  address: '',
1128
1138
  router: '',
1129
1139
  gasRate: new BigNumber(0),
@@ -1134,7 +1144,7 @@ class ThorchainCache {
1134
1144
  haltedTrading: !!mimirDetails['HALTTRADING'],
1135
1145
  haltedLP: false, //
1136
1146
  };
1137
- inboundDetails[Chain.THORChain] = details;
1147
+ inboundDetails[THORChain] = details;
1138
1148
  this.inboundDetailCache = {
1139
1149
  lastRefreshed: Date.now(),
1140
1150
  inboundDetails,
@@ -1341,8 +1351,8 @@ const getPoolShare = (unitData, pool) => {
1341
1351
  const asset = T.times(units).div(total);
1342
1352
  const rune = R.times(units).div(total);
1343
1353
  const poolShareDetail = {
1344
- assetShare: new CryptoAmount(baseAmount$1(asset), pool.asset),
1345
- runeShare: new CryptoAmount(baseAmount$1(rune), AssetRuneNative$1),
1354
+ assetShare: new CryptoAmount(baseAmount(asset), pool.asset),
1355
+ runeShare: new CryptoAmount(baseAmount(rune), AssetRuneNative),
1346
1356
  };
1347
1357
  return poolShareDetail;
1348
1358
  };
@@ -1391,7 +1401,7 @@ const getLiquidityProtectionData = (depositValue, poolShare, block) => {
1391
1401
  const result = coverage.times(protectionProgress); // impermanent loss protection result
1392
1402
  const maxILP = result.lt(0) ? new BigNumber(0) : result; // max negative ILP to 0
1393
1403
  const ILProtection = {
1394
- ILProtection: new CryptoAmount(baseAmount$1(maxILP), AssetRuneNative$1),
1404
+ ILProtection: new CryptoAmount(baseAmount(maxILP), AssetRuneNative),
1395
1405
  totalDays: (fractionOfFullILPProtection * 100).toFixed(2),
1396
1406
  };
1397
1407
  return ILProtection;
@@ -1601,7 +1611,7 @@ class ThorchainQuery {
1601
1611
  const contractAddress = getContractAddressFromAsset(asset);
1602
1612
  if (contractAddress && contractAddress.length > 5) {
1603
1613
  const abrev = contractAddress.substring(contractAddress.length - 5);
1604
- const sep = asset.chain !== Chain.THORChain && asset.synth ? '/' : '.';
1614
+ const sep = asset.chain !== THORChain && asset.synth ? '/' : '.';
1605
1615
  return `${asset.chain}${sep}${asset.ticker}-${abrev}`;
1606
1616
  }
1607
1617
  return assetToString(asset);
@@ -1632,7 +1642,7 @@ class ThorchainQuery {
1632
1642
  // private async validateAffiliateAddress(affiliateAddress: string) {
1633
1643
  // // Affiliate address should be THORName or THORAddress
1634
1644
  // if (affiliateAddress.length > 0) {
1635
- // const isValidThorchainAddress = this.clients[Chain.THORChain].validateAddress(affiliateAddress)
1645
+ // const isValidThorchainAddress = this.clients[THORChain].validateAddress(affiliateAddress)
1636
1646
  // const isValidThorname = await this.isThorname(affiliateAddress)
1637
1647
  // if (!(isValidThorchainAddress || isValidThorname))
1638
1648
  // throw Error(`affiliateAddress ${affiliateAddress} is not a valid THOR address`)
@@ -1759,10 +1769,10 @@ class ThorchainQuery {
1759
1769
  return __awaiter(this, void 0, void 0, function* () {
1760
1770
  // RUNE, BNB and Synths have near instant finality, so no conf counting required. - need to make a BFT only case.
1761
1771
  if (isAssetRuneNative(inbound.asset) ||
1762
- inbound.asset.chain == AssetBNB.chain ||
1763
- inbound.asset.chain == AssetAtom.chain ||
1772
+ inbound.asset.chain == BNBChain ||
1773
+ inbound.asset.chain == GAIAChain ||
1764
1774
  inbound.asset.synth) {
1765
- return this.chainAttributes[Chain.THORChain].avgBlockTimeInSecs;
1775
+ return this.chainAttributes[THORChain].avgBlockTimeInSecs;
1766
1776
  }
1767
1777
  // Get the gas asset for the inbound.asset.chain
1768
1778
  const chainGasAsset = getChainAsset(inbound.asset.chain);
@@ -1793,7 +1803,7 @@ class ThorchainQuery {
1793
1803
  .amount()
1794
1804
  .toNumber();
1795
1805
  const getScheduledOutboundValue = yield this.thorchainCache.midgard.getScheduledOutboundValue();
1796
- const thorChainblocktime = this.chainAttributes[Chain.THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
1806
+ const thorChainblocktime = this.chainAttributes[THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
1797
1807
  // If asset is equal to Rune set runeValue as outbound amount else set it to the asset's value in rune
1798
1808
  const runeValue = yield this.thorchainCache.convert(outboundAmount, AssetRuneNative);
1799
1809
  // Check rune value amount
@@ -2281,7 +2291,7 @@ class TransactionStage {
2281
2291
  case 1:
2282
2292
  if (((_b = (_a = txData.observed_tx) === null || _a === void 0 ? void 0 : _a.tx) === null || _b === void 0 ? void 0 : _b.chain) != undefined) {
2283
2293
  sourceChain = getChain(txData.observed_tx.tx.chain);
2284
- if (sourceChain == (Chain.Bitcoin || Chain.BitcoinCash || Chain.Litecoin)) {
2294
+ if (sourceChain == (BTCChain || BCHChain || LTCChain)) {
2285
2295
  const lastBlockHeight = lastBlock.find((obj) => obj.chain === sourceChain);
2286
2296
  const checkConf = yield this.checkConfcounting(sourceChain, lastBlockHeight, txData.observed_tx);
2287
2297
  transactionProgress.seconds = checkConf.seconds;
package/lib/index.js CHANGED
@@ -2,14 +2,22 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var xchainBinance = require('@xchainjs/xchain-binance');
6
+ var xchainBitcoin = require('@xchainjs/xchain-bitcoin');
7
+ var xchainCosmos = require('@xchainjs/xchain-cosmos');
8
+ var xchainThorchain = require('@xchainjs/xchain-thorchain');
5
9
  var xchainUtil = require('@xchainjs/xchain-util');
6
10
  var bignumber_js = require('bignumber.js');
7
11
  var xchainClient = require('@xchainjs/xchain-client');
8
12
  var xchainMidgard = require('@xchainjs/xchain-midgard');
9
13
  var axios = require('axios');
10
14
  var axiosRetry = require('axios-retry');
15
+ var xchainAvax = require('@xchainjs/xchain-avax');
16
+ var xchainBitcoincash = require('@xchainjs/xchain-bitcoincash');
17
+ var xchainDoge = require('@xchainjs/xchain-doge');
18
+ var xchainEthereum = require('@xchainjs/xchain-ethereum');
19
+ var xchainLitecoin = require('@xchainjs/xchain-litecoin');
11
20
  var xchainThornode = require('@xchainjs/xchain-thornode');
12
- var lib = require('@xchainjs/xchain-util/lib');
13
21
 
14
22
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
23
 
@@ -278,7 +286,7 @@ class Midgard {
278
286
  for (const baseUrl of this.config.midgardBaseUrls) {
279
287
  try {
280
288
  const { data } = yield axios__default['default'].get(`${baseUrl}${path}`);
281
- const value = new CryptoAmount(xchainUtil.baseAmount(data['scheduled_outbound_value']), xchainUtil.AssetRuneNative);
289
+ const value = new CryptoAmount(xchainUtil.baseAmount(data['scheduled_outbound_value']), xchainThorchain.AssetRuneNative);
282
290
  return value;
283
291
  }
284
292
  catch (e) {
@@ -436,7 +444,7 @@ const getSwapFee = (inputAmount, pool, toRune) => {
436
444
  const x = getBaseAmountWithDiffDecimals(inputAmount, 8);
437
445
  const X = toRune ? pool.assetBalance.amount() : pool.runeBalance.amount(); // input is asset if toRune
438
446
  const Y = toRune ? pool.runeBalance.amount() : pool.assetBalance.amount(); // output is rune if toRune
439
- const units = toRune ? xchainUtil.AssetRuneNative : pool.asset;
447
+ const units = toRune ? xchainThorchain.AssetRuneNative : pool.asset;
440
448
  const numerator = x.times(x).multipliedBy(Y);
441
449
  const denominator = x.plus(X).pow(2);
442
450
  const result = numerator.div(denominator);
@@ -475,7 +483,7 @@ const getSwapOutput = (inputAmount, pool, toRune) => {
475
483
  const x = getBaseAmountWithDiffDecimals(inputAmount, 8);
476
484
  const X = toRune ? pool.assetBalance.amount() : pool.runeBalance.amount(); // input is asset if toRune
477
485
  const Y = toRune ? pool.runeBalance.amount() : pool.assetBalance.amount(); // output is rune if toRune
478
- const units = toRune ? xchainUtil.AssetRuneNative : pool.asset;
486
+ const units = toRune ? xchainThorchain.AssetRuneNative : pool.asset;
479
487
  // const decimals = toRune || !pool.decimals ? 8 : pool.decimals
480
488
  const numerator = x.times(X).times(Y);
481
489
  const denominator = x.plus(X).pow(2);
@@ -520,7 +528,7 @@ const getDoubleSwapFee = (inputAmount, pool1, pool2, thorchainCache) => __awaite
520
528
  const fee1InRune = getSwapFee(inputAmount, pool1, true);
521
529
  const swapOutput = getSwapOutput(inputAmount, pool1, true);
522
530
  const fee2InAsset = getSwapFee(swapOutput, pool2, false);
523
- const fee2InRune = yield thorchainCache.convert(fee2InAsset, xchainUtil.AssetRuneNative);
531
+ const fee2InRune = yield thorchainCache.convert(fee2InAsset, xchainThorchain.AssetRuneNative);
524
532
  const result = fee1InRune.plus(fee2InRune);
525
533
  return result;
526
534
  });
@@ -553,42 +561,42 @@ const getDoubleSwap = (inputAmount, pool1, pool2, thorchainCache) => __awaiter(v
553
561
  */
554
562
  const calcNetworkFee = (asset, inbound) => {
555
563
  if (asset.synth)
556
- return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainUtil.AssetRuneNative);
564
+ return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainThorchain.AssetRuneNative);
557
565
  switch (asset.chain) {
558
- case xchainUtil.Chain.Bitcoin:
559
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), xchainUtil.AssetBTC);
560
- case xchainUtil.Chain.BitcoinCash:
561
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), xchainUtil.AssetBCH);
562
- case xchainUtil.Chain.Litecoin:
563
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), xchainUtil.AssetLTC);
564
- case xchainUtil.Chain.Doge:
566
+ case xchainBitcoin.BTCChain:
567
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), xchainBitcoin.AssetBTC);
568
+ case xchainBitcoin.BTCChain:
569
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), xchainBitcoincash.AssetBCH);
570
+ case xchainLitecoin.LTCChain:
571
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), xchainLitecoin.AssetLTC);
572
+ case xchainDoge.DOGEChain:
565
573
  // NOTE: UTXO chains estimate fees with a 250 byte size
566
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), xchainUtil.AssetDOGE);
567
- case xchainUtil.Chain.Binance:
574
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), xchainDoge.AssetDOGE);
575
+ case xchainBinance.BNBChain:
568
576
  //flat fee
569
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), xchainUtil.AssetBNB);
570
- case xchainUtil.Chain.Ethereum:
577
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), xchainBinance.AssetBNB);
578
+ case xchainEthereum.ETHChain:
571
579
  const gasRateinETHGwei = inbound.gasRate;
572
580
  const gasRateinETHWei = xchainUtil.baseAmount(gasRateinETHGwei.multipliedBy(Math.pow(10, 9)), 18);
573
- if (xchainUtil.eqAsset(asset, xchainUtil.AssetETH)) {
574
- return new CryptoAmount(gasRateinETHWei.times(21000), xchainUtil.AssetETH);
581
+ if (xchainUtil.eqAsset(asset, xchainEthereum.AssetETH)) {
582
+ return new CryptoAmount(gasRateinETHWei.times(21000), xchainEthereum.AssetETH);
575
583
  }
576
584
  else {
577
- return new CryptoAmount(gasRateinETHWei.times(70000), xchainUtil.AssetETH);
585
+ return new CryptoAmount(gasRateinETHWei.times(70000), xchainEthereum.AssetETH);
578
586
  }
579
- case xchainUtil.Chain.Avalanche:
587
+ case xchainAvax.AVAXChain:
580
588
  const gasRateinAVAXGwei = inbound.gasRate;
581
589
  const gasRateinAVAXWei = xchainUtil.baseAmount(gasRateinAVAXGwei.multipliedBy(Math.pow(10, 9)), 18);
582
- if (xchainUtil.eqAsset(asset, xchainUtil.AssetAVAX)) {
583
- return new CryptoAmount(gasRateinAVAXWei.times(21000), xchainUtil.AssetAVAX);
590
+ if (xchainUtil.eqAsset(asset, xchainAvax.AssetAVAX)) {
591
+ return new CryptoAmount(gasRateinAVAXWei.times(21000), xchainAvax.AssetAVAX);
584
592
  }
585
593
  else {
586
- return new CryptoAmount(gasRateinAVAXWei.times(70000), xchainUtil.AssetAVAX);
594
+ return new CryptoAmount(gasRateinAVAXWei.times(70000), xchainAvax.AssetAVAX);
587
595
  }
588
- case xchainUtil.Chain.Cosmos:
589
- return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), xchainUtil.AssetAtom);
590
- case xchainUtil.Chain.THORChain:
591
- return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainUtil.AssetRuneNative);
596
+ case xchainCosmos.GAIAChain:
597
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate), xchainCosmos.AssetATOM);
598
+ case xchainThorchain.THORChain:
599
+ return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainThorchain.AssetRuneNative);
592
600
  }
593
601
  throw new Error(`could not calculate inbound fee for ${asset.chain}`);
594
602
  };
@@ -603,28 +611,28 @@ const calcNetworkFee = (asset, inbound) => {
603
611
  */
604
612
  const calcOutboundFee = (asset, inbound) => {
605
613
  if (asset.synth)
606
- return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainUtil.AssetRuneNative);
614
+ return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainThorchain.AssetRuneNative);
607
615
  switch (asset.chain) {
608
- case xchainUtil.Chain.Bitcoin:
609
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainUtil.AssetBTC);
610
- case xchainUtil.Chain.BitcoinCash:
611
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainUtil.AssetBCH);
612
- case xchainUtil.Chain.Litecoin:
613
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainUtil.AssetLTC);
614
- case xchainUtil.Chain.Doge:
616
+ case xchainBitcoin.BTCChain:
617
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainBitcoin.AssetBTC);
618
+ case xchainBitcoincash.BCHChain:
619
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainBitcoincash.AssetBCH);
620
+ case xchainLitecoin.LTCChain:
621
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainLitecoin.AssetLTC);
622
+ case xchainDoge.DOGEChain:
615
623
  // NOTE: UTXO chains estimate fees with a 250 byte size
616
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainUtil.AssetDOGE);
617
- case xchainUtil.Chain.Binance:
624
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainDoge.AssetDOGE);
625
+ case xchainBinance.BNBChain:
618
626
  //flat fee
619
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainUtil.AssetBNB);
620
- case xchainUtil.Chain.Ethereum:
621
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), xchainUtil.AssetETH);
622
- case xchainUtil.Chain.Avalanche:
623
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), xchainUtil.AssetAVAX);
624
- case xchainUtil.Chain.Cosmos:
625
- return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainUtil.AssetAtom);
626
- case xchainUtil.Chain.THORChain:
627
- return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainUtil.AssetRuneNative);
627
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainBinance.AssetBNB);
628
+ case xchainEthereum.ETHChain:
629
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), xchainEthereum.AssetETH);
630
+ case xchainAvax.AVAXChain:
631
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), xchainAvax.AssetAVAX);
632
+ case xchainCosmos.GAIAChain:
633
+ return new CryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), xchainCosmos.AssetATOM);
634
+ case xchainThorchain.THORChain:
635
+ return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainThorchain.AssetRuneNative);
628
636
  }
629
637
  throw new Error(`could not calculate outbound fee for ${asset.chain}`);
630
638
  };
@@ -635,24 +643,24 @@ const calcOutboundFee = (asset, inbound) => {
635
643
  */
636
644
  const getChainAsset = (chain) => {
637
645
  switch (chain) {
638
- case xchainUtil.BNBChain:
639
- return xchainUtil.AssetBNB;
640
- case xchainUtil.BTCChain:
641
- return xchainUtil.AssetBTC;
642
- case xchainUtil.ETHChain:
643
- return xchainUtil.AssetETH;
644
- case xchainUtil.THORChain:
645
- return xchainUtil.AssetRuneNative;
646
- case xchainUtil.CosmosChain:
647
- return xchainUtil.AssetAtom;
648
- case xchainUtil.BCHChain:
649
- return xchainUtil.AssetBCH;
650
- case xchainUtil.LTCChain:
651
- return xchainUtil.AssetLTC;
652
- case xchainUtil.DOGEChain:
653
- return xchainUtil.AssetDOGE;
654
- case xchainUtil.AvalancheChain:
655
- return xchainUtil.AssetAVAX;
646
+ case xchainBinance.BNBChain:
647
+ return xchainBinance.AssetBNB;
648
+ case xchainBitcoin.BTCChain:
649
+ return xchainBitcoin.AssetBTC;
650
+ case xchainEthereum.ETHChain:
651
+ return xchainEthereum.AssetETH;
652
+ case xchainThorchain.THORChain:
653
+ return xchainThorchain.AssetRuneNative;
654
+ case xchainCosmos.GAIAChain:
655
+ return xchainCosmos.AssetATOM;
656
+ case xchainBitcoincash.BCHChain:
657
+ return xchainBitcoincash.AssetBCH;
658
+ case xchainLitecoin.LTCChain:
659
+ return xchainLitecoin.AssetLTC;
660
+ case xchainDoge.DOGEChain:
661
+ return xchainDoge.AssetDOGE;
662
+ case xchainAvax.AVAXChain:
663
+ return xchainAvax.AssetAVAX;
656
664
  default:
657
665
  throw Error('Unknown chain');
658
666
  }
@@ -664,22 +672,24 @@ const getChainAsset = (chain) => {
664
672
  */
665
673
  const getChain = (chain) => {
666
674
  switch (chain) {
675
+ case 'AVAX':
676
+ return xchainAvax.AVAXChain;
667
677
  case 'BNB':
668
- return xchainUtil.BNBChain;
678
+ return xchainBinance.BNBChain;
669
679
  case 'BTC':
670
- return xchainUtil.BTCChain;
680
+ return xchainBitcoin.BTCChain;
671
681
  case 'ETH':
672
- return xchainUtil.ETHChain;
682
+ return xchainEthereum.ETHChain;
673
683
  case 'THOR':
674
- return xchainUtil.THORChain;
684
+ return xchainThorchain.THORChain;
675
685
  case 'GAIA':
676
- return xchainUtil.CosmosChain;
686
+ return xchainCosmos.GAIAChain;
677
687
  case 'BCH':
678
- return xchainUtil.BCHChain;
688
+ return xchainBitcoincash.BCHChain;
679
689
  case 'LTC':
680
- return xchainUtil.LTCChain;
690
+ return xchainLitecoin.LTCChain;
681
691
  case 'DOGE':
682
- return xchainUtil.DOGEChain;
692
+ return xchainDoge.DOGEChain;
683
693
  default:
684
694
  throw Error('Unknown chain');
685
695
  }
@@ -1001,12 +1011,12 @@ class ThorchainCache {
1001
1011
  if (xchainUtil.eqAsset(from, to)) {
1002
1012
  exchangeRate = SAME_ASSET_EXCHANGE_RATE;
1003
1013
  }
1004
- else if (xchainUtil.isAssetRuneNative(from)) {
1014
+ else if (xchainThorchain.isAssetRuneNative(from)) {
1005
1015
  // Runes per Asset
1006
1016
  const lpTo = yield this.getPoolForAsset(to);
1007
1017
  exchangeRate = lpTo.assetToRuneRatio;
1008
1018
  }
1009
- else if (xchainUtil.isAssetRuneNative(to)) {
1019
+ else if (xchainThorchain.isAssetRuneNative(to)) {
1010
1020
  // Asset per rune
1011
1021
  const lpFrom = yield this.getPoolForAsset(from);
1012
1022
  exchangeRate = lpFrom.runeToAssetRatio;
@@ -1030,7 +1040,7 @@ class ThorchainCache {
1030
1040
  */
1031
1041
  getPoolForAsset(asset) {
1032
1042
  return __awaiter(this, void 0, void 0, function* () {
1033
- if (xchainUtil.isAssetRuneNative(asset))
1043
+ if (xchainThorchain.isAssetRuneNative(asset))
1034
1044
  throw Error(`AssetRuneNative doesn't have a pool`);
1035
1045
  const pools = yield this.getPools();
1036
1046
  // Note: we use ticker, not asset string to get the same pool for both assets and synths
@@ -1132,7 +1142,7 @@ class ThorchainCache {
1132
1142
  }
1133
1143
  // add mock THORCHAIN inbound details
1134
1144
  const details = {
1135
- chain: xchainUtil.Chain.THORChain,
1145
+ chain: xchainThorchain.THORChain,
1136
1146
  address: '',
1137
1147
  router: '',
1138
1148
  gasRate: new bignumber_js.BigNumber(0),
@@ -1143,7 +1153,7 @@ class ThorchainCache {
1143
1153
  haltedTrading: !!mimirDetails['HALTTRADING'],
1144
1154
  haltedLP: false, //
1145
1155
  };
1146
- inboundDetails[xchainUtil.Chain.THORChain] = details;
1156
+ inboundDetails[xchainThorchain.THORChain] = details;
1147
1157
  this.inboundDetailCache = {
1148
1158
  lastRefreshed: Date.now(),
1149
1159
  inboundDetails,
@@ -1180,12 +1190,12 @@ class ThorchainCache {
1180
1190
  getExpectedSwapOutput(inputAmount, destinationAsset) {
1181
1191
  return __awaiter(this, void 0, void 0, function* () {
1182
1192
  let swapOutput;
1183
- if (xchainUtil.isAssetRuneNative(inputAmount.asset)) {
1193
+ if (xchainThorchain.isAssetRuneNative(inputAmount.asset)) {
1184
1194
  //singleswap from rune -> asset
1185
1195
  const pool = yield this.getPoolForAsset(destinationAsset);
1186
1196
  swapOutput = getSingleSwap(inputAmount, pool, false);
1187
1197
  }
1188
- else if (xchainUtil.isAssetRuneNative(destinationAsset)) {
1198
+ else if (xchainThorchain.isAssetRuneNative(destinationAsset)) {
1189
1199
  //singleswap from asset -> rune
1190
1200
  const pool = yield this.getPoolForAsset(inputAmount.asset);
1191
1201
  swapOutput = getSingleSwap(inputAmount, pool, true);
@@ -1228,7 +1238,7 @@ class ThorchainCache {
1228
1238
  }
1229
1239
  getDecimalForAsset(asset) {
1230
1240
  return __awaiter(this, void 0, void 0, function* () {
1231
- if (!xchainUtil.isAssetRuneNative(asset)) {
1241
+ if (!xchainThorchain.isAssetRuneNative(asset)) {
1232
1242
  const pool = yield this.getPoolForAsset(asset);
1233
1243
  const decimals = Number(pool.pool.nativeDecimal);
1234
1244
  if (decimals > 0)
@@ -1350,8 +1360,8 @@ const getPoolShare = (unitData, pool) => {
1350
1360
  const asset = T.times(units).div(total);
1351
1361
  const rune = R.times(units).div(total);
1352
1362
  const poolShareDetail = {
1353
- assetShare: new CryptoAmount(lib.baseAmount(asset), pool.asset),
1354
- runeShare: new CryptoAmount(lib.baseAmount(rune), lib.AssetRuneNative),
1363
+ assetShare: new CryptoAmount(xchainUtil.baseAmount(asset), pool.asset),
1364
+ runeShare: new CryptoAmount(xchainUtil.baseAmount(rune), xchainThorchain.AssetRuneNative),
1355
1365
  };
1356
1366
  return poolShareDetail;
1357
1367
  };
@@ -1400,7 +1410,7 @@ const getLiquidityProtectionData = (depositValue, poolShare, block) => {
1400
1410
  const result = coverage.times(protectionProgress); // impermanent loss protection result
1401
1411
  const maxILP = result.lt(0) ? new bignumber_js.BigNumber(0) : result; // max negative ILP to 0
1402
1412
  const ILProtection = {
1403
- ILProtection: new CryptoAmount(lib.baseAmount(maxILP), lib.AssetRuneNative),
1413
+ ILProtection: new CryptoAmount(xchainUtil.baseAmount(maxILP), xchainThorchain.AssetRuneNative),
1404
1414
  totalDays: (fractionOfFullILPProtection * 100).toFixed(2),
1405
1415
  };
1406
1416
  return ILProtection;
@@ -1518,7 +1528,7 @@ class ThorchainQuery {
1518
1528
  isValidSwap(params) {
1519
1529
  var _a, _b;
1520
1530
  return __awaiter(this, void 0, void 0, function* () {
1521
- if (xchainUtil.isAssetRuneNative(params.input.asset)) {
1531
+ if (xchainThorchain.isAssetRuneNative(params.input.asset)) {
1522
1532
  if (params.input.baseAmount.decimal !== 8)
1523
1533
  throw Error(`input asset ${xchainUtil.assetToString(params.input.asset)} must have decimals of 8`);
1524
1534
  }
@@ -1572,15 +1582,15 @@ class ThorchainQuery {
1572
1582
  const affiliateFeePercent = params.affiliateFeeBasisPoints ? params.affiliateFeeBasisPoints / 10000 : 0;
1573
1583
  const affiliateFeeInAsset = inputMinusInboundFeeInAsset.times(affiliateFeePercent);
1574
1584
  let affiliateFeeSwapOutputInRune;
1575
- if (xchainUtil.isAssetRuneNative(affiliateFeeInAsset.asset)) {
1585
+ if (xchainThorchain.isAssetRuneNative(affiliateFeeInAsset.asset)) {
1576
1586
  affiliateFeeSwapOutputInRune = {
1577
1587
  output: affiliateFeeInAsset,
1578
- swapFee: new CryptoAmount(xchainUtil.baseAmount(0), xchainUtil.AssetRuneNative),
1588
+ swapFee: new CryptoAmount(xchainUtil.baseAmount(0), xchainThorchain.AssetRuneNative),
1579
1589
  slip: new bignumber_js.BigNumber(0),
1580
1590
  };
1581
1591
  }
1582
1592
  else {
1583
- affiliateFeeSwapOutputInRune = yield this.thorchainCache.getExpectedSwapOutput(affiliateFeeInAsset, xchainUtil.AssetRuneNative);
1593
+ affiliateFeeSwapOutputInRune = yield this.thorchainCache.getExpectedSwapOutput(affiliateFeeInAsset, xchainThorchain.AssetRuneNative);
1584
1594
  }
1585
1595
  // remove the affiliate fee from the input.
1586
1596
  const inputNetInAsset = inputMinusInboundFeeInAsset.minus(affiliateFeeInAsset);
@@ -1610,7 +1620,7 @@ class ThorchainQuery {
1610
1620
  const contractAddress = xchainUtil.getContractAddressFromAsset(asset);
1611
1621
  if (contractAddress && contractAddress.length > 5) {
1612
1622
  const abrev = contractAddress.substring(contractAddress.length - 5);
1613
- const sep = asset.chain !== xchainUtil.Chain.THORChain && asset.synth ? '/' : '.';
1623
+ const sep = asset.chain !== xchainThorchain.THORChain && asset.synth ? '/' : '.';
1614
1624
  return `${asset.chain}${sep}${asset.ticker}-${abrev}`;
1615
1625
  }
1616
1626
  return xchainUtil.assetToString(asset);
@@ -1631,7 +1641,7 @@ class ThorchainQuery {
1631
1641
  memo = memo.concat(`:${params.affiliateAddress}:${params.affiliateFeeBasisPoints}`);
1632
1642
  }
1633
1643
  // If memo length is too long for BTC, trim it
1634
- if (xchainUtil.eqAsset(params.input.asset, xchainUtil.AssetBTC) && memo.length > 80) {
1644
+ if (xchainUtil.eqAsset(params.input.asset, xchainBitcoin.AssetBTC) && memo.length > 80) {
1635
1645
  memo = `=:${this.abbreviateAssetString(params.destinationAsset)}:${params.destinationAddress}:${lim}`;
1636
1646
  }
1637
1647
  return memo;
@@ -1641,7 +1651,7 @@ class ThorchainQuery {
1641
1651
  // private async validateAffiliateAddress(affiliateAddress: string) {
1642
1652
  // // Affiliate address should be THORName or THORAddress
1643
1653
  // if (affiliateAddress.length > 0) {
1644
- // const isValidThorchainAddress = this.clients[Chain.THORChain].validateAddress(affiliateAddress)
1654
+ // const isValidThorchainAddress = this.clients[THORChain].validateAddress(affiliateAddress)
1645
1655
  // const isValidThorname = await this.isThorname(affiliateAddress)
1646
1656
  // if (!(isValidThorchainAddress || isValidThorname))
1647
1657
  // throw Error(`affiliateAddress ${affiliateAddress} is not a valid THOR address`)
@@ -1669,12 +1679,12 @@ class ThorchainQuery {
1669
1679
  const errors = [];
1670
1680
  const sourceAsset = params.input.asset;
1671
1681
  const destAsset = params.destinationAsset;
1672
- if (!xchainUtil.isAssetRuneNative(sourceAsset)) {
1682
+ if (!xchainThorchain.isAssetRuneNative(sourceAsset)) {
1673
1683
  const sourcePool = yield this.thorchainCache.getPoolForAsset(sourceAsset);
1674
1684
  if (!sourcePool.isAvailable())
1675
1685
  errors.push(`sourceAsset ${sourceAsset.ticker} does not have a valid liquidity pool`);
1676
1686
  }
1677
- if (!xchainUtil.isAssetRuneNative(destAsset)) {
1687
+ if (!xchainThorchain.isAssetRuneNative(destAsset)) {
1678
1688
  const destPool = yield this.thorchainCache.getPoolForAsset(destAsset);
1679
1689
  if (!destPool.isAvailable())
1680
1690
  errors.push(`destinationAsset ${destAsset.ticker} does not have a valid liquidity pool`);
@@ -1708,8 +1718,8 @@ class ThorchainQuery {
1708
1718
  checkCoverFees(params, estimate) {
1709
1719
  return __awaiter(this, void 0, void 0, function* () {
1710
1720
  let result = undefined;
1711
- const inputInRune = yield this.thorchainCache.convert(params.input, xchainUtil.AssetRuneNative);
1712
- const feesInRune = yield this.getFeesIn(estimate.totalFees, xchainUtil.AssetRuneNative);
1721
+ const inputInRune = yield this.thorchainCache.convert(params.input, xchainThorchain.AssetRuneNative);
1722
+ const feesInRune = yield this.getFeesIn(estimate.totalFees, xchainThorchain.AssetRuneNative);
1713
1723
  const totalSwapFeesInRune = feesInRune.inboundFee
1714
1724
  .plus(feesInRune.outboundFee)
1715
1725
  .plus(feesInRune.swapFee)
@@ -1767,11 +1777,11 @@ class ThorchainQuery {
1767
1777
  confCounting(inbound) {
1768
1778
  return __awaiter(this, void 0, void 0, function* () {
1769
1779
  // RUNE, BNB and Synths have near instant finality, so no conf counting required. - need to make a BFT only case.
1770
- if (xchainUtil.isAssetRuneNative(inbound.asset) ||
1771
- inbound.asset.chain == xchainUtil.AssetBNB.chain ||
1772
- inbound.asset.chain == xchainUtil.AssetAtom.chain ||
1780
+ if (xchainThorchain.isAssetRuneNative(inbound.asset) ||
1781
+ inbound.asset.chain == xchainBinance.BNBChain ||
1782
+ inbound.asset.chain == xchainCosmos.GAIAChain ||
1773
1783
  inbound.asset.synth) {
1774
- return this.chainAttributes[xchainUtil.Chain.THORChain].avgBlockTimeInSecs;
1784
+ return this.chainAttributes[xchainThorchain.THORChain].avgBlockTimeInSecs;
1775
1785
  }
1776
1786
  // Get the gas asset for the inbound.asset.chain
1777
1787
  const chainGasAsset = getChainAsset(inbound.asset.chain);
@@ -1796,15 +1806,15 @@ class ThorchainQuery {
1796
1806
  outboundDelay(outboundAmount) {
1797
1807
  return __awaiter(this, void 0, void 0, function* () {
1798
1808
  const networkValues = yield this.thorchainCache.getNetworkValues();
1799
- const minTxOutVolumeThreshold = new CryptoAmount(xchainUtil.baseAmount(networkValues['MINTXOUTVOLUMETHRESHOLD']), xchainUtil.AssetRuneNative);
1809
+ const minTxOutVolumeThreshold = new CryptoAmount(xchainUtil.baseAmount(networkValues['MINTXOUTVOLUMETHRESHOLD']), xchainThorchain.AssetRuneNative);
1800
1810
  const maxTxOutOffset = networkValues['MAXTXOUTOFFSET'];
1801
- let txOutDelayRate = new CryptoAmount(xchainUtil.baseAmount(networkValues['TXOUTDELAYRATE']), xchainUtil.AssetRuneNative).assetAmount
1811
+ let txOutDelayRate = new CryptoAmount(xchainUtil.baseAmount(networkValues['TXOUTDELAYRATE']), xchainThorchain.AssetRuneNative).assetAmount
1802
1812
  .amount()
1803
1813
  .toNumber();
1804
1814
  const getScheduledOutboundValue = yield this.thorchainCache.midgard.getScheduledOutboundValue();
1805
- const thorChainblocktime = this.chainAttributes[xchainUtil.Chain.THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
1815
+ const thorChainblocktime = this.chainAttributes[xchainThorchain.THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
1806
1816
  // If asset is equal to Rune set runeValue as outbound amount else set it to the asset's value in rune
1807
- const runeValue = yield this.thorchainCache.convert(outboundAmount, xchainUtil.AssetRuneNative);
1817
+ const runeValue = yield this.thorchainCache.convert(outboundAmount, xchainThorchain.AssetRuneNative);
1808
1818
  // Check rune value amount
1809
1819
  if (runeValue.lt(minTxOutVolumeThreshold)) {
1810
1820
  return thorChainblocktime;
@@ -1835,7 +1845,7 @@ class ThorchainQuery {
1835
1845
  const errors = [];
1836
1846
  if (params.asset.asset.synth || params.rune.asset.synth)
1837
1847
  errors.push('you cannot add liquidity with a synth');
1838
- if (!xchainUtil.isAssetRuneNative(params.rune.asset))
1848
+ if (!xchainThorchain.isAssetRuneNative(params.rune.asset))
1839
1849
  errors.push('params.rune must be THOR.RUNE');
1840
1850
  const assetPool = yield this.thorchainCache.getPoolForAsset(params.asset.asset);
1841
1851
  const lpUnits = getLiquidityUnits({ asset: params.asset, rune: params.rune }, assetPool);
@@ -1849,7 +1859,7 @@ class ThorchainQuery {
1849
1859
  const runeWaitTimeSeconds = yield this.confCounting(params.rune);
1850
1860
  const waitTimeSeconds = assetWaitTimeSeconds > runeWaitTimeSeconds ? assetWaitTimeSeconds : runeWaitTimeSeconds;
1851
1861
  let assetInboundFee = new CryptoAmount(xchainUtil.baseAmount(0), params.asset.asset);
1852
- let runeInboundFee = new CryptoAmount(xchainUtil.baseAmount(0), xchainUtil.AssetRuneNative);
1862
+ let runeInboundFee = new CryptoAmount(xchainUtil.baseAmount(0), xchainThorchain.AssetRuneNative);
1853
1863
  if (!params.asset.assetAmount.eq(0)) {
1854
1864
  assetInboundFee = calcNetworkFee(params.asset.asset, inboundDetails[params.asset.asset.chain]);
1855
1865
  if (assetInboundFee.assetAmount.amount().times(3).gt(params.asset.assetAmount.amount()))
@@ -1860,7 +1870,7 @@ class ThorchainQuery {
1860
1870
  if (runeInboundFee.assetAmount.amount().times(3).gt(params.rune.assetAmount.amount()))
1861
1871
  errors.push(`Rune amount is less than fees`);
1862
1872
  }
1863
- const totalFees = (yield this.convert(assetInboundFee, xchainUtil.AssetRuneNative)).plus(runeInboundFee);
1873
+ const totalFees = (yield this.convert(assetInboundFee, xchainThorchain.AssetRuneNative)).plus(runeInboundFee);
1864
1874
  const slip = getSlipOnLiquidity({ asset: params.asset, rune: params.rune }, assetPool);
1865
1875
  const estimateLP = {
1866
1876
  assetPool: assetPool.pool.asset,
@@ -1990,9 +2000,9 @@ class ThorchainQuery {
1990
2000
  }
1991
2001
  const allInboundDetails = yield this.thorchainCache.getInboundDetails();
1992
2002
  const inboundDetails = allInboundDetails[params.asset.chain];
1993
- const runeInbound = calcNetworkFee(xchainUtil.AssetRuneNative, inboundDetails);
2003
+ const runeInbound = calcNetworkFee(xchainThorchain.AssetRuneNative, inboundDetails);
1994
2004
  const assetInbound = calcNetworkFee(params.asset, inboundDetails);
1995
- const runeOutbound = calcOutboundFee(xchainUtil.AssetRuneNative, inboundDetails);
2005
+ const runeOutbound = calcOutboundFee(xchainThorchain.AssetRuneNative, inboundDetails);
1996
2006
  const assetOutbound = calcOutboundFee(params.asset, inboundDetails);
1997
2007
  const estimateLP = {
1998
2008
  assetAddress: memberDetail.position.asset_address,
@@ -2002,18 +2012,18 @@ class ThorchainQuery {
2002
2012
  minToSend: {
2003
2013
  rune: dustValues.rune,
2004
2014
  asset: dustValues.asset,
2005
- total: (yield this.convert(dustValues.asset, xchainUtil.AssetRuneNative)).plus(dustValues.rune),
2015
+ total: (yield this.convert(dustValues.asset, xchainThorchain.AssetRuneNative)).plus(dustValues.rune),
2006
2016
  },
2007
2017
  fees: {
2008
2018
  rune: runeInbound,
2009
2019
  asset: assetInbound,
2010
- total: (yield this.convert(assetInbound, xchainUtil.AssetRuneNative)).plus(runeInbound),
2020
+ total: (yield this.convert(assetInbound, xchainThorchain.AssetRuneNative)).plus(runeInbound),
2011
2021
  },
2012
2022
  },
2013
2023
  outboundFee: {
2014
2024
  asset: assetOutbound,
2015
2025
  rune: runeOutbound,
2016
- total: (yield this.convert(assetOutbound, xchainUtil.AssetRuneNative)).plus(runeOutbound),
2026
+ total: (yield this.convert(assetOutbound, xchainThorchain.AssetRuneNative)).plus(runeOutbound),
2017
2027
  },
2018
2028
  assetAmount: poolShare.assetShare,
2019
2029
  runeAmount: poolShare.runeShare,
@@ -2036,8 +2046,8 @@ class ThorchainQuery {
2036
2046
  switch (asset.chain) {
2037
2047
  case 'BNB':
2038
2048
  dustValues = {
2039
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.000001)), xchainUtil.AssetBNB),
2040
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2049
+ asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.000001)), xchainBinance.AssetBNB),
2050
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2041
2051
  };
2042
2052
  return dustValues;
2043
2053
  case 'BTC':
@@ -2046,42 +2056,42 @@ class ThorchainQuery {
2046
2056
  // 10k sats
2047
2057
  dustValues = {
2048
2058
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.0001)), asset),
2049
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2059
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2050
2060
  };
2051
2061
  return dustValues;
2052
2062
  case 'ETH':
2053
2063
  // 0 wei
2054
2064
  dustValues = {
2055
2065
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
2056
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2066
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2057
2067
  };
2058
2068
  return dustValues;
2059
2069
  case 'THOR':
2060
2070
  // 0 Rune
2061
2071
  dustValues = {
2062
2072
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
2063
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2073
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2064
2074
  };
2065
2075
  return dustValues;
2066
2076
  case 'GAIA':
2067
2077
  // 0 GAIA
2068
2078
  dustValues = {
2069
2079
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
2070
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2080
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2071
2081
  };
2072
2082
  return dustValues;
2073
2083
  case 'DOGE':
2074
2084
  // 1 million sats
2075
2085
  dustValues = {
2076
2086
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.01)), asset),
2077
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2087
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2078
2088
  };
2079
2089
  return dustValues;
2080
2090
  case 'AVAX':
2081
2091
  // 0 AVAX
2082
2092
  dustValues = {
2083
2093
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
2084
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2094
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2085
2095
  };
2086
2096
  return dustValues;
2087
2097
  default:
@@ -2155,7 +2165,7 @@ class ThorchainQuery {
2155
2165
  */
2156
2166
  estimateWithdrawSaver(withdrawParams) {
2157
2167
  return __awaiter(this, void 0, void 0, function* () {
2158
- if (xchainUtil.isAssetRuneNative(withdrawParams.asset) || withdrawParams.asset.synth)
2168
+ if (xchainThorchain.isAssetRuneNative(withdrawParams.asset) || withdrawParams.asset.synth)
2159
2169
  throw Error(`Native Rune and synth assets are not supported only L1's`);
2160
2170
  const withdrawQuote = yield this.thorchainCache.thornode.getSaversWithdrawQuote(withdrawParams);
2161
2171
  if (!withdrawQuote.expected_amount_out)
@@ -2290,7 +2300,7 @@ class TransactionStage {
2290
2300
  case 1:
2291
2301
  if (((_b = (_a = txData.observed_tx) === null || _a === void 0 ? void 0 : _a.tx) === null || _b === void 0 ? void 0 : _b.chain) != undefined) {
2292
2302
  sourceChain = getChain(txData.observed_tx.tx.chain);
2293
- if (sourceChain == (xchainUtil.Chain.Bitcoin || xchainUtil.Chain.BitcoinCash || xchainUtil.Chain.Litecoin)) {
2303
+ if (sourceChain == (xchainBitcoin.BTCChain || xchainBitcoincash.BCHChain || xchainLitecoin.LTCChain)) {
2294
2304
  const lastBlockHeight = lastBlock.find((obj) => obj.chain === sourceChain);
2295
2305
  const checkConf = yield this.checkConfcounting(sourceChain, lastBlockHeight, txData.observed_tx);
2296
2306
  transactionProgress.seconds = checkConf.seconds;
@@ -2400,7 +2410,7 @@ class TransactionStage {
2400
2410
  else {
2401
2411
  if ((scheduledQueueItem === null || scheduledQueueItem === void 0 ? void 0 : scheduledQueueItem.height) && (lastBlockHeight === null || lastBlockHeight === void 0 ? void 0 : lastBlockHeight.thorchain)) {
2402
2412
  stageStatus.seconds =
2403
- (scheduledQueueItem.height - (lastBlockHeight === null || lastBlockHeight === void 0 ? void 0 : lastBlockHeight.thorchain)) * this.chainAttributes[xchainUtil.THORChain].avgBlockTimeInSecs;
2413
+ (scheduledQueueItem.height - (lastBlockHeight === null || lastBlockHeight === void 0 ? void 0 : lastBlockHeight.thorchain)) * this.chainAttributes[xchainThorchain.THORChain].avgBlockTimeInSecs;
2404
2414
  }
2405
2415
  }
2406
2416
  return stageStatus;
@@ -4,7 +4,7 @@ import { ChainAttributes, TransactionProgress } from './types';
4
4
  export declare class TransactionStage {
5
5
  readonly thorchainCache: ThorchainCache;
6
6
  private chainAttributes;
7
- constructor(thorchainCache: ThorchainCache, chainAttributes?: Record<Chain, ChainAttributes>);
7
+ constructor(thorchainCache: ThorchainCache, chainAttributes?: Record<string, ChainAttributes>);
8
8
  /**
9
9
  *
10
10
  * @param inboundTxHash - Input needed to determine the transaction stage
@@ -1,4 +1,4 @@
1
- import { Asset, Chain } from '@xchainjs/xchain-util';
1
+ import { Asset } from '@xchainjs/xchain-util';
2
2
  import { CryptoAmount } from './crypto-amount';
3
3
  import { ThorchainCache } from './thorchain-cache';
4
4
  import { AddliquidityPosition, ChainAttributes, EstimateAddLP, EstimateAddSaver, EstimateSwapParams, EstimateWithdrawLP, EstimateWithdrawSaver, LiquidityPosition, PoolRatios, SaversPosition, SaversWithdraw, TotalFees, TxDetails, WithdrawLiquidityPosition, getSaver } from './types';
@@ -17,7 +17,7 @@ export declare class ThorchainQuery {
17
17
  * @param chainAttributes - atrributes used to calculate waitTime & conf counting
18
18
  * @returns ThorchainAMM
19
19
  */
20
- constructor(thorchainCache?: ThorchainCache, chainAttributes?: Record<Chain, ChainAttributes>);
20
+ constructor(thorchainCache?: ThorchainCache, chainAttributes?: Record<string, ChainAttributes>);
21
21
  /**
22
22
  * Provides a swap estimate for the given swap detail. Will check the params for errors before trying to get the estimate.
23
23
  * Uses current pool data, works out inbound and outboud fee, affiliate fees and works out the expected wait time for the swap (in and out)
@@ -1,5 +1,5 @@
1
1
  import { Network } from '@xchainjs/xchain-client';
2
- import { InboundAddress, LastBlock, LiquidityProviderSummary, Pool, QuoteSaverDepositResponse, QuoteSaverWithdrawResponse, QuoteSwapResponse, SaverResponse, TxOutItem, TxResponse } from '@xchainjs/xchain-thornode';
2
+ import { InboundAddress, LastBlock, LiquidityProviderSummary, Pool, QuoteSaverDepositResponse, QuoteSaverWithdrawResponse, QuoteSwapResponse, Saver, SaversResponse, TxOutItem, TxResponse } from '@xchainjs/xchain-thornode';
3
3
  import { SaversWithdraw } from '../types';
4
4
  export declare type ThornodeConfig = {
5
5
  apiRetries: number;
@@ -63,14 +63,14 @@ export declare class Thornode {
63
63
  * @param height - optional thorchain block height parameter
64
64
  * @returns - Liquidity Provider Object
65
65
  */
66
- getSavers(asset: string, height?: number): Promise<SaverResponse>;
66
+ getSavers(asset: string, height?: number): Promise<SaversResponse>;
67
67
  /**
68
68
  *
69
69
  * @param asset - asset string
70
70
  * @param height - optional thorchain block height parameter
71
71
  * @returns - Liquidity Provider Object
72
72
  */
73
- getSaver(asset: string, address: string, height?: number): Promise<SaverResponse>;
73
+ getSaver(asset: string, address: string, height?: number): Promise<Saver>;
74
74
  /**
75
75
  *
76
76
  * @param asset - asset to add to savers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain-query",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "license": "MIT",
5
5
  "description": "Thorchain query module that is resposible for estimating swap calculations and add/remove liquidity for thorchain ",
6
6
  "keywords": [
@@ -33,20 +33,38 @@
33
33
  "postversion": "git push --follow-tags"
34
34
  },
35
35
  "devDependencies": {
36
- "@xchainjs/xchain-client": "^0.13.4",
36
+ "@xchainjs/xchain-avax": "^0.1.3",
37
+ "@xchainjs/xchain-binance": "^5.6.6",
38
+ "@xchainjs/xchain-bitcoin": "^0.20.7",
39
+ "@xchainjs/xchain-bitcoincash": "^0.15.6",
40
+ "@xchainjs/xchain-client": "^0.13.5",
41
+ "@xchainjs/xchain-cosmos": "^0.20.6",
42
+ "@xchainjs/xchain-doge": "^0.5.6",
43
+ "@xchainjs/xchain-ethereum": "^0.27.6",
44
+ "@xchainjs/xchain-litecoin": "^0.10.8",
37
45
  "@xchainjs/xchain-midgard": "^0.4.0",
38
- "@xchainjs/xchain-thornode": "^0.1.3",
39
- "@xchainjs/xchain-util": "^0.11.0",
46
+ "@xchainjs/xchain-thorchain": "^0.27.7",
47
+ "@xchainjs/xchain-thornode": "^0.2.0",
48
+ "@xchainjs/xchain-util": "^0.12.0",
40
49
  "axios": "^0.25.0",
41
50
  "axios-retry": "^3.2.5",
42
51
  "bignumber.js": "^9.0.0",
43
52
  "rimraf": "~3.0.2"
44
53
  },
45
54
  "peerDependencies": {
46
- "@xchainjs/xchain-client": "^0.13.4",
55
+ "@xchainjs/xchain-avax": "^0.1.3",
56
+ "@xchainjs/xchain-binance": "^5.6.6",
57
+ "@xchainjs/xchain-bitcoincash": "^0.15.6",
58
+ "@xchainjs/xchain-cosmos": "^0.20.6",
59
+ "@xchainjs/xchain-doge": "^0.5.6",
60
+ "@xchainjs/xchain-ethereum": "^0.27.6",
61
+ "@xchainjs/xchain-bitcoin": "^0.20.7",
62
+ "@xchainjs/xchain-litecoin": "^0.10.8",
63
+ "@xchainjs/xchain-client": "^0.13.5",
47
64
  "@xchainjs/xchain-midgard": "^0.4.1",
48
- "@xchainjs/xchain-thornode": "^0.1.5",
49
- "@xchainjs/xchain-util": "^0.11.1",
65
+ "@xchainjs/xchain-thorchain": "^0.27.7",
66
+ "@xchainjs/xchain-thornode": "^0.2.0",
67
+ "@xchainjs/xchain-util": "^0.12.0",
50
68
  "axios": "^0.25.0",
51
69
  "axios-retry": "^3.2.5",
52
70
  "bignumber.js": "^9.0.0",