@xchainjs/xchain-thorchain-amm 0.8.2 → 0.8.4

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
@@ -86,6 +86,26 @@ If you plan on using the publically accessible endpoints provided by Nine Realms
86
86
  - https://haskoin.ninerealms.com (BTC/BCH/LTC)
87
87
  - https://thornode.ninerealms.com
88
88
 
89
+ ### Setting environment variables
90
+
91
+ ```sh
92
+ SNOWTRACE_API_KEY={YOUR_SNOWTRACE_API_KEY}
93
+ COVALENT_API_KEY={YOUR_COVALENT_API_KEY}
94
+ BLOCKCYPHER_API_KEY={YOUR_BLOCKCYPHER_API_KEY}
95
+ SOCHAIN_API_KEY={YOUR_SOCHAIN_API_KEY}
96
+ BSCSCAN_API_KEY={YOUR_BSCSCAN_API_KEY}
97
+ ```
98
+
99
+ //Default config can access.
100
+
101
+ ```sh
102
+ process.env.SNOWTRACE_API_KEY
103
+ process.env.COVALENT_API_KEY
104
+ process.env.BLOCKCYPHER_API_KEY
105
+ process.env.SOCHAIN_API_KEY
106
+ process.env.BSCSCAN_API_KEY
107
+ ```
108
+
89
109
  Example
90
110
 
91
111
  ```typescript
package/lib/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { Client as Client$5, BNBChain } from '@xchainjs/xchain-binance';
3
3
  import { Client as Client$1, defaultBTCParams, BTCChain } from '@xchainjs/xchain-bitcoin';
4
4
  import { Client, defaultBchParams, BCHChain } from '@xchainjs/xchain-bitcoincash';
5
5
  import { Client as Client$a, defaultBscParams, BSCChain } from '@xchainjs/xchain-bsc';
6
- import { FeeOption } from '@xchainjs/xchain-client';
6
+ import { FeeOption, Protocol as Protocol$1 } from '@xchainjs/xchain-client';
7
7
  import { Client as Client$6, GAIAChain } from '@xchainjs/xchain-cosmos';
8
8
  import { Client as Client$2, defaultDogeParams, DOGEChain } from '@xchainjs/xchain-doge';
9
9
  import { Client as Client$8, defaultEthParams, ETHChain } from '@xchainjs/xchain-ethereum';
@@ -399,6 +399,25 @@ class Wallet {
399
399
  const hash = yield evmHelper.sendDeposit(addParams);
400
400
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
401
401
  }
402
+ else if (this.isUTXOChain(assetAmount.asset)) {
403
+ const feeRates = yield assetClient.getFeeRates(Protocol$1.THORCHAIN);
404
+ const addParams = {
405
+ wallIndex: 0,
406
+ asset: assetAmount.asset,
407
+ amount: assetAmount.baseAmount,
408
+ recipient: toAddress,
409
+ memo: memo,
410
+ feeRate: feeRates.fast,
411
+ };
412
+ try {
413
+ const hash = yield assetClient.transfer(addParams);
414
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
415
+ }
416
+ catch (err) {
417
+ const hash = JSON.stringify(err);
418
+ return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()) };
419
+ }
420
+ }
402
421
  else {
403
422
  const addParams = {
404
423
  wallIndex: 0,
@@ -440,6 +459,25 @@ class Wallet {
440
459
  const hash = yield evmHelper.sendDeposit(addParams);
441
460
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
442
461
  }
462
+ else if (this.isUTXOChain(assetAmount.asset)) {
463
+ const feeRates = yield assetClient.getFeeRates(Protocol$1.THORCHAIN);
464
+ const addParams = {
465
+ wallIndex: 0,
466
+ asset: assetAmount.asset,
467
+ amount: assetAmount.baseAmount,
468
+ recipient: toAddress,
469
+ memo: memo,
470
+ feeRate: feeRates.fast,
471
+ };
472
+ try {
473
+ const hash = yield assetClient.transfer(addParams);
474
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
475
+ }
476
+ catch (err) {
477
+ const hash = JSON.stringify(err);
478
+ return { hash, url: yield assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
479
+ }
480
+ }
443
481
  else {
444
482
  const addParams = {
445
483
  wallIndex: 0,
@@ -474,6 +512,25 @@ class Wallet {
474
512
  const hash = yield evmHelper.sendDeposit(addParams);
475
513
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
476
514
  }
515
+ else if (this.isUTXOChain(params.amount.asset)) {
516
+ const feeRates = yield assetClient.getFeeRates(Protocol$1.THORCHAIN);
517
+ const addParams = {
518
+ wallIndex: 0,
519
+ asset: params.amount.asset,
520
+ amount: params.amount.baseAmount,
521
+ recipient: params.toAddress,
522
+ memo: params.memo,
523
+ feeRate: feeRates.fast,
524
+ };
525
+ try {
526
+ const hash = yield assetClient.transfer(addParams);
527
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
528
+ }
529
+ catch (err) {
530
+ const hash = JSON.stringify(err);
531
+ return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
532
+ }
533
+ }
477
534
  else {
478
535
  const addParams = {
479
536
  wallIndex: 0,
@@ -508,6 +565,25 @@ class Wallet {
508
565
  const hash = yield evmHelper.sendDeposit(addParams);
509
566
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
510
567
  }
568
+ else if (this.isUTXOChain(params.amount.asset)) {
569
+ const feeRates = yield assetClient.getFeeRates(Protocol$1.THORCHAIN);
570
+ const addParams = {
571
+ wallIndex: 0,
572
+ asset: params.amount.asset,
573
+ amount: params.amount.baseAmount,
574
+ recipient: params.toAddress,
575
+ memo: params.memo,
576
+ feeRate: feeRates.average,
577
+ };
578
+ try {
579
+ const hash = yield assetClient.transfer(addParams);
580
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
581
+ }
582
+ catch (err) {
583
+ const hash = JSON.stringify(err);
584
+ return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
585
+ }
586
+ }
511
587
  else {
512
588
  const addParams = {
513
589
  wallIndex: 0,
@@ -611,6 +687,25 @@ class Wallet {
611
687
  const hash = yield evmHelper.sendDeposit(addParams);
612
688
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
613
689
  }
690
+ else if (this.isUTXOChain(params.asset.asset)) {
691
+ const feeRates = yield assetClient.getFeeRates(Protocol$1.THORCHAIN);
692
+ const addParams = {
693
+ wallIndex: 0,
694
+ asset: params.asset.asset,
695
+ amount: params.asset.baseAmount,
696
+ recipient: inboundAsgard,
697
+ memo: constructedMemo,
698
+ feeRate: feeRates.fast,
699
+ };
700
+ try {
701
+ const hash = yield assetClient.transfer(addParams);
702
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
703
+ }
704
+ catch (err) {
705
+ const hash = JSON.stringify(err);
706
+ return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
707
+ }
708
+ }
614
709
  else {
615
710
  const addParams = {
616
711
  wallIndex: 0,
@@ -653,6 +748,25 @@ class Wallet {
653
748
  const hash = yield evmHelper.sendDeposit(withdrawParams);
654
749
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
655
750
  }
751
+ else if (this.isUTXOChain(params.assetFee.asset)) {
752
+ const feeRates = yield assetClient.getFeeRates(Protocol$1.THORCHAIN);
753
+ const withdrawParams = {
754
+ wallIndex: 0,
755
+ asset: params.assetFee.asset,
756
+ amount: params.assetFee.baseAmount,
757
+ recipient: inboundAsgard,
758
+ memo: constructedMemo,
759
+ feeRate: feeRates.fast,
760
+ };
761
+ try {
762
+ const hash = yield assetClient.transfer(withdrawParams);
763
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
764
+ }
765
+ catch (err) {
766
+ const hash = JSON.stringify(err);
767
+ return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
768
+ }
769
+ }
656
770
  else {
657
771
  const withdrawParams = {
658
772
  wallIndex: 0,
@@ -716,6 +830,9 @@ class Wallet {
716
830
  const isEvmChain = ['ETH', 'BSC', 'AVAX'].includes(asset.chain);
717
831
  return isEvmChain;
718
832
  }
833
+ isUTXOChain(asset) {
834
+ return ['BTC', 'BCH', 'DOGE'].includes(asset.chain);
835
+ }
719
836
  }
720
837
 
721
838
  const defaultQuery = new ThorchainQuery();
package/lib/index.js CHANGED
@@ -403,6 +403,25 @@ class Wallet {
403
403
  const hash = yield evmHelper.sendDeposit(addParams);
404
404
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
405
405
  }
406
+ else if (this.isUTXOChain(assetAmount.asset)) {
407
+ const feeRates = yield assetClient.getFeeRates(xchainClient.Protocol.THORCHAIN);
408
+ const addParams = {
409
+ wallIndex: 0,
410
+ asset: assetAmount.asset,
411
+ amount: assetAmount.baseAmount,
412
+ recipient: toAddress,
413
+ memo: memo,
414
+ feeRate: feeRates.fast,
415
+ };
416
+ try {
417
+ const hash = yield assetClient.transfer(addParams);
418
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
419
+ }
420
+ catch (err) {
421
+ const hash = JSON.stringify(err);
422
+ return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()) };
423
+ }
424
+ }
406
425
  else {
407
426
  const addParams = {
408
427
  wallIndex: 0,
@@ -444,6 +463,25 @@ class Wallet {
444
463
  const hash = yield evmHelper.sendDeposit(addParams);
445
464
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
446
465
  }
466
+ else if (this.isUTXOChain(assetAmount.asset)) {
467
+ const feeRates = yield assetClient.getFeeRates(xchainClient.Protocol.THORCHAIN);
468
+ const addParams = {
469
+ wallIndex: 0,
470
+ asset: assetAmount.asset,
471
+ amount: assetAmount.baseAmount,
472
+ recipient: toAddress,
473
+ memo: memo,
474
+ feeRate: feeRates.fast,
475
+ };
476
+ try {
477
+ const hash = yield assetClient.transfer(addParams);
478
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
479
+ }
480
+ catch (err) {
481
+ const hash = JSON.stringify(err);
482
+ return { hash, url: yield assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
483
+ }
484
+ }
447
485
  else {
448
486
  const addParams = {
449
487
  wallIndex: 0,
@@ -478,6 +516,25 @@ class Wallet {
478
516
  const hash = yield evmHelper.sendDeposit(addParams);
479
517
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
480
518
  }
519
+ else if (this.isUTXOChain(params.amount.asset)) {
520
+ const feeRates = yield assetClient.getFeeRates(xchainClient.Protocol.THORCHAIN);
521
+ const addParams = {
522
+ wallIndex: 0,
523
+ asset: params.amount.asset,
524
+ amount: params.amount.baseAmount,
525
+ recipient: params.toAddress,
526
+ memo: params.memo,
527
+ feeRate: feeRates.fast,
528
+ };
529
+ try {
530
+ const hash = yield assetClient.transfer(addParams);
531
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
532
+ }
533
+ catch (err) {
534
+ const hash = JSON.stringify(err);
535
+ return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
536
+ }
537
+ }
481
538
  else {
482
539
  const addParams = {
483
540
  wallIndex: 0,
@@ -512,6 +569,25 @@ class Wallet {
512
569
  const hash = yield evmHelper.sendDeposit(addParams);
513
570
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
514
571
  }
572
+ else if (this.isUTXOChain(params.amount.asset)) {
573
+ const feeRates = yield assetClient.getFeeRates(xchainClient.Protocol.THORCHAIN);
574
+ const addParams = {
575
+ wallIndex: 0,
576
+ asset: params.amount.asset,
577
+ amount: params.amount.baseAmount,
578
+ recipient: params.toAddress,
579
+ memo: params.memo,
580
+ feeRate: feeRates.average,
581
+ };
582
+ try {
583
+ const hash = yield assetClient.transfer(addParams);
584
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
585
+ }
586
+ catch (err) {
587
+ const hash = JSON.stringify(err);
588
+ return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
589
+ }
590
+ }
515
591
  else {
516
592
  const addParams = {
517
593
  wallIndex: 0,
@@ -615,6 +691,25 @@ class Wallet {
615
691
  const hash = yield evmHelper.sendDeposit(addParams);
616
692
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
617
693
  }
694
+ else if (this.isUTXOChain(params.asset.asset)) {
695
+ const feeRates = yield assetClient.getFeeRates(xchainClient.Protocol.THORCHAIN);
696
+ const addParams = {
697
+ wallIndex: 0,
698
+ asset: params.asset.asset,
699
+ amount: params.asset.baseAmount,
700
+ recipient: inboundAsgard,
701
+ memo: constructedMemo,
702
+ feeRate: feeRates.fast,
703
+ };
704
+ try {
705
+ const hash = yield assetClient.transfer(addParams);
706
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
707
+ }
708
+ catch (err) {
709
+ const hash = JSON.stringify(err);
710
+ return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
711
+ }
712
+ }
618
713
  else {
619
714
  const addParams = {
620
715
  wallIndex: 0,
@@ -657,6 +752,25 @@ class Wallet {
657
752
  const hash = yield evmHelper.sendDeposit(withdrawParams);
658
753
  return { hash, url: assetClient.getExplorerTxUrl(hash) };
659
754
  }
755
+ else if (this.isUTXOChain(params.assetFee.asset)) {
756
+ const feeRates = yield assetClient.getFeeRates(xchainClient.Protocol.THORCHAIN);
757
+ const withdrawParams = {
758
+ wallIndex: 0,
759
+ asset: params.assetFee.asset,
760
+ amount: params.assetFee.baseAmount,
761
+ recipient: inboundAsgard,
762
+ memo: constructedMemo,
763
+ feeRate: feeRates.fast,
764
+ };
765
+ try {
766
+ const hash = yield assetClient.transfer(withdrawParams);
767
+ return { hash, url: assetClient.getExplorerTxUrl(hash) };
768
+ }
769
+ catch (err) {
770
+ const hash = JSON.stringify(err);
771
+ return { hash, url: assetClient.getExplorerAddressUrl(yield assetClient.getAddressAsync()) };
772
+ }
773
+ }
660
774
  else {
661
775
  const withdrawParams = {
662
776
  wallIndex: 0,
@@ -720,6 +834,9 @@ class Wallet {
720
834
  const isEvmChain = ['ETH', 'BSC', 'AVAX'].includes(asset.chain);
721
835
  return isEvmChain;
722
836
  }
837
+ isUTXOChain(asset) {
838
+ return ['BTC', 'BCH', 'DOGE'].includes(asset.chain);
839
+ }
723
840
  }
724
841
 
725
842
  const defaultQuery = new xchainThorchainQuery.ThorchainQuery();
package/lib/wallet.d.ts CHANGED
@@ -168,4 +168,5 @@ export declare class Wallet {
168
168
  private withdrawRuneLP;
169
169
  private isERC20Asset;
170
170
  private isEVMChain;
171
+ private isUTXOChain;
171
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain-amm",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -41,23 +41,23 @@
41
41
  "@psf/bitcoincashjs-lib": "^4.0.3",
42
42
  "@xchainjs/xchain-avax": "^0.4.1",
43
43
  "@xchainjs/xchain-binance": "^5.7.5",
44
- "@xchainjs/xchain-bitcoin": "^0.23.4",
45
- "@xchainjs/xchain-bitcoincash": "^0.17.4",
46
- "@xchainjs/xchain-client": "^0.15.3",
44
+ "@xchainjs/xchain-bitcoin": "^0.23.6",
45
+ "@xchainjs/xchain-bitcoincash": "^0.17.5",
46
+ "@xchainjs/xchain-client": "^0.15.4",
47
47
  "@xchainjs/xchain-cosmos": "^0.21.7",
48
- "@xchainjs/xchain-bsc": "^0.4.1",
48
+ "@xchainjs/xchain-bsc": "^0.4.2",
49
49
  "@xchainjs/xchain-crypto": "^0.3.0",
50
- "@xchainjs/xchain-doge": "^0.7.5",
50
+ "@xchainjs/xchain-doge": "^0.7.7",
51
51
  "@xchainjs/xchain-ethereum": "^0.31.1",
52
52
  "@xchainjs/xchain-thornode": "^0.3.8",
53
- "@xchainjs/xchain-thorchain-query": "^0.6.11",
53
+ "@xchainjs/xchain-thorchain-query": "^0.6.12",
54
54
  "@xchainjs/xchain-evm": "^0.4.1",
55
- "@xchainjs/xchain-litecoin": "^0.13.4",
55
+ "@xchainjs/xchain-litecoin": "^0.13.6",
56
56
  "@xchainjs/xchain-mayachain": "^0.2.10",
57
57
  "@xchainjs/xchain-midgard": "^0.5.2",
58
58
  "@xchainjs/xchain-thorchain": "^0.28.13",
59
59
  "@xchainjs/xchain-util": "^0.13.1",
60
- "@xchainjs/xchain-utxo-providers": "^0.2.7",
60
+ "@xchainjs/xchain-utxo-providers": "^0.2.8",
61
61
  "axios": "^1.3.6",
62
62
  "axios-retry": "^3.2.5",
63
63
  "bchaddrjs": "^0.5.2",
@@ -77,23 +77,23 @@
77
77
  "@psf/bitcoincashjs-lib": "^4.0.3",
78
78
  "@xchainjs/xchain-avax": "^0.4.1",
79
79
  "@xchainjs/xchain-binance": "^5.7.5",
80
- "@xchainjs/xchain-bitcoin": "^0.23.4",
81
- "@xchainjs/xchain-bitcoincash": "^0.17.4",
82
- "@xchainjs/xchain-client": "^0.15.3",
80
+ "@xchainjs/xchain-bitcoin": "^0.23.6",
81
+ "@xchainjs/xchain-bitcoincash": "^0.17.5",
82
+ "@xchainjs/xchain-client": "^0.15.4",
83
83
  "@xchainjs/xchain-cosmos": "^0.21.7",
84
- "@xchainjs/xchain-bsc": "^0.4.1",
84
+ "@xchainjs/xchain-bsc": "^0.4.2",
85
85
  "@xchainjs/xchain-crypto": "^0.3.0",
86
- "@xchainjs/xchain-doge": "^0.7.5",
86
+ "@xchainjs/xchain-doge": "^0.7.7",
87
87
  "@xchainjs/xchain-ethereum": "^0.31.1",
88
88
  "@xchainjs/xchain-thornode": "^0.3.8",
89
- "@xchainjs/xchain-thorchain-query": "^0.6.11",
89
+ "@xchainjs/xchain-thorchain-query": "^0.6.12",
90
90
  "@xchainjs/xchain-evm": "^0.4.1",
91
- "@xchainjs/xchain-litecoin": "^0.13.4",
91
+ "@xchainjs/xchain-litecoin": "^0.13.6",
92
92
  "@xchainjs/xchain-mayachain": "^0.2.10",
93
93
  "@xchainjs/xchain-midgard": "^0.5.2",
94
94
  "@xchainjs/xchain-thorchain": "^0.28.13",
95
95
  "@xchainjs/xchain-util": "^0.13.1",
96
- "@xchainjs/xchain-utxo-providers": "^0.2.7",
96
+ "@xchainjs/xchain-utxo-providers": "^0.2.8",
97
97
  "axios": "^1.3.6",
98
98
  "axios-retry": "^3.2.5",
99
99
  "bchaddrjs": "^0.5.2",