@shapeshiftoss/swapper 20.1.1 → 20.3.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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +1 -2
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.js +4 -7
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +0 -1
- package/dist/cjs/swappers/BobGatewaySwapper/BobGatewaySwapper.js +10 -1
- package/dist/cjs/swappers/BobGatewaySwapper/endpoints.js +2 -33
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -8
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +1 -2
- package/dist/cjs/swappers/BobGatewaySwapper/types.d.ts +3 -3
- package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.d.ts +3 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.js +8 -5
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.d.ts +2 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.js +30 -34
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.js +117 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +1 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.d.ts +8 -11
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.js +36 -31
- package/dist/cjs/swappers/ButterSwap/ButterSwap.js +0 -3
- package/dist/cjs/swappers/ButterSwap/endpoints.js +0 -3
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -3
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +0 -51
- package/dist/cjs/swappers/ButterSwap/types.d.ts +3 -14
- package/dist/cjs/swappers/ButterSwap/utils/constants.d.ts +2 -0
- package/dist/cjs/swappers/ButterSwap/utils/constants.js +4 -1
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.d.ts +2 -3
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.js +42 -65
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.test.js +115 -73
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -4
- package/dist/cjs/swappers/ButterSwap/xhr.js +3 -3
- package/dist/cjs/swappers/ChainflipSwapper/endpoints.js +3 -19
- package/dist/cjs/swappers/ChainflipSwapper/utils/getChainflipStepData.d.ts +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/utils/getChainflipStepData.js +31 -12
- package/dist/cjs/swappers/NearIntentsSwapper/constants.d.ts +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/constants.js +3 -1
- package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +10 -5
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/constant.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/constant.js +3 -2
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +1 -2
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayAssetAddress.js +2 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.d.ts +2 -3
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.js +46 -13
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.test.js +139 -0
- package/dist/cjs/swappers/RelaySwapper/utils/helpers.js +1 -2
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +1 -4
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +3 -63
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +3 -4
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +7 -1
- package/dist/cjs/swappers/SunioSwapper/types.d.ts +0 -3
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +11 -6
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.js +33 -30
- package/dist/cjs/swappers/SunioSwapper/utils/constants.d.ts +3 -3
- package/dist/cjs/swappers/SunioSwapper/utils/constants.js +5 -9
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.d.ts +8 -3
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.js +54 -20
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.test.js +177 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTradeContext.js +3 -2
- package/dist/cjs/swappers/SunioSwapper/utils/helpers.js +2 -1
- package/dist/cjs/swappers/ThorchainSwapper/endpoints.js +3 -4
- package/dist/cjs/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.js +6 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.test.js +15 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/assertValidLongtailTrade.js +7 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +0 -2
- package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +0 -2
- package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.d.ts +1 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.js +17 -20
- package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.test.js +31 -0
- package/dist/cjs/types.d.ts +9 -8
- package/dist/cjs/utils/helpers.js +3 -0
- package/dist/cjs/utils/helpers.test.js +3 -0
- package/dist/cjs/utils/thorchain/getThorStepData.js +32 -49
- package/dist/cjs/utils/thorchain/getThorStepData.tron.test.d.ts +1 -0
- package/dist/cjs/utils/thorchain/getThorStepData.tron.test.js +93 -0
- package/dist/cjs/utils/thorchain/index.d.ts +0 -1
- package/dist/cjs/utils/thorchain/index.js +1 -14
- package/dist/cjs/utils/tron/constants.d.ts +1 -0
- package/dist/cjs/utils/tron/constants.js +5 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.d.ts +27 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.js +64 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.js +157 -0
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.d.ts +2 -1
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.js +14 -48
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.test.d.ts +1 -0
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.test.js +76 -0
- package/dist/cjs/utils/tron/index.d.ts +2 -0
- package/dist/cjs/utils/tron/index.js +2 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +1 -2
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.js +4 -7
- package/dist/esm/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +0 -1
- package/dist/esm/swappers/BobGatewaySwapper/BobGatewaySwapper.js +11 -2
- package/dist/esm/swappers/BobGatewaySwapper/endpoints.js +5 -36
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -8
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +1 -2
- package/dist/esm/swappers/BobGatewaySwapper/types.d.ts +3 -3
- package/dist/esm/swappers/BobGatewaySwapper/utils/constants.d.ts +3 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/constants.js +8 -7
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.d.ts +2 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.js +21 -25
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.d.ts +1 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.js +115 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +1 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.d.ts +8 -11
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.js +13 -30
- package/dist/esm/swappers/ButterSwap/ButterSwap.js +0 -3
- package/dist/esm/swappers/ButterSwap/endpoints.js +0 -3
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -3
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +1 -49
- package/dist/esm/swappers/ButterSwap/types.d.ts +3 -14
- package/dist/esm/swappers/ButterSwap/utils/constants.d.ts +2 -0
- package/dist/esm/swappers/ButterSwap/utils/constants.js +3 -0
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.d.ts +2 -3
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.js +42 -65
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.test.js +116 -74
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +2 -5
- package/dist/esm/swappers/ButterSwap/xhr.js +3 -3
- package/dist/esm/swappers/ChainflipSwapper/endpoints.js +3 -19
- package/dist/esm/swappers/ChainflipSwapper/utils/getChainflipStepData.d.ts +1 -1
- package/dist/esm/swappers/ChainflipSwapper/utils/getChainflipStepData.js +32 -13
- package/dist/esm/swappers/NearIntentsSwapper/constants.d.ts +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/constants.js +2 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +10 -5
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +2 -2
- package/dist/esm/swappers/RelaySwapper/constant.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/constant.js +2 -1
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +1 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayAssetAddress.js +3 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.d.ts +2 -3
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.js +46 -13
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.test.d.ts +1 -0
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.test.js +137 -0
- package/dist/esm/swappers/RelaySwapper/utils/helpers.js +1 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +3 -3
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +1 -4
- package/dist/esm/swappers/SunioSwapper/endpoints.js +5 -65
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +3 -4
- package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +7 -1
- package/dist/esm/swappers/SunioSwapper/types.d.ts +0 -3
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +11 -6
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.js +31 -28
- package/dist/esm/swappers/SunioSwapper/utils/constants.d.ts +3 -3
- package/dist/esm/swappers/SunioSwapper/utils/constants.js +4 -8
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.d.ts +8 -3
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.js +52 -18
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.test.d.ts +1 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.test.js +175 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTradeContext.js +2 -1
- package/dist/esm/swappers/SunioSwapper/utils/helpers.js +3 -2
- package/dist/esm/swappers/ThorchainSwapper/endpoints.js +4 -5
- package/dist/esm/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.js +6 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.test.js +15 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/assertValidLongtailTrade.js +7 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +0 -2
- package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +0 -2
- package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.d.ts +1 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.js +17 -20
- package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.test.js +29 -1
- package/dist/esm/types.d.ts +9 -8
- package/dist/esm/utils/helpers.js +4 -1
- package/dist/esm/utils/helpers.test.js +3 -0
- package/dist/esm/utils/thorchain/getThorStepData.js +32 -49
- package/dist/esm/utils/thorchain/getThorStepData.tron.test.d.ts +1 -0
- package/dist/esm/utils/thorchain/getThorStepData.tron.test.js +91 -0
- package/dist/esm/utils/thorchain/index.d.ts +0 -1
- package/dist/esm/utils/thorchain/index.js +0 -1
- package/dist/esm/utils/tron/constants.d.ts +1 -0
- package/dist/esm/utils/tron/constants.js +2 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.d.ts +27 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.js +59 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.js +155 -0
- package/dist/esm/utils/tron/getUnsignedTronTransaction.d.ts +2 -1
- package/dist/esm/utils/tron/getUnsignedTronTransaction.js +14 -48
- package/dist/esm/utils/tron/getUnsignedTronTransaction.test.d.ts +1 -0
- package/dist/esm/utils/tron/getUnsignedTronTransaction.test.js +74 -0
- package/dist/esm/utils/tron/index.d.ts +2 -0
- package/dist/esm/utils/tron/index.js +2 -0
- package/package.json +9 -9
- package/dist/cjs/swappers/ButterSwap/test-data/eth-btc.json +0 -461
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +0 -14
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +0 -32
- package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +0 -12
- package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +0 -78
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +0 -2
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.js +0 -36
- package/dist/cjs/utils/thorchain/tron/getTronTransactionFees.d.ts +0 -2
- package/dist/cjs/utils/thorchain/tron/getTronTransactionFees.js +0 -68
- package/dist/cjs/utils/thorchain/tron/getUnsignedTronTransaction.d.ts +0 -3
- package/dist/cjs/utils/thorchain/tron/getUnsignedTronTransaction.js +0 -35
- package/dist/cjs/utils/thorchain/tron/index.d.ts +0 -2
- package/dist/cjs/utils/thorchain/tron/index.js +0 -18
- package/dist/esm/swappers/ButterSwap/test-data/eth-btc.json +0 -461
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +0 -14
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +0 -28
- package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +0 -12
- package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +0 -74
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +0 -2
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.js +0 -32
- package/dist/esm/utils/thorchain/tron/getTronTransactionFees.d.ts +0 -2
- package/dist/esm/utils/thorchain/tron/getTronTransactionFees.js +0 -64
- package/dist/esm/utils/thorchain/tron/getUnsignedTronTransaction.d.ts +0 -3
- package/dist/esm/utils/thorchain/tron/getUnsignedTronTransaction.js +0 -31
- package/dist/esm/utils/thorchain/tron/index.d.ts +0 -2
- package/dist/esm/utils/thorchain/tron/index.js +0 -2
- /package/dist/cjs/swappers/SunioSwapper/utils/{fetchFromSunio.d.ts → fetchSunioQuote.d.ts} +0 -0
- /package/dist/cjs/swappers/SunioSwapper/utils/{fetchFromSunio.js → fetchSunioQuote.js} +0 -0
- /package/dist/esm/swappers/SunioSwapper/utils/{fetchFromSunio.d.ts → fetchSunioQuote.d.ts} +0 -0
- /package/dist/esm/swappers/SunioSwapper/utils/{fetchFromSunio.js → fetchSunioQuote.js} +0 -0
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { SunioRoute } from '../types';
|
|
2
|
-
type EstimateSunioNetworkFeeArgs = {
|
|
3
|
-
rpcUrl: string;
|
|
4
|
-
apiKey: string;
|
|
5
|
-
route: SunioRoute;
|
|
6
|
-
sellAmountCryptoBaseUnit: string;
|
|
7
|
-
isSellingNativeTrx: boolean;
|
|
8
|
-
address: string | undefined;
|
|
9
|
-
slippageTolerancePercentageDecimal: string | undefined;
|
|
10
|
-
};
|
|
11
|
-
export declare const estimateSunioNetworkFeeCryptoBaseUnit: ({ rpcUrl, apiKey, route, sellAmountCryptoBaseUnit, isSellingNativeTrx, address, slippageTolerancePercentageDecimal, }: EstimateSunioNetworkFeeArgs) => Promise<string>;
|
|
12
|
-
export {};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.estimateSunioNetworkFeeCryptoBaseUnit = void 0;
|
|
4
|
-
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
|
-
const tronweb_1 = require("tronweb");
|
|
6
|
-
const buildSwapContractCall_1 = require("./buildSwapContractCall");
|
|
7
|
-
const buildSwapRouteParameters_1 = require("./buildSwapRouteParameters");
|
|
8
|
-
const constants_1 = require("./constants");
|
|
9
|
-
// Estimates the network fee (in TRX base units) for a Sun.io swap. The router sponsors only ~1%
|
|
10
|
-
// of energy (origin_energy_usage); the user pays the rest, so we simulate the real swapExactInput
|
|
11
|
-
// call when we have an address to estimate from. The simulation reverts before approval for TRC20
|
|
12
|
-
// sells (and when the account lacks the sell balance), so we fall back to a conservative per-sell-
|
|
13
|
-
// type constant. Used both at quote time and re-run at confirm time, where a now-granted allowance
|
|
14
|
-
// lets the simulation produce the true cost.
|
|
15
|
-
const estimateSunioNetworkFeeCryptoBaseUnit = async ({ rpcUrl, apiKey, route, sellAmountCryptoBaseUnit, isSellingNativeTrx, address, slippageTolerancePercentageDecimal, }) => {
|
|
16
|
-
const tronGridHeaders = apiKey ? { 'TRON-PRO-API-KEY': apiKey } : {};
|
|
17
|
-
const tronWeb = new tronweb_1.TronWeb({ fullHost: rpcUrl, headers: tronGridHeaders });
|
|
18
|
-
// Live network prices, defaulting if the node is unavailable so we still produce a fee
|
|
19
|
-
const { bandwidthPrice, energyPrice } = await (async () => {
|
|
20
|
-
try {
|
|
21
|
-
const params = await tronWeb.trx.getChainParameters();
|
|
22
|
-
return {
|
|
23
|
-
bandwidthPrice: params.find(p => p.key === 'getTransactionFee')?.value ?? 1000,
|
|
24
|
-
energyPrice: params.find(p => p.key === 'getEnergyFee')?.value ?? 100,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return { bandwidthPrice: 1000, energyPrice: 100 };
|
|
29
|
-
}
|
|
30
|
-
})();
|
|
31
|
-
// Account activation (1 TRX) is only charged when the recipient receives native TRX, mirroring
|
|
32
|
-
// the chain adapter. A TRC20 buy doesn't incur the flat activation fee (its account-creation
|
|
33
|
-
// cost is folded into energy). Only checkable with an address.
|
|
34
|
-
const isBuyingNativeTrx = route.tokens[route.tokens.length - 1] === constants_1.SUNIO_TRON_NATIVE_ADDRESS;
|
|
35
|
-
const accountActivationFee = await (async () => {
|
|
36
|
-
if (!address || !isBuyingNativeTrx)
|
|
37
|
-
return 0;
|
|
38
|
-
try {
|
|
39
|
-
const recipientInfoResponse = await fetch(`${rpcUrl}/wallet/getaccount`, {
|
|
40
|
-
method: 'POST',
|
|
41
|
-
headers: { 'Content-Type': 'application/json', ...tronGridHeaders },
|
|
42
|
-
body: JSON.stringify({ address, visible: true }),
|
|
43
|
-
});
|
|
44
|
-
const recipientInfo = await recipientInfoResponse.json();
|
|
45
|
-
const recipientExists = recipientInfo && Object.keys(recipientInfo).length > 1;
|
|
46
|
-
return recipientExists ? 0 : 1_000_000; // 1 TRX
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return 0;
|
|
50
|
-
}
|
|
51
|
-
})();
|
|
52
|
-
const energyUsed = await (async () => {
|
|
53
|
-
// TRC20 sells cost far more energy than native sells (the extra transferFrom token pull)
|
|
54
|
-
const fallbackEnergy = isSellingNativeTrx
|
|
55
|
-
? constants_1.SUNIO_FALLBACK_SWAP_ENERGY_NATIVE
|
|
56
|
-
: constants_1.SUNIO_FALLBACK_SWAP_ENERGY_TRC20;
|
|
57
|
-
if (!address)
|
|
58
|
-
return fallbackEnergy;
|
|
59
|
-
try {
|
|
60
|
-
const routeParams = (0, buildSwapRouteParameters_1.buildSwapRouteParameters)(route, sellAmountCryptoBaseUnit, '0', address, slippageTolerancePercentageDecimal ?? constants_1.DEFAULT_SLIPPAGE_PERCENTAGE);
|
|
61
|
-
const callValue = isSellingNativeTrx ? Number(sellAmountCryptoBaseUnit) : 0;
|
|
62
|
-
const result = await tronWeb.transactionBuilder.triggerConstantContract(constants_1.SUNIO_SMART_ROUTER_CONTRACT, buildSwapContractCall_1.SUNIO_SWAP_EXACT_INPUT_SELECTOR, { callValue }, (0, buildSwapContractCall_1.buildSwapExactInputParameters)(routeParams), address);
|
|
63
|
-
// A reverted simulation (e.g. TRC20 sell pre-approval) can still return a small energy_used;
|
|
64
|
-
// only trust it when the call actually succeeded, otherwise use the conservative fallback.
|
|
65
|
-
if (result?.result?.result !== true || result.energy_used == null)
|
|
66
|
-
return fallbackEnergy;
|
|
67
|
-
return result.energy_used;
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
return fallbackEnergy;
|
|
71
|
-
}
|
|
72
|
-
})();
|
|
73
|
-
// 1.2x safety margin for energy price/usage variance between estimate and execution
|
|
74
|
-
const energyFee = Math.ceil(energyUsed * energyPrice * 1.2);
|
|
75
|
-
const bandwidthFee = 1100 * bandwidthPrice;
|
|
76
|
-
return (0, utils_1.bn)(energyFee).plus(bandwidthFee).plus(accountActivationFee).toFixed(0);
|
|
77
|
-
};
|
|
78
|
-
exports.estimateSunioNetworkFeeCryptoBaseUnit = estimateSunioNetworkFeeCryptoBaseUnit;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSunioTransactionFees = void 0;
|
|
4
|
-
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
-
const utils_1 = require("../../../utils");
|
|
6
|
-
const estimateSunioNetworkFee_1 = require("./estimateSunioNetworkFee");
|
|
7
|
-
const getSunioTransactionFees = async ({ tradeQuote, stepIndex, from, slippageTolerancePercentageDecimal, assertGetTronChainAdapter, config, }) => {
|
|
8
|
-
if (!(0, utils_1.isExecutableTradeQuote)(tradeQuote))
|
|
9
|
-
throw new Error('Unable to execute a trade rate quote');
|
|
10
|
-
const step = (0, utils_1.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
11
|
-
const storedNetworkFeeCryptoBaseUnit = step.feeData.networkFeeCryptoBaseUnit;
|
|
12
|
-
const route = step.sunioTransactionData?.route;
|
|
13
|
-
if (!route) {
|
|
14
|
-
if (!storedNetworkFeeCryptoBaseUnit)
|
|
15
|
-
throw new Error('Missing network fee in quote');
|
|
16
|
-
return storedNetworkFeeCryptoBaseUnit;
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
const adapter = assertGetTronChainAdapter(caip_1.tronChainId);
|
|
20
|
-
return await (0, estimateSunioNetworkFee_1.estimateSunioNetworkFeeCryptoBaseUnit)({
|
|
21
|
-
rpcUrl: adapter.httpProvider.getRpcUrl(),
|
|
22
|
-
apiKey: config.VITE_TRON_GRID_API_KEY,
|
|
23
|
-
route,
|
|
24
|
-
sellAmountCryptoBaseUnit: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
25
|
-
isSellingNativeTrx: step.sellAsset.assetId === caip_1.tronAssetId,
|
|
26
|
-
address: from,
|
|
27
|
-
slippageTolerancePercentageDecimal,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
if (!storedNetworkFeeCryptoBaseUnit)
|
|
32
|
-
throw new Error('Missing network fee in quote');
|
|
33
|
-
return storedNetworkFeeCryptoBaseUnit;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
exports.getSunioTransactionFees = getSunioTransactionFees;
|
|
@@ -1,68 +0,0 @@
|
|
|
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, headers) => {
|
|
9
|
-
try {
|
|
10
|
-
const tronWeb = new tronweb_1.TronWeb({ fullHost: rpcUrl, headers });
|
|
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
|
-
const tronGridHeaders = config.VITE_TRON_GRID_API_KEY
|
|
33
|
-
? { 'TRON-PRO-API-KEY': config.VITE_TRON_GRID_API_KEY }
|
|
34
|
-
: {};
|
|
35
|
-
try {
|
|
36
|
-
const tronWeb = new tronweb_1.TronWeb({ fullHost: rpcUrl, headers: tronGridHeaders });
|
|
37
|
-
if (contractAddress) {
|
|
38
|
-
// TRC20 transfer - estimate energy cost
|
|
39
|
-
const { energyPrice } = await getChainPrices(rpcUrl, tronGridHeaders);
|
|
40
|
-
const result = await tronWeb.transactionBuilder.triggerConstantContract(contractAddress, 'transfer(address,uint256)', {}, [
|
|
41
|
-
{ type: 'address', value: vault },
|
|
42
|
-
{ type: 'uint256', value: sellAmountIncludingProtocolFeesCryptoBaseUnit },
|
|
43
|
-
], from);
|
|
44
|
-
const energyUsed = result.energy_used ?? 65000; // Conservative default for TRC20 transfer
|
|
45
|
-
const feeInSun = energyUsed * energyPrice;
|
|
46
|
-
return String(feeInSun);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
// TRX transfer with memo - build transaction to get accurate size
|
|
50
|
-
const { bandwidthPrice } = await getChainPrices(rpcUrl, tronGridHeaders);
|
|
51
|
-
let tx = await tronWeb.transactionBuilder.sendTrx(vault, (0, utils_1.bnOrZero)(sellAmountIncludingProtocolFeesCryptoBaseUnit).toNumber(), from);
|
|
52
|
-
// Add memo to get accurate size with memo overhead
|
|
53
|
-
const txWithMemo = await tronWeb.transactionBuilder.addUpdateData(tx, memo, 'utf8');
|
|
54
|
-
// Calculate bandwidth fee from transaction size
|
|
55
|
-
const rawDataBytes = txWithMemo.raw_data_hex ? txWithMemo.raw_data_hex.length / 2 : 268;
|
|
56
|
-
const signatureBytes = 65;
|
|
57
|
-
const totalBytes = rawDataBytes + signatureBytes;
|
|
58
|
-
const feeInSun = totalBytes * bandwidthPrice;
|
|
59
|
-
return String(feeInSun);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
// Fallback to conservative estimate if fee estimation fails
|
|
64
|
-
// TRX transfer: ~1 TRX, TRC20: ~10 TRX
|
|
65
|
-
return contractAddress ? '10000000' : '1000000';
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
exports.getTronTransactionFees = getTronTransactionFees;
|
|
@@ -1,3 +0,0 @@
|
|
|
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>;
|
|
@@ -1,35 +0,0 @@
|
|
|
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;
|
|
@@ -1,18 +0,0 @@
|
|
|
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("./getUnsignedTronTransaction"), exports);
|
|
18
|
-
__exportStar(require("./getTronTransactionFees"), exports);
|