@xchainjs/xchain-thorchain-query 0.1.11 → 0.1.12

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 BTCChain:
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');
@@ -664,7 +672,7 @@ const getChain = (chain) => {
664
672
  case 'THOR':
665
673
  return THORChain;
666
674
  case 'GAIA':
667
- return CosmosChain;
675
+ return GAIAChain;
668
676
  case 'BCH':
669
677
  return BCHChain;
670
678
  case 'LTC':
@@ -1123,7 +1131,7 @@ class ThorchainCache {
1123
1131
  }
1124
1132
  // add mock THORCHAIN inbound details
1125
1133
  const details = {
1126
- chain: Chain.THORChain,
1134
+ chain: THORChain,
1127
1135
  address: '',
1128
1136
  router: '',
1129
1137
  gasRate: new BigNumber(0),
@@ -1134,7 +1142,7 @@ class ThorchainCache {
1134
1142
  haltedTrading: !!mimirDetails['HALTTRADING'],
1135
1143
  haltedLP: false, //
1136
1144
  };
1137
- inboundDetails[Chain.THORChain] = details;
1145
+ inboundDetails[THORChain] = details;
1138
1146
  this.inboundDetailCache = {
1139
1147
  lastRefreshed: Date.now(),
1140
1148
  inboundDetails,
@@ -1341,8 +1349,8 @@ const getPoolShare = (unitData, pool) => {
1341
1349
  const asset = T.times(units).div(total);
1342
1350
  const rune = R.times(units).div(total);
1343
1351
  const poolShareDetail = {
1344
- assetShare: new CryptoAmount(baseAmount$1(asset), pool.asset),
1345
- runeShare: new CryptoAmount(baseAmount$1(rune), AssetRuneNative$1),
1352
+ assetShare: new CryptoAmount(baseAmount(asset), pool.asset),
1353
+ runeShare: new CryptoAmount(baseAmount(rune), AssetRuneNative),
1346
1354
  };
1347
1355
  return poolShareDetail;
1348
1356
  };
@@ -1391,7 +1399,7 @@ const getLiquidityProtectionData = (depositValue, poolShare, block) => {
1391
1399
  const result = coverage.times(protectionProgress); // impermanent loss protection result
1392
1400
  const maxILP = result.lt(0) ? new BigNumber(0) : result; // max negative ILP to 0
1393
1401
  const ILProtection = {
1394
- ILProtection: new CryptoAmount(baseAmount$1(maxILP), AssetRuneNative$1),
1402
+ ILProtection: new CryptoAmount(baseAmount(maxILP), AssetRuneNative),
1395
1403
  totalDays: (fractionOfFullILPProtection * 100).toFixed(2),
1396
1404
  };
1397
1405
  return ILProtection;
@@ -1601,7 +1609,7 @@ class ThorchainQuery {
1601
1609
  const contractAddress = getContractAddressFromAsset(asset);
1602
1610
  if (contractAddress && contractAddress.length > 5) {
1603
1611
  const abrev = contractAddress.substring(contractAddress.length - 5);
1604
- const sep = asset.chain !== Chain.THORChain && asset.synth ? '/' : '.';
1612
+ const sep = asset.chain !== THORChain && asset.synth ? '/' : '.';
1605
1613
  return `${asset.chain}${sep}${asset.ticker}-${abrev}`;
1606
1614
  }
1607
1615
  return assetToString(asset);
@@ -1632,7 +1640,7 @@ class ThorchainQuery {
1632
1640
  // private async validateAffiliateAddress(affiliateAddress: string) {
1633
1641
  // // Affiliate address should be THORName or THORAddress
1634
1642
  // if (affiliateAddress.length > 0) {
1635
- // const isValidThorchainAddress = this.clients[Chain.THORChain].validateAddress(affiliateAddress)
1643
+ // const isValidThorchainAddress = this.clients[THORChain].validateAddress(affiliateAddress)
1636
1644
  // const isValidThorname = await this.isThorname(affiliateAddress)
1637
1645
  // if (!(isValidThorchainAddress || isValidThorname))
1638
1646
  // throw Error(`affiliateAddress ${affiliateAddress} is not a valid THOR address`)
@@ -1759,10 +1767,10 @@ class ThorchainQuery {
1759
1767
  return __awaiter(this, void 0, void 0, function* () {
1760
1768
  // RUNE, BNB and Synths have near instant finality, so no conf counting required. - need to make a BFT only case.
1761
1769
  if (isAssetRuneNative(inbound.asset) ||
1762
- inbound.asset.chain == AssetBNB.chain ||
1763
- inbound.asset.chain == AssetAtom.chain ||
1770
+ inbound.asset.chain == BNBChain ||
1771
+ inbound.asset.chain == GAIAChain ||
1764
1772
  inbound.asset.synth) {
1765
- return this.chainAttributes[Chain.THORChain].avgBlockTimeInSecs;
1773
+ return this.chainAttributes[THORChain].avgBlockTimeInSecs;
1766
1774
  }
1767
1775
  // Get the gas asset for the inbound.asset.chain
1768
1776
  const chainGasAsset = getChainAsset(inbound.asset.chain);
@@ -1793,7 +1801,7 @@ class ThorchainQuery {
1793
1801
  .amount()
1794
1802
  .toNumber();
1795
1803
  const getScheduledOutboundValue = yield this.thorchainCache.midgard.getScheduledOutboundValue();
1796
- const thorChainblocktime = this.chainAttributes[Chain.THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
1804
+ const thorChainblocktime = this.chainAttributes[THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
1797
1805
  // If asset is equal to Rune set runeValue as outbound amount else set it to the asset's value in rune
1798
1806
  const runeValue = yield this.thorchainCache.convert(outboundAmount, AssetRuneNative);
1799
1807
  // Check rune value amount
@@ -2281,7 +2289,7 @@ class TransactionStage {
2281
2289
  case 1:
2282
2290
  if (((_b = (_a = txData.observed_tx) === null || _a === void 0 ? void 0 : _a.tx) === null || _b === void 0 ? void 0 : _b.chain) != undefined) {
2283
2291
  sourceChain = getChain(txData.observed_tx.tx.chain);
2284
- if (sourceChain == (Chain.Bitcoin || Chain.BitcoinCash || Chain.Litecoin)) {
2292
+ if (sourceChain == (BTCChain || BCHChain || LTCChain)) {
2285
2293
  const lastBlockHeight = lastBlock.find((obj) => obj.chain === sourceChain);
2286
2294
  const checkConf = yield this.checkConfcounting(sourceChain, lastBlockHeight, txData.observed_tx);
2287
2295
  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 xchainBitcoin.BTCChain:
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
  }
@@ -665,21 +673,21 @@ const getChainAsset = (chain) => {
665
673
  const getChain = (chain) => {
666
674
  switch (chain) {
667
675
  case 'BNB':
668
- return xchainUtil.BNBChain;
676
+ return xchainBinance.BNBChain;
669
677
  case 'BTC':
670
- return xchainUtil.BTCChain;
678
+ return xchainBitcoin.BTCChain;
671
679
  case 'ETH':
672
- return xchainUtil.ETHChain;
680
+ return xchainEthereum.ETHChain;
673
681
  case 'THOR':
674
- return xchainUtil.THORChain;
682
+ return xchainThorchain.THORChain;
675
683
  case 'GAIA':
676
- return xchainUtil.CosmosChain;
684
+ return xchainCosmos.GAIAChain;
677
685
  case 'BCH':
678
- return xchainUtil.BCHChain;
686
+ return xchainBitcoincash.BCHChain;
679
687
  case 'LTC':
680
- return xchainUtil.LTCChain;
688
+ return xchainLitecoin.LTCChain;
681
689
  case 'DOGE':
682
- return xchainUtil.DOGEChain;
690
+ return xchainDoge.DOGEChain;
683
691
  default:
684
692
  throw Error('Unknown chain');
685
693
  }
@@ -1001,12 +1009,12 @@ class ThorchainCache {
1001
1009
  if (xchainUtil.eqAsset(from, to)) {
1002
1010
  exchangeRate = SAME_ASSET_EXCHANGE_RATE;
1003
1011
  }
1004
- else if (xchainUtil.isAssetRuneNative(from)) {
1012
+ else if (xchainThorchain.isAssetRuneNative(from)) {
1005
1013
  // Runes per Asset
1006
1014
  const lpTo = yield this.getPoolForAsset(to);
1007
1015
  exchangeRate = lpTo.assetToRuneRatio;
1008
1016
  }
1009
- else if (xchainUtil.isAssetRuneNative(to)) {
1017
+ else if (xchainThorchain.isAssetRuneNative(to)) {
1010
1018
  // Asset per rune
1011
1019
  const lpFrom = yield this.getPoolForAsset(from);
1012
1020
  exchangeRate = lpFrom.runeToAssetRatio;
@@ -1030,7 +1038,7 @@ class ThorchainCache {
1030
1038
  */
1031
1039
  getPoolForAsset(asset) {
1032
1040
  return __awaiter(this, void 0, void 0, function* () {
1033
- if (xchainUtil.isAssetRuneNative(asset))
1041
+ if (xchainThorchain.isAssetRuneNative(asset))
1034
1042
  throw Error(`AssetRuneNative doesn't have a pool`);
1035
1043
  const pools = yield this.getPools();
1036
1044
  // Note: we use ticker, not asset string to get the same pool for both assets and synths
@@ -1132,7 +1140,7 @@ class ThorchainCache {
1132
1140
  }
1133
1141
  // add mock THORCHAIN inbound details
1134
1142
  const details = {
1135
- chain: xchainUtil.Chain.THORChain,
1143
+ chain: xchainThorchain.THORChain,
1136
1144
  address: '',
1137
1145
  router: '',
1138
1146
  gasRate: new bignumber_js.BigNumber(0),
@@ -1143,7 +1151,7 @@ class ThorchainCache {
1143
1151
  haltedTrading: !!mimirDetails['HALTTRADING'],
1144
1152
  haltedLP: false, //
1145
1153
  };
1146
- inboundDetails[xchainUtil.Chain.THORChain] = details;
1154
+ inboundDetails[xchainThorchain.THORChain] = details;
1147
1155
  this.inboundDetailCache = {
1148
1156
  lastRefreshed: Date.now(),
1149
1157
  inboundDetails,
@@ -1180,12 +1188,12 @@ class ThorchainCache {
1180
1188
  getExpectedSwapOutput(inputAmount, destinationAsset) {
1181
1189
  return __awaiter(this, void 0, void 0, function* () {
1182
1190
  let swapOutput;
1183
- if (xchainUtil.isAssetRuneNative(inputAmount.asset)) {
1191
+ if (xchainThorchain.isAssetRuneNative(inputAmount.asset)) {
1184
1192
  //singleswap from rune -> asset
1185
1193
  const pool = yield this.getPoolForAsset(destinationAsset);
1186
1194
  swapOutput = getSingleSwap(inputAmount, pool, false);
1187
1195
  }
1188
- else if (xchainUtil.isAssetRuneNative(destinationAsset)) {
1196
+ else if (xchainThorchain.isAssetRuneNative(destinationAsset)) {
1189
1197
  //singleswap from asset -> rune
1190
1198
  const pool = yield this.getPoolForAsset(inputAmount.asset);
1191
1199
  swapOutput = getSingleSwap(inputAmount, pool, true);
@@ -1228,7 +1236,7 @@ class ThorchainCache {
1228
1236
  }
1229
1237
  getDecimalForAsset(asset) {
1230
1238
  return __awaiter(this, void 0, void 0, function* () {
1231
- if (!xchainUtil.isAssetRuneNative(asset)) {
1239
+ if (!xchainThorchain.isAssetRuneNative(asset)) {
1232
1240
  const pool = yield this.getPoolForAsset(asset);
1233
1241
  const decimals = Number(pool.pool.nativeDecimal);
1234
1242
  if (decimals > 0)
@@ -1350,8 +1358,8 @@ const getPoolShare = (unitData, pool) => {
1350
1358
  const asset = T.times(units).div(total);
1351
1359
  const rune = R.times(units).div(total);
1352
1360
  const poolShareDetail = {
1353
- assetShare: new CryptoAmount(lib.baseAmount(asset), pool.asset),
1354
- runeShare: new CryptoAmount(lib.baseAmount(rune), lib.AssetRuneNative),
1361
+ assetShare: new CryptoAmount(xchainUtil.baseAmount(asset), pool.asset),
1362
+ runeShare: new CryptoAmount(xchainUtil.baseAmount(rune), xchainThorchain.AssetRuneNative),
1355
1363
  };
1356
1364
  return poolShareDetail;
1357
1365
  };
@@ -1400,7 +1408,7 @@ const getLiquidityProtectionData = (depositValue, poolShare, block) => {
1400
1408
  const result = coverage.times(protectionProgress); // impermanent loss protection result
1401
1409
  const maxILP = result.lt(0) ? new bignumber_js.BigNumber(0) : result; // max negative ILP to 0
1402
1410
  const ILProtection = {
1403
- ILProtection: new CryptoAmount(lib.baseAmount(maxILP), lib.AssetRuneNative),
1411
+ ILProtection: new CryptoAmount(xchainUtil.baseAmount(maxILP), xchainThorchain.AssetRuneNative),
1404
1412
  totalDays: (fractionOfFullILPProtection * 100).toFixed(2),
1405
1413
  };
1406
1414
  return ILProtection;
@@ -1518,7 +1526,7 @@ class ThorchainQuery {
1518
1526
  isValidSwap(params) {
1519
1527
  var _a, _b;
1520
1528
  return __awaiter(this, void 0, void 0, function* () {
1521
- if (xchainUtil.isAssetRuneNative(params.input.asset)) {
1529
+ if (xchainThorchain.isAssetRuneNative(params.input.asset)) {
1522
1530
  if (params.input.baseAmount.decimal !== 8)
1523
1531
  throw Error(`input asset ${xchainUtil.assetToString(params.input.asset)} must have decimals of 8`);
1524
1532
  }
@@ -1572,15 +1580,15 @@ class ThorchainQuery {
1572
1580
  const affiliateFeePercent = params.affiliateFeeBasisPoints ? params.affiliateFeeBasisPoints / 10000 : 0;
1573
1581
  const affiliateFeeInAsset = inputMinusInboundFeeInAsset.times(affiliateFeePercent);
1574
1582
  let affiliateFeeSwapOutputInRune;
1575
- if (xchainUtil.isAssetRuneNative(affiliateFeeInAsset.asset)) {
1583
+ if (xchainThorchain.isAssetRuneNative(affiliateFeeInAsset.asset)) {
1576
1584
  affiliateFeeSwapOutputInRune = {
1577
1585
  output: affiliateFeeInAsset,
1578
- swapFee: new CryptoAmount(xchainUtil.baseAmount(0), xchainUtil.AssetRuneNative),
1586
+ swapFee: new CryptoAmount(xchainUtil.baseAmount(0), xchainThorchain.AssetRuneNative),
1579
1587
  slip: new bignumber_js.BigNumber(0),
1580
1588
  };
1581
1589
  }
1582
1590
  else {
1583
- affiliateFeeSwapOutputInRune = yield this.thorchainCache.getExpectedSwapOutput(affiliateFeeInAsset, xchainUtil.AssetRuneNative);
1591
+ affiliateFeeSwapOutputInRune = yield this.thorchainCache.getExpectedSwapOutput(affiliateFeeInAsset, xchainThorchain.AssetRuneNative);
1584
1592
  }
1585
1593
  // remove the affiliate fee from the input.
1586
1594
  const inputNetInAsset = inputMinusInboundFeeInAsset.minus(affiliateFeeInAsset);
@@ -1610,7 +1618,7 @@ class ThorchainQuery {
1610
1618
  const contractAddress = xchainUtil.getContractAddressFromAsset(asset);
1611
1619
  if (contractAddress && contractAddress.length > 5) {
1612
1620
  const abrev = contractAddress.substring(contractAddress.length - 5);
1613
- const sep = asset.chain !== xchainUtil.Chain.THORChain && asset.synth ? '/' : '.';
1621
+ const sep = asset.chain !== xchainThorchain.THORChain && asset.synth ? '/' : '.';
1614
1622
  return `${asset.chain}${sep}${asset.ticker}-${abrev}`;
1615
1623
  }
1616
1624
  return xchainUtil.assetToString(asset);
@@ -1631,7 +1639,7 @@ class ThorchainQuery {
1631
1639
  memo = memo.concat(`:${params.affiliateAddress}:${params.affiliateFeeBasisPoints}`);
1632
1640
  }
1633
1641
  // If memo length is too long for BTC, trim it
1634
- if (xchainUtil.eqAsset(params.input.asset, xchainUtil.AssetBTC) && memo.length > 80) {
1642
+ if (xchainUtil.eqAsset(params.input.asset, xchainBitcoin.AssetBTC) && memo.length > 80) {
1635
1643
  memo = `=:${this.abbreviateAssetString(params.destinationAsset)}:${params.destinationAddress}:${lim}`;
1636
1644
  }
1637
1645
  return memo;
@@ -1641,7 +1649,7 @@ class ThorchainQuery {
1641
1649
  // private async validateAffiliateAddress(affiliateAddress: string) {
1642
1650
  // // Affiliate address should be THORName or THORAddress
1643
1651
  // if (affiliateAddress.length > 0) {
1644
- // const isValidThorchainAddress = this.clients[Chain.THORChain].validateAddress(affiliateAddress)
1652
+ // const isValidThorchainAddress = this.clients[THORChain].validateAddress(affiliateAddress)
1645
1653
  // const isValidThorname = await this.isThorname(affiliateAddress)
1646
1654
  // if (!(isValidThorchainAddress || isValidThorname))
1647
1655
  // throw Error(`affiliateAddress ${affiliateAddress} is not a valid THOR address`)
@@ -1669,12 +1677,12 @@ class ThorchainQuery {
1669
1677
  const errors = [];
1670
1678
  const sourceAsset = params.input.asset;
1671
1679
  const destAsset = params.destinationAsset;
1672
- if (!xchainUtil.isAssetRuneNative(sourceAsset)) {
1680
+ if (!xchainThorchain.isAssetRuneNative(sourceAsset)) {
1673
1681
  const sourcePool = yield this.thorchainCache.getPoolForAsset(sourceAsset);
1674
1682
  if (!sourcePool.isAvailable())
1675
1683
  errors.push(`sourceAsset ${sourceAsset.ticker} does not have a valid liquidity pool`);
1676
1684
  }
1677
- if (!xchainUtil.isAssetRuneNative(destAsset)) {
1685
+ if (!xchainThorchain.isAssetRuneNative(destAsset)) {
1678
1686
  const destPool = yield this.thorchainCache.getPoolForAsset(destAsset);
1679
1687
  if (!destPool.isAvailable())
1680
1688
  errors.push(`destinationAsset ${destAsset.ticker} does not have a valid liquidity pool`);
@@ -1708,8 +1716,8 @@ class ThorchainQuery {
1708
1716
  checkCoverFees(params, estimate) {
1709
1717
  return __awaiter(this, void 0, void 0, function* () {
1710
1718
  let result = undefined;
1711
- const inputInRune = yield this.thorchainCache.convert(params.input, xchainUtil.AssetRuneNative);
1712
- const feesInRune = yield this.getFeesIn(estimate.totalFees, xchainUtil.AssetRuneNative);
1719
+ const inputInRune = yield this.thorchainCache.convert(params.input, xchainThorchain.AssetRuneNative);
1720
+ const feesInRune = yield this.getFeesIn(estimate.totalFees, xchainThorchain.AssetRuneNative);
1713
1721
  const totalSwapFeesInRune = feesInRune.inboundFee
1714
1722
  .plus(feesInRune.outboundFee)
1715
1723
  .plus(feesInRune.swapFee)
@@ -1767,11 +1775,11 @@ class ThorchainQuery {
1767
1775
  confCounting(inbound) {
1768
1776
  return __awaiter(this, void 0, void 0, function* () {
1769
1777
  // 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 ||
1778
+ if (xchainThorchain.isAssetRuneNative(inbound.asset) ||
1779
+ inbound.asset.chain == xchainBinance.BNBChain ||
1780
+ inbound.asset.chain == xchainCosmos.GAIAChain ||
1773
1781
  inbound.asset.synth) {
1774
- return this.chainAttributes[xchainUtil.Chain.THORChain].avgBlockTimeInSecs;
1782
+ return this.chainAttributes[xchainThorchain.THORChain].avgBlockTimeInSecs;
1775
1783
  }
1776
1784
  // Get the gas asset for the inbound.asset.chain
1777
1785
  const chainGasAsset = getChainAsset(inbound.asset.chain);
@@ -1796,15 +1804,15 @@ class ThorchainQuery {
1796
1804
  outboundDelay(outboundAmount) {
1797
1805
  return __awaiter(this, void 0, void 0, function* () {
1798
1806
  const networkValues = yield this.thorchainCache.getNetworkValues();
1799
- const minTxOutVolumeThreshold = new CryptoAmount(xchainUtil.baseAmount(networkValues['MINTXOUTVOLUMETHRESHOLD']), xchainUtil.AssetRuneNative);
1807
+ const minTxOutVolumeThreshold = new CryptoAmount(xchainUtil.baseAmount(networkValues['MINTXOUTVOLUMETHRESHOLD']), xchainThorchain.AssetRuneNative);
1800
1808
  const maxTxOutOffset = networkValues['MAXTXOUTOFFSET'];
1801
- let txOutDelayRate = new CryptoAmount(xchainUtil.baseAmount(networkValues['TXOUTDELAYRATE']), xchainUtil.AssetRuneNative).assetAmount
1809
+ let txOutDelayRate = new CryptoAmount(xchainUtil.baseAmount(networkValues['TXOUTDELAYRATE']), xchainThorchain.AssetRuneNative).assetAmount
1802
1810
  .amount()
1803
1811
  .toNumber();
1804
1812
  const getScheduledOutboundValue = yield this.thorchainCache.midgard.getScheduledOutboundValue();
1805
- const thorChainblocktime = this.chainAttributes[xchainUtil.Chain.THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
1813
+ const thorChainblocktime = this.chainAttributes[xchainThorchain.THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
1806
1814
  // 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);
1815
+ const runeValue = yield this.thorchainCache.convert(outboundAmount, xchainThorchain.AssetRuneNative);
1808
1816
  // Check rune value amount
1809
1817
  if (runeValue.lt(minTxOutVolumeThreshold)) {
1810
1818
  return thorChainblocktime;
@@ -1835,7 +1843,7 @@ class ThorchainQuery {
1835
1843
  const errors = [];
1836
1844
  if (params.asset.asset.synth || params.rune.asset.synth)
1837
1845
  errors.push('you cannot add liquidity with a synth');
1838
- if (!xchainUtil.isAssetRuneNative(params.rune.asset))
1846
+ if (!xchainThorchain.isAssetRuneNative(params.rune.asset))
1839
1847
  errors.push('params.rune must be THOR.RUNE');
1840
1848
  const assetPool = yield this.thorchainCache.getPoolForAsset(params.asset.asset);
1841
1849
  const lpUnits = getLiquidityUnits({ asset: params.asset, rune: params.rune }, assetPool);
@@ -1849,7 +1857,7 @@ class ThorchainQuery {
1849
1857
  const runeWaitTimeSeconds = yield this.confCounting(params.rune);
1850
1858
  const waitTimeSeconds = assetWaitTimeSeconds > runeWaitTimeSeconds ? assetWaitTimeSeconds : runeWaitTimeSeconds;
1851
1859
  let assetInboundFee = new CryptoAmount(xchainUtil.baseAmount(0), params.asset.asset);
1852
- let runeInboundFee = new CryptoAmount(xchainUtil.baseAmount(0), xchainUtil.AssetRuneNative);
1860
+ let runeInboundFee = new CryptoAmount(xchainUtil.baseAmount(0), xchainThorchain.AssetRuneNative);
1853
1861
  if (!params.asset.assetAmount.eq(0)) {
1854
1862
  assetInboundFee = calcNetworkFee(params.asset.asset, inboundDetails[params.asset.asset.chain]);
1855
1863
  if (assetInboundFee.assetAmount.amount().times(3).gt(params.asset.assetAmount.amount()))
@@ -1860,7 +1868,7 @@ class ThorchainQuery {
1860
1868
  if (runeInboundFee.assetAmount.amount().times(3).gt(params.rune.assetAmount.amount()))
1861
1869
  errors.push(`Rune amount is less than fees`);
1862
1870
  }
1863
- const totalFees = (yield this.convert(assetInboundFee, xchainUtil.AssetRuneNative)).plus(runeInboundFee);
1871
+ const totalFees = (yield this.convert(assetInboundFee, xchainThorchain.AssetRuneNative)).plus(runeInboundFee);
1864
1872
  const slip = getSlipOnLiquidity({ asset: params.asset, rune: params.rune }, assetPool);
1865
1873
  const estimateLP = {
1866
1874
  assetPool: assetPool.pool.asset,
@@ -1990,9 +1998,9 @@ class ThorchainQuery {
1990
1998
  }
1991
1999
  const allInboundDetails = yield this.thorchainCache.getInboundDetails();
1992
2000
  const inboundDetails = allInboundDetails[params.asset.chain];
1993
- const runeInbound = calcNetworkFee(xchainUtil.AssetRuneNative, inboundDetails);
2001
+ const runeInbound = calcNetworkFee(xchainThorchain.AssetRuneNative, inboundDetails);
1994
2002
  const assetInbound = calcNetworkFee(params.asset, inboundDetails);
1995
- const runeOutbound = calcOutboundFee(xchainUtil.AssetRuneNative, inboundDetails);
2003
+ const runeOutbound = calcOutboundFee(xchainThorchain.AssetRuneNative, inboundDetails);
1996
2004
  const assetOutbound = calcOutboundFee(params.asset, inboundDetails);
1997
2005
  const estimateLP = {
1998
2006
  assetAddress: memberDetail.position.asset_address,
@@ -2002,18 +2010,18 @@ class ThorchainQuery {
2002
2010
  minToSend: {
2003
2011
  rune: dustValues.rune,
2004
2012
  asset: dustValues.asset,
2005
- total: (yield this.convert(dustValues.asset, xchainUtil.AssetRuneNative)).plus(dustValues.rune),
2013
+ total: (yield this.convert(dustValues.asset, xchainThorchain.AssetRuneNative)).plus(dustValues.rune),
2006
2014
  },
2007
2015
  fees: {
2008
2016
  rune: runeInbound,
2009
2017
  asset: assetInbound,
2010
- total: (yield this.convert(assetInbound, xchainUtil.AssetRuneNative)).plus(runeInbound),
2018
+ total: (yield this.convert(assetInbound, xchainThorchain.AssetRuneNative)).plus(runeInbound),
2011
2019
  },
2012
2020
  },
2013
2021
  outboundFee: {
2014
2022
  asset: assetOutbound,
2015
2023
  rune: runeOutbound,
2016
- total: (yield this.convert(assetOutbound, xchainUtil.AssetRuneNative)).plus(runeOutbound),
2024
+ total: (yield this.convert(assetOutbound, xchainThorchain.AssetRuneNative)).plus(runeOutbound),
2017
2025
  },
2018
2026
  assetAmount: poolShare.assetShare,
2019
2027
  runeAmount: poolShare.runeShare,
@@ -2036,8 +2044,8 @@ class ThorchainQuery {
2036
2044
  switch (asset.chain) {
2037
2045
  case 'BNB':
2038
2046
  dustValues = {
2039
- asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.000001)), xchainUtil.AssetBNB),
2040
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2047
+ asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.000001)), xchainBinance.AssetBNB),
2048
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2041
2049
  };
2042
2050
  return dustValues;
2043
2051
  case 'BTC':
@@ -2046,42 +2054,42 @@ class ThorchainQuery {
2046
2054
  // 10k sats
2047
2055
  dustValues = {
2048
2056
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.0001)), asset),
2049
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2057
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2050
2058
  };
2051
2059
  return dustValues;
2052
2060
  case 'ETH':
2053
2061
  // 0 wei
2054
2062
  dustValues = {
2055
2063
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
2056
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2064
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2057
2065
  };
2058
2066
  return dustValues;
2059
2067
  case 'THOR':
2060
2068
  // 0 Rune
2061
2069
  dustValues = {
2062
2070
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
2063
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2071
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2064
2072
  };
2065
2073
  return dustValues;
2066
2074
  case 'GAIA':
2067
2075
  // 0 GAIA
2068
2076
  dustValues = {
2069
2077
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
2070
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2078
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2071
2079
  };
2072
2080
  return dustValues;
2073
2081
  case 'DOGE':
2074
2082
  // 1 million sats
2075
2083
  dustValues = {
2076
2084
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0.01)), asset),
2077
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2085
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2078
2086
  };
2079
2087
  return dustValues;
2080
2088
  case 'AVAX':
2081
2089
  // 0 AVAX
2082
2090
  dustValues = {
2083
2091
  asset: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), asset),
2084
- rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainUtil.AssetRuneNative),
2092
+ rune: new CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), xchainThorchain.AssetRuneNative),
2085
2093
  };
2086
2094
  return dustValues;
2087
2095
  default:
@@ -2155,7 +2163,7 @@ class ThorchainQuery {
2155
2163
  */
2156
2164
  estimateWithdrawSaver(withdrawParams) {
2157
2165
  return __awaiter(this, void 0, void 0, function* () {
2158
- if (xchainUtil.isAssetRuneNative(withdrawParams.asset) || withdrawParams.asset.synth)
2166
+ if (xchainThorchain.isAssetRuneNative(withdrawParams.asset) || withdrawParams.asset.synth)
2159
2167
  throw Error(`Native Rune and synth assets are not supported only L1's`);
2160
2168
  const withdrawQuote = yield this.thorchainCache.thornode.getSaversWithdrawQuote(withdrawParams);
2161
2169
  if (!withdrawQuote.expected_amount_out)
@@ -2290,7 +2298,7 @@ class TransactionStage {
2290
2298
  case 1:
2291
2299
  if (((_b = (_a = txData.observed_tx) === null || _a === void 0 ? void 0 : _a.tx) === null || _b === void 0 ? void 0 : _b.chain) != undefined) {
2292
2300
  sourceChain = getChain(txData.observed_tx.tx.chain);
2293
- if (sourceChain == (xchainUtil.Chain.Bitcoin || xchainUtil.Chain.BitcoinCash || xchainUtil.Chain.Litecoin)) {
2301
+ if (sourceChain == (xchainBitcoin.BTCChain || xchainBitcoincash.BCHChain || xchainLitecoin.LTCChain)) {
2294
2302
  const lastBlockHeight = lastBlock.find((obj) => obj.chain === sourceChain);
2295
2303
  const checkConf = yield this.checkConfcounting(sourceChain, lastBlockHeight, txData.observed_tx);
2296
2304
  transactionProgress.seconds = checkConf.seconds;
@@ -2400,7 +2408,7 @@ class TransactionStage {
2400
2408
  else {
2401
2409
  if ((scheduledQueueItem === null || scheduledQueueItem === void 0 ? void 0 : scheduledQueueItem.height) && (lastBlockHeight === null || lastBlockHeight === void 0 ? void 0 : lastBlockHeight.thorchain)) {
2402
2410
  stageStatus.seconds =
2403
- (scheduledQueueItem.height - (lastBlockHeight === null || lastBlockHeight === void 0 ? void 0 : lastBlockHeight.thorchain)) * this.chainAttributes[xchainUtil.THORChain].avgBlockTimeInSecs;
2411
+ (scheduledQueueItem.height - (lastBlockHeight === null || lastBlockHeight === void 0 ? void 0 : lastBlockHeight.thorchain)) * this.chainAttributes[xchainThorchain.THORChain].avgBlockTimeInSecs;
2404
2412
  }
2405
2413
  }
2406
2414
  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)
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.12",
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",
46
+ "@xchainjs/xchain-thorchain": "^0.27.7",
38
47
  "@xchainjs/xchain-thornode": "^0.1.3",
39
- "@xchainjs/xchain-util": "^0.11.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",
65
+ "@xchainjs/xchain-thorchain": "^0.27.7",
48
66
  "@xchainjs/xchain-thornode": "^0.1.5",
49
- "@xchainjs/xchain-util": "^0.11.1",
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",