@xchainjs/xchain-thorchain-amm 0.3.16 → 0.3.18

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
@@ -2,6 +2,7 @@ import { Client as Client$8, defaultAvaxParams, AVAXChain } from '@xchainjs/xcha
2
2
  import { Client as Client$6 } from '@xchainjs/xchain-binance';
3
3
  import { Client as Client$1 } from '@xchainjs/xchain-bitcoin';
4
4
  import { Client } from '@xchainjs/xchain-bitcoincash';
5
+ import { Client as Client$9, defaultBscParams, BSCChain } from '@xchainjs/xchain-bsc';
5
6
  import { FeeOption } from '@xchainjs/xchain-client';
6
7
  import { Client as Client$7 } from '@xchainjs/xchain-cosmos';
7
8
  import { Client as Client$2 } from '@xchainjs/xchain-doge';
@@ -82,7 +83,7 @@ class EthHelper {
82
83
  //erc-20 must be depsited to the router
83
84
  const isApprovedResult = yield this.isTCRouterApprovedToSpend(params.asset, params.amount, params.walletIndex);
84
85
  if (!isApprovedResult) {
85
- throw new Error('The amount is not allowed to spend');
86
+ throw new Error('TC router has not been approved to spend this amount');
86
87
  }
87
88
  const contractAddress = getContractAddressFromAsset(params.asset);
88
89
  const checkSummedContractAddress = ethers.utils.getAddress(contractAddress);
@@ -258,6 +259,7 @@ class Wallet {
258
259
  BNB: new Client$6(settings),
259
260
  GAIA: new Client$7(settings),
260
261
  AVAX: new Client$8(Object.assign(Object.assign({}, defaultAvaxParams), { network: settings.network, phrase })),
262
+ BSC: new Client$9(Object.assign(Object.assign({}, defaultBscParams), { network: settings.network, phrase })),
261
263
  };
262
264
  this.ethHelper = new EthHelper(this.clients.ETH, this.thorchainQuery.thorchainCache);
263
265
  }
@@ -384,6 +386,18 @@ class Wallet {
384
386
  const hash = yield evmHelper.sendDeposit(params);
385
387
  return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
386
388
  }
389
+ else if (swap.input.asset.chain === BSCChain) {
390
+ const params = {
391
+ walletIndex: 0,
392
+ asset: swap.input.asset,
393
+ amount: swap.input.baseAmount,
394
+ feeOption: swap.feeOption || FeeOption.Fast,
395
+ memo: swap.memo,
396
+ };
397
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
398
+ const hash = yield evmHelper.sendDeposit(params);
399
+ return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
400
+ }
387
401
  else {
388
402
  const params = {
389
403
  walletIndex: 0,
@@ -504,6 +518,18 @@ class Wallet {
504
518
  const hash = yield evmHelper.sendDeposit(addParams);
505
519
  return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
506
520
  }
521
+ else if (assetAmount.asset.chain === BSCChain) {
522
+ const addParams = {
523
+ wallIndex: 0,
524
+ asset: assetAmount.asset,
525
+ amount: assetAmount.baseAmount,
526
+ feeOption: FeeOption.Fast,
527
+ memo: memo,
528
+ };
529
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
530
+ const hash = yield evmHelper.sendDeposit(addParams);
531
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
532
+ }
507
533
  else {
508
534
  const addParams = {
509
535
  wallIndex: 0,
@@ -556,6 +582,18 @@ class Wallet {
556
582
  const hash = yield evmHelper.sendDeposit(addParams);
557
583
  return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
558
584
  }
585
+ else if (dustAssetAmount.asset.chain === BSCChain) {
586
+ const addParams = {
587
+ wallIndex: 0,
588
+ asset: dustAssetAmount.asset,
589
+ amount: dustAssetAmount.baseAmount,
590
+ feeOption: FeeOption.Fast,
591
+ memo: memo,
592
+ };
593
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
594
+ const hash = yield evmHelper.sendDeposit(addParams);
595
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
596
+ }
559
597
  else {
560
598
  const addParams = {
561
599
  wallIndex: 0,
@@ -609,6 +647,18 @@ class Wallet {
609
647
  const hash = yield evmHelper.sendDeposit(addParams);
610
648
  return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
611
649
  }
650
+ else if (params.asset.asset.chain === BSCChain) {
651
+ const addParams = {
652
+ wallIndex: 0,
653
+ asset: params.asset.asset,
654
+ amount: params.asset.baseAmount,
655
+ feeOption: FeeOption.Fast,
656
+ memo: constructedMemo,
657
+ };
658
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
659
+ const hash = yield evmHelper.sendDeposit(addParams);
660
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
661
+ }
612
662
  else {
613
663
  const addParams = {
614
664
  wallIndex: 0,
@@ -663,6 +713,18 @@ class Wallet {
663
713
  const hash = yield evmHelper.sendDeposit(withdrawParams);
664
714
  return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
665
715
  }
716
+ else if (params.assetFee.asset.chain === BSCChain) {
717
+ const withdrawParams = {
718
+ wallIndex: 0,
719
+ asset: params.assetFee.asset,
720
+ amount: params.assetFee.baseAmount,
721
+ feeOption: FeeOption.Fast,
722
+ memo: constructedMemo,
723
+ };
724
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
725
+ const hash = yield evmHelper.sendDeposit(withdrawParams);
726
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
727
+ }
666
728
  else {
667
729
  const withdrawParams = {
668
730
  wallIndex: 0,
package/lib/index.js CHANGED
@@ -6,6 +6,7 @@ var xchainAvax = require('@xchainjs/xchain-avax');
6
6
  var xchainBinance = require('@xchainjs/xchain-binance');
7
7
  var xchainBitcoin = require('@xchainjs/xchain-bitcoin');
8
8
  var xchainBitcoincash = require('@xchainjs/xchain-bitcoincash');
9
+ var xchainBsc = require('@xchainjs/xchain-bsc');
9
10
  var xchainClient = require('@xchainjs/xchain-client');
10
11
  var xchainCosmos = require('@xchainjs/xchain-cosmos');
11
12
  var xchainDoge = require('@xchainjs/xchain-doge');
@@ -86,7 +87,7 @@ class EthHelper {
86
87
  //erc-20 must be depsited to the router
87
88
  const isApprovedResult = yield this.isTCRouterApprovedToSpend(params.asset, params.amount, params.walletIndex);
88
89
  if (!isApprovedResult) {
89
- throw new Error('The amount is not allowed to spend');
90
+ throw new Error('TC router has not been approved to spend this amount');
90
91
  }
91
92
  const contractAddress = xchainUtil.getContractAddressFromAsset(params.asset);
92
93
  const checkSummedContractAddress = ethers.ethers.utils.getAddress(contractAddress);
@@ -262,6 +263,7 @@ class Wallet {
262
263
  BNB: new xchainBinance.Client(settings),
263
264
  GAIA: new xchainCosmos.Client(settings),
264
265
  AVAX: new xchainAvax.Client(Object.assign(Object.assign({}, xchainAvax.defaultAvaxParams), { network: settings.network, phrase })),
266
+ BSC: new xchainBsc.Client(Object.assign(Object.assign({}, xchainBsc.defaultBscParams), { network: settings.network, phrase })),
265
267
  };
266
268
  this.ethHelper = new EthHelper(this.clients.ETH, this.thorchainQuery.thorchainCache);
267
269
  }
@@ -388,6 +390,18 @@ class Wallet {
388
390
  const hash = yield evmHelper.sendDeposit(params);
389
391
  return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
390
392
  }
393
+ else if (swap.input.asset.chain === xchainBsc.BSCChain) {
394
+ const params = {
395
+ walletIndex: 0,
396
+ asset: swap.input.asset,
397
+ amount: swap.input.baseAmount,
398
+ feeOption: swap.feeOption || xchainClient.FeeOption.Fast,
399
+ memo: swap.memo,
400
+ };
401
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
402
+ const hash = yield evmHelper.sendDeposit(params);
403
+ return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
404
+ }
391
405
  else {
392
406
  const params = {
393
407
  walletIndex: 0,
@@ -508,6 +522,18 @@ class Wallet {
508
522
  const hash = yield evmHelper.sendDeposit(addParams);
509
523
  return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
510
524
  }
525
+ else if (assetAmount.asset.chain === xchainBsc.BSCChain) {
526
+ const addParams = {
527
+ wallIndex: 0,
528
+ asset: assetAmount.asset,
529
+ amount: assetAmount.baseAmount,
530
+ feeOption: xchainClient.FeeOption.Fast,
531
+ memo: memo,
532
+ };
533
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
534
+ const hash = yield evmHelper.sendDeposit(addParams);
535
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
536
+ }
511
537
  else {
512
538
  const addParams = {
513
539
  wallIndex: 0,
@@ -560,6 +586,18 @@ class Wallet {
560
586
  const hash = yield evmHelper.sendDeposit(addParams);
561
587
  return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
562
588
  }
589
+ else if (dustAssetAmount.asset.chain === xchainBsc.BSCChain) {
590
+ const addParams = {
591
+ wallIndex: 0,
592
+ asset: dustAssetAmount.asset,
593
+ amount: dustAssetAmount.baseAmount,
594
+ feeOption: xchainClient.FeeOption.Fast,
595
+ memo: memo,
596
+ };
597
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
598
+ const hash = yield evmHelper.sendDeposit(addParams);
599
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
600
+ }
563
601
  else {
564
602
  const addParams = {
565
603
  wallIndex: 0,
@@ -613,6 +651,18 @@ class Wallet {
613
651
  const hash = yield evmHelper.sendDeposit(addParams);
614
652
  return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
615
653
  }
654
+ else if (params.asset.asset.chain === xchainBsc.BSCChain) {
655
+ const addParams = {
656
+ wallIndex: 0,
657
+ asset: params.asset.asset,
658
+ amount: params.asset.baseAmount,
659
+ feeOption: xchainClient.FeeOption.Fast,
660
+ memo: constructedMemo,
661
+ };
662
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
663
+ const hash = yield evmHelper.sendDeposit(addParams);
664
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
665
+ }
616
666
  else {
617
667
  const addParams = {
618
668
  wallIndex: 0,
@@ -667,6 +717,18 @@ class Wallet {
667
717
  const hash = yield evmHelper.sendDeposit(withdrawParams);
668
718
  return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
669
719
  }
720
+ else if (params.assetFee.asset.chain === xchainBsc.BSCChain) {
721
+ const withdrawParams = {
722
+ wallIndex: 0,
723
+ asset: params.assetFee.asset,
724
+ amount: params.assetFee.baseAmount,
725
+ feeOption: xchainClient.FeeOption.Fast,
726
+ memo: constructedMemo,
727
+ };
728
+ const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
729
+ const hash = yield evmHelper.sendDeposit(withdrawParams);
730
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
731
+ }
670
732
  else {
671
733
  const withdrawParams = {
672
734
  wallIndex: 0,
@@ -0,0 +1,2 @@
1
+ export * from './evm-helper';
2
+ export * from './eth-helper';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain-amm",
3
- "version": "0.3.16",
3
+ "version": "0.3.18",
4
4
  "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -40,6 +40,7 @@
40
40
  "@cosmos-client/core": "0.46.1",
41
41
  "@psf/bitcoincashjs-lib": "^4.0.2",
42
42
  "@xchainjs/xchain-avax": "^0.1.4",
43
+ "@xchainjs/xchain-bsc": "^0.1.0",
43
44
  "@xchainjs/xchain-binance": "^5.6.7",
44
45
  "@xchainjs/xchain-bitcoin": "^0.20.9",
45
46
  "@xchainjs/xchain-bitcoincash": "^0.15.7",
@@ -50,10 +51,10 @@
50
51
  "@xchainjs/xchain-ethereum": "^0.27.7",
51
52
  "@xchainjs/xchain-evm": "^0.1.3",
52
53
  "@xchainjs/xchain-litecoin": "^0.10.10",
53
- "@xchainjs/xchain-midgard": "0.4.2",
54
- "@xchainjs/xchain-thorchain": "^0.27.7",
54
+ "@xchainjs/xchain-midgard": "0.4.3",
55
+ "@xchainjs/xchain-thorchain": "^0.27.9",
55
56
  "@xchainjs/xchain-thorchain-query": "^0.1.17",
56
- "@xchainjs/xchain-thornode": "^0.2.0",
57
+ "@xchainjs/xchain-thornode": "^0.2.1",
57
58
  "@xchainjs/xchain-util": "^0.12.0",
58
59
  "axios": "^0.25.0",
59
60
  "axios-retry": "^3.2.5",
@@ -73,6 +74,7 @@
73
74
  "@cosmos-client/core": "0.46.1",
74
75
  "@psf/bitcoincashjs-lib": "^4.0.2",
75
76
  "@xchainjs/xchain-avax": "^0.1.4",
77
+ "@xchainjs/xchain-bsc": "^0.1.0",
76
78
  "@xchainjs/xchain-binance": "^5.6.7",
77
79
  "@xchainjs/xchain-bitcoin": "^0.20.9",
78
80
  "@xchainjs/xchain-bitcoincash": "^0.15.7",
@@ -83,10 +85,10 @@
83
85
  "@xchainjs/xchain-ethereum": "^0.27.7",
84
86
  "@xchainjs/xchain-evm": "^0.1.3",
85
87
  "@xchainjs/xchain-litecoin": "^0.10.10",
86
- "@xchainjs/xchain-midgard": "0.4.2",
87
- "@xchainjs/xchain-thorchain": "^0.27.7",
88
- "@xchainjs/xchain-thorchain-query": "^0.1.17",
89
- "@xchainjs/xchain-thornode": "^0.2.0",
88
+ "@xchainjs/xchain-midgard": "0.4.3",
89
+ "@xchainjs/xchain-thorchain": "^0.27.9",
90
+ "@xchainjs/xchain-thorchain-query": "^0.1.18",
91
+ "@xchainjs/xchain-thornode": "^0.2.1",
90
92
  "@xchainjs/xchain-util": "^0.12.0",
91
93
  "axios": "^0.25.0",
92
94
  "axios-retry": "^3.2.5",