@shapeshiftoss/swapper 9.15.0 → 9.15.1
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/dist/manager/SwapperManager.js +3 -3
- package/dist/swappercli.js +8 -8
- package/dist/swappers/cow/CowSwapper.js +1 -1
- package/dist/swappers/cow/cowApprovalNeeded/cowApprovalNeeded.js +4 -4
- package/dist/swappers/cow/cowApproveInfinite/cowApproveInfinite.js +3 -3
- package/dist/swappers/cow/cowBuildTrade/cowBuildTrade.js +11 -11
- package/dist/swappers/cow/cowExecuteTrade/cowExecuteTrade.js +7 -7
- package/dist/swappers/cow/cowGetTradeTxs/cowGetTradeTxs.js +4 -4
- package/dist/swappers/cow/getCowSwapMinMax/getCowSwapMinMax.js +1 -1
- package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +12 -12
- package/dist/swappers/cow/utils/blacklist.js +1 -1
- package/dist/swappers/cow/utils/cowService.js +2 -2
- package/dist/swappers/cow/utils/helpers/helpers.js +7 -7
- package/dist/swappers/osmosis/OsmosisSwapper.js +20 -20
- package/dist/swappers/osmosis/utils/helpers.d.ts +1 -1
- package/dist/swappers/osmosis/utils/helpers.js +35 -35
- package/dist/swappers/test/TestSwapper.js +2 -2
- package/dist/swappers/thorchain/ThorchainSwapper.js +13 -13
- package/dist/swappers/thorchain/buildThorTrade/buildThorTrade.d.ts +1 -1
- package/dist/swappers/thorchain/buildThorTrade/buildThorTrade.js +14 -14
- package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +14 -14
- package/dist/swappers/thorchain/thorTradeApprovalNeeded/thorTradeApprovalNeeded.d.ts +1 -1
- package/dist/swappers/thorchain/thorTradeApprovalNeeded/thorTradeApprovalNeeded.js +7 -7
- package/dist/swappers/thorchain/thorTradeApproveInfinite/thorTradeApproveInfinite.d.ts +1 -1
- package/dist/swappers/thorchain/thorTradeApproveInfinite/thorTradeApproveInfinite.js +7 -7
- package/dist/swappers/thorchain/utils/bitcoin/utils/getThorTxData.js +5 -5
- package/dist/swappers/thorchain/utils/constants.js +1 -1
- package/dist/swappers/thorchain/utils/cosmos/cosmosTxData.js +6 -6
- package/dist/swappers/thorchain/utils/estimateTradeFee/estimateTradeFee.js +6 -6
- package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.d.ts +1 -1
- package/dist/swappers/thorchain/utils/ethereum/makeTradeTx.js +6 -6
- package/dist/swappers/thorchain/utils/ethereum/utils/getThorTxData.js +5 -5
- package/dist/swappers/thorchain/utils/getLimit/getLimit.d.ts +1 -1
- package/dist/swappers/thorchain/utils/getLimit/getLimit.js +2 -2
- package/dist/swappers/thorchain/utils/getPriceRatio/getPriceRatio.js +3 -3
- package/dist/swappers/thorchain/utils/getTradeRate/getTradeRate.js +5 -5
- package/dist/swappers/thorchain/utils/getUsdRate/getUsdRate.d.ts +1 -1
- package/dist/swappers/thorchain/utils/getUsdRate/getUsdRate.js +4 -4
- package/dist/swappers/thorchain/utils/makeSwapMemo/makeSwapMemo.d.ts +1 -1
- package/dist/swappers/thorchain/utils/makeSwapMemo/makeSwapMemo.js +4 -4
- package/dist/swappers/thorchain/utils/test-data/midgardResponse.js +11 -11
- package/dist/swappers/thorchain/utils/test-data/setupThorswapDeps.js +9 -9
- package/dist/swappers/thorchain/utils/thorService.js +2 -2
- package/dist/swappers/thorchain/utils/txFeeHelpers/btcTxFees/getBtcTxFees.d.ts +1 -1
- package/dist/swappers/thorchain/utils/txFeeHelpers/btcTxFees/getBtcTxFees.js +4 -4
- package/dist/swappers/thorchain/utils/txFeeHelpers/ethTxFees/getEthTxFees.d.ts +1 -1
- package/dist/swappers/thorchain/utils/txFeeHelpers/ethTxFees/getEthTxFees.js +7 -7
- package/dist/swappers/utils/abi/erc20-abi.js +54 -54
- package/dist/swappers/utils/abi/erc20Allowance-abi.js +7 -7
- package/dist/swappers/utils/helpers/helpers.d.ts +4 -4
- package/dist/swappers/utils/helpers/helpers.js +13 -13
- package/dist/swappers/utils/test-data/assets.js +8 -8
- package/dist/swappers/utils/test-data/setupDeps.js +3 -3
- package/dist/swappers/utils/test-data/setupSwapQuote.js +3 -3
- package/dist/swappers/zrx/ZrxSwapper.js +2 -2
- package/dist/swappers/zrx/getZrxMinMax/getZrxMinMax.js +1 -1
- package/dist/swappers/zrx/getZrxTradeQuote/getZrxTradeQuote.js +7 -7
- package/dist/swappers/zrx/utils/blacklist.js +1 -1
- package/dist/swappers/zrx/utils/helpers/helpers.js +6 -6
- package/dist/swappers/zrx/utils/test-data/setupZrxSwapQuote.js +2 -2
- package/dist/swappers/zrx/utils/zrxService.js +2 -2
- package/dist/swappers/zrx/zrxApprovalNeeded/zrxApprovalNeeded.js +6 -6
- package/dist/swappers/zrx/zrxApprove/zrxApprove.js +6 -6
- package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +13 -11
- package/dist/swappers/zrx/zrxExecuteTrade/zrxExecuteTrade.js +6 -6
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ const api_1 = require("../../../../../api");
|
|
|
5
5
|
const getLimit_1 = require("../../getLimit/getLimit");
|
|
6
6
|
const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
|
|
7
7
|
const thorService_1 = require("../../thorService");
|
|
8
|
-
const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, wallet, bip44Params, accountType, tradeFee }) => {
|
|
8
|
+
const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, wallet, bip44Params, accountType, tradeFee, }) => {
|
|
9
9
|
try {
|
|
10
10
|
const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.midgardUrl}/thorchain/inbound_addresses`);
|
|
11
11
|
const sellAssetInboundAddresses = inboundAddresses.find((inbound) => inbound.chain === sellAsset.symbol.toUpperCase());
|
|
@@ -13,7 +13,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
|
|
|
13
13
|
if (!vault)
|
|
14
14
|
throw new api_1.SwapError(`[getThorTxInfo]: vault not found for asset`, {
|
|
15
15
|
code: api_1.SwapErrorTypes.RESPONSE_ERROR,
|
|
16
|
-
details: { inboundAddresses, sellAsset }
|
|
16
|
+
details: { inboundAddresses, sellAsset },
|
|
17
17
|
});
|
|
18
18
|
const limit = await (0, getLimit_1.getLimit)({
|
|
19
19
|
buyAssetId: buyAsset.assetId,
|
|
@@ -23,19 +23,19 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
|
|
|
23
23
|
buyAsset,
|
|
24
24
|
slippageTolerance,
|
|
25
25
|
deps,
|
|
26
|
-
tradeFee
|
|
26
|
+
tradeFee,
|
|
27
27
|
});
|
|
28
28
|
const memo = (0, makeSwapMemo_1.makeSwapMemo)({
|
|
29
29
|
buyAssetId: buyAsset.assetId,
|
|
30
30
|
destinationAddress,
|
|
31
|
-
limit
|
|
31
|
+
limit,
|
|
32
32
|
});
|
|
33
33
|
const adapter = deps.adapterManager.get(sellAsset.chainId);
|
|
34
34
|
const pubkey = await adapter.getPublicKey(wallet, bip44Params, accountType);
|
|
35
35
|
return {
|
|
36
36
|
opReturnData: memo,
|
|
37
37
|
vault,
|
|
38
|
-
pubkey: pubkey.xpub
|
|
38
|
+
pubkey: pubkey.xpub,
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
catch (e) {
|
|
@@ -22,5 +22,5 @@ exports.THOR_TRADE_FEE_MULTIPLIERS = {
|
|
|
22
22
|
[types_1.KnownChainIds.LitecoinMainnet]: (0, bignumber_1.bn)(0.000005),
|
|
23
23
|
[types_1.KnownChainIds.BitcoinCashMainnet]: (0, bignumber_1.bn)(0.00003),
|
|
24
24
|
[types_1.KnownChainIds.CosmosMainnet]: (0, bignumber_1.bn)(0.00000002),
|
|
25
|
-
[types_1.KnownChainIds.EthereumMainnet]: (0, bignumber_1.bn)(0.00024) // A value that "works". Discord recommended value (80,000 gas * 2 or 160k) is often too low
|
|
25
|
+
[types_1.KnownChainIds.EthereumMainnet]: (0, bignumber_1.bn)(0.00024), // A value that "works". Discord recommended value (80,000 gas * 2 or 160k) is often too low
|
|
26
26
|
};
|
|
@@ -6,7 +6,7 @@ const getLimit_1 = require("../getLimit/getLimit");
|
|
|
6
6
|
const makeSwapMemo_1 = require("../makeSwapMemo/makeSwapMemo");
|
|
7
7
|
const thorService_1 = require("../thorService");
|
|
8
8
|
const cosmosTxData = async (input) => {
|
|
9
|
-
const { deps, destinationAddress, sellAmount, sellAsset, buyAsset, slippageTolerance, quote, wallet, sellAdapter } = input;
|
|
9
|
+
const { deps, destinationAddress, sellAmount, sellAsset, buyAsset, slippageTolerance, quote, wallet, sellAdapter, } = input;
|
|
10
10
|
const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.midgardUrl}/thorchain/inbound_addresses`);
|
|
11
11
|
const atomInboundAddresses = inboundAddresses.find((inbound) => inbound.chain === 'GAIA');
|
|
12
12
|
const vault = atomInboundAddresses === null || atomInboundAddresses === void 0 ? void 0 : atomInboundAddresses.address;
|
|
@@ -14,7 +14,7 @@ const cosmosTxData = async (input) => {
|
|
|
14
14
|
throw new api_1.SwapError('[buildTrade]: no vault for chain', {
|
|
15
15
|
code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
|
|
16
16
|
fn: 'buildTrade',
|
|
17
|
-
details: { chainId: input.chainId }
|
|
17
|
+
details: { chainId: input.chainId },
|
|
18
18
|
});
|
|
19
19
|
const limit = await (0, getLimit_1.getLimit)({
|
|
20
20
|
buyAssetId: buyAsset.assetId,
|
|
@@ -24,12 +24,12 @@ const cosmosTxData = async (input) => {
|
|
|
24
24
|
buyAsset,
|
|
25
25
|
slippageTolerance,
|
|
26
26
|
deps,
|
|
27
|
-
tradeFee: quote.feeData.tradeFee
|
|
27
|
+
tradeFee: quote.feeData.tradeFee,
|
|
28
28
|
});
|
|
29
29
|
const memo = (0, makeSwapMemo_1.makeSwapMemo)({
|
|
30
30
|
buyAssetId: buyAsset.assetId,
|
|
31
31
|
destinationAddress,
|
|
32
|
-
limit
|
|
32
|
+
limit,
|
|
33
33
|
});
|
|
34
34
|
const buildTxResponse = await sellAdapter.buildSendTransaction({
|
|
35
35
|
value: sellAmount,
|
|
@@ -38,8 +38,8 @@ const cosmosTxData = async (input) => {
|
|
|
38
38
|
memo,
|
|
39
39
|
chainSpecific: {
|
|
40
40
|
gas: quote.feeData.chainSpecific.estimatedGas,
|
|
41
|
-
fee: quote.feeData.fee
|
|
42
|
-
}
|
|
41
|
+
fee: quote.feeData.fee,
|
|
42
|
+
},
|
|
43
43
|
});
|
|
44
44
|
return buildTxResponse.txToSign;
|
|
45
45
|
};
|
|
@@ -11,7 +11,7 @@ const estimateTradeFee = async (deps, buyAsset) => {
|
|
|
11
11
|
if (!thorId)
|
|
12
12
|
throw new api_1.SwapError('[estimateTradeFee] - undefined thorId for given buyAssetId', {
|
|
13
13
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
14
|
-
details: { buyAssetId: buyAsset.assetId }
|
|
14
|
+
details: { buyAssetId: buyAsset.assetId },
|
|
15
15
|
});
|
|
16
16
|
const thorPoolChainId = thorId.slice(0, thorId.indexOf('.'));
|
|
17
17
|
const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.midgardUrl}/thorchain/inbound_addresses`);
|
|
@@ -19,7 +19,7 @@ const estimateTradeFee = async (deps, buyAsset) => {
|
|
|
19
19
|
if (!inboundInfo)
|
|
20
20
|
throw new api_1.SwapError('[estimateTradeFee] - unable to locate inbound pool info', {
|
|
21
21
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
22
|
-
details: { thorPoolChainId }
|
|
22
|
+
details: { thorPoolChainId },
|
|
23
23
|
});
|
|
24
24
|
const gasRate = inboundInfo.gas_rate;
|
|
25
25
|
const { chainId: buyChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
@@ -27,24 +27,24 @@ const estimateTradeFee = async (deps, buyAsset) => {
|
|
|
27
27
|
if (!buyAdapter)
|
|
28
28
|
throw new api_1.SwapError('[estimateTradeFee] - unable to get buy asset adapter', {
|
|
29
29
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
30
|
-
details: { buyChainId }
|
|
30
|
+
details: { buyChainId },
|
|
31
31
|
});
|
|
32
32
|
const buyFeeAssetId = buyAdapter.getFeeAssetId();
|
|
33
33
|
if (!buyFeeAssetId)
|
|
34
34
|
throw new api_1.SwapError('[estimateTradeFee] - no fee assetId', {
|
|
35
35
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
36
|
-
details: { buyAssetId: buyAsset.assetId }
|
|
36
|
+
details: { buyAssetId: buyAsset.assetId },
|
|
37
37
|
});
|
|
38
38
|
const buyFeeAssetRatio = buyAsset.assetId !== buyFeeAssetId
|
|
39
39
|
? await (0, getPriceRatio_1.getPriceRatio)(deps, {
|
|
40
40
|
sellAssetId: buyAsset.assetId,
|
|
41
|
-
buyAssetId: buyFeeAssetId
|
|
41
|
+
buyAssetId: buyFeeAssetId,
|
|
42
42
|
})
|
|
43
43
|
: '1';
|
|
44
44
|
if (!constants_1.THOR_TRADE_FEE_MULTIPLIERS[buyChainId])
|
|
45
45
|
throw new api_1.SwapError('[estimateTradeFee] - no trade fee multiplier', {
|
|
46
46
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
47
|
-
details: { buyChainId }
|
|
47
|
+
details: { buyChainId },
|
|
48
48
|
});
|
|
49
49
|
return constants_1.THOR_TRADE_FEE_MULTIPLIERS[buyChainId].times(buyFeeAssetRatio).times(gasRate).toString();
|
|
50
50
|
};
|
|
@@ -3,7 +3,7 @@ import { ethereum } from '@shapeshiftoss/chain-adapters';
|
|
|
3
3
|
import { ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core';
|
|
4
4
|
import { BIP44Params } from '@shapeshiftoss/types';
|
|
5
5
|
import { ThorchainSwapperDeps } from '../../types';
|
|
6
|
-
export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, tradeFee }: {
|
|
6
|
+
export declare const makeTradeTx: ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, tradeFee, }: {
|
|
7
7
|
wallet: HDWallet;
|
|
8
8
|
bip44Params: BIP44Params;
|
|
9
9
|
sellAmount: string;
|
|
@@ -5,7 +5,7 @@ const caip_1 = require("@shapeshiftoss/caip");
|
|
|
5
5
|
const web3_utils_1 = require("web3-utils");
|
|
6
6
|
const api_1 = require("../../../../api");
|
|
7
7
|
const getThorTxData_1 = require("../ethereum/utils/getThorTxData");
|
|
8
|
-
const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, tradeFee }) => {
|
|
8
|
+
const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsset, destinationAddress, adapter, maxFeePerGas, maxPriorityFeePerGas, gasPrice, slippageTolerance, deps, gasLimit, tradeFee, }) => {
|
|
9
9
|
try {
|
|
10
10
|
const { assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
11
11
|
const isErc20Trade = assetNamespace === 'erc20';
|
|
@@ -16,7 +16,7 @@ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsse
|
|
|
16
16
|
sellAmount,
|
|
17
17
|
slippageTolerance,
|
|
18
18
|
destinationAddress,
|
|
19
|
-
tradeFee
|
|
19
|
+
tradeFee,
|
|
20
20
|
});
|
|
21
21
|
return adapter.buildCustomTx({
|
|
22
22
|
wallet,
|
|
@@ -25,14 +25,14 @@ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsse
|
|
|
25
25
|
gasLimit,
|
|
26
26
|
...(gasPrice !== undefined
|
|
27
27
|
? {
|
|
28
|
-
gasPrice
|
|
28
|
+
gasPrice,
|
|
29
29
|
}
|
|
30
30
|
: {
|
|
31
31
|
maxFeePerGas,
|
|
32
|
-
maxPriorityFeePerGas
|
|
32
|
+
maxPriorityFeePerGas,
|
|
33
33
|
}),
|
|
34
34
|
value: isErc20Trade ? '0x0' : (0, web3_utils_1.numberToHex)(sellAmount),
|
|
35
|
-
data
|
|
35
|
+
data,
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
catch (e) {
|
|
@@ -40,7 +40,7 @@ const makeTradeTx = async ({ wallet, bip44Params, sellAmount, buyAsset, sellAsse
|
|
|
40
40
|
throw e;
|
|
41
41
|
throw new api_1.SwapError('[makeTradeTx]: error making trade tx', {
|
|
42
42
|
code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
|
|
43
|
-
cause: e
|
|
43
|
+
cause: e,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
};
|
|
@@ -7,7 +7,7 @@ const getLimit_1 = require("../../getLimit/getLimit");
|
|
|
7
7
|
const makeSwapMemo_1 = require("../../makeSwapMemo/makeSwapMemo");
|
|
8
8
|
const thorService_1 = require("../../thorService");
|
|
9
9
|
const routerCalldata_1 = require("../routerCalldata");
|
|
10
|
-
const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, tradeFee }) => {
|
|
10
|
+
const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTolerance, destinationAddress, tradeFee, }) => {
|
|
11
11
|
try {
|
|
12
12
|
const { assetReference, assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
13
13
|
const isErc20Trade = assetNamespace === 'erc20';
|
|
@@ -18,7 +18,7 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
|
|
|
18
18
|
if (!vault || !router)
|
|
19
19
|
throw new api_1.SwapError(`[getPriceRatio]: router or vault found for ETH`, {
|
|
20
20
|
code: api_1.SwapErrorTypes.RESPONSE_ERROR,
|
|
21
|
-
details: { inboundAddresses }
|
|
21
|
+
details: { inboundAddresses },
|
|
22
22
|
});
|
|
23
23
|
const limit = await (0, getLimit_1.getLimit)({
|
|
24
24
|
buyAssetId: buyAsset.assetId,
|
|
@@ -28,18 +28,18 @@ const getThorTxInfo = async ({ deps, sellAsset, buyAsset, sellAmount, slippageTo
|
|
|
28
28
|
buyAsset,
|
|
29
29
|
slippageTolerance,
|
|
30
30
|
deps,
|
|
31
|
-
tradeFee
|
|
31
|
+
tradeFee,
|
|
32
32
|
});
|
|
33
33
|
const memo = (0, makeSwapMemo_1.makeSwapMemo)({
|
|
34
34
|
buyAssetId: buyAsset.assetId,
|
|
35
35
|
destinationAddress,
|
|
36
|
-
limit
|
|
36
|
+
limit,
|
|
37
37
|
});
|
|
38
38
|
const data = await (0, routerCalldata_1.deposit)(router, vault, isErc20Trade ? assetReference : '0x0000000000000000000000000000000000000000', sellAmount, memo);
|
|
39
39
|
return {
|
|
40
40
|
data,
|
|
41
41
|
memo,
|
|
42
|
-
router
|
|
42
|
+
router,
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
catch (e) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Asset } from '@shapeshiftoss/asset-service';
|
|
2
2
|
import { ThorchainSwapperDeps } from '../../types';
|
|
3
|
-
export declare const getLimit: ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, tradeFee }: {
|
|
3
|
+
export declare const getLimit: ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, tradeFee, }: {
|
|
4
4
|
buyAssetId: string;
|
|
5
5
|
destinationAddress: string;
|
|
6
6
|
sellAsset: Asset;
|
|
@@ -5,14 +5,14 @@ const api_1 = require("../../../../api");
|
|
|
5
5
|
const bignumber_1 = require("../../../utils/bignumber");
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
7
|
const getTradeRate_1 = require("../getTradeRate/getTradeRate");
|
|
8
|
-
const getLimit = async ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, tradeFee }) => {
|
|
8
|
+
const getLimit = async ({ sellAsset, buyAsset, sellAmount, deps, slippageTolerance, tradeFee, }) => {
|
|
9
9
|
const tradeRate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmount, deps);
|
|
10
10
|
const expectedBuyAmountPrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(sellAmount).times(tradeRate), sellAsset.precision), constants_1.THORCHAIN_FIXED_PRECISION);
|
|
11
11
|
const isValidSlippageRange = (0, bignumber_1.bnOrZero)(slippageTolerance).gte(0) && (0, bignumber_1.bnOrZero)(slippageTolerance).lte(1);
|
|
12
12
|
if ((0, bignumber_1.bnOrZero)(expectedBuyAmountPrecision8).lt(0) || !isValidSlippageRange)
|
|
13
13
|
throw new api_1.SwapError('[getThorTxInfo]: bad expected buy amount or bad slippage tolerance', {
|
|
14
14
|
code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED,
|
|
15
|
-
details: { expectedBuyAmountPrecision8, slippageTolerance }
|
|
15
|
+
details: { expectedBuyAmountPrecision8, slippageTolerance },
|
|
16
16
|
});
|
|
17
17
|
const tradeFeePrecision8 = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)(tradeFee), constants_1.THORCHAIN_FIXED_PRECISION);
|
|
18
18
|
return (0, bignumber_1.bnOrZero)(expectedBuyAmountPrecision8)
|
|
@@ -14,7 +14,7 @@ const getPriceRatio = async (deps, input) => {
|
|
|
14
14
|
if (!buyPoolId || !sellPoolId)
|
|
15
15
|
throw new api_1.SwapError(`[getPriceRatio]: No thorchain pool found`, {
|
|
16
16
|
code: api_1.SwapErrorTypes.RESPONSE_ERROR,
|
|
17
|
-
details: { buyPoolId, sellPoolId }
|
|
17
|
+
details: { buyPoolId, sellPoolId },
|
|
18
18
|
});
|
|
19
19
|
const { data: responseData } = await thorService_1.thorService.get(`${deps.midgardUrl}/pools`);
|
|
20
20
|
const buyUsdPrice = (_a = responseData.find((response) => response.asset === buyPoolId)) === null || _a === void 0 ? void 0 : _a.assetPrice;
|
|
@@ -22,7 +22,7 @@ const getPriceRatio = async (deps, input) => {
|
|
|
22
22
|
if (!buyUsdPrice || !sellUsdPrice)
|
|
23
23
|
throw new api_1.SwapError(`[getPriceRatio]: No rate found for pools`, {
|
|
24
24
|
code: api_1.SwapErrorTypes.RESPONSE_ERROR,
|
|
25
|
-
details: { buyPoolId, sellPoolId }
|
|
25
|
+
details: { buyPoolId, sellPoolId },
|
|
26
26
|
});
|
|
27
27
|
return (0, bignumber_1.bnOrZero)(sellUsdPrice).dividedBy(buyUsdPrice).toString();
|
|
28
28
|
}
|
|
@@ -31,7 +31,7 @@ const getPriceRatio = async (deps, input) => {
|
|
|
31
31
|
throw e;
|
|
32
32
|
throw new api_1.SwapError('[getPriceRatio]: Thorchain getPriceRatio failed', {
|
|
33
33
|
code: api_1.SwapErrorTypes.PRICE_RATIO_FAILED,
|
|
34
|
-
cause: e
|
|
34
|
+
cause: e,
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
};
|
|
@@ -28,7 +28,7 @@ const getTradeRate = async (sellAsset, buyAssetId, sellAmount, deps) => {
|
|
|
28
28
|
if ((0, bignumber_1.bnOrZero)(sellAmount).eq(0)) {
|
|
29
29
|
return (0, getPriceRatio_1.getPriceRatio)(deps, {
|
|
30
30
|
sellAssetId: sellAsset.assetId,
|
|
31
|
-
buyAssetId
|
|
31
|
+
buyAssetId,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
const buyPoolId = caip_1.adapters.assetIdToPoolAssetId({ assetId: buyAssetId });
|
|
@@ -37,7 +37,7 @@ const getTradeRate = async (sellAsset, buyAssetId, sellAmount, deps) => {
|
|
|
37
37
|
throw new api_1.SwapError(`[getPriceRatio]: No thorchain pool found`, {
|
|
38
38
|
code: api_1.SwapErrorTypes.POOL_NOT_FOUND,
|
|
39
39
|
fn: 'getPriceRatio',
|
|
40
|
-
details: { buyPoolId, sellPoolId }
|
|
40
|
+
details: { buyPoolId, sellPoolId },
|
|
41
41
|
});
|
|
42
42
|
const { data: responseData } = await thorService_1.thorService.get(`${deps.midgardUrl}/pools`);
|
|
43
43
|
const buyPool = responseData.find((response) => response.asset === buyPoolId);
|
|
@@ -46,17 +46,17 @@ const getTradeRate = async (sellAsset, buyAssetId, sellAmount, deps) => {
|
|
|
46
46
|
throw new api_1.SwapError(`[getPriceRatio]: no pools found for`, {
|
|
47
47
|
code: api_1.SwapErrorTypes.POOL_NOT_FOUND,
|
|
48
48
|
fn: 'getPriceRatio',
|
|
49
|
-
details: { buyPoolId, sellPoolId }
|
|
49
|
+
details: { buyPoolId, sellPoolId },
|
|
50
50
|
});
|
|
51
51
|
// All thorchain pool amounts are base 8 regardless of token precision
|
|
52
52
|
const sellBaseAmount = (0, bignumber_1.bn)((0, bignumber_2.toBaseUnit)((0, bignumber_2.fromBaseUnit)(sellAmount, sellAsset.precision), THOR_PRECISION));
|
|
53
53
|
const sellAssetPoolData = {
|
|
54
54
|
assetBalance: (0, bignumber_1.bn)(sellPool.assetDepth),
|
|
55
|
-
runeBalance: (0, bignumber_1.bn)(sellPool.runeDepth)
|
|
55
|
+
runeBalance: (0, bignumber_1.bn)(sellPool.runeDepth),
|
|
56
56
|
};
|
|
57
57
|
const buyAssetPoolData = {
|
|
58
58
|
assetBalance: (0, bignumber_1.bn)(buyPool.assetDepth),
|
|
59
|
-
runeBalance: (0, bignumber_1.bn)(buyPool.runeDepth)
|
|
59
|
+
runeBalance: (0, bignumber_1.bn)(buyPool.runeDepth),
|
|
60
60
|
};
|
|
61
61
|
const outputAmountBase8 = getDoubleSwapOutput(sellBaseAmount, sellAssetPoolData, buyAssetPoolData);
|
|
62
62
|
const outputAmount = (0, bignumber_2.fromBaseUnit)(outputAmountBase8, THOR_PRECISION);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Asset } from '@shapeshiftoss/asset-service';
|
|
2
2
|
import { ThorchainSwapperDeps } from '../../types';
|
|
3
|
-
export declare const getUsdRate: ({ deps, input }: {
|
|
3
|
+
export declare const getUsdRate: ({ deps, input, }: {
|
|
4
4
|
deps: ThorchainSwapperDeps;
|
|
5
5
|
input: Pick<Asset, 'assetId'>;
|
|
6
6
|
}) => Promise<string>;
|
|
@@ -4,19 +4,19 @@ exports.getUsdRate = void 0;
|
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const api_1 = require("../../../../api");
|
|
6
6
|
const thorService_1 = require("../thorService");
|
|
7
|
-
const getUsdRate = async ({ deps, input }) => {
|
|
7
|
+
const getUsdRate = async ({ deps, input, }) => {
|
|
8
8
|
const { assetId } = input;
|
|
9
9
|
try {
|
|
10
10
|
const thorchainPoolId = caip_1.adapters.assetIdToPoolAssetId({ assetId });
|
|
11
11
|
if (!thorchainPoolId)
|
|
12
12
|
throw new api_1.SwapError(`[getUsdRate]: No thorchainPoolId found for assetId: ${assetId}`, {
|
|
13
|
-
code: api_1.SwapErrorTypes.USD_RATE_FAILED
|
|
13
|
+
code: api_1.SwapErrorTypes.USD_RATE_FAILED,
|
|
14
14
|
});
|
|
15
15
|
const { data: responseData } = await thorService_1.thorService.get(`${deps.midgardUrl}/pool/${thorchainPoolId}`);
|
|
16
16
|
const rate = responseData === null || responseData === void 0 ? void 0 : responseData.assetPriceUSD;
|
|
17
17
|
if (!rate)
|
|
18
18
|
throw new api_1.SwapError(`[getUsdRate]: No rate found`, {
|
|
19
|
-
code: api_1.SwapErrorTypes.USD_RATE_FAILED
|
|
19
|
+
code: api_1.SwapErrorTypes.USD_RATE_FAILED,
|
|
20
20
|
});
|
|
21
21
|
return rate;
|
|
22
22
|
}
|
|
@@ -25,7 +25,7 @@ const getUsdRate = async ({ deps, input }) => {
|
|
|
25
25
|
throw e;
|
|
26
26
|
throw new api_1.SwapError('[getUsdRate]: Thorchain getUsdRate failed', {
|
|
27
27
|
code: api_1.SwapErrorTypes.USD_RATE_FAILED,
|
|
28
|
-
cause: e
|
|
28
|
+
cause: e,
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @returns thorchain memo shortened to a max of 80 characters as described:
|
|
3
3
|
* https://dev.thorchain.org/thorchain-dev/memos#mechanism-for-transaction-intent
|
|
4
4
|
*/
|
|
5
|
-
export declare const makeSwapMemo: ({ buyAssetId, destinationAddress, limit }: {
|
|
5
|
+
export declare const makeSwapMemo: ({ buyAssetId, destinationAddress, limit, }: {
|
|
6
6
|
buyAssetId: string;
|
|
7
7
|
destinationAddress: string;
|
|
8
8
|
limit: string;
|
|
@@ -10,12 +10,12 @@ const MAX_LENGTH = 80;
|
|
|
10
10
|
* @returns thorchain memo shortened to a max of 80 characters as described:
|
|
11
11
|
* https://dev.thorchain.org/thorchain-dev/memos#mechanism-for-transaction-intent
|
|
12
12
|
*/
|
|
13
|
-
const makeSwapMemo = ({ buyAssetId, destinationAddress, limit }) => {
|
|
13
|
+
const makeSwapMemo = ({ buyAssetId, destinationAddress, limit, }) => {
|
|
14
14
|
const thorId = caip_1.adapters.assetIdToPoolAssetId({ assetId: buyAssetId });
|
|
15
15
|
if (!thorId)
|
|
16
16
|
throw new api_1.SwapError('[makeSwapMemo] - undefined thorId for given buyAssetId', {
|
|
17
17
|
code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED,
|
|
18
|
-
details: { buyAssetId }
|
|
18
|
+
details: { buyAssetId },
|
|
19
19
|
});
|
|
20
20
|
// bch hack
|
|
21
21
|
// Our bitcoin cash addresses are prefixed with `bitcoincash:`
|
|
@@ -30,13 +30,13 @@ const makeSwapMemo = ({ buyAssetId, destinationAddress, limit }) => {
|
|
|
30
30
|
const abbreviationAmount = memo.length - MAX_LENGTH;
|
|
31
31
|
if (abbreviationAmount > 39)
|
|
32
32
|
throw new api_1.SwapError('[makeSwapMemo] - too much abbreviation for accurate matching', {
|
|
33
|
-
code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED
|
|
33
|
+
code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED,
|
|
34
34
|
});
|
|
35
35
|
// delimeter between ticker and id allowing us to abbreviate the id: https://dev.thorchain.org/thorchain-dev/memos#asset-notation
|
|
36
36
|
const delimeterIndex = memo.indexOf('-') + 1;
|
|
37
37
|
if (!delimeterIndex) {
|
|
38
38
|
throw new api_1.SwapError('[makeSwapMemo] - unable to abbreviate asset, no delimeter found', {
|
|
39
|
-
code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED
|
|
39
|
+
code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
return memo.replace(memo.slice(delimeterIndex, delimeterIndex + abbreviationAmount), '');
|
|
@@ -13,7 +13,7 @@ exports.btcMidgardPool = {
|
|
|
13
13
|
synthSupply: '3281284823',
|
|
14
14
|
synthUnits: '9838954536080',
|
|
15
15
|
units: '545894929144923',
|
|
16
|
-
volume24h: '15031085906495'
|
|
16
|
+
volume24h: '15031085906495',
|
|
17
17
|
};
|
|
18
18
|
exports.ethMidgardPool = {
|
|
19
19
|
asset: 'ETH.ETH',
|
|
@@ -27,7 +27,7 @@ exports.ethMidgardPool = {
|
|
|
27
27
|
synthSupply: '3572065751',
|
|
28
28
|
synthUnits: '535301524652',
|
|
29
29
|
units: '274245264962453',
|
|
30
|
-
volume24h: '9890096673763'
|
|
30
|
+
volume24h: '9890096673763',
|
|
31
31
|
};
|
|
32
32
|
exports.foxMidgardPool = {
|
|
33
33
|
asset: 'ETH.FOX-0XC770EEFAD204B5180DF6A14EE197D99D808EE52D',
|
|
@@ -41,7 +41,7 @@ exports.foxMidgardPool = {
|
|
|
41
41
|
synthSupply: '17428372569375',
|
|
42
42
|
synthUnits: '552604585625',
|
|
43
43
|
units: '10568061707512',
|
|
44
|
-
volume24h: '251596933033'
|
|
44
|
+
volume24h: '251596933033',
|
|
45
45
|
};
|
|
46
46
|
exports.mockInboundAdresses = [
|
|
47
47
|
{
|
|
@@ -49,28 +49,28 @@ exports.mockInboundAdresses = [
|
|
|
49
49
|
pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
|
|
50
50
|
address: 'qp5a6rn8zmamgmsyspqsl0p6ktk4hrheggdjdvntv0',
|
|
51
51
|
halted: false,
|
|
52
|
-
gas_rate: '3'
|
|
52
|
+
gas_rate: '3',
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
chain: 'BNB',
|
|
56
56
|
pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
|
|
57
57
|
address: 'bnb1d8wsuecklw6xupyqgy8mcw4ja4dca72z7nvqzw',
|
|
58
58
|
halted: false,
|
|
59
|
-
gas_rate: '11250'
|
|
59
|
+
gas_rate: '11250',
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
chain: 'BTC',
|
|
63
63
|
pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
|
|
64
64
|
address: 'bc1qd8wsuecklw6xupyqgy8mcw4ja4dca72z2dd88d',
|
|
65
65
|
halted: false,
|
|
66
|
-
gas_rate: '18'
|
|
66
|
+
gas_rate: '18',
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
69
|
chain: 'DOGE',
|
|
70
70
|
pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
|
|
71
71
|
address: 'DEnrJfAjC4KMsLsGtoTGSmYaFZLPunWw9q',
|
|
72
72
|
halted: false,
|
|
73
|
-
gas_rate: '550384'
|
|
73
|
+
gas_rate: '550384',
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
chain: 'ETH',
|
|
@@ -78,21 +78,21 @@ exports.mockInboundAdresses = [
|
|
|
78
78
|
address: '0x78e4e10dcacb0a8261eb3d5e57ffb98ae8d4dff1',
|
|
79
79
|
router: '0x3624525075b88B24ecc29CE226b0CEc1fFcB6976',
|
|
80
80
|
halted: false,
|
|
81
|
-
gas_rate: '280'
|
|
81
|
+
gas_rate: '280',
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
84
|
chain: 'LTC',
|
|
85
85
|
pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
|
|
86
86
|
address: 'ltc1qd8wsuecklw6xupyqgy8mcw4ja4dca72zw3hrla',
|
|
87
87
|
halted: false,
|
|
88
|
-
gas_rate: '60'
|
|
88
|
+
gas_rate: '60',
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
chain: 'TERRA',
|
|
92
92
|
pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
|
|
93
93
|
address: 'terra1d8wsuecklw6xupyqgy8mcw4ja4dca72z6nfvpq',
|
|
94
94
|
halted: true,
|
|
95
|
-
gas_rate: '182523800'
|
|
96
|
-
}
|
|
95
|
+
gas_rate: '182523800',
|
|
96
|
+
},
|
|
97
97
|
];
|
|
98
98
|
exports.poolResponse = [exports.btcMidgardPool, exports.ethMidgardPool, exports.foxMidgardPool];
|
|
@@ -13,8 +13,8 @@ const setupThorswapDeps = () => {
|
|
|
13
13
|
fast: {
|
|
14
14
|
txFee: '1',
|
|
15
15
|
chainSpecific: { approvalFee: '1', gasLimit: '1', gasPrice: '1' },
|
|
16
|
-
tradeFee: '2'
|
|
17
|
-
}
|
|
16
|
+
tradeFee: '2',
|
|
17
|
+
},
|
|
18
18
|
};
|
|
19
19
|
const adapterManager = new Map([
|
|
20
20
|
[
|
|
@@ -28,21 +28,21 @@ const setupThorswapDeps = () => {
|
|
|
28
28
|
[chain_adapters_1.FeeDataKey.Slow]: {
|
|
29
29
|
gasPrice: '1',
|
|
30
30
|
maxFeePerGas: '2',
|
|
31
|
-
maxPriorityFeePerGas: '3'
|
|
31
|
+
maxPriorityFeePerGas: '3',
|
|
32
32
|
},
|
|
33
33
|
[chain_adapters_1.FeeDataKey.Average]: {
|
|
34
34
|
gasPrice: '4',
|
|
35
35
|
maxFeePerGas: '5',
|
|
36
|
-
maxPriorityFeePerGas: '6'
|
|
36
|
+
maxPriorityFeePerGas: '6',
|
|
37
37
|
},
|
|
38
38
|
[chain_adapters_1.FeeDataKey.Fast]: {
|
|
39
39
|
gasPrice: '7',
|
|
40
40
|
maxFeePerGas: '8',
|
|
41
|
-
maxPriorityFeePerGas: '9'
|
|
42
|
-
}
|
|
43
|
-
}))
|
|
44
|
-
}
|
|
45
|
-
]
|
|
41
|
+
maxPriorityFeePerGas: '9',
|
|
42
|
+
},
|
|
43
|
+
})),
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
46
|
]);
|
|
47
47
|
const midgardUrl = 'localhost:3000';
|
|
48
48
|
const ethNodeUrl = 'http://localhost:1000';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UtxoBaseAdapter } from '@shapeshiftoss/chain-adapters';
|
|
2
2
|
import { QuoteFeeData, UtxoSupportedChainIds } from '../../../../../api';
|
|
3
|
-
export declare const getBtcTxFees: ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, tradeFee }: {
|
|
3
|
+
export declare const getBtcTxFees: ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, tradeFee, }: {
|
|
4
4
|
opReturnData: string;
|
|
5
5
|
vault: string;
|
|
6
6
|
sellAmount: string;
|
|
@@ -4,12 +4,12 @@ exports.getBtcTxFees = void 0;
|
|
|
4
4
|
const types_1 = require("@shapeshiftoss/types");
|
|
5
5
|
const api_1 = require("../../../../../api");
|
|
6
6
|
const bignumber_1 = require("../../../../utils/bignumber");
|
|
7
|
-
const getBtcTxFees = async ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, tradeFee }) => {
|
|
7
|
+
const getBtcTxFees = async ({ opReturnData, vault, sellAmount, sellAdapter, pubkey, tradeFee, }) => {
|
|
8
8
|
try {
|
|
9
9
|
const feeDataOptions = await sellAdapter.getFeeData({
|
|
10
10
|
to: vault,
|
|
11
11
|
value: sellAmount,
|
|
12
|
-
chainSpecific: { pubkey, opReturnData }
|
|
12
|
+
chainSpecific: { pubkey, opReturnData },
|
|
13
13
|
});
|
|
14
14
|
const feeData = feeDataOptions['fast'];
|
|
15
15
|
// BCH specific hack:
|
|
@@ -29,8 +29,8 @@ const getBtcTxFees = async ({ opReturnData, vault, sellAmount, sellAdapter, pubk
|
|
|
29
29
|
byteCount: (0, bignumber_1.bn)(feeData.txFee)
|
|
30
30
|
.dividedBy(feeData.chainSpecific.satoshiPerByte)
|
|
31
31
|
.dp(0)
|
|
32
|
-
.toString()
|
|
33
|
-
}
|
|
32
|
+
.toString(),
|
|
33
|
+
},
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
catch (e) {
|
|
@@ -2,7 +2,7 @@ import { AssetReference } from '@shapeshiftoss/caip';
|
|
|
2
2
|
import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
|
|
3
3
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
4
4
|
import { QuoteFeeData } from '../../../../../api';
|
|
5
|
-
export declare const getEthTxFees: ({ adapterManager, sellAssetReference, tradeFee }: {
|
|
5
|
+
export declare const getEthTxFees: ({ adapterManager, sellAssetReference, tradeFee, }: {
|
|
6
6
|
adapterManager: ChainAdapterManager;
|
|
7
7
|
sellAssetReference: AssetReference | string;
|
|
8
8
|
tradeFee: string;
|
|
@@ -7,13 +7,13 @@ const api_1 = require("../../../../../api");
|
|
|
7
7
|
const bignumber_1 = require("../../../../utils/bignumber");
|
|
8
8
|
const constants_1 = require("../../../../utils/constants");
|
|
9
9
|
const constants_2 = require("../../constants");
|
|
10
|
-
const getEthTxFees = async ({ adapterManager, sellAssetReference, tradeFee }) => {
|
|
10
|
+
const getEthTxFees = async ({ adapterManager, sellAssetReference, tradeFee, }) => {
|
|
11
11
|
try {
|
|
12
12
|
const adapter = adapterManager.get(types_1.KnownChainIds.EthereumMainnet);
|
|
13
13
|
if (!adapter) {
|
|
14
14
|
throw new api_1.SwapError(`[getThorTxInfo] - No chain adapter found for ${types_1.KnownChainIds.EthereumMainnet}.`, {
|
|
15
15
|
code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
|
|
16
|
-
details: { chainId: types_1.KnownChainIds.EthereumMainnet }
|
|
16
|
+
details: { chainId: types_1.KnownChainIds.EthereumMainnet },
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
const gasFeeData = await adapter.getGasFeeData();
|
|
@@ -25,9 +25,9 @@ const getEthTxFees = async ({ adapterManager, sellAssetReference, tradeFee }) =>
|
|
|
25
25
|
txFee: (0, bignumber_1.bn)(gasLimit).times(gasFeeData[chain_adapters_1.FeeDataKey.Fast].gasPrice).toString(),
|
|
26
26
|
chainSpecific: {
|
|
27
27
|
gasPrice: gasFeeData[chain_adapters_1.FeeDataKey.Fast].gasPrice,
|
|
28
|
-
gasLimit
|
|
29
|
-
}
|
|
30
|
-
}
|
|
28
|
+
gasLimit,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
31
|
};
|
|
32
32
|
const feeData = feeDataOptions['fast'];
|
|
33
33
|
return {
|
|
@@ -38,9 +38,9 @@ const getEthTxFees = async ({ adapterManager, sellAssetReference, tradeFee }) =>
|
|
|
38
38
|
approvalFee: sellAssetReference &&
|
|
39
39
|
(0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT)
|
|
40
40
|
.multipliedBy((0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasPrice))
|
|
41
|
-
.toString()
|
|
41
|
+
.toString(),
|
|
42
42
|
},
|
|
43
|
-
tradeFee
|
|
43
|
+
tradeFee,
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
catch (e) {
|