@shapeshiftoss/swapper 17.6.7 → 17.6.8
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/constants.js +42 -24
- package/dist/cjs/cowswap-utils/constants.js +1 -0
- package/dist/cjs/cowswap-utils/index.js +2 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/swappers/AvnuSwapper/AvnuSwapper.d.ts +2 -0
- package/dist/cjs/swappers/AvnuSwapper/AvnuSwapper.js +7 -0
- package/dist/cjs/swappers/AvnuSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/AvnuSwapper/endpoints.js +181 -0
- package/dist/cjs/swappers/AvnuSwapper/index.d.ts +1 -0
- package/dist/cjs/swappers/AvnuSwapper/index.js +5 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +142 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.js +120 -0
- package/dist/cjs/swappers/AvnuSwapper/types.d.ts +2 -0
- package/dist/cjs/swappers/AvnuSwapper/types.js +2 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/constants.d.ts +5 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/constants.js +11 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/helpers.d.ts +7 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/helpers.js +21 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +2 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +4 -0
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/cjs/swappers/CetusSwapper/endpoints.js +33 -27
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getCetusTradeData.d.ts +24 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getCetusTradeData.js +79 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +44 -69
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeRate.js +49 -65
- package/dist/cjs/swappers/CetusSwapper/utils/constants.d.ts +1 -0
- package/dist/cjs/swappers/CetusSwapper/utils/constants.js +2 -1
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.d.ts +6 -11
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.js +41 -96
- package/dist/cjs/swappers/JupiterSwapper/utils/helpers.d.ts +0 -2
- package/dist/cjs/swappers/MayachainSwapper/generated/generatedTradableAssetMap.json +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +2 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +68 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +30 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +53 -5
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.js +8 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +28 -8
- package/dist/cjs/swappers/PortalsSwapper/constants.js +1 -1
- package/dist/cjs/swappers/PortalsSwapper/endpoints.js +92 -1
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +29 -17
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +21 -17
- package/dist/cjs/swappers/PortalsSwapper/types.js +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.d.ts +9 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.js +52 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchPortalsTradeOrder.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchSquidStatus.d.ts +9 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchSquidStatus.js +57 -0
- package/dist/cjs/swappers/RelaySwapper/constant.js +3 -0
- package/dist/cjs/swappers/RelaySwapper/utils/fetchRelayTrade.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +16 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +20 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +13 -4
- package/dist/cjs/swappers/RelaySwapper/utils/types.js +5 -1
- package/dist/cjs/swappers/SunioSwapper/SunioSwapper.d.ts +2 -0
- package/dist/cjs/swappers/SunioSwapper/SunioSwapper.js +7 -0
- package/dist/cjs/swappers/SunioSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +131 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +8 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +8 -0
- package/dist/cjs/swappers/SunioSwapper/index.d.ts +4 -0
- package/dist/cjs/swappers/SunioSwapper/index.js +23 -0
- package/dist/cjs/swappers/SunioSwapper/types.d.ts +22 -0
- package/dist/cjs/swappers/SunioSwapper/types.js +12 -0
- package/dist/cjs/swappers/SunioSwapper/utils/abi.d.ts +48 -0
- package/dist/cjs/swappers/SunioSwapper/utils/abi.js +28 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +14 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +32 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +11 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.js +57 -0
- package/dist/cjs/swappers/SunioSwapper/utils/constants.d.ts +6 -0
- package/dist/cjs/swappers/SunioSwapper/utils/constants.js +16 -0
- package/dist/cjs/swappers/SunioSwapper/utils/fetchFromSunio.d.ts +11 -0
- package/dist/cjs/swappers/SunioSwapper/utils/fetchFromSunio.js +45 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.d.ts +4 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.js +203 -0
- package/dist/cjs/swappers/SunioSwapper/utils/helpers/helpers.d.ts +4 -0
- package/dist/cjs/swappers/SunioSwapper/utils/helpers/helpers.js +22 -0
- package/dist/cjs/swappers/SunioSwapper/utils/sunioService.d.ts +6 -0
- package/dist/cjs/swappers/SunioSwapper/utils/sunioService.js +18 -0
- package/dist/cjs/swappers/ThorchainSwapper/ThorchainSwapper.js +3 -0
- package/dist/cjs/swappers/ThorchainSwapper/endpoints.js +2 -0
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +2 -2
- package/dist/cjs/swappers/utils/helpers/helpers.js +7 -0
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +80 -3
- package/dist/cjs/thorchain-utils/index.d.ts +1 -0
- package/dist/cjs/thorchain-utils/index.js +2 -1
- package/dist/cjs/thorchain-utils/tron/getThorTxData.d.ts +12 -0
- package/dist/cjs/thorchain-utils/tron/getThorTxData.js +14 -0
- package/dist/cjs/thorchain-utils/tron/getTronTransactionFees.d.ts +2 -0
- package/dist/cjs/thorchain-utils/tron/getTronTransactionFees.js +65 -0
- package/dist/cjs/thorchain-utils/tron/getUnsignedTronTransaction.d.ts +3 -0
- package/dist/cjs/thorchain-utils/tron/getUnsignedTronTransaction.js +35 -0
- package/dist/cjs/thorchain-utils/tron/index.d.ts +3 -0
- package/dist/cjs/thorchain-utils/tron/index.js +19 -0
- package/dist/cjs/types.d.ts +74 -9
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/tenderly/simulate.d.ts +6 -1
- package/dist/cjs/utils/tenderly/simulate.js +22 -2
- package/dist/cjs/utils/tenderly/types.d.ts +21 -0
- package/dist/cjs/utils.d.ts +9 -3
- package/dist/cjs/utils.js +53 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +18 -0
- package/dist/esm/cowswap-utils/constants.js +1 -0
- package/dist/esm/cowswap-utils/index.js +2 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/swappers/AvnuSwapper/AvnuSwapper.d.ts +2 -0
- package/dist/esm/swappers/AvnuSwapper/AvnuSwapper.js +4 -0
- package/dist/esm/swappers/AvnuSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/AvnuSwapper/endpoints.js +178 -0
- package/dist/esm/swappers/AvnuSwapper/index.d.ts +1 -0
- package/dist/esm/swappers/AvnuSwapper/index.js +1 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +138 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.js +116 -0
- package/dist/esm/swappers/AvnuSwapper/types.d.ts +2 -0
- package/dist/esm/swappers/AvnuSwapper/types.js +1 -0
- package/dist/esm/swappers/AvnuSwapper/utils/constants.d.ts +5 -0
- package/dist/esm/swappers/AvnuSwapper/utils/constants.js +7 -0
- package/dist/esm/swappers/AvnuSwapper/utils/helpers.d.ts +7 -0
- package/dist/esm/swappers/AvnuSwapper/utils/helpers.js +17 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +2 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +4 -0
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/esm/swappers/CetusSwapper/endpoints.js +28 -22
- package/dist/esm/swappers/CetusSwapper/swapperApi/getCetusTradeData.d.ts +24 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getCetusTradeData.js +75 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +44 -69
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeRate.js +50 -66
- package/dist/esm/swappers/CetusSwapper/utils/constants.d.ts +1 -0
- package/dist/esm/swappers/CetusSwapper/utils/constants.js +1 -0
- package/dist/esm/swappers/CetusSwapper/utils/helpers.d.ts +6 -11
- package/dist/esm/swappers/CetusSwapper/utils/helpers.js +37 -67
- package/dist/esm/swappers/JupiterSwapper/utils/helpers.d.ts +0 -2
- package/dist/esm/swappers/MayachainSwapper/generated/generatedTradableAssetMap.json +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +3 -1
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +68 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +30 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +54 -6
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.js +8 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +29 -9
- package/dist/esm/swappers/PortalsSwapper/constants.js +1 -1
- package/dist/esm/swappers/PortalsSwapper/endpoints.js +92 -1
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +30 -18
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +21 -17
- package/dist/esm/swappers/PortalsSwapper/types.js +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.d.ts +9 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.js +47 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchPortalsTradeOrder.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchSquidStatus.d.ts +9 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchSquidStatus.js +52 -0
- package/dist/esm/swappers/RelaySwapper/constant.js +5 -2
- package/dist/esm/swappers/RelaySwapper/utils/fetchRelayTrade.js +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +18 -3
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +20 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +13 -4
- package/dist/esm/swappers/RelaySwapper/utils/types.js +3 -0
- package/dist/esm/swappers/SunioSwapper/SunioSwapper.d.ts +2 -0
- package/dist/esm/swappers/SunioSwapper/SunioSwapper.js +4 -0
- package/dist/esm/swappers/SunioSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/SunioSwapper/endpoints.js +128 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +4 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.d.ts +3 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +4 -0
- package/dist/esm/swappers/SunioSwapper/index.d.ts +4 -0
- package/dist/esm/swappers/SunioSwapper/index.js +4 -0
- package/dist/esm/swappers/SunioSwapper/types.d.ts +22 -0
- package/dist/esm/swappers/SunioSwapper/types.js +9 -0
- package/dist/esm/swappers/SunioSwapper/utils/abi.d.ts +48 -0
- package/dist/esm/swappers/SunioSwapper/utils/abi.js +25 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +14 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +28 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +11 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.js +53 -0
- package/dist/esm/swappers/SunioSwapper/utils/constants.d.ts +6 -0
- package/dist/esm/swappers/SunioSwapper/utils/constants.js +13 -0
- package/dist/esm/swappers/SunioSwapper/utils/fetchFromSunio.d.ts +11 -0
- package/dist/esm/swappers/SunioSwapper/utils/fetchFromSunio.js +41 -0
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.d.ts +4 -0
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.js +199 -0
- package/dist/esm/swappers/SunioSwapper/utils/helpers/helpers.d.ts +4 -0
- package/dist/esm/swappers/SunioSwapper/utils/helpers/helpers.js +16 -0
- package/dist/esm/swappers/SunioSwapper/utils/sunioService.d.ts +6 -0
- package/dist/esm/swappers/SunioSwapper/utils/sunioService.js +14 -0
- package/dist/esm/swappers/ThorchainSwapper/ThorchainSwapper.js +3 -0
- package/dist/esm/swappers/ThorchainSwapper/endpoints.js +3 -1
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +2 -2
- package/dist/esm/swappers/utils/helpers/helpers.js +9 -2
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +81 -4
- package/dist/esm/thorchain-utils/index.d.ts +1 -0
- package/dist/esm/thorchain-utils/index.js +1 -0
- package/dist/esm/thorchain-utils/tron/getThorTxData.d.ts +12 -0
- package/dist/esm/thorchain-utils/tron/getThorTxData.js +10 -0
- package/dist/esm/thorchain-utils/tron/getTronTransactionFees.d.ts +2 -0
- package/dist/esm/thorchain-utils/tron/getTronTransactionFees.js +61 -0
- package/dist/esm/thorchain-utils/tron/getUnsignedTronTransaction.d.ts +3 -0
- package/dist/esm/thorchain-utils/tron/getUnsignedTronTransaction.js +31 -0
- package/dist/esm/thorchain-utils/tron/index.d.ts +3 -0
- package/dist/esm/thorchain-utils/tron/index.js +3 -0
- package/dist/esm/types.d.ts +74 -9
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/tenderly/simulate.d.ts +6 -1
- package/dist/esm/utils/tenderly/simulate.js +20 -1
- package/dist/esm/utils/tenderly/types.d.ts +21 -0
- package/dist/esm/utils.d.ts +9 -3
- package/dist/esm/utils.js +50 -1
- package/package.json +9 -8
|
@@ -23,6 +23,12 @@ const isNativeEvmAsset = (assetId) => {
|
|
|
23
23
|
return assetId === caip_1.arbitrumAssetId;
|
|
24
24
|
case types_1.KnownChainIds.BaseMainnet:
|
|
25
25
|
return assetId === caip_1.baseAssetId;
|
|
26
|
+
case types_1.KnownChainIds.MonadMainnet:
|
|
27
|
+
return assetId === caip_1.monadAssetId;
|
|
28
|
+
case types_1.KnownChainIds.PlasmaMainnet:
|
|
29
|
+
return assetId === caip_1.plasmaAssetId;
|
|
30
|
+
case types_1.KnownChainIds.KatanaMainnet:
|
|
31
|
+
return assetId === caip_1.katanaAssetId;
|
|
26
32
|
default:
|
|
27
33
|
return false;
|
|
28
34
|
}
|
|
@@ -39,6 +45,7 @@ const DAO_TREASURY_BY_CHAIN_ID = {
|
|
|
39
45
|
[types_1.KnownChainIds.BaseMainnet]: utils_1.DAO_TREASURY_BASE,
|
|
40
46
|
[types_1.KnownChainIds.SolanaMainnet]: utils_1.DAO_TREASURY_SOLANA,
|
|
41
47
|
[types_1.KnownChainIds.BitcoinMainnet]: utils_1.DAO_TREASURY_BITCOIN,
|
|
48
|
+
[types_1.KnownChainIds.StarknetMainnet]: utils_1.DAO_TREASURY_STARKNET,
|
|
42
49
|
};
|
|
43
50
|
const getTreasuryAddressFromChainId = (chainId) => {
|
|
44
51
|
const maybeTreasuryChainId = (0, utils_1.isTreasuryChainId)(chainId) ? chainId : undefined;
|
|
@@ -28,6 +28,7 @@ const caip_1 = require("@shapeshiftoss/caip");
|
|
|
28
28
|
const adapters = __importStar(require("@shapeshiftoss/chain-adapters"));
|
|
29
29
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
30
30
|
const monads_1 = require("@sniptt/monads");
|
|
31
|
+
const tronweb_1 = require("tronweb");
|
|
31
32
|
const uuid_1 = require("uuid");
|
|
32
33
|
const index_1 = require("../index");
|
|
33
34
|
const types_1 = require("../types");
|
|
@@ -36,6 +37,7 @@ const evm = __importStar(require("./evm"));
|
|
|
36
37
|
const getLimitWithManualSlippage_1 = require("./getLimitWithManualSlippage/getLimitWithManualSlippage");
|
|
37
38
|
const getQuote_1 = require("./getQuote");
|
|
38
39
|
const index_2 = require("./index");
|
|
40
|
+
const tron = __importStar(require("./tron"));
|
|
39
41
|
const utxo = __importStar(require("./utxo"));
|
|
40
42
|
const SAFE_GAS_LIMIT = '100000'; // depositWithExpiry()
|
|
41
43
|
const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapperName) => {
|
|
@@ -299,10 +301,73 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
|
|
|
299
301
|
}));
|
|
300
302
|
}
|
|
301
303
|
case caip_1.CHAIN_NAMESPACE.Tron: {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
304
|
+
const maybeRoutes = await Promise.allSettled(perRouteValues.map(async (route) => {
|
|
305
|
+
const memo = getMemo(route);
|
|
306
|
+
let networkFeeCryptoBaseUnit = undefined;
|
|
307
|
+
// Calculate fees for rates when we have a receive address (wallet connected)
|
|
308
|
+
if (input.quoteOrRate === 'rate' && input.receiveAddress) {
|
|
309
|
+
try {
|
|
310
|
+
const { sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit } = input;
|
|
311
|
+
const contractAddress = (0, utils_1.contractAddressOrUndefined)(sellAsset.assetId);
|
|
312
|
+
// Get vault address
|
|
313
|
+
const { vault } = await tron.getThorTxData({ sellAsset, config, swapperName });
|
|
314
|
+
// Estimate fees using the receive address for accurate energy calculation
|
|
315
|
+
const tronWeb = new tronweb_1.TronWeb({ fullHost: deps.config.VITE_TRON_NODE_URL });
|
|
316
|
+
const params = await tronWeb.trx.getChainParameters();
|
|
317
|
+
const bandwidthPrice = params.find(p => p.key === 'getTransactionFee')?.value ?? 1000;
|
|
318
|
+
const energyPrice = params.find(p => p.key === 'getEnergyFee')?.value ?? 100;
|
|
319
|
+
let totalFee = 0;
|
|
320
|
+
if (contractAddress) {
|
|
321
|
+
// TRC20: Estimate energy with actual recipient
|
|
322
|
+
try {
|
|
323
|
+
const result = await tronWeb.transactionBuilder.triggerConstantContract(contractAddress, 'transfer(address,uint256)', {}, [
|
|
324
|
+
{ type: 'address', value: vault },
|
|
325
|
+
{ type: 'uint256', value: sellAmountIncludingProtocolFeesCryptoBaseUnit },
|
|
326
|
+
], input.receiveAddress);
|
|
327
|
+
const energyUsed = result.energy_used ?? 65000;
|
|
328
|
+
const energyFee = energyUsed * energyPrice * 1.5; // 1.5x safety margin
|
|
329
|
+
const bandwidthFee = 276 * bandwidthPrice; // TRC20 bandwidth
|
|
330
|
+
totalFee = Math.ceil(energyFee + bandwidthFee);
|
|
331
|
+
}
|
|
332
|
+
catch {
|
|
333
|
+
// Fallback: Conservative estimate
|
|
334
|
+
totalFee = 13_000_000; // 13 TRX worst case
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
// TRX transfer bandwidth: Base tx + memo bytes
|
|
339
|
+
const baseBytes = 198;
|
|
340
|
+
const memoBytes = route.quote.memo
|
|
341
|
+
? Buffer.from(route.quote.memo, 'utf8').length
|
|
342
|
+
: 0;
|
|
343
|
+
const totalBandwidth = baseBytes + memoBytes;
|
|
344
|
+
totalFee = totalBandwidth * bandwidthPrice;
|
|
345
|
+
}
|
|
346
|
+
networkFeeCryptoBaseUnit = String(totalFee);
|
|
347
|
+
}
|
|
348
|
+
catch {
|
|
349
|
+
// Leave as undefined if estimation fails
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// For quotes, fees will be calculated in getTronTransactionFees when executing
|
|
353
|
+
return Promise.resolve(makeThorTradeRateOrQuote({
|
|
354
|
+
route,
|
|
355
|
+
allowanceContract: '0x0',
|
|
356
|
+
memo,
|
|
357
|
+
feeData: {
|
|
358
|
+
networkFeeCryptoBaseUnit,
|
|
359
|
+
protocolFees: getProtocolFees(route.quote),
|
|
360
|
+
},
|
|
361
|
+
}));
|
|
305
362
|
}));
|
|
363
|
+
const routes = maybeRoutes.filter(utils_1.isFulfilled).map(maybeRoute => maybeRoute.value);
|
|
364
|
+
if (!routes.length)
|
|
365
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
366
|
+
message: 'Unable to create any routes',
|
|
367
|
+
code: types_1.TradeQuoteError.UnsupportedTradePair,
|
|
368
|
+
cause: maybeRoutes.filter(utils_1.isRejected).map(maybeRoute => maybeRoute.reason),
|
|
369
|
+
}));
|
|
370
|
+
return (0, monads_1.Ok)(routes);
|
|
306
371
|
}
|
|
307
372
|
case caip_1.CHAIN_NAMESPACE.Sui: {
|
|
308
373
|
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
@@ -310,6 +375,18 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
|
|
|
310
375
|
code: types_1.TradeQuoteError.UnsupportedTradePair,
|
|
311
376
|
}));
|
|
312
377
|
}
|
|
378
|
+
case caip_1.CHAIN_NAMESPACE.Near: {
|
|
379
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
380
|
+
message: 'NEAR is not supported',
|
|
381
|
+
code: types_1.TradeQuoteError.UnsupportedTradePair,
|
|
382
|
+
}));
|
|
383
|
+
}
|
|
384
|
+
case caip_1.CHAIN_NAMESPACE.Starknet: {
|
|
385
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
386
|
+
message: 'Starknet is not supported',
|
|
387
|
+
code: types_1.TradeQuoteError.UnsupportedTradePair,
|
|
388
|
+
}));
|
|
389
|
+
}
|
|
313
390
|
default:
|
|
314
391
|
return (0, utils_1.assertUnreachable)(chainNamespace);
|
|
315
392
|
}
|
|
@@ -13,6 +13,7 @@ export * from './getL1RateOrQuote';
|
|
|
13
13
|
export * from './getPoolDetails';
|
|
14
14
|
export * as cosmossdk from './cosmossdk';
|
|
15
15
|
export * as evm from './evm';
|
|
16
|
+
export * as tron from './tron';
|
|
16
17
|
export * as utxo from './utxo';
|
|
17
18
|
export declare const getChainIdBySwapper: (swapperName: SwapperName) => import("@shapeshiftoss/caip").ChainId;
|
|
18
19
|
export declare const isThorTradeRate: (quote: TradeRate | undefined) => quote is ThorTradeRate;
|
|
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getSwapSource = exports.getPoolAssetId = exports.getAffiliate = exports.getNativeFee = exports.getNativePrecision = exports.isNativeAsset = exports.getMidgardUrl = exports.getDaemonUrl = exports.isThorTradeQuote = exports.isThorTradeRate = exports.getChainIdBySwapper = exports.utxo = exports.evm = exports.cosmossdk = void 0;
|
|
29
|
+
exports.getSwapSource = exports.getPoolAssetId = exports.getAffiliate = exports.getNativeFee = exports.getNativePrecision = exports.isNativeAsset = exports.getMidgardUrl = exports.getDaemonUrl = exports.isThorTradeQuote = exports.isThorTradeRate = exports.getChainIdBySwapper = exports.utxo = exports.tron = exports.evm = exports.cosmossdk = void 0;
|
|
30
30
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
31
31
|
const adapters = __importStar(require("@shapeshiftoss/chain-adapters"));
|
|
32
32
|
const MayachainSwapper_1 = require("../swappers/MayachainSwapper");
|
|
@@ -43,6 +43,7 @@ __exportStar(require("./getL1RateOrQuote"), exports);
|
|
|
43
43
|
__exportStar(require("./getPoolDetails"), exports);
|
|
44
44
|
exports.cosmossdk = __importStar(require("./cosmossdk"));
|
|
45
45
|
exports.evm = __importStar(require("./evm"));
|
|
46
|
+
exports.tron = __importStar(require("./tron"));
|
|
46
47
|
exports.utxo = __importStar(require("./utxo"));
|
|
47
48
|
const getChainIdBySwapper = (swapperName) => {
|
|
48
49
|
switch (swapperName) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Asset } from '@shapeshiftoss/types';
|
|
2
|
+
import type { SwapperConfig, SwapperName } from '../../types';
|
|
3
|
+
type GetThorTxDataArgs = {
|
|
4
|
+
sellAsset: Asset;
|
|
5
|
+
config: SwapperConfig;
|
|
6
|
+
swapperName: SwapperName;
|
|
7
|
+
};
|
|
8
|
+
type GetThorTxDataReturn = {
|
|
9
|
+
vault: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const getThorTxData: ({ sellAsset, config, swapperName, }: GetThorTxDataArgs) => Promise<GetThorTxDataReturn>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getThorTxData = void 0;
|
|
4
|
+
const getInboundAddressDataForChain_1 = require("../getInboundAddressDataForChain");
|
|
5
|
+
const index_1 = require("../index");
|
|
6
|
+
const getThorTxData = async ({ sellAsset, config, swapperName, }) => {
|
|
7
|
+
const daemonUrl = (0, index_1.getDaemonUrl)(config, swapperName);
|
|
8
|
+
const res = await (0, getInboundAddressDataForChain_1.getInboundAddressDataForChain)(daemonUrl, sellAsset.assetId, false, swapperName);
|
|
9
|
+
if (res.isErr())
|
|
10
|
+
throw res.unwrapErr();
|
|
11
|
+
const { address: vault } = res.unwrap();
|
|
12
|
+
return { vault };
|
|
13
|
+
};
|
|
14
|
+
exports.getThorTxData = getThorTxData;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTronTransactionFees = void 0;
|
|
4
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
|
+
const tronweb_1 = require("tronweb");
|
|
6
|
+
const utils_2 = require("../../utils");
|
|
7
|
+
const getThorTxData_1 = require("./getThorTxData");
|
|
8
|
+
const getChainPrices = async (rpcUrl) => {
|
|
9
|
+
try {
|
|
10
|
+
const tronWeb = new tronweb_1.TronWeb({ fullHost: rpcUrl });
|
|
11
|
+
const params = await tronWeb.trx.getChainParameters();
|
|
12
|
+
const bandwidthPrice = params.find(p => p.key === 'getTransactionFee')?.value ?? 1000;
|
|
13
|
+
const energyPrice = params.find(p => p.key === 'getEnergyFee')?.value ?? 420;
|
|
14
|
+
return { bandwidthPrice, energyPrice };
|
|
15
|
+
}
|
|
16
|
+
catch (_err) {
|
|
17
|
+
return { bandwidthPrice: 1000, energyPrice: 420 };
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const getTronTransactionFees = async (args, swapperName) => {
|
|
21
|
+
const { tradeQuote, stepIndex, config, from } = args;
|
|
22
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
23
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
24
|
+
const { memo } = tradeQuote;
|
|
25
|
+
if (!memo)
|
|
26
|
+
throw new Error('Memo is required');
|
|
27
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
28
|
+
const { sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit } = step;
|
|
29
|
+
const { vault } = await (0, getThorTxData_1.getThorTxData)({ sellAsset, config, swapperName });
|
|
30
|
+
const contractAddress = (0, utils_1.contractAddressOrUndefined)(sellAsset.assetId);
|
|
31
|
+
const rpcUrl = config.VITE_TRON_NODE_URL;
|
|
32
|
+
try {
|
|
33
|
+
const tronWeb = new tronweb_1.TronWeb({ fullHost: rpcUrl });
|
|
34
|
+
if (contractAddress) {
|
|
35
|
+
// TRC20 transfer - estimate energy cost
|
|
36
|
+
const { energyPrice } = await getChainPrices(rpcUrl);
|
|
37
|
+
const result = await tronWeb.transactionBuilder.triggerConstantContract(contractAddress, 'transfer(address,uint256)', {}, [
|
|
38
|
+
{ type: 'address', value: vault },
|
|
39
|
+
{ type: 'uint256', value: sellAmountIncludingProtocolFeesCryptoBaseUnit },
|
|
40
|
+
], from);
|
|
41
|
+
const energyUsed = result.energy_used ?? 65000; // Conservative default for TRC20 transfer
|
|
42
|
+
const feeInSun = energyUsed * energyPrice;
|
|
43
|
+
return String(feeInSun);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// TRX transfer with memo - build transaction to get accurate size
|
|
47
|
+
const { bandwidthPrice } = await getChainPrices(rpcUrl);
|
|
48
|
+
let tx = await tronWeb.transactionBuilder.sendTrx(vault, (0, utils_1.bnOrZero)(sellAmountIncludingProtocolFeesCryptoBaseUnit).toNumber(), from);
|
|
49
|
+
// Add memo to get accurate size with memo overhead
|
|
50
|
+
const txWithMemo = await tronWeb.transactionBuilder.addUpdateData(tx, memo, 'utf8');
|
|
51
|
+
// Calculate bandwidth fee from transaction size
|
|
52
|
+
const rawDataBytes = txWithMemo.raw_data_hex ? txWithMemo.raw_data_hex.length / 2 : 268;
|
|
53
|
+
const signatureBytes = 65;
|
|
54
|
+
const totalBytes = rawDataBytes + signatureBytes;
|
|
55
|
+
const feeInSun = totalBytes * bandwidthPrice;
|
|
56
|
+
return String(feeInSun);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
// Fallback to conservative estimate if fee estimation fails
|
|
61
|
+
// TRX transfer: ~1 TRX, TRC20: ~10 TRX
|
|
62
|
+
return contractAddress ? '10000000' : '1000000';
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
exports.getTronTransactionFees = getTronTransactionFees;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import type { GetUnsignedTronTransactionArgs, SwapperName } from '../../types';
|
|
3
|
+
export declare const getUnsignedTronTransaction: (args: GetUnsignedTronTransactionArgs, swapperName: SwapperName) => Promise<tron.TronSignTx>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUnsignedTronTransaction = void 0;
|
|
4
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
|
+
const utils_2 = require("../../utils");
|
|
6
|
+
const getThorTxData_1 = require("./getThorTxData");
|
|
7
|
+
const getUnsignedTronTransaction = async (args, swapperName) => {
|
|
8
|
+
const { tradeQuote, stepIndex, from, assertGetTronChainAdapter, config } = args;
|
|
9
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
10
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
11
|
+
const { memo } = tradeQuote;
|
|
12
|
+
if (!memo)
|
|
13
|
+
throw new Error('Memo is required');
|
|
14
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
15
|
+
const { accountNumber, sellAmountIncludingProtocolFeesCryptoBaseUnit, sellAsset } = step;
|
|
16
|
+
const { vault } = await (0, getThorTxData_1.getThorTxData)({
|
|
17
|
+
sellAsset,
|
|
18
|
+
config,
|
|
19
|
+
swapperName,
|
|
20
|
+
});
|
|
21
|
+
const adapter = assertGetTronChainAdapter(sellAsset.chainId);
|
|
22
|
+
// For TRC20 tokens, extract contract address
|
|
23
|
+
const contractAddress = (0, utils_1.contractAddressOrUndefined)(sellAsset.assetId);
|
|
24
|
+
return adapter.buildSendApiTransaction({
|
|
25
|
+
to: vault,
|
|
26
|
+
from,
|
|
27
|
+
value: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
28
|
+
accountNumber,
|
|
29
|
+
chainSpecific: {
|
|
30
|
+
contractAddress,
|
|
31
|
+
memo,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.getUnsignedTronTransaction = getUnsignedTronTransaction;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getThorTxData"), exports);
|
|
18
|
+
__exportStar(require("./getUnsignedTronTransaction"), exports);
|
|
19
|
+
__exportStar(require("./getTronTransactionFees"), exports);
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { QuoteResponse } from '@jup-ag/api';
|
|
2
2
|
import type { AccountId, AssetId, ChainId, Nominal } from '@shapeshiftoss/caip';
|
|
3
|
-
import type { ChainAdapter, CosmosSdkChainAdapter, EvmChainAdapter, SignTx, solana, sui, tron, UtxoChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
4
|
-
import type { HDWallet, SolanaSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
5
|
-
import type { AccountMetadata, Asset, AssetsByIdPartial, CosmosSdkChainId, EvmChainId, KnownChainIds, OrderQuoteResponse, PartialRecord, TronChainId, UtxoAccountType, UtxoChainId } from '@shapeshiftoss/types';
|
|
3
|
+
import type { ChainAdapter, CosmosSdkChainAdapter, EvmChainAdapter, near, SignTx, solana, starknet, sui, tron, UtxoChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
4
|
+
import type { HDWallet, SolanaSignTx, StarknetSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
5
|
+
import type { AccountMetadata, Asset, AssetsByIdPartial, CosmosSdkChainId, EvmChainId, KnownChainIds, NearChainId, OrderQuoteResponse, PartialRecord, TronChainId, UtxoAccountType, UtxoChainId } from '@shapeshiftoss/types';
|
|
6
6
|
import type { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
7
7
|
import type { Result } from '@sniptt/monads';
|
|
8
8
|
import type { TransactionInstruction } from '@solana/web3.js';
|
|
@@ -20,6 +20,7 @@ export type SwapperConfig = {
|
|
|
20
20
|
VITE_UNCHAINED_COSMOS_HTTP_URL: string;
|
|
21
21
|
VITE_THORCHAIN_NODE_URL: string;
|
|
22
22
|
VITE_MAYACHAIN_NODE_URL: string;
|
|
23
|
+
VITE_TRON_NODE_URL: string;
|
|
23
24
|
VITE_FEATURE_THORCHAINSWAP_LONGTAIL: boolean;
|
|
24
25
|
VITE_FEATURE_THORCHAINSWAP_L1_TO_LONGTAIL: boolean;
|
|
25
26
|
VITE_THORCHAIN_MIDGARD_URL: string;
|
|
@@ -45,6 +46,7 @@ export type SwapperConfig = {
|
|
|
45
46
|
VITE_TENDERLY_API_KEY: string;
|
|
46
47
|
VITE_TENDERLY_ACCOUNT_SLUG: string;
|
|
47
48
|
VITE_TENDERLY_PROJECT_SLUG: string;
|
|
49
|
+
VITE_SUI_NODE_URL: string;
|
|
48
50
|
};
|
|
49
51
|
export declare enum SwapperName {
|
|
50
52
|
Thorchain = "THORChain",
|
|
@@ -60,7 +62,9 @@ export declare enum SwapperName {
|
|
|
60
62
|
ButterSwap = "ButterSwap",
|
|
61
63
|
Bebop = "Bebop",
|
|
62
64
|
NearIntents = "NEAR Intents",
|
|
63
|
-
Cetus = "Cetus"
|
|
65
|
+
Cetus = "Cetus",
|
|
66
|
+
Sunio = "Sun.io",
|
|
67
|
+
Avnu = "AVNU"
|
|
64
68
|
}
|
|
65
69
|
export type SwapSource = SwapperName | `${SwapperName} • ${string}`;
|
|
66
70
|
export type SwapErrorRight = {
|
|
@@ -170,6 +174,15 @@ export type GetCosmosSdkTradeRateInput = CommonTradeRateInput & {
|
|
|
170
174
|
export type GetTronTradeRateInput = CommonTradeRateInput & {
|
|
171
175
|
chainId: TronChainId;
|
|
172
176
|
};
|
|
177
|
+
export type GetNearTradeQuoteInputBase = CommonTradeInput & {
|
|
178
|
+
chainId: NearChainId;
|
|
179
|
+
};
|
|
180
|
+
export type GetNearTradeQuoteInput = CommonTradeInput & {
|
|
181
|
+
chainId: NearChainId;
|
|
182
|
+
};
|
|
183
|
+
export type GetNearTradeRateInput = CommonTradeRateInput & {
|
|
184
|
+
chainId: NearChainId;
|
|
185
|
+
};
|
|
173
186
|
type GetUtxoTradeQuoteWithWallet = CommonTradeQuoteInput & {
|
|
174
187
|
chainId: UtxoChainId;
|
|
175
188
|
accountType: UtxoAccountType;
|
|
@@ -183,9 +196,9 @@ export type GetUtxoTradeRateInput = CommonTradeRateInput & {
|
|
|
183
196
|
xpub: string | undefined;
|
|
184
197
|
};
|
|
185
198
|
export type GetUtxoTradeQuoteInput = GetUtxoTradeQuoteWithWallet;
|
|
186
|
-
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput;
|
|
187
|
-
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput;
|
|
188
|
-
export type GetTradeQuoteInputWithWallet = GetUtxoTradeQuoteWithWallet | GetEvmTradeQuoteInputBase | GetCosmosSdkTradeQuoteInputBase | GetTronTradeQuoteInputBase;
|
|
199
|
+
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput | GetNearTradeQuoteInput;
|
|
200
|
+
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput | GetNearTradeRateInput;
|
|
201
|
+
export type GetTradeQuoteInputWithWallet = GetUtxoTradeQuoteWithWallet | GetEvmTradeQuoteInputBase | GetCosmosSdkTradeQuoteInputBase | GetTronTradeQuoteInputBase | GetNearTradeQuoteInputBase;
|
|
189
202
|
export type EvmSwapperDeps = {
|
|
190
203
|
assertGetEvmChainAdapter: (chainId: ChainId) => EvmChainAdapter;
|
|
191
204
|
fetchIsSmartContractAddressQuery: (userAddress: string, chainId: ChainId) => Promise<boolean>;
|
|
@@ -205,12 +218,18 @@ export type TronSwapperDeps = {
|
|
|
205
218
|
export type SuiSwapperDeps = {
|
|
206
219
|
assertGetSuiChainAdapter: (chainId: ChainId) => sui.ChainAdapter;
|
|
207
220
|
};
|
|
221
|
+
export type NearSwapperDeps = {
|
|
222
|
+
assertGetNearChainAdapter: (chainId: ChainId) => near.ChainAdapter;
|
|
223
|
+
};
|
|
224
|
+
export type StarknetSwapperDeps = {
|
|
225
|
+
assertGetStarknetChainAdapter: (chainId: ChainId) => starknet.ChainAdapter;
|
|
226
|
+
};
|
|
208
227
|
export type SwapperDeps = {
|
|
209
228
|
assetsById: AssetsByIdPartial;
|
|
210
229
|
config: SwapperConfig;
|
|
211
230
|
mixPanel: Mixpanel | undefined;
|
|
212
231
|
assertGetChainAdapter: (chainId: ChainId) => ChainAdapter<KnownChainIds>;
|
|
213
|
-
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps;
|
|
232
|
+
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps;
|
|
214
233
|
export type TradeQuoteStep = {
|
|
215
234
|
buyAmountBeforeFeesCryptoBaseUnit: string;
|
|
216
235
|
buyAmountAfterFeesCryptoBaseUnit: string;
|
|
@@ -238,6 +257,11 @@ export type TradeQuoteStep = {
|
|
|
238
257
|
data: string;
|
|
239
258
|
value: string;
|
|
240
259
|
gasLimit: string;
|
|
260
|
+
isCrossChain?: boolean;
|
|
261
|
+
buyAssetChainId?: ChainId;
|
|
262
|
+
expiry?: number;
|
|
263
|
+
steps?: string[];
|
|
264
|
+
route?: string[];
|
|
241
265
|
};
|
|
242
266
|
bebopTransactionMetadata?: {
|
|
243
267
|
to: Address;
|
|
@@ -274,6 +298,25 @@ export type TradeQuoteStep = {
|
|
|
274
298
|
value: Hex;
|
|
275
299
|
gasLimit: string;
|
|
276
300
|
};
|
|
301
|
+
sunioTransactionMetadata?: {
|
|
302
|
+
route: {
|
|
303
|
+
amountIn: string;
|
|
304
|
+
amountOut: string;
|
|
305
|
+
inUsd: string;
|
|
306
|
+
outUsd: string;
|
|
307
|
+
impact: string;
|
|
308
|
+
fee: string;
|
|
309
|
+
tokens: string[];
|
|
310
|
+
symbols: string[];
|
|
311
|
+
poolFees: string[];
|
|
312
|
+
poolVersions: string[];
|
|
313
|
+
stepAmountsOut: string[];
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
avnuSpecific?: {
|
|
317
|
+
quoteId: string;
|
|
318
|
+
routes: any[];
|
|
319
|
+
};
|
|
277
320
|
};
|
|
278
321
|
export type TradeRateStep = Omit<TradeQuoteStep, 'accountNumber'> & {
|
|
279
322
|
accountNumber: undefined;
|
|
@@ -426,6 +469,12 @@ export type TronTransactionExecutionProps = {
|
|
|
426
469
|
export type SuiTransactionExecutionProps = {
|
|
427
470
|
signAndBroadcastTransaction: (txToSign: SuiSignTx) => Promise<string>;
|
|
428
471
|
};
|
|
472
|
+
export type NearTransactionExecutionProps = {
|
|
473
|
+
signAndBroadcastTransaction: (txToSign: near.NearSignTx) => Promise<string>;
|
|
474
|
+
};
|
|
475
|
+
export type StarknetTransactionExecutionProps = {
|
|
476
|
+
signAndBroadcastTransaction: (txToSign: StarknetSignTx) => Promise<string>;
|
|
477
|
+
};
|
|
429
478
|
type EvmAccountMetadata = {
|
|
430
479
|
from: string;
|
|
431
480
|
};
|
|
@@ -438,6 +487,12 @@ type TronAccountMetadata = {
|
|
|
438
487
|
type SuiAccountMetadata = {
|
|
439
488
|
from: string;
|
|
440
489
|
};
|
|
490
|
+
type NearAccountMetadata = {
|
|
491
|
+
from: string;
|
|
492
|
+
};
|
|
493
|
+
type StarknetAccountMetadata = {
|
|
494
|
+
from: string;
|
|
495
|
+
};
|
|
441
496
|
type UtxoAccountMetadata = {
|
|
442
497
|
senderAddress: string;
|
|
443
498
|
xpub: string;
|
|
@@ -460,6 +515,8 @@ export type GetUnsignedEvmTransactionArgs = CommonGetUnsignedTransactionArgs & E
|
|
|
460
515
|
export type GetUnsignedSolanaTransactionArgs = CommonGetUnsignedTransactionArgs & SolanaAccountMetadata & SolanaSwapperDeps;
|
|
461
516
|
export type GetUnsignedTronTransactionArgs = CommonGetUnsignedTransactionArgs & TronAccountMetadata & TronSwapperDeps;
|
|
462
517
|
export type GetUnsignedSuiTransactionArgs = CommonGetUnsignedTransactionArgs & SuiAccountMetadata & SuiSwapperDeps;
|
|
518
|
+
export type GetUnsignedNearTransactionArgs = CommonGetUnsignedTransactionArgs & NearAccountMetadata & NearSwapperDeps;
|
|
519
|
+
export type GetUnsignedStarknetTransactionArgs = CommonGetUnsignedTransactionArgs & StarknetAccountMetadata & StarknetSwapperDeps;
|
|
463
520
|
export type GetUnsignedEvmMessageArgs = CommonGetUnsignedTransactionArgs & EvmAccountMetadata & Omit<EvmSwapperDeps, 'fetchIsSmartContractAddressQuery'>;
|
|
464
521
|
export type GetUnsignedUtxoTransactionArgs = CommonGetUnsignedTransactionArgs & UtxoAccountMetadata & UtxoSwapperDeps;
|
|
465
522
|
export type GetUnsignedCosmosSdkTransactionArgs = CommonGetUnsignedTransactionArgs & CosmosSdkAccountMetadata & CosmosSdkSwapperDeps;
|
|
@@ -478,7 +535,7 @@ export type CheckTradeStatusInput = {
|
|
|
478
535
|
stepIndex: SupportedTradeQuoteStepIndex;
|
|
479
536
|
config: SwapperConfig;
|
|
480
537
|
swap: Swap | undefined;
|
|
481
|
-
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & SuiSwapperDeps;
|
|
538
|
+
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps;
|
|
482
539
|
export type TradeStatus = {
|
|
483
540
|
status: TxStatus;
|
|
484
541
|
buyTxHash: string | undefined;
|
|
@@ -499,6 +556,8 @@ export type Swapper = {
|
|
|
499
556
|
executeSolanaTransaction?: (txToSign: SolanaSignTx, callbacks: SolanaTransactionExecutionProps) => Promise<string>;
|
|
500
557
|
executeTronTransaction?: (txToSign: tron.TronSignTx, callbacks: TronTransactionExecutionProps) => Promise<string>;
|
|
501
558
|
executeSuiTransaction?: (txToSign: SuiSignTx, callbacks: SuiTransactionExecutionProps) => Promise<string>;
|
|
559
|
+
executeNearTransaction?: (txToSign: near.NearSignTx, callbacks: NearTransactionExecutionProps) => Promise<string>;
|
|
560
|
+
executeStarknetTransaction?: (txToSign: StarknetSignTx, callbacks: StarknetTransactionExecutionProps) => Promise<string>;
|
|
502
561
|
};
|
|
503
562
|
export type SwapperApi = {
|
|
504
563
|
checkTradeStatus: (input: CheckTradeStatusInput) => Promise<TradeStatus>;
|
|
@@ -512,12 +571,16 @@ export type SwapperApi = {
|
|
|
512
571
|
getUnsignedSolanaTransaction?: (input: GetUnsignedSolanaTransactionArgs) => Promise<SolanaSignTx>;
|
|
513
572
|
getUnsignedTronTransaction?: (input: GetUnsignedTronTransactionArgs) => Promise<tron.TronSignTx>;
|
|
514
573
|
getUnsignedSuiTransaction?: (input: GetUnsignedSuiTransactionArgs) => Promise<SuiSignTx>;
|
|
574
|
+
getUnsignedNearTransaction?: (input: GetUnsignedNearTransactionArgs) => Promise<near.NearSignTx>;
|
|
575
|
+
getUnsignedStarknetTransaction?: (input: GetUnsignedStarknetTransactionArgs) => Promise<StarknetSignTx>;
|
|
515
576
|
getEvmTransactionFees?: (input: GetUnsignedEvmTransactionArgs) => Promise<string>;
|
|
516
577
|
getSolanaTransactionFees?: (input: GetUnsignedSolanaTransactionArgs) => Promise<string>;
|
|
517
578
|
getSuiTransactionFees?: (input: GetUnsignedSuiTransactionArgs) => Promise<string>;
|
|
518
579
|
getUtxoTransactionFees?: (input: GetUnsignedUtxoTransactionArgs) => Promise<string>;
|
|
519
580
|
getCosmosSdkTransactionFees?: (input: GetUnsignedCosmosSdkTransactionArgs) => Promise<string>;
|
|
520
581
|
getTronTransactionFees?: (input: GetUnsignedTronTransactionArgs) => Promise<string>;
|
|
582
|
+
getNearTransactionFees?: (input: GetUnsignedNearTransactionArgs) => Promise<string>;
|
|
583
|
+
getStarknetTransactionFees?: (input: GetUnsignedStarknetTransactionArgs) => Promise<string>;
|
|
521
584
|
};
|
|
522
585
|
export type QuoteResult = Result<TradeQuote[], SwapErrorRight> & {
|
|
523
586
|
swapperName: SwapperName;
|
|
@@ -542,6 +605,8 @@ export type CosmosSdkTransactionExecutionInput = CommonTradeExecutionInput & Cos
|
|
|
542
605
|
export type SolanaTransactionExecutionInput = CommonTradeExecutionInput & SolanaTransactionExecutionProps & SolanaAccountMetadata;
|
|
543
606
|
export type TronTransactionExecutionInput = CommonTradeExecutionInput & TronTransactionExecutionProps & TronAccountMetadata;
|
|
544
607
|
export type SuiTransactionExecutionInput = CommonTradeExecutionInput & SuiTransactionExecutionProps & SuiAccountMetadata;
|
|
608
|
+
export type NearTransactionExecutionInput = CommonTradeExecutionInput & NearTransactionExecutionProps & NearAccountMetadata;
|
|
609
|
+
export type StarknetTransactionExecutionInput = CommonTradeExecutionInput & StarknetTransactionExecutionProps & StarknetAccountMetadata;
|
|
545
610
|
export declare enum TradeExecutionEvent {
|
|
546
611
|
SellTxHash = "sellTxHash",
|
|
547
612
|
RelayerTxHash = "relayerTxHash",
|
package/dist/cjs/types.js
CHANGED
|
@@ -17,6 +17,8 @@ var SwapperName;
|
|
|
17
17
|
SwapperName["Bebop"] = "Bebop";
|
|
18
18
|
SwapperName["NearIntents"] = "NEAR Intents";
|
|
19
19
|
SwapperName["Cetus"] = "Cetus";
|
|
20
|
+
SwapperName["Sunio"] = "Sun.io";
|
|
21
|
+
SwapperName["Avnu"] = "AVNU";
|
|
20
22
|
})(SwapperName || (exports.SwapperName = SwapperName = {}));
|
|
21
23
|
var TradeQuoteError;
|
|
22
24
|
(function (TradeQuoteError) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import type { Asset } from '@shapeshiftoss/types';
|
|
3
3
|
import type { Address, Hex } from 'viem';
|
|
4
|
-
import type { TenderlyConfig } from './types';
|
|
4
|
+
import type { TenderlyConfig, TenderlyInternalTransaction } from './types';
|
|
5
5
|
export type SimulationResult = {
|
|
6
6
|
success: boolean;
|
|
7
7
|
gasUsed: bigint;
|
|
@@ -16,5 +16,10 @@ export type SimulateTransactionParams = {
|
|
|
16
16
|
value?: string | bigint;
|
|
17
17
|
sellAsset: Asset;
|
|
18
18
|
spenderAddress?: Address;
|
|
19
|
+
gas?: number;
|
|
19
20
|
};
|
|
20
21
|
export declare const simulateWithStateOverrides: (params: SimulateTransactionParams, config: TenderlyConfig) => Promise<SimulationResult>;
|
|
22
|
+
export declare const fetchInternalTransactions: (params: {
|
|
23
|
+
chainId: ChainId;
|
|
24
|
+
txHash: string;
|
|
25
|
+
}, config: TenderlyConfig) => Promise<TenderlyInternalTransaction[]>;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.simulateWithStateOverrides = void 0;
|
|
6
|
+
exports.fetchInternalTransactions = exports.simulateWithStateOverrides = void 0;
|
|
7
7
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
8
8
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
9
9
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -11,7 +11,7 @@ const viem_1 = require("viem");
|
|
|
11
11
|
const helpers_1 = require("../../swappers/utils/helpers/helpers");
|
|
12
12
|
const storageSlots_1 = require("./storageSlots");
|
|
13
13
|
const simulateWithStateOverrides = async (params, config) => {
|
|
14
|
-
const { chainId, from, to, data, value, sellAsset, spenderAddress } = params;
|
|
14
|
+
const { chainId, from, to, data, value, sellAsset, spenderAddress, gas } = params;
|
|
15
15
|
try {
|
|
16
16
|
if (!(0, viem_1.isAddress)(from))
|
|
17
17
|
throw new Error(`Invalid from address: ${from}`);
|
|
@@ -29,6 +29,7 @@ const simulateWithStateOverrides = async (params, config) => {
|
|
|
29
29
|
from: from.toLowerCase(),
|
|
30
30
|
to: to.toLowerCase(),
|
|
31
31
|
input: data,
|
|
32
|
+
gas,
|
|
32
33
|
value: value ? (0, viem_1.toHex)(BigInt(value)) : '0x0',
|
|
33
34
|
save: false,
|
|
34
35
|
state_objects: stateOverrides,
|
|
@@ -69,6 +70,25 @@ const simulateWithStateOverrides = async (params, config) => {
|
|
|
69
70
|
}
|
|
70
71
|
};
|
|
71
72
|
exports.simulateWithStateOverrides = simulateWithStateOverrides;
|
|
73
|
+
const fetchInternalTransactions = async (params, config) => {
|
|
74
|
+
const { chainId, txHash } = params;
|
|
75
|
+
try {
|
|
76
|
+
const evmNetworkId = Number((0, caip_1.fromChainId)(chainId).chainReference);
|
|
77
|
+
const url = `https://api.tenderly.co/api/v1/account/${config.accountSlug}/project/${config.projectSlug}/transactions/by-hash/${evmNetworkId}/${txHash}`;
|
|
78
|
+
const response = await axios_1.default.get(url, {
|
|
79
|
+
headers: {
|
|
80
|
+
'Content-Type': 'application/json',
|
|
81
|
+
'X-Access-Key': config.apiKey,
|
|
82
|
+
},
|
|
83
|
+
timeout: 10000,
|
|
84
|
+
});
|
|
85
|
+
return response.data.transaction.internal_transactions ?? [];
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.fetchInternalTransactions = fetchInternalTransactions;
|
|
72
92
|
const buildStateOverrides = (params) => {
|
|
73
93
|
const { from, spender, sellAsset } = params;
|
|
74
94
|
// Large native balance for gas (1B is overkill but guarantees success on all chains)
|
|
@@ -54,3 +54,24 @@ export type TenderlyConfig = {
|
|
|
54
54
|
accountSlug: string;
|
|
55
55
|
projectSlug: string;
|
|
56
56
|
};
|
|
57
|
+
export type TenderlyInternalTransaction = {
|
|
58
|
+
from: Address;
|
|
59
|
+
to: Address;
|
|
60
|
+
value: string;
|
|
61
|
+
};
|
|
62
|
+
export type TenderlyTransactionResponse = {
|
|
63
|
+
transaction: {
|
|
64
|
+
hash: string;
|
|
65
|
+
block_number: number;
|
|
66
|
+
from: Address;
|
|
67
|
+
to: Address;
|
|
68
|
+
input: string;
|
|
69
|
+
value: string;
|
|
70
|
+
gas: number;
|
|
71
|
+
gas_used: number;
|
|
72
|
+
gas_price: string;
|
|
73
|
+
status: boolean;
|
|
74
|
+
error_message?: string;
|
|
75
|
+
internal_transactions?: TenderlyInternalTransaction[];
|
|
76
|
+
};
|
|
77
|
+
};
|