@xchainjs/xchain-thorchain-amm 1.0.4 → 1.1.0
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 +26 -4
- package/lib/index.js +25 -3
- package/lib/thorchain-amm.d.ts +7 -1
- package/lib/types.d.ts +4 -0
- package/package.json +5 -5
package/lib/index.esm.js
CHANGED
|
@@ -7,11 +7,11 @@ import { Network, FeeOption, Protocol } from '@xchainjs/xchain-client';
|
|
|
7
7
|
import { AssetATOM, Client as Client$7 } from '@xchainjs/xchain-cosmos';
|
|
8
8
|
import { Client as Client$3, defaultDogeParams } from '@xchainjs/xchain-doge';
|
|
9
9
|
import { AssetETH, Client as Client$4, defaultEthParams } from '@xchainjs/xchain-ethereum';
|
|
10
|
+
import { abi, MAX_APPROVAL } from '@xchainjs/xchain-evm';
|
|
10
11
|
import { Client as Client$2, defaultLtcParams } from '@xchainjs/xchain-litecoin';
|
|
11
12
|
import { THORChain, Client as Client$9, defaultClientConfig } from '@xchainjs/xchain-thorchain';
|
|
12
13
|
import { ThorchainQuery, ThorchainCache, Thornode } from '@xchainjs/xchain-thorchain-query';
|
|
13
|
-
import {
|
|
14
|
-
import { eqAsset, getContractAddressFromAsset as getContractAddressFromAsset$1 } from '@xchainjs/xchain-util';
|
|
14
|
+
import { eqAsset, getContractAddressFromAsset as getContractAddressFromAsset$1, baseAmount as baseAmount$1 } from '@xchainjs/xchain-util';
|
|
15
15
|
import { ethers } from 'ethers';
|
|
16
16
|
|
|
17
17
|
/******************************************************************************
|
|
@@ -12596,7 +12596,8 @@ const isProtocolEVMChain = (chain) => {
|
|
|
12596
12596
|
*/
|
|
12597
12597
|
const isProtocolERC20Asset = (asset) => {
|
|
12598
12598
|
return isProtocolEVMChain(asset.chain)
|
|
12599
|
-
? [AssetETH, AssetAVAX, AssetBSC].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, asset)) === -1
|
|
12599
|
+
? [AssetETH, AssetAVAX, AssetBSC].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, asset)) === -1 &&
|
|
12600
|
+
!asset.synth
|
|
12600
12601
|
: false;
|
|
12601
12602
|
};
|
|
12602
12603
|
/**
|
|
@@ -12626,7 +12627,7 @@ class ThorchainAction {
|
|
|
12626
12627
|
});
|
|
12627
12628
|
return {
|
|
12628
12629
|
hash,
|
|
12629
|
-
url: yield wallet.getExplorerTxUrl(
|
|
12630
|
+
url: yield wallet.getExplorerTxUrl(THORChain, hash),
|
|
12630
12631
|
};
|
|
12631
12632
|
});
|
|
12632
12633
|
}
|
|
@@ -12832,6 +12833,27 @@ class ThorchainAMM {
|
|
|
12832
12833
|
});
|
|
12833
12834
|
});
|
|
12834
12835
|
}
|
|
12836
|
+
/**
|
|
12837
|
+
* Approve the Thorchain router to spend a certain amount in the asset chain.
|
|
12838
|
+
* @param {ApproveParams} approveParams Parameters for approving the router to spend
|
|
12839
|
+
* @returns {Promise<TxSubmitted>} Transaction hash and URL
|
|
12840
|
+
*/
|
|
12841
|
+
approveRouterToSpend({ asset, amount }) {
|
|
12842
|
+
return __awaiter$6(this, void 0, void 0, function* () {
|
|
12843
|
+
// Get inbound details for the asset chain
|
|
12844
|
+
const inboundDetails = yield this.thorchainQuery.getChainInboundDetails(asset.chain);
|
|
12845
|
+
if (!inboundDetails.router)
|
|
12846
|
+
throw Error(`Unknown router address for ${asset.chain}`);
|
|
12847
|
+
// Perform approval
|
|
12848
|
+
const tx = yield this.wallet.approve(asset, (amount === null || amount === void 0 ? void 0 : amount.baseAmount) ||
|
|
12849
|
+
baseAmount$1(MAX_APPROVAL.toString(), yield this.thorchainQuery.thorchainCache.midgardQuery.getDecimalForAsset(asset)), inboundDetails.router);
|
|
12850
|
+
// Return transaction hash and URL
|
|
12851
|
+
return {
|
|
12852
|
+
hash: tx.hash,
|
|
12853
|
+
url: yield this.wallet.getExplorerTxUrl(asset.chain, tx.hash),
|
|
12854
|
+
};
|
|
12855
|
+
});
|
|
12856
|
+
}
|
|
12835
12857
|
/**
|
|
12836
12858
|
* Validate if the asset router is allowed to spend the asset amount in name of the address
|
|
12837
12859
|
* @param {IsApprovedParams} isApprovedParams contains the asset and the amount the router is supposed to spend
|
package/lib/index.js
CHANGED
|
@@ -11,10 +11,10 @@ var xchainClient = require('@xchainjs/xchain-client');
|
|
|
11
11
|
var xchainCosmos = require('@xchainjs/xchain-cosmos');
|
|
12
12
|
var xchainDoge = require('@xchainjs/xchain-doge');
|
|
13
13
|
var xchainEthereum = require('@xchainjs/xchain-ethereum');
|
|
14
|
+
var xchainEvm = require('@xchainjs/xchain-evm');
|
|
14
15
|
var xchainLitecoin = require('@xchainjs/xchain-litecoin');
|
|
15
16
|
var xchainThorchain = require('@xchainjs/xchain-thorchain');
|
|
16
17
|
var xchainThorchainQuery = require('@xchainjs/xchain-thorchain-query');
|
|
17
|
-
var xchainEvm = require('@xchainjs/xchain-evm');
|
|
18
18
|
var xchainUtil = require('@xchainjs/xchain-util');
|
|
19
19
|
var ethers = require('ethers');
|
|
20
20
|
|
|
@@ -12600,7 +12600,8 @@ const isProtocolEVMChain = (chain) => {
|
|
|
12600
12600
|
*/
|
|
12601
12601
|
const isProtocolERC20Asset = (asset) => {
|
|
12602
12602
|
return isProtocolEVMChain(asset.chain)
|
|
12603
|
-
? [xchainEthereum.AssetETH, xchainAvax.AssetAVAX, xchainBsc.AssetBSC].findIndex((nativeEVMAsset) => xchainUtil.eqAsset(nativeEVMAsset, asset)) === -1
|
|
12603
|
+
? [xchainEthereum.AssetETH, xchainAvax.AssetAVAX, xchainBsc.AssetBSC].findIndex((nativeEVMAsset) => xchainUtil.eqAsset(nativeEVMAsset, asset)) === -1 &&
|
|
12604
|
+
!asset.synth
|
|
12604
12605
|
: false;
|
|
12605
12606
|
};
|
|
12606
12607
|
/**
|
|
@@ -12630,7 +12631,7 @@ class ThorchainAction {
|
|
|
12630
12631
|
});
|
|
12631
12632
|
return {
|
|
12632
12633
|
hash,
|
|
12633
|
-
url: yield wallet.getExplorerTxUrl(
|
|
12634
|
+
url: yield wallet.getExplorerTxUrl(xchainThorchain.THORChain, hash),
|
|
12634
12635
|
};
|
|
12635
12636
|
});
|
|
12636
12637
|
}
|
|
@@ -12836,6 +12837,27 @@ class ThorchainAMM {
|
|
|
12836
12837
|
});
|
|
12837
12838
|
});
|
|
12838
12839
|
}
|
|
12840
|
+
/**
|
|
12841
|
+
* Approve the Thorchain router to spend a certain amount in the asset chain.
|
|
12842
|
+
* @param {ApproveParams} approveParams Parameters for approving the router to spend
|
|
12843
|
+
* @returns {Promise<TxSubmitted>} Transaction hash and URL
|
|
12844
|
+
*/
|
|
12845
|
+
approveRouterToSpend({ asset, amount }) {
|
|
12846
|
+
return __awaiter$6(this, void 0, void 0, function* () {
|
|
12847
|
+
// Get inbound details for the asset chain
|
|
12848
|
+
const inboundDetails = yield this.thorchainQuery.getChainInboundDetails(asset.chain);
|
|
12849
|
+
if (!inboundDetails.router)
|
|
12850
|
+
throw Error(`Unknown router address for ${asset.chain}`);
|
|
12851
|
+
// Perform approval
|
|
12852
|
+
const tx = yield this.wallet.approve(asset, (amount === null || amount === void 0 ? void 0 : amount.baseAmount) ||
|
|
12853
|
+
xchainUtil.baseAmount(xchainEvm.MAX_APPROVAL.toString(), yield this.thorchainQuery.thorchainCache.midgardQuery.getDecimalForAsset(asset)), inboundDetails.router);
|
|
12854
|
+
// Return transaction hash and URL
|
|
12855
|
+
return {
|
|
12856
|
+
hash: tx.hash,
|
|
12857
|
+
url: yield this.wallet.getExplorerTxUrl(asset.chain, tx.hash),
|
|
12858
|
+
};
|
|
12859
|
+
});
|
|
12860
|
+
}
|
|
12839
12861
|
/**
|
|
12840
12862
|
* Validate if the asset router is allowed to spend the asset amount in name of the address
|
|
12841
12863
|
* @param {IsApprovedParams} isApprovedParams contains the asset and the amount the router is supposed to spend
|
package/lib/thorchain-amm.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AddliquidityPosition, EstimateAddLP, EstimateAddSaver, EstimateWithdrawLP, EstimateWithdrawSaver, LoanCloseParams, LoanCloseQuote, LoanOpenParams, LoanOpenQuote, QuoteSwapParams, SaversPosition, SaversWithdraw, ThorchainQuery, TxDetails, 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 { IsApprovedParams, TxSubmitted } from './types';
|
|
4
|
+
import { ApproveParams, IsApprovedParams, TxSubmitted } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* THORChain Class for interacting with THORChain.
|
|
7
7
|
* Recommended main class to use for swapping with THORChain
|
|
@@ -41,6 +41,12 @@ export declare class ThorchainAMM {
|
|
|
41
41
|
* @returns {SwapSubmitted} - The transaction hash, URL of BlockExplorer, and expected wait time.
|
|
42
42
|
*/
|
|
43
43
|
doSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, }: QuoteSwapParams): Promise<TxSubmitted>;
|
|
44
|
+
/**
|
|
45
|
+
* Approve the Thorchain router to spend a certain amount in the asset chain.
|
|
46
|
+
* @param {ApproveParams} approveParams Parameters for approving the router to spend
|
|
47
|
+
* @returns {Promise<TxSubmitted>} Transaction hash and URL
|
|
48
|
+
*/
|
|
49
|
+
approveRouterToSpend({ asset, amount }: ApproveParams): Promise<TxSubmitted>;
|
|
44
50
|
/**
|
|
45
51
|
* Validate if the asset router is allowed to spend the asset amount in name of the address
|
|
46
52
|
* @param {IsApprovedParams} isApprovedParams contains the asset and the amount the router is supposed to spend
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-amm",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "git@github.com:xchainjs/xchainjs-lib.git"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"clean": "
|
|
27
|
+
"clean": "rm -rf .turbo && rm -rf lib",
|
|
28
28
|
"build": "yarn clean && rollup -c",
|
|
29
29
|
"test": "jest",
|
|
30
30
|
"e2e": "jest --config jest.config.e2e.js",
|
|
@@ -44,9 +44,10 @@
|
|
|
44
44
|
"@xchainjs/xchain-cosmos": "1.0.1",
|
|
45
45
|
"@xchainjs/xchain-doge": "0.7.12",
|
|
46
46
|
"@xchainjs/xchain-ethereum": "0.31.6",
|
|
47
|
+
"@xchainjs/xchain-evm": "0.4.5",
|
|
47
48
|
"@xchainjs/xchain-litecoin": "0.13.11",
|
|
48
49
|
"@xchainjs/xchain-thorchain": "1.0.4",
|
|
49
|
-
"@xchainjs/xchain-thorchain-query": "0.7.
|
|
50
|
+
"@xchainjs/xchain-thorchain-query": "0.7.7",
|
|
50
51
|
"@xchainjs/xchain-util": "^0.13.3",
|
|
51
52
|
"@xchainjs/xchain-wallet": "0.1.8",
|
|
52
53
|
"@xchainjs/xchain-mayachain": "1.0.1"
|
|
@@ -58,7 +59,6 @@
|
|
|
58
59
|
"@xchainjs/xchain-client": "^0.16.2",
|
|
59
60
|
"@xchainjs/xchain-crypto": "^0.3.1",
|
|
60
61
|
"@xchainjs/xchain-thornode": "^0.3.11",
|
|
61
|
-
"@xchainjs/xchain-evm": "^0.4.5",
|
|
62
62
|
"@xchainjs/xchain-midgard": "^0.5.2",
|
|
63
63
|
"@xchainjs/xchain-utxo-providers": "^0.2.12",
|
|
64
64
|
"axios": "^1.3.6",
|
|
@@ -100,4 +100,4 @@
|
|
|
100
100
|
"publishConfig": {
|
|
101
101
|
"access": "public"
|
|
102
102
|
}
|
|
103
|
-
}
|
|
103
|
+
}
|