@xchainjs/xchain-thorchain-amm 3.0.13 → 3.0.15
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 +64 -60
- package/lib/index.js +31 -27
- package/package.json +21 -20
package/lib/index.esm.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { AssetAVAX, AVAXChain, Client as Client$
|
|
2
|
-
import { AssetBETH, BASEChain, Client as Client$
|
|
3
|
-
import { XRPChain, Client, defaultXRPParams } from '@xchainjs/xchain-ripple';
|
|
4
|
-
import { BTCChain, Client as Client$
|
|
5
|
-
import { BCHChain, Client as Client$
|
|
6
|
-
import { AssetBSC, BSCChain, Client as Client$
|
|
1
|
+
import { AssetAVAX, AVAXChain, Client as Client$6, defaultAvaxParams } from '@xchainjs/xchain-avax';
|
|
2
|
+
import { AssetBETH, BASEChain, Client as Client$4, defaultBaseParams } from '@xchainjs/xchain-base';
|
|
3
|
+
import { XRPChain, Client as Client$1, defaultXRPParams } from '@xchainjs/xchain-ripple';
|
|
4
|
+
import { BTCChain, Client as Client$b, defaultBTCParams } from '@xchainjs/xchain-bitcoin';
|
|
5
|
+
import { BCHChain, Client as Client$a, defaultBchParams } from '@xchainjs/xchain-bitcoincash';
|
|
6
|
+
import { AssetBSC, BSCChain, Client as Client$5, defaultBscParams } from '@xchainjs/xchain-bsc';
|
|
7
|
+
import { SOLChain, Client, defaultSolanaParams } from '@xchainjs/xchain-solana';
|
|
7
8
|
import { Protocol, Network } from '@xchainjs/xchain-client';
|
|
8
|
-
import { GAIAChain, Client as Client$
|
|
9
|
-
import { DOGEChain, Client as Client$
|
|
10
|
-
import { AssetETH, ETHChain, Client as Client$
|
|
9
|
+
import { GAIAChain, Client as Client$3, AssetATOM } from '@xchainjs/xchain-cosmos';
|
|
10
|
+
import { DOGEChain, Client as Client$8, defaultDogeParams } from '@xchainjs/xchain-doge';
|
|
11
|
+
import { AssetETH, ETHChain, Client as Client$7, defaultEthParams } from '@xchainjs/xchain-ethereum';
|
|
11
12
|
import { abi, MAX_APPROVAL } from '@xchainjs/xchain-evm';
|
|
12
|
-
import { LTCChain, Client as Client$
|
|
13
|
-
import { THORChain, Client as Client$
|
|
13
|
+
import { LTCChain, Client as Client$9, defaultLtcParams } from '@xchainjs/xchain-litecoin';
|
|
14
|
+
import { THORChain, Client as Client$2, defaultClientConfig, AssetRuneNative, RUNE_DECIMAL } from '@xchainjs/xchain-thorchain';
|
|
14
15
|
import { ThorchainQuery, ThorchainCache, Thornode } from '@xchainjs/xchain-thorchain-query';
|
|
15
16
|
import { eqAsset, isSynthAsset, getContractAddressFromAsset, baseAmount, isTradeAsset, isSecuredAsset, assetToString, AssetCryptoAmount, CryptoAmount } from '@xchainjs/xchain-util';
|
|
16
17
|
import { Wallet } from '@xchainjs/xchain-wallet';
|
|
@@ -2994,27 +2995,29 @@ const isProtocolBFTChain = (chain) => {
|
|
|
2994
2995
|
const validateAddress = (network, chain, address) => {
|
|
2995
2996
|
switch (chain) {
|
|
2996
2997
|
case BTCChain:
|
|
2997
|
-
return new Client$
|
|
2998
|
+
return new Client$b(Object.assign(Object.assign({}, defaultBTCParams), { network })).validateAddress(address);
|
|
2998
2999
|
case BCHChain:
|
|
2999
|
-
return new Client$
|
|
3000
|
+
return new Client$a(Object.assign(Object.assign({}, defaultBchParams), { network })).validateAddress(address);
|
|
3000
3001
|
case LTCChain:
|
|
3001
|
-
return new Client$
|
|
3002
|
+
return new Client$9(Object.assign(Object.assign({}, defaultLtcParams), { network })).validateAddress(address);
|
|
3002
3003
|
case DOGEChain:
|
|
3003
|
-
return new Client$
|
|
3004
|
+
return new Client$8(Object.assign(Object.assign({}, defaultDogeParams), { network })).validateAddress(address);
|
|
3004
3005
|
case ETHChain:
|
|
3005
|
-
return new Client$
|
|
3006
|
+
return new Client$7(Object.assign(Object.assign({}, defaultEthParams), { network })).validateAddress(address);
|
|
3006
3007
|
case AVAXChain:
|
|
3007
|
-
return new Client$
|
|
3008
|
+
return new Client$6(Object.assign(Object.assign({}, defaultAvaxParams), { network })).validateAddress(address);
|
|
3008
3009
|
case BSCChain:
|
|
3009
|
-
return new Client$
|
|
3010
|
+
return new Client$5(Object.assign(Object.assign({}, defaultBscParams), { network })).validateAddress(address);
|
|
3010
3011
|
case BASEChain:
|
|
3011
|
-
return new Client$
|
|
3012
|
+
return new Client$4(Object.assign(Object.assign({}, defaultBaseParams), { network })).validateAddress(address);
|
|
3012
3013
|
case GAIAChain:
|
|
3013
|
-
return new Client$
|
|
3014
|
+
return new Client$3({ network }).validateAddress(address);
|
|
3014
3015
|
case THORChain:
|
|
3015
|
-
return new Client$
|
|
3016
|
+
return new Client$2(Object.assign(Object.assign({}, defaultClientConfig), { network })).validateAddress(address);
|
|
3016
3017
|
case XRPChain:
|
|
3017
|
-
return new Client(Object.assign(Object.assign({}, defaultXRPParams), { network })).validateAddress(address);
|
|
3018
|
+
return new Client$1(Object.assign(Object.assign({}, defaultXRPParams), { network })).validateAddress(address);
|
|
3019
|
+
case SOLChain:
|
|
3020
|
+
return new Client(Object.assign(Object.assign({}, defaultSolanaParams), { network })).validateAddress(address);
|
|
3018
3021
|
default:
|
|
3019
3022
|
throw Error('Unsupported chain');
|
|
3020
3023
|
}
|
|
@@ -3028,8 +3031,8 @@ class ThorchainAction {
|
|
|
3028
3031
|
: this.makeProtocolAction(actionParams);
|
|
3029
3032
|
});
|
|
3030
3033
|
}
|
|
3031
|
-
static makeProtocolAction(
|
|
3032
|
-
return __awaiter(this,
|
|
3034
|
+
static makeProtocolAction(_a) {
|
|
3035
|
+
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, memo }) {
|
|
3033
3036
|
const hash = yield wallet.deposit({
|
|
3034
3037
|
chain: THORChain,
|
|
3035
3038
|
asset: assetAmount.asset,
|
|
@@ -3042,8 +3045,8 @@ class ThorchainAction {
|
|
|
3042
3045
|
};
|
|
3043
3046
|
});
|
|
3044
3047
|
}
|
|
3045
|
-
static makeNonProtocolAction(
|
|
3046
|
-
return __awaiter(this,
|
|
3048
|
+
static makeNonProtocolAction(_a) {
|
|
3049
|
+
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, recipient, memo, }) {
|
|
3047
3050
|
// Non EVM actions
|
|
3048
3051
|
if (!isProtocolEVMChain(assetAmount.asset.chain)) {
|
|
3049
3052
|
if (isProtocolBFTChain(assetAmount.asset.chain)) {
|
|
@@ -3136,17 +3139,18 @@ class ThorchainAMM {
|
|
|
3136
3139
|
* @returns ThorchainAMM
|
|
3137
3140
|
*/
|
|
3138
3141
|
constructor(thorchainQuery = new ThorchainQuery(), wallet = new Wallet({
|
|
3139
|
-
BTC: new Client$
|
|
3140
|
-
BCH: new Client$
|
|
3141
|
-
LTC: new Client$
|
|
3142
|
-
DOGE: new Client$
|
|
3143
|
-
ETH: new Client$
|
|
3144
|
-
AVAX: new Client$
|
|
3145
|
-
BSC: new Client$
|
|
3146
|
-
GAIA: new Client$
|
|
3147
|
-
THOR: new Client$
|
|
3148
|
-
BASE: new Client$
|
|
3149
|
-
XRP: new Client(Object.assign(Object.assign({}, defaultXRPParams), { network: Network.Mainnet })),
|
|
3142
|
+
BTC: new Client$b(Object.assign(Object.assign({}, defaultBTCParams), { network: Network.Mainnet })),
|
|
3143
|
+
BCH: new Client$a(Object.assign(Object.assign({}, defaultBchParams), { network: Network.Mainnet })),
|
|
3144
|
+
LTC: new Client$9(Object.assign(Object.assign({}, defaultLtcParams), { network: Network.Mainnet })),
|
|
3145
|
+
DOGE: new Client$8(Object.assign(Object.assign({}, defaultDogeParams), { network: Network.Mainnet })),
|
|
3146
|
+
ETH: new Client$7(Object.assign(Object.assign({}, defaultEthParams), { network: Network.Mainnet })),
|
|
3147
|
+
AVAX: new Client$6(Object.assign(Object.assign({}, defaultAvaxParams), { network: Network.Mainnet })),
|
|
3148
|
+
BSC: new Client$5(Object.assign(Object.assign({}, defaultBscParams), { network: Network.Mainnet })),
|
|
3149
|
+
GAIA: new Client$3({ network: Network.Mainnet }),
|
|
3150
|
+
THOR: new Client$2(Object.assign(Object.assign({}, defaultClientConfig), { network: Network.Mainnet })),
|
|
3151
|
+
BASE: new Client$4(Object.assign(Object.assign({}, defaultBaseParams), { network: Network.Mainnet })),
|
|
3152
|
+
XRP: new Client$1(Object.assign(Object.assign({}, defaultXRPParams), { network: Network.Mainnet })),
|
|
3153
|
+
SOL: new Client(Object.assign(Object.assign({}, defaultSolanaParams), { network: Network.Mainnet })),
|
|
3150
3154
|
})) {
|
|
3151
3155
|
this.thorchainQuery = thorchainQuery;
|
|
3152
3156
|
this.wallet = wallet;
|
|
@@ -3160,8 +3164,8 @@ class ThorchainAMM {
|
|
|
3160
3164
|
|
|
3161
3165
|
* @returns The estimated swap details.
|
|
3162
3166
|
*/
|
|
3163
|
-
estimateSwap(
|
|
3164
|
-
return __awaiter(this,
|
|
3167
|
+
estimateSwap(_a) {
|
|
3168
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress = '', affiliateBps = 0, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
|
|
3165
3169
|
const errors = yield this.validateSwap({
|
|
3166
3170
|
fromAddress,
|
|
3167
3171
|
fromAsset,
|
|
@@ -3192,8 +3196,8 @@ class ThorchainAMM {
|
|
|
3192
3196
|
* @param {QuoteSwapParams} quoteSwapParams Swap params
|
|
3193
3197
|
* @returns {string[]} the reasons the swap can not be done. If it is empty there are no reason to avoid the swap
|
|
3194
3198
|
*/
|
|
3195
|
-
validateSwap(
|
|
3196
|
-
return __awaiter(this,
|
|
3199
|
+
validateSwap(_a) {
|
|
3200
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }) {
|
|
3197
3201
|
const errors = [];
|
|
3198
3202
|
if (destinationAddress &&
|
|
3199
3203
|
!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, isSynthAsset(destinationAsset) || isTradeAsset(destinationAsset) || isSecuredAsset(destinationAsset)
|
|
@@ -3245,8 +3249,8 @@ class ThorchainAMM {
|
|
|
3245
3249
|
* @param params - The swap parameters.
|
|
3246
3250
|
* @returns {SwapSubmitted} - The transaction hash, URL of BlockExplorer, and expected wait time.
|
|
3247
3251
|
*/
|
|
3248
|
-
doSwap(
|
|
3249
|
-
return __awaiter(this,
|
|
3252
|
+
doSwap(_a) {
|
|
3253
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }) {
|
|
3250
3254
|
// Retrieve swap details from ThorchainQuery to ensure validity
|
|
3251
3255
|
const txDetails = yield this.thorchainQuery.quoteSwap({
|
|
3252
3256
|
fromAsset,
|
|
@@ -3277,8 +3281,8 @@ class ThorchainAMM {
|
|
|
3277
3281
|
* @param {ApproveParams} approveParams Parameters for approving the router to spend
|
|
3278
3282
|
* @returns {Promise<TxSubmitted>} Transaction hash and URL
|
|
3279
3283
|
*/
|
|
3280
|
-
approveRouterToSpend(
|
|
3281
|
-
return __awaiter(this,
|
|
3284
|
+
approveRouterToSpend(_a) {
|
|
3285
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, amount }) {
|
|
3282
3286
|
// Get inbound details for the asset chain
|
|
3283
3287
|
const inboundDetails = yield this.thorchainQuery.getChainInboundDetails(asset.chain);
|
|
3284
3288
|
if (!inboundDetails.router)
|
|
@@ -3299,8 +3303,8 @@ class ThorchainAMM {
|
|
|
3299
3303
|
* int name of address
|
|
3300
3304
|
* @returns {string[]} the reasons the router of the asset is not allowed to spend the amount. If it is empty, the asset router is allowed to spend the amount
|
|
3301
3305
|
*/
|
|
3302
|
-
isRouterApprovedToSpend(
|
|
3303
|
-
return __awaiter(this,
|
|
3306
|
+
isRouterApprovedToSpend(_a) {
|
|
3307
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, amount, address }) {
|
|
3304
3308
|
const errors = [];
|
|
3305
3309
|
if (!isProtocolERC20Asset(asset)) {
|
|
3306
3310
|
errors.push('Asset should be ERC20');
|
|
@@ -3705,8 +3709,8 @@ class ThorchainAMM {
|
|
|
3705
3709
|
* @param {AddToTradeAccountParams} param Add to trade account params
|
|
3706
3710
|
* @returns {AddToTradeAccount} Estimation to add amount to trade account
|
|
3707
3711
|
*/
|
|
3708
|
-
estimateAddToTradeAccount(
|
|
3709
|
-
return __awaiter(this,
|
|
3712
|
+
estimateAddToTradeAccount(_a) {
|
|
3713
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, address }) {
|
|
3710
3714
|
const errors = [];
|
|
3711
3715
|
if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, THORChain, address)) {
|
|
3712
3716
|
errors.push('Invalid trade account address');
|
|
@@ -3715,7 +3719,7 @@ class ThorchainAMM {
|
|
|
3715
3719
|
try {
|
|
3716
3720
|
inboundDetails = yield this.thorchainQuery.getChainInboundDetails(amount.asset.chain);
|
|
3717
3721
|
}
|
|
3718
|
-
catch (
|
|
3722
|
+
catch (_b) {
|
|
3719
3723
|
errors.push(`Can not get inbound address for ${amount.asset.chain}`);
|
|
3720
3724
|
}
|
|
3721
3725
|
if (errors.length) {
|
|
@@ -3741,8 +3745,8 @@ class ThorchainAMM {
|
|
|
3741
3745
|
* @param {AddToTradeAccountParams} param Add to trade account params
|
|
3742
3746
|
* @returns {TxSubmitted} Transaction made to add the trade amount
|
|
3743
3747
|
*/
|
|
3744
|
-
addToTradeAccount(
|
|
3745
|
-
return __awaiter(this,
|
|
3748
|
+
addToTradeAccount(_a) {
|
|
3749
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, address }) {
|
|
3746
3750
|
const quote = yield this.estimateAddToTradeAccount({ amount, address });
|
|
3747
3751
|
if (!quote.allowed)
|
|
3748
3752
|
throw Error(`Can not add to trade account. ${quote.errors.join(' ')}`);
|
|
@@ -3759,8 +3763,8 @@ class ThorchainAMM {
|
|
|
3759
3763
|
* @param {WithdrawFromTradeAccountParams} param Withdraw from trade account params
|
|
3760
3764
|
* @returns {WithdrawFromTradeAccount} Estimation to withdraw amount from trade account
|
|
3761
3765
|
*/
|
|
3762
|
-
estimateWithdrawFromTradeAccount(
|
|
3763
|
-
return __awaiter(this,
|
|
3766
|
+
estimateWithdrawFromTradeAccount(_a) {
|
|
3767
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, address, }) {
|
|
3764
3768
|
const errors = [];
|
|
3765
3769
|
if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, amount.asset.chain, address)) {
|
|
3766
3770
|
errors.push('Invalid address to send the withdraw');
|
|
@@ -3786,8 +3790,8 @@ class ThorchainAMM {
|
|
|
3786
3790
|
* @param {WithdrawFromTradeAccountParams} param Withdraw from trade account params
|
|
3787
3791
|
* @returns {TxSubmitted} Estimation to withdraw amount from trade account
|
|
3788
3792
|
*/
|
|
3789
|
-
withdrawFromTradeAccount(
|
|
3790
|
-
return __awaiter(this,
|
|
3793
|
+
withdrawFromTradeAccount(_a) {
|
|
3794
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, address }) {
|
|
3791
3795
|
const quote = yield this.estimateWithdrawFromTradeAccount({ amount, address });
|
|
3792
3796
|
if (!quote.allowed)
|
|
3793
3797
|
throw Error(`Can not withdraw from trade account. ${quote.errors.join(' ')}`);
|
|
@@ -3803,8 +3807,8 @@ class ThorchainAMM {
|
|
|
3803
3807
|
* @param {DepositToRunePoolParams} params Deposit to Rune pool params
|
|
3804
3808
|
* @returns {EstimateDepositToRunePool} Estimation to make the deposit
|
|
3805
3809
|
*/
|
|
3806
|
-
estimateDepositToRunePool(
|
|
3807
|
-
return __awaiter(this,
|
|
3810
|
+
estimateDepositToRunePool(_a) {
|
|
3811
|
+
return __awaiter(this, arguments, void 0, function* ({ amount }) {
|
|
3808
3812
|
const constants = yield this.thorchainQuery.thorchainCache.thornode.getTcConstants();
|
|
3809
3813
|
return {
|
|
3810
3814
|
allowed: true,
|
|
@@ -3837,8 +3841,8 @@ class ThorchainAMM {
|
|
|
3837
3841
|
* @param {WithdrawFromRunePoolParams} params Withdraw from Rune pool params
|
|
3838
3842
|
* @returns {EstimateWithdrawFromRunePool} Estimation to make a withdraw from Rune pool
|
|
3839
3843
|
*/
|
|
3840
|
-
estimateWithdrawFromRunePool(
|
|
3841
|
-
return __awaiter(this,
|
|
3844
|
+
estimateWithdrawFromRunePool(_a) {
|
|
3845
|
+
return __awaiter(this, arguments, void 0, function* ({ withdrawBps, affiliate, feeBps, }) {
|
|
3842
3846
|
const errors = [];
|
|
3843
3847
|
if (withdrawBps <= 0 || withdrawBps > 10000) {
|
|
3844
3848
|
errors.push('withdrawBps out of range. Range 0-10000');
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var xchainRipple = require('@xchainjs/xchain-ripple');
|
|
|
6
6
|
var xchainBitcoin = require('@xchainjs/xchain-bitcoin');
|
|
7
7
|
var xchainBitcoincash = require('@xchainjs/xchain-bitcoincash');
|
|
8
8
|
var xchainBsc = require('@xchainjs/xchain-bsc');
|
|
9
|
+
var xchainSolana = require('@xchainjs/xchain-solana');
|
|
9
10
|
var xchainClient = require('@xchainjs/xchain-client');
|
|
10
11
|
var xchainCosmos = require('@xchainjs/xchain-cosmos');
|
|
11
12
|
var xchainDoge = require('@xchainjs/xchain-doge');
|
|
@@ -3017,6 +3018,8 @@ const validateAddress = (network, chain, address) => {
|
|
|
3017
3018
|
return new xchainThorchain.Client(Object.assign(Object.assign({}, xchainThorchain.defaultClientConfig), { network })).validateAddress(address);
|
|
3018
3019
|
case xchainRipple.XRPChain:
|
|
3019
3020
|
return new xchainRipple.Client(Object.assign(Object.assign({}, xchainRipple.defaultXRPParams), { network })).validateAddress(address);
|
|
3021
|
+
case xchainSolana.SOLChain:
|
|
3022
|
+
return new xchainSolana.Client(Object.assign(Object.assign({}, xchainSolana.defaultSolanaParams), { network })).validateAddress(address);
|
|
3020
3023
|
default:
|
|
3021
3024
|
throw Error('Unsupported chain');
|
|
3022
3025
|
}
|
|
@@ -3030,8 +3033,8 @@ class ThorchainAction {
|
|
|
3030
3033
|
: this.makeProtocolAction(actionParams);
|
|
3031
3034
|
});
|
|
3032
3035
|
}
|
|
3033
|
-
static makeProtocolAction(
|
|
3034
|
-
return __awaiter(this,
|
|
3036
|
+
static makeProtocolAction(_a) {
|
|
3037
|
+
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, memo }) {
|
|
3035
3038
|
const hash = yield wallet.deposit({
|
|
3036
3039
|
chain: xchainThorchain.THORChain,
|
|
3037
3040
|
asset: assetAmount.asset,
|
|
@@ -3044,8 +3047,8 @@ class ThorchainAction {
|
|
|
3044
3047
|
};
|
|
3045
3048
|
});
|
|
3046
3049
|
}
|
|
3047
|
-
static makeNonProtocolAction(
|
|
3048
|
-
return __awaiter(this,
|
|
3050
|
+
static makeNonProtocolAction(_a) {
|
|
3051
|
+
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, recipient, memo, }) {
|
|
3049
3052
|
// Non EVM actions
|
|
3050
3053
|
if (!isProtocolEVMChain(assetAmount.asset.chain)) {
|
|
3051
3054
|
if (isProtocolBFTChain(assetAmount.asset.chain)) {
|
|
@@ -3149,6 +3152,7 @@ class ThorchainAMM {
|
|
|
3149
3152
|
THOR: new xchainThorchain.Client(Object.assign(Object.assign({}, xchainThorchain.defaultClientConfig), { network: xchainClient.Network.Mainnet })),
|
|
3150
3153
|
BASE: new xchainBase.Client(Object.assign(Object.assign({}, xchainBase.defaultBaseParams), { network: xchainClient.Network.Mainnet })),
|
|
3151
3154
|
XRP: new xchainRipple.Client(Object.assign(Object.assign({}, xchainRipple.defaultXRPParams), { network: xchainClient.Network.Mainnet })),
|
|
3155
|
+
SOL: new xchainSolana.Client(Object.assign(Object.assign({}, xchainSolana.defaultSolanaParams), { network: xchainClient.Network.Mainnet })),
|
|
3152
3156
|
})) {
|
|
3153
3157
|
this.thorchainQuery = thorchainQuery;
|
|
3154
3158
|
this.wallet = wallet;
|
|
@@ -3162,8 +3166,8 @@ class ThorchainAMM {
|
|
|
3162
3166
|
|
|
3163
3167
|
* @returns The estimated swap details.
|
|
3164
3168
|
*/
|
|
3165
|
-
estimateSwap(
|
|
3166
|
-
return __awaiter(this,
|
|
3169
|
+
estimateSwap(_a) {
|
|
3170
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress = '', affiliateBps = 0, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
|
|
3167
3171
|
const errors = yield this.validateSwap({
|
|
3168
3172
|
fromAddress,
|
|
3169
3173
|
fromAsset,
|
|
@@ -3194,8 +3198,8 @@ class ThorchainAMM {
|
|
|
3194
3198
|
* @param {QuoteSwapParams} quoteSwapParams Swap params
|
|
3195
3199
|
* @returns {string[]} the reasons the swap can not be done. If it is empty there are no reason to avoid the swap
|
|
3196
3200
|
*/
|
|
3197
|
-
validateSwap(
|
|
3198
|
-
return __awaiter(this,
|
|
3201
|
+
validateSwap(_a) {
|
|
3202
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }) {
|
|
3199
3203
|
const errors = [];
|
|
3200
3204
|
if (destinationAddress &&
|
|
3201
3205
|
!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, xchainUtil.isSynthAsset(destinationAsset) || xchainUtil.isTradeAsset(destinationAsset) || xchainUtil.isSecuredAsset(destinationAsset)
|
|
@@ -3247,8 +3251,8 @@ class ThorchainAMM {
|
|
|
3247
3251
|
* @param params - The swap parameters.
|
|
3248
3252
|
* @returns {SwapSubmitted} - The transaction hash, URL of BlockExplorer, and expected wait time.
|
|
3249
3253
|
*/
|
|
3250
|
-
doSwap(
|
|
3251
|
-
return __awaiter(this,
|
|
3254
|
+
doSwap(_a) {
|
|
3255
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }) {
|
|
3252
3256
|
// Retrieve swap details from ThorchainQuery to ensure validity
|
|
3253
3257
|
const txDetails = yield this.thorchainQuery.quoteSwap({
|
|
3254
3258
|
fromAsset,
|
|
@@ -3279,8 +3283,8 @@ class ThorchainAMM {
|
|
|
3279
3283
|
* @param {ApproveParams} approveParams Parameters for approving the router to spend
|
|
3280
3284
|
* @returns {Promise<TxSubmitted>} Transaction hash and URL
|
|
3281
3285
|
*/
|
|
3282
|
-
approveRouterToSpend(
|
|
3283
|
-
return __awaiter(this,
|
|
3286
|
+
approveRouterToSpend(_a) {
|
|
3287
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, amount }) {
|
|
3284
3288
|
// Get inbound details for the asset chain
|
|
3285
3289
|
const inboundDetails = yield this.thorchainQuery.getChainInboundDetails(asset.chain);
|
|
3286
3290
|
if (!inboundDetails.router)
|
|
@@ -3301,8 +3305,8 @@ class ThorchainAMM {
|
|
|
3301
3305
|
* int name of address
|
|
3302
3306
|
* @returns {string[]} the reasons the router of the asset is not allowed to spend the amount. If it is empty, the asset router is allowed to spend the amount
|
|
3303
3307
|
*/
|
|
3304
|
-
isRouterApprovedToSpend(
|
|
3305
|
-
return __awaiter(this,
|
|
3308
|
+
isRouterApprovedToSpend(_a) {
|
|
3309
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, amount, address }) {
|
|
3306
3310
|
const errors = [];
|
|
3307
3311
|
if (!isProtocolERC20Asset(asset)) {
|
|
3308
3312
|
errors.push('Asset should be ERC20');
|
|
@@ -3707,8 +3711,8 @@ class ThorchainAMM {
|
|
|
3707
3711
|
* @param {AddToTradeAccountParams} param Add to trade account params
|
|
3708
3712
|
* @returns {AddToTradeAccount} Estimation to add amount to trade account
|
|
3709
3713
|
*/
|
|
3710
|
-
estimateAddToTradeAccount(
|
|
3711
|
-
return __awaiter(this,
|
|
3714
|
+
estimateAddToTradeAccount(_a) {
|
|
3715
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, address }) {
|
|
3712
3716
|
const errors = [];
|
|
3713
3717
|
if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, xchainThorchain.THORChain, address)) {
|
|
3714
3718
|
errors.push('Invalid trade account address');
|
|
@@ -3717,7 +3721,7 @@ class ThorchainAMM {
|
|
|
3717
3721
|
try {
|
|
3718
3722
|
inboundDetails = yield this.thorchainQuery.getChainInboundDetails(amount.asset.chain);
|
|
3719
3723
|
}
|
|
3720
|
-
catch (
|
|
3724
|
+
catch (_b) {
|
|
3721
3725
|
errors.push(`Can not get inbound address for ${amount.asset.chain}`);
|
|
3722
3726
|
}
|
|
3723
3727
|
if (errors.length) {
|
|
@@ -3743,8 +3747,8 @@ class ThorchainAMM {
|
|
|
3743
3747
|
* @param {AddToTradeAccountParams} param Add to trade account params
|
|
3744
3748
|
* @returns {TxSubmitted} Transaction made to add the trade amount
|
|
3745
3749
|
*/
|
|
3746
|
-
addToTradeAccount(
|
|
3747
|
-
return __awaiter(this,
|
|
3750
|
+
addToTradeAccount(_a) {
|
|
3751
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, address }) {
|
|
3748
3752
|
const quote = yield this.estimateAddToTradeAccount({ amount, address });
|
|
3749
3753
|
if (!quote.allowed)
|
|
3750
3754
|
throw Error(`Can not add to trade account. ${quote.errors.join(' ')}`);
|
|
@@ -3761,8 +3765,8 @@ class ThorchainAMM {
|
|
|
3761
3765
|
* @param {WithdrawFromTradeAccountParams} param Withdraw from trade account params
|
|
3762
3766
|
* @returns {WithdrawFromTradeAccount} Estimation to withdraw amount from trade account
|
|
3763
3767
|
*/
|
|
3764
|
-
estimateWithdrawFromTradeAccount(
|
|
3765
|
-
return __awaiter(this,
|
|
3768
|
+
estimateWithdrawFromTradeAccount(_a) {
|
|
3769
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, address, }) {
|
|
3766
3770
|
const errors = [];
|
|
3767
3771
|
if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, amount.asset.chain, address)) {
|
|
3768
3772
|
errors.push('Invalid address to send the withdraw');
|
|
@@ -3788,8 +3792,8 @@ class ThorchainAMM {
|
|
|
3788
3792
|
* @param {WithdrawFromTradeAccountParams} param Withdraw from trade account params
|
|
3789
3793
|
* @returns {TxSubmitted} Estimation to withdraw amount from trade account
|
|
3790
3794
|
*/
|
|
3791
|
-
withdrawFromTradeAccount(
|
|
3792
|
-
return __awaiter(this,
|
|
3795
|
+
withdrawFromTradeAccount(_a) {
|
|
3796
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, address }) {
|
|
3793
3797
|
const quote = yield this.estimateWithdrawFromTradeAccount({ amount, address });
|
|
3794
3798
|
if (!quote.allowed)
|
|
3795
3799
|
throw Error(`Can not withdraw from trade account. ${quote.errors.join(' ')}`);
|
|
@@ -3805,8 +3809,8 @@ class ThorchainAMM {
|
|
|
3805
3809
|
* @param {DepositToRunePoolParams} params Deposit to Rune pool params
|
|
3806
3810
|
* @returns {EstimateDepositToRunePool} Estimation to make the deposit
|
|
3807
3811
|
*/
|
|
3808
|
-
estimateDepositToRunePool(
|
|
3809
|
-
return __awaiter(this,
|
|
3812
|
+
estimateDepositToRunePool(_a) {
|
|
3813
|
+
return __awaiter(this, arguments, void 0, function* ({ amount }) {
|
|
3810
3814
|
const constants = yield this.thorchainQuery.thorchainCache.thornode.getTcConstants();
|
|
3811
3815
|
return {
|
|
3812
3816
|
allowed: true,
|
|
@@ -3839,8 +3843,8 @@ class ThorchainAMM {
|
|
|
3839
3843
|
* @param {WithdrawFromRunePoolParams} params Withdraw from Rune pool params
|
|
3840
3844
|
* @returns {EstimateWithdrawFromRunePool} Estimation to make a withdraw from Rune pool
|
|
3841
3845
|
*/
|
|
3842
|
-
estimateWithdrawFromRunePool(
|
|
3843
|
-
return __awaiter(this,
|
|
3846
|
+
estimateWithdrawFromRunePool(_a) {
|
|
3847
|
+
return __awaiter(this, arguments, void 0, function* ({ withdrawBps, affiliate, feeBps, }) {
|
|
3844
3848
|
const errors = [];
|
|
3845
3849
|
if (withdrawBps <= 0 || withdrawBps > 10000) {
|
|
3846
3850
|
errors.push('withdrawBps out of range. Range 0-10000');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-amm",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.15",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -36,28 +36,29 @@
|
|
|
36
36
|
"url": "https://github.com/xchainjs/xchainjs-lib/issues"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@xchainjs/xchain-avax": "2.0.
|
|
40
|
-
"@xchainjs/xchain-base": "1.0.
|
|
41
|
-
"@xchainjs/xchain-bitcoin": "2.0.
|
|
42
|
-
"@xchainjs/xchain-bitcoincash": "2.0.
|
|
43
|
-
"@xchainjs/xchain-bsc": "2.0.
|
|
44
|
-
"@xchainjs/xchain-client": "2.0.
|
|
45
|
-
"@xchainjs/xchain-cosmos": "3.0.
|
|
46
|
-
"@xchainjs/xchain-doge": "2.0.
|
|
47
|
-
"@xchainjs/xchain-ethereum": "2.0.
|
|
48
|
-
"@xchainjs/xchain-evm": "2.0.
|
|
49
|
-
"@xchainjs/xchain-litecoin": "2.0.
|
|
50
|
-
"@xchainjs/xchain-ripple": "1.0.
|
|
51
|
-
"@xchainjs/xchain-
|
|
52
|
-
"@xchainjs/xchain-thorchain
|
|
53
|
-
"@xchainjs/xchain-
|
|
54
|
-
"@xchainjs/xchain-
|
|
39
|
+
"@xchainjs/xchain-avax": "2.0.9",
|
|
40
|
+
"@xchainjs/xchain-base": "1.0.9",
|
|
41
|
+
"@xchainjs/xchain-bitcoin": "2.0.6",
|
|
42
|
+
"@xchainjs/xchain-bitcoincash": "2.0.7",
|
|
43
|
+
"@xchainjs/xchain-bsc": "2.0.10",
|
|
44
|
+
"@xchainjs/xchain-client": "2.0.6",
|
|
45
|
+
"@xchainjs/xchain-cosmos": "3.0.6",
|
|
46
|
+
"@xchainjs/xchain-doge": "2.0.6",
|
|
47
|
+
"@xchainjs/xchain-ethereum": "2.0.10",
|
|
48
|
+
"@xchainjs/xchain-evm": "2.0.9",
|
|
49
|
+
"@xchainjs/xchain-litecoin": "2.0.6",
|
|
50
|
+
"@xchainjs/xchain-ripple": "1.0.7",
|
|
51
|
+
"@xchainjs/xchain-solana": "1.0.6",
|
|
52
|
+
"@xchainjs/xchain-thorchain": "3.0.10",
|
|
53
|
+
"@xchainjs/xchain-thorchain-query": "2.0.8",
|
|
54
|
+
"@xchainjs/xchain-util": "2.0.4",
|
|
55
|
+
"@xchainjs/xchain-wallet": "2.0.13",
|
|
55
56
|
"ethers": "^6.14.3"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"@ledgerhq/hw-transport-node-hid": "6.28.6",
|
|
59
|
-
"axios": "1.8.4",
|
|
60
|
-
"axios-mock-adapter": "2.1.0"
|
|
59
|
+
"@ledgerhq/hw-transport-node-hid": "^6.28.6",
|
|
60
|
+
"axios": "^1.8.4",
|
|
61
|
+
"axios-mock-adapter": "^2.1.0"
|
|
61
62
|
},
|
|
62
63
|
"publishConfig": {
|
|
63
64
|
"access": "public",
|