@xchainjs/xchain-thorchain-amm 1.1.16 → 1.1.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
@@ -9,9 +9,9 @@ import { DOGEChain, Client as Client$6, defaultDogeParams } from '@xchainjs/xcha
9
9
  import { AssetETH, ETHChain, Client as Client$5, defaultEthParams } from '@xchainjs/xchain-ethereum';
10
10
  import { abi, MAX_APPROVAL } from '@xchainjs/xchain-evm';
11
11
  import { LTCChain, Client as Client$7, defaultLtcParams } from '@xchainjs/xchain-litecoin';
12
- import { THORChain, Client, defaultClientConfig } from '@xchainjs/xchain-thorchain';
12
+ import { THORChain, Client, defaultClientConfig, RUNE_DECIMAL, AssetRuneNative } from '@xchainjs/xchain-thorchain';
13
13
  import { ThorchainQuery, ThorchainCache, Thornode } from '@xchainjs/xchain-thorchain-query';
14
- import { eqAsset, getContractAddressFromAsset, baseAmount } from '@xchainjs/xchain-util';
14
+ import { eqAsset, getContractAddressFromAsset, baseAmount, CryptoAmount } from '@xchainjs/xchain-util';
15
15
  import { Wallet } from '@xchainjs/xchain-wallet';
16
16
  import { ethers } from 'ethers';
17
17
 
@@ -635,6 +635,120 @@ class ThorchainAMM {
635
635
  return this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameReverseLookup(address);
636
636
  });
637
637
  }
638
+ /**
639
+ * Estimate the cost of a THORName registration
640
+ * @param {RegisterTHORName} params Params to make the registration
641
+ * @returns {QuoteTHORName} Memo to make the registration and the estimation of the operation
642
+ */
643
+ estimateTHORNameRegistration(params) {
644
+ return __awaiter(this, void 0, void 0, function* () {
645
+ const errors = [];
646
+ if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, params.chain, params.chainAddress)) {
647
+ errors.push(`Invalid address ${params.chainAddress} for ${params.chain} chain`);
648
+ }
649
+ if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, THORChain, params.owner)) {
650
+ errors.push(`Invalid owner ${params.owner} due it is not a THORChain address`);
651
+ }
652
+ if (errors.length) {
653
+ return {
654
+ memo: '',
655
+ errors,
656
+ value: new CryptoAmount(baseAmount(0, RUNE_DECIMAL), AssetRuneNative),
657
+ allowed: false,
658
+ };
659
+ }
660
+ try {
661
+ const estimated = yield this.thorchainQuery.estimateThorname(Object.assign({}, params));
662
+ return Object.assign(Object.assign({}, estimated), { allowed: true, errors: [] });
663
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
664
+ }
665
+ catch (e) {
666
+ return {
667
+ memo: '',
668
+ errors: ['message' in e ? e.message : `Unknown error: ${e}`],
669
+ value: new CryptoAmount(baseAmount(0, RUNE_DECIMAL), AssetRuneNative),
670
+ allowed: false,
671
+ };
672
+ }
673
+ });
674
+ }
675
+ /**
676
+ * Estimate the cost of an update of a THORName
677
+ * @param {QuoteTHORNameParams} params Params to make the update
678
+ * @returns {QuoteTHORName} Memo to make the update and the estimation of the operation
679
+ */
680
+ estimateTHORNameUpdate(params) {
681
+ return __awaiter(this, void 0, void 0, function* () {
682
+ const errors = [];
683
+ if ((params.chain && !params.chainAddress) || (!params.chain && params.chainAddress)) {
684
+ errors.push(`Alias not provided correctly`);
685
+ }
686
+ if (params.chain &&
687
+ params.chainAddress &&
688
+ !validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, params.chain, params.chainAddress)) {
689
+ errors.push(`Invalid alias ${params.chainAddress} for ${params.chain} chain`);
690
+ }
691
+ if (params.owner &&
692
+ !validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, THORChain, params.owner)) {
693
+ errors.push(`Invalid owner ${params.owner} due it is not a THORChain address`);
694
+ }
695
+ if (errors.length) {
696
+ return {
697
+ memo: '',
698
+ errors,
699
+ value: new CryptoAmount(baseAmount(0, RUNE_DECIMAL), AssetRuneNative),
700
+ allowed: false,
701
+ };
702
+ }
703
+ try {
704
+ const estimated = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { isUpdate: true }));
705
+ return Object.assign(Object.assign({}, estimated), { allowed: true, errors: [] });
706
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
707
+ }
708
+ catch (e) {
709
+ return {
710
+ memo: '',
711
+ errors: ['message' in e ? e.message : `Unknown error: ${e}`],
712
+ value: new CryptoAmount(baseAmount(0, RUNE_DECIMAL), AssetRuneNative),
713
+ allowed: false,
714
+ };
715
+ }
716
+ });
717
+ }
718
+ /**
719
+ * Register a THORName
720
+ * @param {RegisterTHORName} params Params to make the registration
721
+ * @returns {TxSubmitted} Transaction made to register the THORName
722
+ */
723
+ registerTHORName(params) {
724
+ return __awaiter(this, void 0, void 0, function* () {
725
+ const quote = yield this.estimateTHORNameRegistration(params);
726
+ if (!quote.allowed)
727
+ throw Error(`Can not register THORName. ${quote.errors.join(' ')}`);
728
+ return ThorchainAction.makeAction({
729
+ wallet: this.wallet,
730
+ assetAmount: quote.value,
731
+ memo: quote.memo,
732
+ });
733
+ });
734
+ }
735
+ /**
736
+ * Update a THORName
737
+ * @param {UpdateTHORName} params Params to make the update
738
+ * @returns {TxSubmitted} Transaction made to update the THORName
739
+ */
740
+ updateTHORName(params) {
741
+ return __awaiter(this, void 0, void 0, function* () {
742
+ const quote = yield this.estimateTHORNameUpdate(params);
743
+ if (!quote.allowed)
744
+ throw Error(`Can not update THORName. ${quote.errors.join(' ')}`);
745
+ return ThorchainAction.makeAction({
746
+ wallet: this.wallet,
747
+ assetAmount: quote.value,
748
+ memo: quote.memo,
749
+ });
750
+ });
751
+ }
638
752
  }
639
753
 
640
754
  export { ThorchainAMM };
package/lib/index.js CHANGED
@@ -639,6 +639,120 @@ class ThorchainAMM {
639
639
  return this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameReverseLookup(address);
640
640
  });
641
641
  }
642
+ /**
643
+ * Estimate the cost of a THORName registration
644
+ * @param {RegisterTHORName} params Params to make the registration
645
+ * @returns {QuoteTHORName} Memo to make the registration and the estimation of the operation
646
+ */
647
+ estimateTHORNameRegistration(params) {
648
+ return __awaiter(this, void 0, void 0, function* () {
649
+ const errors = [];
650
+ if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, params.chain, params.chainAddress)) {
651
+ errors.push(`Invalid address ${params.chainAddress} for ${params.chain} chain`);
652
+ }
653
+ if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, xchainThorchain.THORChain, params.owner)) {
654
+ errors.push(`Invalid owner ${params.owner} due it is not a THORChain address`);
655
+ }
656
+ if (errors.length) {
657
+ return {
658
+ memo: '',
659
+ errors,
660
+ value: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, xchainThorchain.RUNE_DECIMAL), xchainThorchain.AssetRuneNative),
661
+ allowed: false,
662
+ };
663
+ }
664
+ try {
665
+ const estimated = yield this.thorchainQuery.estimateThorname(Object.assign({}, params));
666
+ return Object.assign(Object.assign({}, estimated), { allowed: true, errors: [] });
667
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
668
+ }
669
+ catch (e) {
670
+ return {
671
+ memo: '',
672
+ errors: ['message' in e ? e.message : `Unknown error: ${e}`],
673
+ value: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, xchainThorchain.RUNE_DECIMAL), xchainThorchain.AssetRuneNative),
674
+ allowed: false,
675
+ };
676
+ }
677
+ });
678
+ }
679
+ /**
680
+ * Estimate the cost of an update of a THORName
681
+ * @param {QuoteTHORNameParams} params Params to make the update
682
+ * @returns {QuoteTHORName} Memo to make the update and the estimation of the operation
683
+ */
684
+ estimateTHORNameUpdate(params) {
685
+ return __awaiter(this, void 0, void 0, function* () {
686
+ const errors = [];
687
+ if ((params.chain && !params.chainAddress) || (!params.chain && params.chainAddress)) {
688
+ errors.push(`Alias not provided correctly`);
689
+ }
690
+ if (params.chain &&
691
+ params.chainAddress &&
692
+ !validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, params.chain, params.chainAddress)) {
693
+ errors.push(`Invalid alias ${params.chainAddress} for ${params.chain} chain`);
694
+ }
695
+ if (params.owner &&
696
+ !validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, xchainThorchain.THORChain, params.owner)) {
697
+ errors.push(`Invalid owner ${params.owner} due it is not a THORChain address`);
698
+ }
699
+ if (errors.length) {
700
+ return {
701
+ memo: '',
702
+ errors,
703
+ value: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, xchainThorchain.RUNE_DECIMAL), xchainThorchain.AssetRuneNative),
704
+ allowed: false,
705
+ };
706
+ }
707
+ try {
708
+ const estimated = yield this.thorchainQuery.estimateThorname(Object.assign(Object.assign({}, params), { isUpdate: true }));
709
+ return Object.assign(Object.assign({}, estimated), { allowed: true, errors: [] });
710
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
711
+ }
712
+ catch (e) {
713
+ return {
714
+ memo: '',
715
+ errors: ['message' in e ? e.message : `Unknown error: ${e}`],
716
+ value: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, xchainThorchain.RUNE_DECIMAL), xchainThorchain.AssetRuneNative),
717
+ allowed: false,
718
+ };
719
+ }
720
+ });
721
+ }
722
+ /**
723
+ * Register a THORName
724
+ * @param {RegisterTHORName} params Params to make the registration
725
+ * @returns {TxSubmitted} Transaction made to register the THORName
726
+ */
727
+ registerTHORName(params) {
728
+ return __awaiter(this, void 0, void 0, function* () {
729
+ const quote = yield this.estimateTHORNameRegistration(params);
730
+ if (!quote.allowed)
731
+ throw Error(`Can not register THORName. ${quote.errors.join(' ')}`);
732
+ return ThorchainAction.makeAction({
733
+ wallet: this.wallet,
734
+ assetAmount: quote.value,
735
+ memo: quote.memo,
736
+ });
737
+ });
738
+ }
739
+ /**
740
+ * Update a THORName
741
+ * @param {UpdateTHORName} params Params to make the update
742
+ * @returns {TxSubmitted} Transaction made to update the THORName
743
+ */
744
+ updateTHORName(params) {
745
+ return __awaiter(this, void 0, void 0, function* () {
746
+ const quote = yield this.estimateTHORNameUpdate(params);
747
+ if (!quote.allowed)
748
+ throw Error(`Can not update THORName. ${quote.errors.join(' ')}`);
749
+ return ThorchainAction.makeAction({
750
+ wallet: this.wallet,
751
+ assetAmount: quote.value,
752
+ memo: quote.memo,
753
+ });
754
+ });
755
+ }
642
756
  }
643
757
 
644
758
  exports.ThorchainAMM = ThorchainAMM;
@@ -1,7 +1,7 @@
1
- import { AddliquidityPosition, EstimateAddLP, EstimateAddSaver, EstimateWithdrawLP, EstimateWithdrawSaver, LoanCloseParams, LoanCloseQuote, LoanOpenParams, LoanOpenQuote, QuoteSwapParams, SaversPosition, SaversWithdraw, ThorchainQuery, TxDetails, WithdrawLiquidityPosition, getSaver } from '@xchainjs/xchain-thorchain-query';
1
+ import { AddliquidityPosition, EstimateAddLP, EstimateAddSaver, EstimateWithdrawLP, EstimateWithdrawSaver, LoanCloseParams, LoanCloseQuote, LoanOpenParams, LoanOpenQuote, QuoteSwapParams, RegisterTHORName, SaversPosition, SaversWithdraw, ThorchainQuery, TxDetails, UpdateTHORName, WithdrawLiquidityPosition, getSaver } from '@xchainjs/xchain-thorchain-query';
2
2
  import { CryptoAmount } from '@xchainjs/xchain-util';
3
3
  import { Wallet } from '@xchainjs/xchain-wallet';
4
- import { ApproveParams, IsApprovedParams, TxSubmitted } from './types';
4
+ import { ApproveParams, IsApprovedParams, QuoteTHORName, TxSubmitted } from './types';
5
5
  /**
6
6
  * THORChain Class for interacting with THORChain.
7
7
  * Recommended main class to use for swapping with THORChain
@@ -140,4 +140,28 @@ export declare class ThorchainAMM {
140
140
  * @returns The Thornames data.
141
141
  */
142
142
  getThornamesByAddress(address: string): Promise<import("@xchainjs/xchain-midgard/lib").ReverseTHORNames | undefined>;
143
+ /**
144
+ * Estimate the cost of a THORName registration
145
+ * @param {RegisterTHORName} params Params to make the registration
146
+ * @returns {QuoteTHORName} Memo to make the registration and the estimation of the operation
147
+ */
148
+ estimateTHORNameRegistration(params: RegisterTHORName): Promise<QuoteTHORName>;
149
+ /**
150
+ * Estimate the cost of an update of a THORName
151
+ * @param {QuoteTHORNameParams} params Params to make the update
152
+ * @returns {QuoteTHORName} Memo to make the update and the estimation of the operation
153
+ */
154
+ estimateTHORNameUpdate(params: UpdateTHORName): Promise<QuoteTHORName>;
155
+ /**
156
+ * Register a THORName
157
+ * @param {RegisterTHORName} params Params to make the registration
158
+ * @returns {TxSubmitted} Transaction made to register the THORName
159
+ */
160
+ registerTHORName(params: RegisterTHORName): Promise<TxSubmitted>;
161
+ /**
162
+ * Update a THORName
163
+ * @param {UpdateTHORName} params Params to make the update
164
+ * @returns {TxSubmitted} Transaction made to update the THORName
165
+ */
166
+ updateTHORName(params: UpdateTHORName): Promise<TxSubmitted>;
143
167
  }
package/lib/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Balance, FeeOption } from '@xchainjs/xchain-client';
2
- import { LiquidityPool } from '@xchainjs/xchain-thorchain-query';
2
+ import { LiquidityPool, QuoteTHORName as BaseQuoteTHORName } from '@xchainjs/xchain-thorchain-query';
3
3
  import { Address, Asset, BaseAmount, Chain, CryptoAmount } from '@xchainjs/xchain-util';
4
4
  /**
5
5
  * Represents the balance information for all assets on a particular chain.
@@ -114,3 +114,16 @@ export type ApproveParams = {
114
114
  asset: Asset;
115
115
  amount: CryptoAmount | undefined;
116
116
  };
117
+ /**
118
+ * Estimation quote to register or update a THORName
119
+ */
120
+ export type QuoteTHORName = BaseQuoteTHORName & {
121
+ /**
122
+ * If the action can be or not can be done
123
+ */
124
+ allowed: boolean;
125
+ /**
126
+ * If any, list of errors with the reason the operation is not allowed
127
+ */
128
+ errors: string[];
129
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain-amm",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -48,7 +48,7 @@
48
48
  "@xchainjs/xchain-evm": "0.6.4",
49
49
  "@xchainjs/xchain-litecoin": "0.14.6",
50
50
  "@xchainjs/xchain-thorchain": "1.1.1",
51
- "@xchainjs/xchain-thorchain-query": "0.7.15",
51
+ "@xchainjs/xchain-thorchain-query": "0.7.17",
52
52
  "@xchainjs/xchain-util": "0.13.7",
53
53
  "@xchainjs/xchain-wallet": "0.1.19",
54
54
  "ethers": "5.7.2"