@xchainjs/xchain-thorchain-amm 0.6.0 → 0.7.1

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,6 +1,6 @@
1
1
  import { Client as Client$9, defaultAvaxParams } from '@xchainjs/xchain-avax';
2
2
  import { Client as Client$5 } from '@xchainjs/xchain-binance';
3
- import { Client as Client$1 } from '@xchainjs/xchain-bitcoin';
3
+ import { Client as Client$1, BTCChain } from '@xchainjs/xchain-bitcoin';
4
4
  import { Client } from '@xchainjs/xchain-bitcoincash';
5
5
  import { Client as Client$a, defaultBscParams } from '@xchainjs/xchain-bsc';
6
6
  import { FeeOption } from '@xchainjs/xchain-client';
@@ -10,8 +10,8 @@ import { Client as Client$8, defaultEthParams } from '@xchainjs/xchain-ethereum'
10
10
  import { Client as Client$3 } from '@xchainjs/xchain-litecoin';
11
11
  import { Client as Client$7 } from '@xchainjs/xchain-mayachain';
12
12
  import { Client as Client$4, THORChain } from '@xchainjs/xchain-thorchain';
13
+ import { eqAsset, getContractAddressFromAsset, baseAmount, assetFromString } from '@xchainjs/xchain-util';
13
14
  import { abi, MAX_APPROVAL } from '@xchainjs/xchain-evm';
14
- import { eqAsset, getContractAddressFromAsset, baseAmount } from '@xchainjs/xchain-util';
15
15
  import { ethers } from 'ethers';
16
16
  import { ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
17
17
 
@@ -149,7 +149,7 @@ class Wallet {
149
149
  */
150
150
  constructor(phrase, thorchainQuery) {
151
151
  this.thorchainQuery = thorchainQuery;
152
- const settings = { network: thorchainQuery.thorchainCache.midgard.network, phrase };
152
+ const settings = { network: this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, phrase };
153
153
  this.clients = {
154
154
  BCH: new Client(),
155
155
  BTC: new Client$1(),
@@ -254,7 +254,7 @@ class Wallet {
254
254
  }
255
255
  isThorname(name) {
256
256
  return __awaiter(this, void 0, void 0, function* () {
257
- const thornameDetails = yield this.thorchainQuery.thorchainCache.midgard.getTHORNameDetails(name);
257
+ const thornameDetails = yield this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameDetails(name); // Update when thorchainCache expose getTHORNameDetails method
258
258
  return thornameDetails !== undefined;
259
259
  });
260
260
  }
@@ -533,6 +533,68 @@ class Wallet {
533
533
  }
534
534
  });
535
535
  }
536
+ /**
537
+ * Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
538
+ * By default owner is getting from wallet
539
+ * @param thorname - Name to register
540
+ * @param chain - Chain to add alias
541
+ * @param chainAddress - Address to add to chain alias
542
+ * @param owner - Owner address (rune address)
543
+ * @param preferredAsset - referred asset
544
+ * @param expirity - expirity of the domain in MILLISECONDS
545
+ * @param isUpdate - true only if the domain is already register and you want to update its data
546
+ * @returns memo and value of deposit
547
+ */
548
+ registerThorname(params) {
549
+ return __awaiter(this, void 0, void 0, function* () {
550
+ const chainClient = this.clients[params.chain || BTCChain];
551
+ const thorClient = this.clients.THOR;
552
+ if (!chainClient || !thorClient) {
553
+ throw Error('Can not find a wallet client');
554
+ }
555
+ const thornameEstimation = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { chain: params.chain || BTCChain, chainAddress: params.chainAddress || chainClient.getAddress(), owner: params.owner || thorClient.getAddress() }));
556
+ const castedThorClient = thorClient;
557
+ const result = yield castedThorClient.deposit({
558
+ asset: thornameEstimation.value.asset,
559
+ amount: thornameEstimation.value.baseAmount,
560
+ memo: thornameEstimation.memo,
561
+ });
562
+ return result;
563
+ });
564
+ }
565
+ /**
566
+ * Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
567
+ * By default owner is getting from wallet
568
+ * @param thorname - Name to register
569
+ * @param chain - Chain to add alias
570
+ * @param chainAddress - Address to add to chain alias
571
+ * @param owner - Owner address (rune address)
572
+ * @param preferredAsset - referred asset
573
+ * @param expirity - expirity of the domain in MILLISECONDS
574
+ * @param isUpdate - true only if the domain is already register and you want to update its data
575
+ * @returns memo and value of deposit
576
+ */
577
+ updateThorname(params) {
578
+ return __awaiter(this, void 0, void 0, function* () {
579
+ const chainClient = this.clients[params.chain || BTCChain];
580
+ const thorClient = this.clients.THOR;
581
+ if (!chainClient || !thorClient) {
582
+ throw Error('Can not find a wallet client');
583
+ }
584
+ const thornameDetail = yield this.thorchainQuery.getThornameDetails(params.thorname);
585
+ if ((thornameDetail === null || thornameDetail === void 0 ? void 0 : thornameDetail.owner) !== thorClient.getAddress()) {
586
+ throw Error('You cannot update a domain that is not yours');
587
+ }
588
+ const thornameEstimation = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { chain: params.chain || BTCChain, isUpdate: true, preferredAsset: params.preferredAsset || assetFromString(thornameDetail.preferredAsset), chainAddress: params.chainAddress || chainClient.getAddress() }));
589
+ const castedThorClient = thorClient;
590
+ const result = yield castedThorClient.deposit({
591
+ asset: thornameEstimation.value.asset,
592
+ amount: thornameEstimation.value.baseAmount,
593
+ memo: thornameEstimation.memo,
594
+ });
595
+ return result;
596
+ });
597
+ }
536
598
  /** Function handles liquidity add for all non rune assets
537
599
  *
538
600
  * @param params - parameters for add liquidity
@@ -916,6 +978,16 @@ class ThorchainAMM {
916
978
  });
917
979
  });
918
980
  }
981
+ /**
982
+ * Get all Thornames and its data associated owned by an address
983
+ * @param address - address
984
+ * @returns thornames data
985
+ */
986
+ getThornamesByAddress(address) {
987
+ return __awaiter(this, void 0, void 0, function* () {
988
+ return this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameReverseLookup(address);
989
+ });
990
+ }
919
991
  }
920
992
 
921
993
  export { ThorchainAMM, Wallet };
package/lib/index.js CHANGED
@@ -14,8 +14,8 @@ var xchainEthereum = require('@xchainjs/xchain-ethereum');
14
14
  var xchainLitecoin = require('@xchainjs/xchain-litecoin');
15
15
  var xchainMayachain = require('@xchainjs/xchain-mayachain');
16
16
  var xchainThorchain = require('@xchainjs/xchain-thorchain');
17
- var xchainEvm = require('@xchainjs/xchain-evm');
18
17
  var xchainUtil = require('@xchainjs/xchain-util');
18
+ var xchainEvm = require('@xchainjs/xchain-evm');
19
19
  var ethers = require('ethers');
20
20
  var xchainThorchainQuery = require('@xchainjs/xchain-thorchain-query');
21
21
 
@@ -153,7 +153,7 @@ class Wallet {
153
153
  */
154
154
  constructor(phrase, thorchainQuery) {
155
155
  this.thorchainQuery = thorchainQuery;
156
- const settings = { network: thorchainQuery.thorchainCache.midgard.network, phrase };
156
+ const settings = { network: this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, phrase };
157
157
  this.clients = {
158
158
  BCH: new xchainBitcoincash.Client(),
159
159
  BTC: new xchainBitcoin.Client(),
@@ -258,7 +258,7 @@ class Wallet {
258
258
  }
259
259
  isThorname(name) {
260
260
  return __awaiter(this, void 0, void 0, function* () {
261
- const thornameDetails = yield this.thorchainQuery.thorchainCache.midgard.getTHORNameDetails(name);
261
+ const thornameDetails = yield this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameDetails(name); // Update when thorchainCache expose getTHORNameDetails method
262
262
  return thornameDetails !== undefined;
263
263
  });
264
264
  }
@@ -537,6 +537,68 @@ class Wallet {
537
537
  }
538
538
  });
539
539
  }
540
+ /**
541
+ * Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
542
+ * By default owner is getting from wallet
543
+ * @param thorname - Name to register
544
+ * @param chain - Chain to add alias
545
+ * @param chainAddress - Address to add to chain alias
546
+ * @param owner - Owner address (rune address)
547
+ * @param preferredAsset - referred asset
548
+ * @param expirity - expirity of the domain in MILLISECONDS
549
+ * @param isUpdate - true only if the domain is already register and you want to update its data
550
+ * @returns memo and value of deposit
551
+ */
552
+ registerThorname(params) {
553
+ return __awaiter(this, void 0, void 0, function* () {
554
+ const chainClient = this.clients[params.chain || xchainBitcoin.BTCChain];
555
+ const thorClient = this.clients.THOR;
556
+ if (!chainClient || !thorClient) {
557
+ throw Error('Can not find a wallet client');
558
+ }
559
+ const thornameEstimation = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { chain: params.chain || xchainBitcoin.BTCChain, chainAddress: params.chainAddress || chainClient.getAddress(), owner: params.owner || thorClient.getAddress() }));
560
+ const castedThorClient = thorClient;
561
+ const result = yield castedThorClient.deposit({
562
+ asset: thornameEstimation.value.asset,
563
+ amount: thornameEstimation.value.baseAmount,
564
+ memo: thornameEstimation.memo,
565
+ });
566
+ return result;
567
+ });
568
+ }
569
+ /**
570
+ * Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
571
+ * By default owner is getting from wallet
572
+ * @param thorname - Name to register
573
+ * @param chain - Chain to add alias
574
+ * @param chainAddress - Address to add to chain alias
575
+ * @param owner - Owner address (rune address)
576
+ * @param preferredAsset - referred asset
577
+ * @param expirity - expirity of the domain in MILLISECONDS
578
+ * @param isUpdate - true only if the domain is already register and you want to update its data
579
+ * @returns memo and value of deposit
580
+ */
581
+ updateThorname(params) {
582
+ return __awaiter(this, void 0, void 0, function* () {
583
+ const chainClient = this.clients[params.chain || xchainBitcoin.BTCChain];
584
+ const thorClient = this.clients.THOR;
585
+ if (!chainClient || !thorClient) {
586
+ throw Error('Can not find a wallet client');
587
+ }
588
+ const thornameDetail = yield this.thorchainQuery.getThornameDetails(params.thorname);
589
+ if ((thornameDetail === null || thornameDetail === void 0 ? void 0 : thornameDetail.owner) !== thorClient.getAddress()) {
590
+ throw Error('You cannot update a domain that is not yours');
591
+ }
592
+ const thornameEstimation = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { chain: params.chain || xchainBitcoin.BTCChain, isUpdate: true, preferredAsset: params.preferredAsset || xchainUtil.assetFromString(thornameDetail.preferredAsset), chainAddress: params.chainAddress || chainClient.getAddress() }));
593
+ const castedThorClient = thorClient;
594
+ const result = yield castedThorClient.deposit({
595
+ asset: thornameEstimation.value.asset,
596
+ amount: thornameEstimation.value.baseAmount,
597
+ memo: thornameEstimation.memo,
598
+ });
599
+ return result;
600
+ });
601
+ }
540
602
  /** Function handles liquidity add for all non rune assets
541
603
  *
542
604
  * @param params - parameters for add liquidity
@@ -920,6 +982,16 @@ class ThorchainAMM {
920
982
  });
921
983
  });
922
984
  }
985
+ /**
986
+ * Get all Thornames and its data associated owned by an address
987
+ * @param address - address
988
+ * @returns thornames data
989
+ */
990
+ getThornamesByAddress(address) {
991
+ return __awaiter(this, void 0, void 0, function* () {
992
+ return this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameReverseLookup(address);
993
+ });
994
+ }
923
995
  }
924
996
 
925
997
  exports.ThorchainAMM = ThorchainAMM;
@@ -120,4 +120,10 @@ export declare class ThorchainAMM {
120
120
  * @returns
121
121
  */
122
122
  withdrawLoan(wallet: Wallet, loanCloseParams: LoanCloseParams): Promise<TxSubmitted>;
123
+ /**
124
+ * Get all Thornames and its data associated owned by an address
125
+ * @param address - address
126
+ * @returns thornames data
127
+ */
128
+ getThornamesByAddress(address: string): Promise<import("@xchainjs/xchain-midgard/lib").ReverseTHORNames | undefined>;
123
129
  }
package/lib/types.d.ts CHANGED
@@ -56,3 +56,19 @@ export type LoanCloseParams = {
56
56
  amount: CryptoAmount;
57
57
  toAddress: Address;
58
58
  };
59
+ export type RegisterThornameParams = {
60
+ thorname: string;
61
+ owner?: string;
62
+ chain?: string;
63
+ chainAddress?: string;
64
+ preferredAsset?: Asset;
65
+ expirity?: Date;
66
+ };
67
+ export type UpdateThornameParams = {
68
+ thorname: string;
69
+ owner?: string;
70
+ chain?: string;
71
+ chainAddress?: string;
72
+ preferredAsset?: Asset;
73
+ expirity?: Date;
74
+ };
package/lib/wallet.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Network, XChainClient } from '@xchainjs/xchain-client';
2
2
  import { CryptoAmount, ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
3
3
  import { Address } from '@xchainjs/xchain-util';
4
- import { AddLiquidity, AllBalances, ExecuteSwap, LoanCloseParams, LoanOpenParams, TxSubmitted, WithdrawLiquidity } from './types';
4
+ import { AddLiquidity, AllBalances, ExecuteSwap, LoanCloseParams, LoanOpenParams, RegisterThornameParams, TxSubmitted, UpdateThornameParams, WithdrawLiquidity } from './types';
5
5
  import { EvmHelper } from './utils/evm-helper';
6
6
  export type NodeUrls = Record<Network, string>;
7
7
  /**
@@ -81,6 +81,32 @@ export declare class Wallet {
81
81
  withdrawSavers(assetAmount: CryptoAmount, memo: string, toAddress: Address): Promise<TxSubmitted>;
82
82
  loanOpen(params: LoanOpenParams): Promise<TxSubmitted>;
83
83
  loanClose(params: LoanCloseParams): Promise<TxSubmitted>;
84
+ /**
85
+ * Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
86
+ * By default owner is getting from wallet
87
+ * @param thorname - Name to register
88
+ * @param chain - Chain to add alias
89
+ * @param chainAddress - Address to add to chain alias
90
+ * @param owner - Owner address (rune address)
91
+ * @param preferredAsset - referred asset
92
+ * @param expirity - expirity of the domain in MILLISECONDS
93
+ * @param isUpdate - true only if the domain is already register and you want to update its data
94
+ * @returns memo and value of deposit
95
+ */
96
+ registerThorname(params: RegisterThornameParams): Promise<string>;
97
+ /**
98
+ * Register a THORName with a default expirity of one year. By default chain and chainAddress is getting from wallet instance and is BTC.
99
+ * By default owner is getting from wallet
100
+ * @param thorname - Name to register
101
+ * @param chain - Chain to add alias
102
+ * @param chainAddress - Address to add to chain alias
103
+ * @param owner - Owner address (rune address)
104
+ * @param preferredAsset - referred asset
105
+ * @param expirity - expirity of the domain in MILLISECONDS
106
+ * @param isUpdate - true only if the domain is already register and you want to update its data
107
+ * @returns memo and value of deposit
108
+ */
109
+ updateThorname(params: UpdateThornameParams): Promise<string>;
84
110
  /** Function handles liquidity add for all non rune assets
85
111
  *
86
112
  * @param params - parameters for add liquidity
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain-amm",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -40,24 +40,24 @@
40
40
  "@cosmos-client/core": "0.46.1",
41
41
  "@psf/bitcoincashjs-lib": "^4.0.3",
42
42
  "@xchainjs/xchain-avax": "^0.3.0",
43
- "@xchainjs/xchain-bsc": "^0.3.0",
44
43
  "@xchainjs/xchain-binance": "^5.7.1",
45
44
  "@xchainjs/xchain-bitcoin": "^0.22.2",
46
45
  "@xchainjs/xchain-bitcoincash": "^0.16.2",
47
- "@xchainjs/xchain-client": "^0.14.1",
48
- "@xchainjs/xchain-cosmos": "^0.21.2",
46
+ "@xchainjs/xchain-client": "^0.14.2",
47
+ "@xchainjs/xchain-cosmos": "^0.21.3",
48
+ "@xchainjs/xchain-bsc": "^0.3.0",
49
49
  "@xchainjs/xchain-crypto": "^0.3.0",
50
50
  "@xchainjs/xchain-doge": "^0.6.2",
51
51
  "@xchainjs/xchain-ethereum": "^0.30.0",
52
- "@xchainjs/xchain-evm": "^0.3.0",
52
+ "@xchainjs/xchain-evm": "^0.3.1",
53
53
  "@xchainjs/xchain-litecoin": "^0.12.2",
54
- "@xchainjs/xchain-midgard": "^0.5.1",
55
54
  "@xchainjs/xchain-mayachain": "^0.2.5",
55
+ "@xchainjs/xchain-midgard": "^0.5.1",
56
56
  "@xchainjs/xchain-thorchain": "^0.28.6",
57
- "@xchainjs/xchain-thorchain-query": "^0.5.0",
58
- "@xchainjs/xchain-thornode": "^0.3.4",
57
+ "@xchainjs/xchain-thornode": "^0.3.6",
58
+ "@xchainjs/xchain-thorchain-query": "^0.6.1",
59
59
  "@xchainjs/xchain-util": "^0.13.1",
60
- "@xchainjs/xchain-utxo-providers": "^0.2.1",
60
+ "@xchainjs/xchain-utxo-providers": "^0.2.2",
61
61
  "axios": "^1.3.6",
62
62
  "axios-retry": "^3.2.5",
63
63
  "bchaddrjs": "^0.5.2",
@@ -65,9 +65,9 @@
65
65
  "bech32-buffer": "^0.2.0",
66
66
  "bignumber.js": "^9.0.0",
67
67
  "bitcoinjs-lib": "5.2.0",
68
- "dotenv": "^16.0.0",
69
68
  "coininfo": "^5.1.0",
70
69
  "coinselect": "^3.1.12",
70
+ "dotenv": "^16.0.0",
71
71
  "ethers": "^5.6.6",
72
72
  "wif": "^2.0.6"
73
73
  },
@@ -76,24 +76,24 @@
76
76
  "@cosmos-client/core": "0.46.1",
77
77
  "@psf/bitcoincashjs-lib": "^4.0.3",
78
78
  "@xchainjs/xchain-avax": "^0.3.0",
79
- "@xchainjs/xchain-bsc": "^0.3.0",
80
79
  "@xchainjs/xchain-binance": "^5.7.1",
81
80
  "@xchainjs/xchain-bitcoin": "^0.22.2",
82
81
  "@xchainjs/xchain-bitcoincash": "^0.16.2",
83
- "@xchainjs/xchain-client": "^0.14.1",
84
- "@xchainjs/xchain-cosmos": "^0.21.2",
82
+ "@xchainjs/xchain-client": "^0.14.2",
83
+ "@xchainjs/xchain-cosmos": "^0.21.3",
84
+ "@xchainjs/xchain-bsc": "^0.3.0",
85
85
  "@xchainjs/xchain-crypto": "^0.3.0",
86
86
  "@xchainjs/xchain-doge": "^0.6.2",
87
87
  "@xchainjs/xchain-ethereum": "^0.30.0",
88
- "@xchainjs/xchain-evm": "^0.3.0",
88
+ "@xchainjs/xchain-evm": "^0.3.1",
89
89
  "@xchainjs/xchain-litecoin": "^0.12.2",
90
- "@xchainjs/xchain-midgard": "^0.5.1",
91
90
  "@xchainjs/xchain-mayachain": "^0.2.5",
91
+ "@xchainjs/xchain-midgard": "^0.5.1",
92
92
  "@xchainjs/xchain-thorchain": "^0.28.6",
93
- "@xchainjs/xchain-thorchain-query": "^0.5.0",
94
- "@xchainjs/xchain-thornode": "^0.3.4",
93
+ "@xchainjs/xchain-thornode": "^0.3.6",
94
+ "@xchainjs/xchain-thorchain-query": "^0.6.1",
95
95
  "@xchainjs/xchain-util": "^0.13.1",
96
- "@xchainjs/xchain-utxo-providers": "^0.2.1",
96
+ "@xchainjs/xchain-utxo-providers": "^0.2.2",
97
97
  "axios": "^1.3.6",
98
98
  "axios-retry": "^3.2.5",
99
99
  "bchaddrjs": "^0.5.2",
@@ -109,4 +109,4 @@
109
109
  "publishConfig": {
110
110
  "access": "public"
111
111
  }
112
- }
112
+ }