@xchainjs/xchain-thorchain-amm 0.1.0-alpha → 0.1.0-alpha2

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Modules
4
4
 
5
- module for to interact with Thorchain AMM
5
+ Thorchain AMM module
6
6
 
7
7
 
8
8
  ## Installation
package/lib/index.esm.js CHANGED
@@ -674,7 +674,6 @@ class Midgard {
674
674
  throw Error(`Could not find network value name`);
675
675
  }
676
676
  }
677
- console.log(retVal);
678
677
  return retVal;
679
678
  });
680
679
  }
@@ -697,6 +696,25 @@ class Midgard {
697
696
  throw Error(`Midgard not responding`);
698
697
  });
699
698
  }
699
+ /**
700
+ * Gets actions related to a txID
701
+ * @param txHash transaction id
702
+ * @returns Type Action array of objects
703
+ */
704
+ getActions(txHash) {
705
+ return __awaiter(this, void 0, void 0, function* () {
706
+ for (const api of this.midgardApis) {
707
+ try {
708
+ const actions = (yield api.getActions('', txHash)).data.actions;
709
+ return actions;
710
+ }
711
+ catch (e) {
712
+ console.error(e);
713
+ }
714
+ }
715
+ throw Error(`Midgard not responding`);
716
+ });
717
+ }
700
718
  }
701
719
 
702
720
  /**
@@ -831,23 +849,23 @@ const calcNetworkFee = (asset, gasRate) => {
831
849
  return new CryptoAmount(baseAmount(2000000), AssetRuneNative);
832
850
  switch (asset.chain) {
833
851
  case Chain.Bitcoin:
834
- return new CryptoAmount(baseAmount(gasRate.multipliedBy(250)), AssetBTC);
852
+ return new CryptoAmount(baseAmount(gasRate.multipliedBy(1000)), AssetBTC);
835
853
  case Chain.BitcoinCash:
836
- return new CryptoAmount(baseAmount(gasRate.multipliedBy(250)), AssetBCH);
854
+ return new CryptoAmount(baseAmount(gasRate.multipliedBy(1500)), AssetBCH);
837
855
  case Chain.Litecoin:
838
856
  return new CryptoAmount(baseAmount(gasRate.multipliedBy(250)), AssetLTC);
839
857
  case Chain.Doge:
840
858
  // NOTE: UTXO chains estimate fees with a 250 byte size
841
- return new CryptoAmount(baseAmount(gasRate.multipliedBy(250)), AssetDOGE);
859
+ return new CryptoAmount(baseAmount(gasRate.multipliedBy(1000)), AssetDOGE);
842
860
  case Chain.Binance:
843
861
  //flat fee
844
862
  return new CryptoAmount(baseAmount(gasRate), AssetBNB);
845
863
  case Chain.Ethereum:
846
864
  if (eqAsset(asset, AssetETH)) {
847
- return new CryptoAmount(baseAmount(gasRate.multipliedBy(35000)), AssetETH);
865
+ return new CryptoAmount(baseAmount(gasRate.multipliedBy(80000)), AssetETH);
848
866
  }
849
867
  else {
850
- return new CryptoAmount(baseAmount(gasRate.multipliedBy(70000)), AssetETH);
868
+ return new CryptoAmount(baseAmount(gasRate.multipliedBy(80000)), AssetETH);
851
869
  }
852
870
  case Chain.Terra:
853
871
  return new CryptoAmount(baseAmount(gasRate), AssetLUNA);
@@ -1710,18 +1728,21 @@ class ThorchainAMM {
1710
1728
  */
1711
1729
  confCounting(inbound) {
1712
1730
  return __awaiter(this, void 0, void 0, function* () {
1713
- // RUNE, BNB and Synths have near instant finality, so no conf counting required.
1714
- if (isAssetRuneNative(inbound.asset) || eqAsset(AssetBNB, inbound.asset) || inbound.asset.synth) {
1731
+ // RUNE, BNB and Synths have near instant finality, so no conf counting required. - need to make a BFT only case.
1732
+ if (isAssetRuneNative(inbound.asset) ||
1733
+ inbound.asset.chain == AssetBNB.chain ||
1734
+ inbound.asset.chain == AssetAtom.chain ||
1735
+ inbound.asset.synth) {
1715
1736
  return this.chainAttributes[Chain.THORChain].avgBlockTimeInSecs;
1716
1737
  }
1717
1738
  // Get the gas asset for the inbound.asset.chain
1718
1739
  const chainGasAsset = getChainAsset(inbound.asset.chain);
1719
- // check for chain asset, else need to convert asset value to chain asset.
1740
+ // Check for chain asset, else need to convert asset value to chain asset.
1720
1741
  const amountInGasAsset = yield this.allPools.convert(inbound, chainGasAsset);
1721
1742
  // Convert to Asset Amount
1722
1743
  const amountInGasAssetInAsset = amountInGasAsset.assetAmount;
1723
1744
  const confConfig = this.chainAttributes[inbound.asset.chain];
1724
- // find the requried confs
1745
+ // find the required confs
1725
1746
  const requiredConfs = Math.ceil(amountInGasAssetInAsset.amount().div(confConfig.blockReward).toNumber());
1726
1747
  // convert that into seconds
1727
1748
  return requiredConfs * confConfig.avgBlockTimeInSecs;
package/lib/index.js CHANGED
@@ -684,7 +684,6 @@ class Midgard {
684
684
  throw Error(`Could not find network value name`);
685
685
  }
686
686
  }
687
- console.log(retVal);
688
687
  return retVal;
689
688
  });
690
689
  }
@@ -707,6 +706,25 @@ class Midgard {
707
706
  throw Error(`Midgard not responding`);
708
707
  });
709
708
  }
709
+ /**
710
+ * Gets actions related to a txID
711
+ * @param txHash transaction id
712
+ * @returns Type Action array of objects
713
+ */
714
+ getActions(txHash) {
715
+ return __awaiter(this, void 0, void 0, function* () {
716
+ for (const api of this.midgardApis) {
717
+ try {
718
+ const actions = (yield api.getActions('', txHash)).data.actions;
719
+ return actions;
720
+ }
721
+ catch (e) {
722
+ console.error(e);
723
+ }
724
+ }
725
+ throw Error(`Midgard not responding`);
726
+ });
727
+ }
710
728
  }
711
729
 
712
730
  /**
@@ -841,23 +859,23 @@ const calcNetworkFee = (asset, gasRate) => {
841
859
  return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainUtil.AssetRuneNative);
842
860
  switch (asset.chain) {
843
861
  case xchainUtil.Chain.Bitcoin:
844
- return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(250)), xchainUtil.AssetBTC);
862
+ return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(1000)), xchainUtil.AssetBTC);
845
863
  case xchainUtil.Chain.BitcoinCash:
846
- return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(250)), xchainUtil.AssetBCH);
864
+ return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(1500)), xchainUtil.AssetBCH);
847
865
  case xchainUtil.Chain.Litecoin:
848
866
  return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(250)), xchainUtil.AssetLTC);
849
867
  case xchainUtil.Chain.Doge:
850
868
  // NOTE: UTXO chains estimate fees with a 250 byte size
851
- return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(250)), xchainUtil.AssetDOGE);
869
+ return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(1000)), xchainUtil.AssetDOGE);
852
870
  case xchainUtil.Chain.Binance:
853
871
  //flat fee
854
872
  return new CryptoAmount(xchainUtil.baseAmount(gasRate), xchainUtil.AssetBNB);
855
873
  case xchainUtil.Chain.Ethereum:
856
874
  if (xchainUtil.eqAsset(asset, xchainUtil.AssetETH)) {
857
- return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(35000)), xchainUtil.AssetETH);
875
+ return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(80000)), xchainUtil.AssetETH);
858
876
  }
859
877
  else {
860
- return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(70000)), xchainUtil.AssetETH);
878
+ return new CryptoAmount(xchainUtil.baseAmount(gasRate.multipliedBy(80000)), xchainUtil.AssetETH);
861
879
  }
862
880
  case xchainUtil.Chain.Terra:
863
881
  return new CryptoAmount(xchainUtil.baseAmount(gasRate), lib$1.AssetLUNA);
@@ -1720,18 +1738,21 @@ class ThorchainAMM {
1720
1738
  */
1721
1739
  confCounting(inbound) {
1722
1740
  return __awaiter(this, void 0, void 0, function* () {
1723
- // RUNE, BNB and Synths have near instant finality, so no conf counting required.
1724
- if (lib$2.isAssetRuneNative(inbound.asset) || xchainUtil.eqAsset(xchainUtil.AssetBNB, inbound.asset) || inbound.asset.synth) {
1741
+ // RUNE, BNB and Synths have near instant finality, so no conf counting required. - need to make a BFT only case.
1742
+ if (lib$2.isAssetRuneNative(inbound.asset) ||
1743
+ inbound.asset.chain == xchainUtil.AssetBNB.chain ||
1744
+ inbound.asset.chain == lib.AssetAtom.chain ||
1745
+ inbound.asset.synth) {
1725
1746
  return this.chainAttributes[xchainUtil.Chain.THORChain].avgBlockTimeInSecs;
1726
1747
  }
1727
1748
  // Get the gas asset for the inbound.asset.chain
1728
1749
  const chainGasAsset = getChainAsset(inbound.asset.chain);
1729
- // check for chain asset, else need to convert asset value to chain asset.
1750
+ // Check for chain asset, else need to convert asset value to chain asset.
1730
1751
  const amountInGasAsset = yield this.allPools.convert(inbound, chainGasAsset);
1731
1752
  // Convert to Asset Amount
1732
1753
  const amountInGasAssetInAsset = amountInGasAsset.assetAmount;
1733
1754
  const confConfig = this.chainAttributes[inbound.asset.chain];
1734
- // find the requried confs
1755
+ // find the required confs
1735
1756
  const requiredConfs = Math.ceil(amountInGasAssetInAsset.amount().div(confConfig.blockReward).toNumber());
1736
1757
  // convert that into seconds
1737
1758
  return requiredConfs * confConfig.avgBlockTimeInSecs;
@@ -61,7 +61,7 @@ export declare class ThorchainAMM {
61
61
  * @param interfaceID - id if the calling interface (optional)
62
62
  * @returns {SwapSubmitted} - Tx Hash, URL of BlockExplorer and expected wait time.
63
63
  */
64
- protected doSwap(wallet: Wallet, params: EstimateSwapParams, destinationAddress: string, affiliateAddress?: string, interfaceID?: number): Promise<SwapSubmitted>;
64
+ doSwap(wallet: Wallet, params: EstimateSwapParams, destinationAddress: string, affiliateAddress?: string, interfaceID?: number): Promise<SwapSubmitted>;
65
65
  /**
66
66
  * Basic Checks for swap information
67
67
  * @param params
@@ -1,5 +1,5 @@
1
1
  import { Network } from '@xchainjs/xchain-client';
2
- import { InboundAddressesItem, PoolDetail } from '@xchainjs/xchain-midgard';
2
+ import { Action, InboundAddressesItem, PoolDetail } from '@xchainjs/xchain-midgard';
3
3
  import { Chain } from '@xchainjs/xchain-util';
4
4
  import { CryptoAmount } from '../crypto-amount';
5
5
  import { InboundDetail, MidgardConfig } from '../types';
@@ -41,4 +41,10 @@ export declare class Midgard {
41
41
  * @returns
42
42
  */
43
43
  getLatestBlockHeight(): Promise<number>;
44
+ /**
45
+ * Gets actions related to a txID
46
+ * @param txHash transaction id
47
+ * @returns Type Action array of objects
48
+ */
49
+ getActions(txHash: string): Promise<Action[]>;
44
50
  }
@@ -25,6 +25,7 @@ export declare class Thornode {
25
25
  private transactionsApi;
26
26
  private queueApi;
27
27
  private networkApi;
28
+ private midgard;
28
29
  constructor(network?: Network, config?: ThornodeConfig, chainAttributes?: Record<Chain, ChainAttributes>);
29
30
  /**
30
31
  * Returns the oubound transactions held by THORChain due to outbound delay
@@ -47,10 +48,18 @@ export declare class Thornode {
47
48
  */
48
49
  checkTx(inboundTxHash: string, sourceChain?: Chain): Promise<TxStatus>;
49
50
  /** Stage 1 */
50
- private checkObservedTx;
51
+ private checkTxDefined;
51
52
  /** Stage 2, THORNode has seen it. See if observed only (conf counting) or it has been processed by THORChain */
52
53
  private checkObservedOnly;
53
- /** Stage 3 */
54
+ /**
55
+ * Stage 3
56
+ * @param txStatus
57
+ * @param txData
58
+ * @param scheduledQueue
59
+ * @param scheduledQueueItem
60
+ * @param lastBlockHeight
61
+ * @returns
62
+ */
54
63
  private checkOutboundQueue;
55
64
  /** Stage 4 */
56
65
  private checkOutboundTx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain-amm",
3
- "version": "0.1.0-alpha",
3
+ "version": "0.1.0-alpha2",
4
4
  "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
5
5
  "keywords": [
6
6
  "THORChain",