@xchainjs/xchain-thorchain-amm 1.1.14 → 1.1.16
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 +48 -22
- package/lib/index.js +28 -2
- package/lib/utils.d.ts +3 -1
- package/package.json +16 -16
package/lib/index.esm.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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 } from '@xchainjs/xchain-thorchain';
|
|
13
13
|
import { ThorchainQuery, ThorchainCache, Thornode } from '@xchainjs/xchain-thorchain-query';
|
|
14
14
|
import { eqAsset, getContractAddressFromAsset, baseAmount } from '@xchainjs/xchain-util';
|
|
15
15
|
import { Wallet } from '@xchainjs/xchain-wallet';
|
|
@@ -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`);
|
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`);
|
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.16",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -36,21 +36,21 @@
|
|
|
36
36
|
"url": "https://github.com/xchainjs/xchainjs-lib/issues"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@xchainjs/xchain-avax": "0.5.
|
|
40
|
-
"@xchainjs/xchain-binance": "5.7.
|
|
41
|
-
"@xchainjs/xchain-bitcoin": "0.23.
|
|
42
|
-
"@xchainjs/xchain-bitcoincash": "0.17.
|
|
43
|
-
"@xchainjs/xchain-bsc": "0.5.
|
|
44
|
-
"@xchainjs/xchain-client": "0.16.
|
|
45
|
-
"@xchainjs/xchain-cosmos": "1.1.
|
|
46
|
-
"@xchainjs/xchain-doge": "0.7.
|
|
47
|
-
"@xchainjs/xchain-ethereum": "0.32.
|
|
48
|
-
"@xchainjs/xchain-evm": "0.6.
|
|
49
|
-
"@xchainjs/xchain-litecoin": "0.14.
|
|
50
|
-
"@xchainjs/xchain-thorchain": "1.1.
|
|
51
|
-
"@xchainjs/xchain-thorchain-query": "0.7.
|
|
52
|
-
"@xchainjs/xchain-util": "0.13.
|
|
53
|
-
"@xchainjs/xchain-wallet": "0.1.
|
|
39
|
+
"@xchainjs/xchain-avax": "0.5.6",
|
|
40
|
+
"@xchainjs/xchain-binance": "5.7.17",
|
|
41
|
+
"@xchainjs/xchain-bitcoin": "0.23.19",
|
|
42
|
+
"@xchainjs/xchain-bitcoincash": "0.17.17",
|
|
43
|
+
"@xchainjs/xchain-bsc": "0.5.6",
|
|
44
|
+
"@xchainjs/xchain-client": "0.16.8",
|
|
45
|
+
"@xchainjs/xchain-cosmos": "1.1.6",
|
|
46
|
+
"@xchainjs/xchain-doge": "0.7.20",
|
|
47
|
+
"@xchainjs/xchain-ethereum": "0.32.6",
|
|
48
|
+
"@xchainjs/xchain-evm": "0.6.4",
|
|
49
|
+
"@xchainjs/xchain-litecoin": "0.14.6",
|
|
50
|
+
"@xchainjs/xchain-thorchain": "1.1.1",
|
|
51
|
+
"@xchainjs/xchain-thorchain-query": "0.7.15",
|
|
52
|
+
"@xchainjs/xchain-util": "0.13.7",
|
|
53
|
+
"@xchainjs/xchain-wallet": "0.1.19",
|
|
54
54
|
"ethers": "5.7.2"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|