@xchainjs/xchain-thorchain-amm 1.1.15 → 1.1.17
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 +163 -23
- package/lib/index.js +142 -2
- package/lib/thorchain-amm.d.ts +26 -2
- package/lib/types.d.ts +14 -1
- package/lib/utils.d.ts +3 -1
- package/package.json +2 -2
package/lib/index.esm.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { AssetAVAX, Client as Client$
|
|
2
|
-
import {
|
|
3
|
-
import { Client, defaultBTCParams } from '@xchainjs/xchain-bitcoin';
|
|
4
|
-
import { Client as Client$
|
|
5
|
-
import { AssetBSC, Client as Client$
|
|
1
|
+
import { AssetAVAX, AVAXChain, Client as Client$4, defaultAvaxParams } from '@xchainjs/xchain-avax';
|
|
2
|
+
import { BNBChain, Client as Client$1, AssetBNB } from '@xchainjs/xchain-binance';
|
|
3
|
+
import { BTCChain, Client as Client$9, defaultBTCParams } from '@xchainjs/xchain-bitcoin';
|
|
4
|
+
import { BCHChain, Client as Client$8, defaultBchParams } from '@xchainjs/xchain-bitcoincash';
|
|
5
|
+
import { AssetBSC, BSCChain, Client as Client$3, defaultBscParams } from '@xchainjs/xchain-bsc';
|
|
6
6
|
import { Protocol, Network } from '@xchainjs/xchain-client';
|
|
7
|
-
import {
|
|
8
|
-
import { Client as Client$
|
|
9
|
-
import { AssetETH, Client as Client$
|
|
7
|
+
import { GAIAChain, Client as Client$2, AssetATOM } from '@xchainjs/xchain-cosmos';
|
|
8
|
+
import { DOGEChain, Client as Client$6, defaultDogeParams } from '@xchainjs/xchain-doge';
|
|
9
|
+
import { AssetETH, ETHChain, Client as Client$5, defaultEthParams } from '@xchainjs/xchain-ethereum';
|
|
10
10
|
import { abi, MAX_APPROVAL } from '@xchainjs/xchain-evm';
|
|
11
|
-
import { Client as Client$
|
|
12
|
-
import { THORChain, Client
|
|
11
|
+
import { LTCChain, Client as Client$7, defaultLtcParams } from '@xchainjs/xchain-litecoin';
|
|
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
|
|
|
@@ -67,6 +67,32 @@ const isProtocolERC20Asset = (asset) => {
|
|
|
67
67
|
const isProtocolBFTChain = (chain) => {
|
|
68
68
|
return [AssetBNB.chain, AssetATOM.chain].includes(chain);
|
|
69
69
|
};
|
|
70
|
+
const validateAddress = (network, chain, address) => {
|
|
71
|
+
switch (chain) {
|
|
72
|
+
case BTCChain:
|
|
73
|
+
return new Client$9(Object.assign(Object.assign({}, defaultBTCParams), { network })).validateAddress(address);
|
|
74
|
+
case BCHChain:
|
|
75
|
+
return new Client$8(Object.assign(Object.assign({}, defaultBchParams), { network })).validateAddress(address);
|
|
76
|
+
case LTCChain:
|
|
77
|
+
return new Client$7(Object.assign(Object.assign({}, defaultLtcParams), { network })).validateAddress(address);
|
|
78
|
+
case DOGEChain:
|
|
79
|
+
return new Client$6(Object.assign(Object.assign({}, defaultDogeParams), { network })).validateAddress(address);
|
|
80
|
+
case ETHChain:
|
|
81
|
+
return new Client$5(Object.assign(Object.assign({}, defaultEthParams), { network })).validateAddress(address);
|
|
82
|
+
case AVAXChain:
|
|
83
|
+
return new Client$4(Object.assign(Object.assign({}, defaultAvaxParams), { network })).validateAddress(address);
|
|
84
|
+
case BSCChain:
|
|
85
|
+
return new Client$3(Object.assign(Object.assign({}, defaultBscParams), { network })).validateAddress(address);
|
|
86
|
+
case GAIAChain:
|
|
87
|
+
return new Client$2({ network }).validateAddress(address);
|
|
88
|
+
case BNBChain:
|
|
89
|
+
return new Client$1({ network }).validateAddress(address);
|
|
90
|
+
case THORChain:
|
|
91
|
+
return new Client(Object.assign(Object.assign({}, defaultClientConfig), { network })).validateAddress(address);
|
|
92
|
+
default:
|
|
93
|
+
throw Error('Unsupported chain');
|
|
94
|
+
}
|
|
95
|
+
};
|
|
70
96
|
|
|
71
97
|
class ThorchainAction {
|
|
72
98
|
static makeAction(actionParams) {
|
|
@@ -178,16 +204,16 @@ class ThorchainAMM {
|
|
|
178
204
|
* @returns ThorchainAMM
|
|
179
205
|
*/
|
|
180
206
|
constructor(thorchainQuery = new ThorchainQuery(), wallet = new Wallet({
|
|
181
|
-
BTC: new Client(Object.assign(Object.assign({}, defaultBTCParams), { network: Network.Mainnet })),
|
|
182
|
-
BCH: new Client$
|
|
183
|
-
LTC: new Client$
|
|
184
|
-
DOGE: new Client$
|
|
185
|
-
ETH: new Client$
|
|
186
|
-
AVAX: new Client$
|
|
187
|
-
BSC: new Client$
|
|
188
|
-
GAIA: new Client$
|
|
189
|
-
BNB: new Client$
|
|
190
|
-
THOR: new Client
|
|
207
|
+
BTC: new Client$9(Object.assign(Object.assign({}, defaultBTCParams), { network: Network.Mainnet })),
|
|
208
|
+
BCH: new Client$8(Object.assign(Object.assign({}, defaultBchParams), { network: Network.Mainnet })),
|
|
209
|
+
LTC: new Client$7(Object.assign(Object.assign({}, defaultLtcParams), { network: Network.Mainnet })),
|
|
210
|
+
DOGE: new Client$6(Object.assign(Object.assign({}, defaultDogeParams), { network: Network.Mainnet })),
|
|
211
|
+
ETH: new Client$5(Object.assign(Object.assign({}, defaultEthParams), { network: Network.Mainnet })),
|
|
212
|
+
AVAX: new Client$4(Object.assign(Object.assign({}, defaultAvaxParams), { network: Network.Mainnet })),
|
|
213
|
+
BSC: new Client$3(Object.assign(Object.assign({}, defaultBscParams), { network: Network.Mainnet })),
|
|
214
|
+
GAIA: new Client$2({ network: Network.Mainnet }),
|
|
215
|
+
BNB: new Client$1({ network: Network.Mainnet }),
|
|
216
|
+
THOR: new Client(Object.assign(Object.assign({}, defaultClientConfig), { network: Network.Mainnet })),
|
|
191
217
|
})) {
|
|
192
218
|
this.thorchainQuery = thorchainQuery;
|
|
193
219
|
this.wallet = wallet;
|
|
@@ -236,11 +262,11 @@ class ThorchainAMM {
|
|
|
236
262
|
return __awaiter(this, void 0, void 0, function* () {
|
|
237
263
|
const errors = [];
|
|
238
264
|
if (destinationAddress &&
|
|
239
|
-
!this.
|
|
265
|
+
!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, destinationAsset.synth ? THORChain : destinationAsset.chain, destinationAddress)) {
|
|
240
266
|
errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
|
|
241
267
|
}
|
|
242
268
|
if (affiliateAddress) {
|
|
243
|
-
const isThorAddress = this.
|
|
269
|
+
const isThorAddress = validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, THORChain, affiliateAddress);
|
|
244
270
|
const isThorname = !!(yield this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameDetails(affiliateAddress));
|
|
245
271
|
if (!(isThorAddress || isThorname))
|
|
246
272
|
errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
|
|
@@ -609,6 +635,120 @@ class ThorchainAMM {
|
|
|
609
635
|
return this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameReverseLookup(address);
|
|
610
636
|
});
|
|
611
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
|
+
}
|
|
612
752
|
}
|
|
613
753
|
|
|
614
754
|
export { ThorchainAMM };
|
package/lib/index.js
CHANGED
|
@@ -71,6 +71,32 @@ const isProtocolERC20Asset = (asset) => {
|
|
|
71
71
|
const isProtocolBFTChain = (chain) => {
|
|
72
72
|
return [xchainBinance.AssetBNB.chain, xchainCosmos.AssetATOM.chain].includes(chain);
|
|
73
73
|
};
|
|
74
|
+
const validateAddress = (network, chain, address) => {
|
|
75
|
+
switch (chain) {
|
|
76
|
+
case xchainBitcoin.BTCChain:
|
|
77
|
+
return new xchainBitcoin.Client(Object.assign(Object.assign({}, xchainBitcoin.defaultBTCParams), { network })).validateAddress(address);
|
|
78
|
+
case xchainBitcoincash.BCHChain:
|
|
79
|
+
return new xchainBitcoincash.Client(Object.assign(Object.assign({}, xchainBitcoincash.defaultBchParams), { network })).validateAddress(address);
|
|
80
|
+
case xchainLitecoin.LTCChain:
|
|
81
|
+
return new xchainLitecoin.Client(Object.assign(Object.assign({}, xchainLitecoin.defaultLtcParams), { network })).validateAddress(address);
|
|
82
|
+
case xchainDoge.DOGEChain:
|
|
83
|
+
return new xchainDoge.Client(Object.assign(Object.assign({}, xchainDoge.defaultDogeParams), { network })).validateAddress(address);
|
|
84
|
+
case xchainEthereum.ETHChain:
|
|
85
|
+
return new xchainEthereum.Client(Object.assign(Object.assign({}, xchainEthereum.defaultEthParams), { network })).validateAddress(address);
|
|
86
|
+
case xchainAvax.AVAXChain:
|
|
87
|
+
return new xchainAvax.Client(Object.assign(Object.assign({}, xchainAvax.defaultAvaxParams), { network })).validateAddress(address);
|
|
88
|
+
case xchainBsc.BSCChain:
|
|
89
|
+
return new xchainBsc.Client(Object.assign(Object.assign({}, xchainBsc.defaultBscParams), { network })).validateAddress(address);
|
|
90
|
+
case xchainCosmos.GAIAChain:
|
|
91
|
+
return new xchainCosmos.Client({ network }).validateAddress(address);
|
|
92
|
+
case xchainBinance.BNBChain:
|
|
93
|
+
return new xchainBinance.Client({ network }).validateAddress(address);
|
|
94
|
+
case xchainThorchain.THORChain:
|
|
95
|
+
return new xchainThorchain.Client(Object.assign(Object.assign({}, xchainThorchain.defaultClientConfig), { network })).validateAddress(address);
|
|
96
|
+
default:
|
|
97
|
+
throw Error('Unsupported chain');
|
|
98
|
+
}
|
|
99
|
+
};
|
|
74
100
|
|
|
75
101
|
class ThorchainAction {
|
|
76
102
|
static makeAction(actionParams) {
|
|
@@ -240,11 +266,11 @@ class ThorchainAMM {
|
|
|
240
266
|
return __awaiter(this, void 0, void 0, function* () {
|
|
241
267
|
const errors = [];
|
|
242
268
|
if (destinationAddress &&
|
|
243
|
-
!this.
|
|
269
|
+
!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, destinationAsset.synth ? xchainThorchain.THORChain : destinationAsset.chain, destinationAddress)) {
|
|
244
270
|
errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
|
|
245
271
|
}
|
|
246
272
|
if (affiliateAddress) {
|
|
247
|
-
const isThorAddress = this.
|
|
273
|
+
const isThorAddress = validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, xchainThorchain.THORChain, affiliateAddress);
|
|
248
274
|
const isThorname = !!(yield this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameDetails(affiliateAddress));
|
|
249
275
|
if (!(isThorAddress || isThorname))
|
|
250
276
|
errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
|
|
@@ -613,6 +639,120 @@ class ThorchainAMM {
|
|
|
613
639
|
return this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameReverseLookup(address);
|
|
614
640
|
});
|
|
615
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
|
+
}
|
|
616
756
|
}
|
|
617
757
|
|
|
618
758
|
exports.ThorchainAMM = ThorchainAMM;
|
package/lib/thorchain-amm.d.ts
CHANGED
|
@@ -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/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Network } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Address, Asset, Chain } from '@xchainjs/xchain-util';
|
|
2
3
|
/**
|
|
3
4
|
* Check if a chain is EVM and supported by the protocol
|
|
4
5
|
* @param {Chain} chain to check
|
|
@@ -17,3 +18,4 @@ export declare const isProtocolERC20Asset: (asset: Asset) => boolean;
|
|
|
17
18
|
* @returns true if chain is EVM, otherwise, false
|
|
18
19
|
*/
|
|
19
20
|
export declare const isProtocolBFTChain: (chain: Chain) => boolean;
|
|
21
|
+
export declare const validateAddress: (network: Network, chain: Chain, address: Address) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-amm",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
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.
|
|
51
|
+
"@xchainjs/xchain-thorchain-query": "0.7.16",
|
|
52
52
|
"@xchainjs/xchain-util": "0.13.7",
|
|
53
53
|
"@xchainjs/xchain-wallet": "0.1.19",
|
|
54
54
|
"ethers": "5.7.2"
|