@shapeshiftoss/swapper 20.2.0 → 20.4.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/constants.js +15 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +0 -2
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +1 -2
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +2 -1
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.js +21 -15
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +1 -0
- 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 -10
- 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/swapperApi/getTradeQuote.js +2 -5
- package/dist/cjs/swappers/ButterSwap/types.d.ts +0 -11
- 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 -14
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.test.js +120 -17
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -2
- package/dist/cjs/swappers/ButterSwap/xhr.js +3 -3
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +0 -2
- package/dist/cjs/swappers/ChainflipSwapper/endpoints.js +3 -19
- package/dist/cjs/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +1 -2
- package/dist/cjs/swappers/ChainflipSwapper/types.d.ts +1 -0
- 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/DebridgeSwapper/getTradeQuote/getTradeQuote.js +0 -2
- package/dist/cjs/swappers/FyndSwapper/FyndSwapper.d.ts +2 -0
- package/dist/cjs/swappers/FyndSwapper/FyndSwapper.js +5 -0
- package/dist/cjs/swappers/FyndSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/FyndSwapper/endpoints.js +14 -0
- package/dist/cjs/swappers/FyndSwapper/getTradeQuote/getTradeQuote.d.ts +4 -0
- package/dist/cjs/swappers/FyndSwapper/getTradeQuote/getTradeQuote.js +43 -0
- package/dist/cjs/swappers/FyndSwapper/getTradeRate/getTradeRate.d.ts +4 -0
- package/dist/cjs/swappers/FyndSwapper/getTradeRate/getTradeRate.js +34 -0
- package/dist/cjs/swappers/FyndSwapper/index.d.ts +2 -0
- package/dist/cjs/swappers/FyndSwapper/index.js +7 -0
- package/dist/cjs/swappers/FyndSwapper/types.d.ts +41 -0
- package/dist/cjs/swappers/FyndSwapper/types.js +2 -0
- package/dist/cjs/swappers/FyndSwapper/utils/constants.d.ts +33 -0
- package/dist/cjs/swappers/FyndSwapper/utils/constants.js +38 -0
- package/dist/cjs/swappers/FyndSwapper/utils/fetchFromFynd.d.ts +13 -0
- package/dist/cjs/swappers/FyndSwapper/utils/fetchFromFynd.js +42 -0
- package/dist/cjs/swappers/FyndSwapper/utils/fyndService.d.ts +5 -0
- package/dist/cjs/swappers/FyndSwapper/utils/fyndService.js +9 -0
- package/dist/cjs/swappers/FyndSwapper/utils/getFyndStepData.d.ts +25 -0
- package/dist/cjs/swappers/FyndSwapper/utils/getFyndStepData.js +48 -0
- package/dist/cjs/swappers/FyndSwapper/utils/getFyndTradeContext.d.ts +18 -0
- package/dist/cjs/swappers/FyndSwapper/utils/getFyndTradeContext.js +94 -0
- package/dist/cjs/swappers/FyndSwapper/utils/helpers.d.ts +24 -0
- package/dist/cjs/swappers/FyndSwapper/utils/helpers.js +174 -0
- package/dist/cjs/swappers/FyndSwapper/utils/helpers.test.d.ts +1 -0
- package/dist/cjs/swappers/FyndSwapper/utils/helpers.test.js +101 -0
- package/dist/cjs/swappers/MayachainSwapper/generated/generatedTradableAssetMap.json +0 -1
- 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/PortalsSwapper/endpoints.js +4 -1
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.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 +3 -5
- 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/getRelayTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayTradeContext.js +4 -0
- package/dist/cjs/swappers/RelaySwapper/utils/helpers.js +1 -2
- package/dist/cjs/swappers/RelaySwapper/utils/relayStatus.js +3 -3
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +10 -8
- 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/SymbiosisSwapper/SymbiosisSwapper.d.ts +2 -0
- package/dist/cjs/swappers/SymbiosisSwapper/SymbiosisSwapper.js +8 -0
- package/dist/cjs/swappers/SymbiosisSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/SymbiosisSwapper/endpoints.js +66 -0
- package/dist/cjs/swappers/SymbiosisSwapper/getTradeQuote/getTradeQuote.d.ts +4 -0
- package/dist/cjs/swappers/SymbiosisSwapper/getTradeQuote/getTradeQuote.js +42 -0
- package/dist/cjs/swappers/SymbiosisSwapper/getTradeRate/getTradeRate.d.ts +4 -0
- package/dist/cjs/swappers/SymbiosisSwapper/getTradeRate/getTradeRate.js +34 -0
- package/dist/cjs/swappers/SymbiosisSwapper/index.d.ts +2 -0
- package/dist/cjs/swappers/SymbiosisSwapper/index.js +7 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/constants.d.ts +19 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/constants.js +64 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/getSymbiosisStepData.d.ts +26 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/getSymbiosisStepData.js +106 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/getSymbiosisStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/getSymbiosisStepData.test.js +161 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/getSymbiosisTradeContext.d.ts +17 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/getSymbiosisTradeContext.js +146 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/helpers.d.ts +38 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/helpers.js +172 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/helpers.test.d.ts +1 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/helpers.test.js +151 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/symbiosisService.d.ts +5 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/symbiosisService.js +18 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/types.d.ts +83 -0
- package/dist/cjs/swappers/SymbiosisSwapper/utils/types.js +11 -0
- package/dist/cjs/swappers/ThorchainSwapper/endpoints.js +3 -4
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +1 -0
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +1 -0
- 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/getLongtailQuote.js +1 -1
- 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/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +24 -1
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.test.d.ts +1 -0
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.test.js +110 -0
- package/dist/cjs/swappers/ZrxSwapper/types.d.ts +2 -1
- package/dist/cjs/swappers/ZrxSwapper/utils/getZrxNativeCheckDeadline.d.ts +1 -0
- package/dist/cjs/swappers/ZrxSwapper/utils/getZrxNativeCheckDeadline.js +26 -0
- package/dist/cjs/types.d.ts +15 -13
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/helpers.d.ts +1 -2
- package/dist/cjs/utils/helpers.js +8 -32
- package/dist/cjs/utils/helpers.test.js +6 -2
- 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/constants.js +15 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +0 -2
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +1 -2
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +2 -1
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.js +21 -15
- package/dist/esm/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +1 -0
- 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 -10
- 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/swapperApi/getTradeQuote.js +2 -5
- package/dist/esm/swappers/ButterSwap/types.d.ts +0 -11
- 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 -14
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.test.js +120 -17
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +1 -2
- package/dist/esm/swappers/ButterSwap/xhr.js +3 -3
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +0 -2
- package/dist/esm/swappers/ChainflipSwapper/endpoints.js +3 -19
- package/dist/esm/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +1 -2
- package/dist/esm/swappers/ChainflipSwapper/types.d.ts +1 -0
- 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/DebridgeSwapper/getTradeQuote/getTradeQuote.js +0 -2
- package/dist/esm/swappers/FyndSwapper/FyndSwapper.d.ts +2 -0
- package/dist/esm/swappers/FyndSwapper/FyndSwapper.js +2 -0
- package/dist/esm/swappers/FyndSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/FyndSwapper/endpoints.js +11 -0
- package/dist/esm/swappers/FyndSwapper/getTradeQuote/getTradeQuote.d.ts +4 -0
- package/dist/esm/swappers/FyndSwapper/getTradeQuote/getTradeQuote.js +39 -0
- package/dist/esm/swappers/FyndSwapper/getTradeRate/getTradeRate.d.ts +4 -0
- package/dist/esm/swappers/FyndSwapper/getTradeRate/getTradeRate.js +30 -0
- package/dist/esm/swappers/FyndSwapper/index.d.ts +2 -0
- package/dist/esm/swappers/FyndSwapper/index.js +2 -0
- package/dist/esm/swappers/FyndSwapper/types.d.ts +41 -0
- package/dist/esm/swappers/FyndSwapper/types.js +1 -0
- package/dist/esm/swappers/FyndSwapper/utils/constants.d.ts +33 -0
- package/dist/esm/swappers/FyndSwapper/utils/constants.js +35 -0
- package/dist/esm/swappers/FyndSwapper/utils/fetchFromFynd.d.ts +13 -0
- package/dist/esm/swappers/FyndSwapper/utils/fetchFromFynd.js +38 -0
- package/dist/esm/swappers/FyndSwapper/utils/fyndService.d.ts +5 -0
- package/dist/esm/swappers/FyndSwapper/utils/fyndService.js +3 -0
- package/dist/esm/swappers/FyndSwapper/utils/getFyndStepData.d.ts +25 -0
- package/dist/esm/swappers/FyndSwapper/utils/getFyndStepData.js +44 -0
- package/dist/esm/swappers/FyndSwapper/utils/getFyndTradeContext.d.ts +18 -0
- package/dist/esm/swappers/FyndSwapper/utils/getFyndTradeContext.js +90 -0
- package/dist/esm/swappers/FyndSwapper/utils/helpers.d.ts +24 -0
- package/dist/esm/swappers/FyndSwapper/utils/helpers.js +162 -0
- package/dist/esm/swappers/FyndSwapper/utils/helpers.test.d.ts +1 -0
- package/dist/esm/swappers/FyndSwapper/utils/helpers.test.js +99 -0
- package/dist/esm/swappers/MayachainSwapper/generated/generatedTradableAssetMap.json +0 -1
- 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/PortalsSwapper/endpoints.js +4 -1
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.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 +3 -5
- 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/getRelayTradeContext.d.ts +1 -0
- package/dist/esm/swappers/RelaySwapper/utils/getRelayTradeContext.js +5 -1
- package/dist/esm/swappers/RelaySwapper/utils/helpers.js +1 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayStatus.js +3 -3
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +3 -3
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +10 -8
- 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/SymbiosisSwapper/SymbiosisSwapper.d.ts +2 -0
- package/dist/esm/swappers/SymbiosisSwapper/SymbiosisSwapper.js +5 -0
- package/dist/esm/swappers/SymbiosisSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/SymbiosisSwapper/endpoints.js +63 -0
- package/dist/esm/swappers/SymbiosisSwapper/getTradeQuote/getTradeQuote.d.ts +4 -0
- package/dist/esm/swappers/SymbiosisSwapper/getTradeQuote/getTradeQuote.js +38 -0
- package/dist/esm/swappers/SymbiosisSwapper/getTradeRate/getTradeRate.d.ts +4 -0
- package/dist/esm/swappers/SymbiosisSwapper/getTradeRate/getTradeRate.js +30 -0
- package/dist/esm/swappers/SymbiosisSwapper/index.d.ts +2 -0
- package/dist/esm/swappers/SymbiosisSwapper/index.js +2 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/constants.d.ts +19 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/constants.js +61 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/getSymbiosisStepData.d.ts +26 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/getSymbiosisStepData.js +102 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/getSymbiosisStepData.test.d.ts +1 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/getSymbiosisStepData.test.js +159 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/getSymbiosisTradeContext.d.ts +17 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/getSymbiosisTradeContext.js +139 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/helpers.d.ts +38 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/helpers.js +156 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/helpers.test.d.ts +1 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/helpers.test.js +149 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/symbiosisService.d.ts +5 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/symbiosisService.js +12 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/types.d.ts +83 -0
- package/dist/esm/swappers/SymbiosisSwapper/utils/types.js +8 -0
- package/dist/esm/swappers/ThorchainSwapper/endpoints.js +4 -5
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedThorLongtailTokens.json +1 -0
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +1 -0
- 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/getLongtailQuote.js +1 -1
- 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/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +25 -2
- package/dist/esm/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.test.d.ts +1 -0
- package/dist/esm/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.test.js +108 -0
- package/dist/esm/swappers/ZrxSwapper/types.d.ts +2 -1
- package/dist/esm/swappers/ZrxSwapper/utils/getZrxNativeCheckDeadline.d.ts +1 -0
- package/dist/esm/swappers/ZrxSwapper/utils/getZrxNativeCheckDeadline.js +22 -0
- package/dist/esm/types.d.ts +15 -13
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/helpers.d.ts +1 -2
- package/dist/esm/utils/helpers.js +9 -33
- package/dist/esm/utils/helpers.test.js +6 -2
- 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 +8 -8
- 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/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
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { ETH } from '../test-data/assets.js';
|
|
4
|
+
import { getUnsignedTronTransaction } from './getUnsignedTronTransaction.js';
|
|
5
|
+
const USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
|
|
6
|
+
const TRX = { ...ETH, assetId: `${tronChainId}/slip44:195`, chainId: tronChainId };
|
|
7
|
+
const USDT_TRON = { ...ETH, assetId: `${tronChainId}/trc20:${USDT}`, chainId: tronChainId };
|
|
8
|
+
const FROM = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
|
|
9
|
+
const TO = 'TCFNp179Lg46D16zKoumd4Poa2WFFdtqYj';
|
|
10
|
+
const makeArgs = (sellAsset, transactionData, feeData = {
|
|
11
|
+
networkFeeCryptoBaseUnit: '9000000',
|
|
12
|
+
}) => {
|
|
13
|
+
const adapter = {
|
|
14
|
+
buildCustomApiTx: vi.fn().mockResolvedValue('custom'),
|
|
15
|
+
buildSendApiTransaction: vi.fn().mockResolvedValue('send'),
|
|
16
|
+
};
|
|
17
|
+
const tradeQuote = {
|
|
18
|
+
quoteOrRate: 'quote',
|
|
19
|
+
steps: [{ accountNumber: 0, sellAsset, transactionData, feeData }],
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
adapter,
|
|
23
|
+
args: {
|
|
24
|
+
tradeQuote,
|
|
25
|
+
stepIndex: 0,
|
|
26
|
+
from: FROM,
|
|
27
|
+
assertGetTronChainAdapter: () => adapter,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
describe('getUnsignedTronTransaction', () => {
|
|
32
|
+
it('builds a contract call when data is present', async () => {
|
|
33
|
+
const { adapter, args } = makeArgs(TRX, {
|
|
34
|
+
type: 'tron',
|
|
35
|
+
to: TO,
|
|
36
|
+
data: '0xdeadbeef',
|
|
37
|
+
value: '1',
|
|
38
|
+
});
|
|
39
|
+
expect(await getUnsignedTronTransaction(args)).toBe('custom');
|
|
40
|
+
expect(adapter.buildCustomApiTx).toHaveBeenCalledWith({
|
|
41
|
+
from: FROM,
|
|
42
|
+
to: TO,
|
|
43
|
+
accountNumber: 0,
|
|
44
|
+
data: '0xdeadbeef',
|
|
45
|
+
value: '1',
|
|
46
|
+
feeLimit: 27_000_000,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
it('uses the standard fee limit when the step carries no estimate', async () => {
|
|
50
|
+
const { adapter, args } = makeArgs(TRX, { type: 'tron', to: TO, data: '0xdeadbeef', value: '1' }, { networkFeeCryptoBaseUnit: undefined });
|
|
51
|
+
await getUnsignedTronTransaction(args);
|
|
52
|
+
expect(adapter.buildCustomApiTx).toHaveBeenCalledWith(expect.objectContaining({ feeLimit: 100_000_000 }));
|
|
53
|
+
});
|
|
54
|
+
it('builds a send of the sell asset when data is absent', async () => {
|
|
55
|
+
const { adapter, args } = makeArgs(USDT_TRON, {
|
|
56
|
+
type: 'tron',
|
|
57
|
+
to: TO,
|
|
58
|
+
value: '1',
|
|
59
|
+
memo: '=:ETH.ETH:0xabc',
|
|
60
|
+
});
|
|
61
|
+
expect(await getUnsignedTronTransaction(args)).toBe('send');
|
|
62
|
+
expect(adapter.buildSendApiTransaction).toHaveBeenCalledWith({
|
|
63
|
+
from: FROM,
|
|
64
|
+
to: TO,
|
|
65
|
+
accountNumber: 0,
|
|
66
|
+
value: '1',
|
|
67
|
+
chainSpecific: { contractAddress: USDT, memo: '=:ETH.ETH:0xabc', feeLimit: 27_000_000 },
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it('throws without tron transactionData', () => {
|
|
71
|
+
const { args } = makeArgs(TRX, undefined);
|
|
72
|
+
expect(() => getUnsignedTronTransaction(args)).toThrow('Missing tron transactionData');
|
|
73
|
+
});
|
|
74
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swapper",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.4.0",
|
|
4
4
|
"repository": "https://github.com/shapeshift/web",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@coral-xyz/anchor": "0.29.0",
|
|
29
29
|
"@cowprotocol/app-data": "^2.3.0",
|
|
30
30
|
"@defuse-protocol/one-click-sdk-typescript": "^0.1.1-0.2",
|
|
31
|
-
"@gobob/bob-sdk": "
|
|
31
|
+
"@gobob/bob-sdk": "6.0.1",
|
|
32
32
|
"@mysten/sui": "^1.45.2",
|
|
33
33
|
"@shapeshiftoss/bitcoinjs-lib": "7.0.0-shapeshift.0",
|
|
34
34
|
"@sniptt/monads": "^0.5.10",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"retry-axios": "^2.6.0",
|
|
51
51
|
"uuid": "^9.0.0",
|
|
52
52
|
"viem": "2.55.11",
|
|
53
|
-
"@shapeshiftoss/
|
|
54
|
-
"@shapeshiftoss/
|
|
55
|
-
"@shapeshiftoss/
|
|
53
|
+
"@shapeshiftoss/chain-adapters": "^11.7.0",
|
|
54
|
+
"@shapeshiftoss/caip": "^8.17.2",
|
|
55
|
+
"@shapeshiftoss/types": "^9.1.0",
|
|
56
|
+
"@shapeshiftoss/contracts": "^1.1.0",
|
|
57
|
+
"@shapeshiftoss/utils": "^1.4.0",
|
|
56
58
|
"@shapeshiftoss/hdwallet-core": "^1.62.41",
|
|
57
|
-
"@shapeshiftoss/
|
|
58
|
-
"@shapeshiftoss/unchained-client": "^10.14.11",
|
|
59
|
-
"@shapeshiftoss/utils": "^1.3.0"
|
|
59
|
+
"@shapeshiftoss/unchained-client": "^10.16.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/lodash": "^4.14.178",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SunioRoute } from '../types';
|
|
2
|
-
export type SwapRouteParameters = {
|
|
3
|
-
path: string[];
|
|
4
|
-
poolVersion: string[];
|
|
5
|
-
versionLen: number[];
|
|
6
|
-
fees: number[];
|
|
7
|
-
swapData: {
|
|
8
|
-
amountIn: string;
|
|
9
|
-
amountOutMin: string;
|
|
10
|
-
recipient: string;
|
|
11
|
-
deadline: number;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export declare const buildSwapRouteParameters: (route: SunioRoute, sellAmountCryptoBaseUnit: string, minBuyAmountCryptoBaseUnit: string, recipient: string, slippageTolerancePercentageDecimal: string) => SwapRouteParameters;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildSwapRouteParameters = void 0;
|
|
4
|
-
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
|
-
const buildSwapRouteParameters = (route, sellAmountCryptoBaseUnit, minBuyAmountCryptoBaseUnit, recipient, slippageTolerancePercentageDecimal) => {
|
|
6
|
-
const path = route.tokens;
|
|
7
|
-
const poolVersion = route.poolVersions;
|
|
8
|
-
// The SmartExchangeRouter expects sum(versionLen) === path.length: the first
|
|
9
|
-
// pool segment consumes 2 tokens (input + output) and each subsequent pool
|
|
10
|
-
// reuses the previous output, consuming 1 new token. This relies on the Sun.io
|
|
11
|
-
// API returning poolVersions per-hop (poolVersions.length === tokens.length - 1),
|
|
12
|
-
// which it does — the router also accepts this un-collapsed form for same-version hops.
|
|
13
|
-
const versionLen = poolVersion.map((_, index) => (index === 0 ? 2 : 1));
|
|
14
|
-
const fees = route.poolFees.map(fee => Number(fee));
|
|
15
|
-
const amountOutWithSlippage = (0, utils_1.bn)(minBuyAmountCryptoBaseUnit)
|
|
16
|
-
.times((0, utils_1.bn)(1).minus(slippageTolerancePercentageDecimal))
|
|
17
|
-
.toFixed(0);
|
|
18
|
-
const swapData = {
|
|
19
|
-
amountIn: sellAmountCryptoBaseUnit,
|
|
20
|
-
amountOutMin: amountOutWithSlippage,
|
|
21
|
-
recipient,
|
|
22
|
-
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
path,
|
|
26
|
-
poolVersion,
|
|
27
|
-
versionLen,
|
|
28
|
-
fees,
|
|
29
|
-
swapData,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
exports.buildSwapRouteParameters = buildSwapRouteParameters;
|
|
@@ -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);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SunioRoute } from '../types.js';
|
|
2
|
-
export type SwapRouteParameters = {
|
|
3
|
-
path: string[];
|
|
4
|
-
poolVersion: string[];
|
|
5
|
-
versionLen: number[];
|
|
6
|
-
fees: number[];
|
|
7
|
-
swapData: {
|
|
8
|
-
amountIn: string;
|
|
9
|
-
amountOutMin: string;
|
|
10
|
-
recipient: string;
|
|
11
|
-
deadline: number;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export declare const buildSwapRouteParameters: (route: SunioRoute, sellAmountCryptoBaseUnit: string, minBuyAmountCryptoBaseUnit: string, recipient: string, slippageTolerancePercentageDecimal: string) => SwapRouteParameters;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { bn } from '@shapeshiftoss/utils';
|
|
2
|
-
export const buildSwapRouteParameters = (route, sellAmountCryptoBaseUnit, minBuyAmountCryptoBaseUnit, recipient, slippageTolerancePercentageDecimal) => {
|
|
3
|
-
const path = route.tokens;
|
|
4
|
-
const poolVersion = route.poolVersions;
|
|
5
|
-
// The SmartExchangeRouter expects sum(versionLen) === path.length: the first
|
|
6
|
-
// pool segment consumes 2 tokens (input + output) and each subsequent pool
|
|
7
|
-
// reuses the previous output, consuming 1 new token. This relies on the Sun.io
|
|
8
|
-
// API returning poolVersions per-hop (poolVersions.length === tokens.length - 1),
|
|
9
|
-
// which it does — the router also accepts this un-collapsed form for same-version hops.
|
|
10
|
-
const versionLen = poolVersion.map((_, index) => (index === 0 ? 2 : 1));
|
|
11
|
-
const fees = route.poolFees.map(fee => Number(fee));
|
|
12
|
-
const amountOutWithSlippage = bn(minBuyAmountCryptoBaseUnit)
|
|
13
|
-
.times(bn(1).minus(slippageTolerancePercentageDecimal))
|
|
14
|
-
.toFixed(0);
|
|
15
|
-
const swapData = {
|
|
16
|
-
amountIn: sellAmountCryptoBaseUnit,
|
|
17
|
-
amountOutMin: amountOutWithSlippage,
|
|
18
|
-
recipient,
|
|
19
|
-
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
path,
|
|
23
|
-
poolVersion,
|
|
24
|
-
versionLen,
|
|
25
|
-
fees,
|
|
26
|
-
swapData,
|
|
27
|
-
};
|
|
28
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { SunioRoute } from '../types.js';
|
|
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,74 +0,0 @@
|
|
|
1
|
-
import { bn } from '@shapeshiftoss/utils';
|
|
2
|
-
import { TronWeb } from 'tronweb';
|
|
3
|
-
import { buildSwapExactInputParameters, SUNIO_SWAP_EXACT_INPUT_SELECTOR, } from './buildSwapContractCall.js';
|
|
4
|
-
import { buildSwapRouteParameters } from './buildSwapRouteParameters.js';
|
|
5
|
-
import { DEFAULT_SLIPPAGE_PERCENTAGE, SUNIO_FALLBACK_SWAP_ENERGY_NATIVE, SUNIO_FALLBACK_SWAP_ENERGY_TRC20, SUNIO_SMART_ROUTER_CONTRACT, SUNIO_TRON_NATIVE_ADDRESS, } from './constants.js';
|
|
6
|
-
// Estimates the network fee (in TRX base units) for a Sun.io swap. The router sponsors only ~1%
|
|
7
|
-
// of energy (origin_energy_usage); the user pays the rest, so we simulate the real swapExactInput
|
|
8
|
-
// call when we have an address to estimate from. The simulation reverts before approval for TRC20
|
|
9
|
-
// sells (and when the account lacks the sell balance), so we fall back to a conservative per-sell-
|
|
10
|
-
// type constant. Used both at quote time and re-run at confirm time, where a now-granted allowance
|
|
11
|
-
// lets the simulation produce the true cost.
|
|
12
|
-
export const estimateSunioNetworkFeeCryptoBaseUnit = async ({ rpcUrl, apiKey, route, sellAmountCryptoBaseUnit, isSellingNativeTrx, address, slippageTolerancePercentageDecimal, }) => {
|
|
13
|
-
const tronGridHeaders = apiKey ? { 'TRON-PRO-API-KEY': apiKey } : {};
|
|
14
|
-
const tronWeb = new TronWeb({ fullHost: rpcUrl, headers: tronGridHeaders });
|
|
15
|
-
// Live network prices, defaulting if the node is unavailable so we still produce a fee
|
|
16
|
-
const { bandwidthPrice, energyPrice } = await (async () => {
|
|
17
|
-
try {
|
|
18
|
-
const params = await tronWeb.trx.getChainParameters();
|
|
19
|
-
return {
|
|
20
|
-
bandwidthPrice: params.find(p => p.key === 'getTransactionFee')?.value ?? 1000,
|
|
21
|
-
energyPrice: params.find(p => p.key === 'getEnergyFee')?.value ?? 100,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return { bandwidthPrice: 1000, energyPrice: 100 };
|
|
26
|
-
}
|
|
27
|
-
})();
|
|
28
|
-
// Account activation (1 TRX) is only charged when the recipient receives native TRX, mirroring
|
|
29
|
-
// the chain adapter. A TRC20 buy doesn't incur the flat activation fee (its account-creation
|
|
30
|
-
// cost is folded into energy). Only checkable with an address.
|
|
31
|
-
const isBuyingNativeTrx = route.tokens[route.tokens.length - 1] === SUNIO_TRON_NATIVE_ADDRESS;
|
|
32
|
-
const accountActivationFee = await (async () => {
|
|
33
|
-
if (!address || !isBuyingNativeTrx)
|
|
34
|
-
return 0;
|
|
35
|
-
try {
|
|
36
|
-
const recipientInfoResponse = await fetch(`${rpcUrl}/wallet/getaccount`, {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
headers: { 'Content-Type': 'application/json', ...tronGridHeaders },
|
|
39
|
-
body: JSON.stringify({ address, visible: true }),
|
|
40
|
-
});
|
|
41
|
-
const recipientInfo = await recipientInfoResponse.json();
|
|
42
|
-
const recipientExists = recipientInfo && Object.keys(recipientInfo).length > 1;
|
|
43
|
-
return recipientExists ? 0 : 1_000_000; // 1 TRX
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
|
48
|
-
})();
|
|
49
|
-
const energyUsed = await (async () => {
|
|
50
|
-
// TRC20 sells cost far more energy than native sells (the extra transferFrom token pull)
|
|
51
|
-
const fallbackEnergy = isSellingNativeTrx
|
|
52
|
-
? SUNIO_FALLBACK_SWAP_ENERGY_NATIVE
|
|
53
|
-
: SUNIO_FALLBACK_SWAP_ENERGY_TRC20;
|
|
54
|
-
if (!address)
|
|
55
|
-
return fallbackEnergy;
|
|
56
|
-
try {
|
|
57
|
-
const routeParams = buildSwapRouteParameters(route, sellAmountCryptoBaseUnit, '0', address, slippageTolerancePercentageDecimal ?? DEFAULT_SLIPPAGE_PERCENTAGE);
|
|
58
|
-
const callValue = isSellingNativeTrx ? Number(sellAmountCryptoBaseUnit) : 0;
|
|
59
|
-
const result = await tronWeb.transactionBuilder.triggerConstantContract(SUNIO_SMART_ROUTER_CONTRACT, SUNIO_SWAP_EXACT_INPUT_SELECTOR, { callValue }, buildSwapExactInputParameters(routeParams), address);
|
|
60
|
-
// A reverted simulation (e.g. TRC20 sell pre-approval) can still return a small energy_used;
|
|
61
|
-
// only trust it when the call actually succeeded, otherwise use the conservative fallback.
|
|
62
|
-
if (result?.result?.result !== true || result.energy_used == null)
|
|
63
|
-
return fallbackEnergy;
|
|
64
|
-
return result.energy_used;
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return fallbackEnergy;
|
|
68
|
-
}
|
|
69
|
-
})();
|
|
70
|
-
// 1.2x safety margin for energy price/usage variance between estimate and execution
|
|
71
|
-
const energyFee = Math.ceil(energyUsed * energyPrice * 1.2);
|
|
72
|
-
const bandwidthFee = 1100 * bandwidthPrice;
|
|
73
|
-
return bn(energyFee).plus(bandwidthFee).plus(accountActivationFee).toFixed(0);
|
|
74
|
-
};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import type { GetUnsignedTronTransactionArgs } from '../../../types.js';
|
|
2
|
-
export declare const getSunioTransactionFees: ({ tradeQuote, stepIndex, from, slippageTolerancePercentageDecimal, assertGetTronChainAdapter, config, }: GetUnsignedTronTransactionArgs) => Promise<string>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { tronAssetId, tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { getExecutableTradeStep, isExecutableTradeQuote } from '../../../utils/index.js';
|
|
3
|
-
import { estimateSunioNetworkFeeCryptoBaseUnit } from './estimateSunioNetworkFee.js';
|
|
4
|
-
export const getSunioTransactionFees = async ({ tradeQuote, stepIndex, from, slippageTolerancePercentageDecimal, assertGetTronChainAdapter, config, }) => {
|
|
5
|
-
if (!isExecutableTradeQuote(tradeQuote))
|
|
6
|
-
throw new Error('Unable to execute a trade rate quote');
|
|
7
|
-
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
8
|
-
const storedNetworkFeeCryptoBaseUnit = step.feeData.networkFeeCryptoBaseUnit;
|
|
9
|
-
const route = step.sunioTransactionData?.route;
|
|
10
|
-
if (!route) {
|
|
11
|
-
if (!storedNetworkFeeCryptoBaseUnit)
|
|
12
|
-
throw new Error('Missing network fee in quote');
|
|
13
|
-
return storedNetworkFeeCryptoBaseUnit;
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
const adapter = assertGetTronChainAdapter(tronChainId);
|
|
17
|
-
return await estimateSunioNetworkFeeCryptoBaseUnit({
|
|
18
|
-
rpcUrl: adapter.httpProvider.getRpcUrl(),
|
|
19
|
-
apiKey: config.VITE_TRON_GRID_API_KEY,
|
|
20
|
-
route,
|
|
21
|
-
sellAmountCryptoBaseUnit: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
22
|
-
isSellingNativeTrx: step.sellAsset.assetId === tronAssetId,
|
|
23
|
-
address: from,
|
|
24
|
-
slippageTolerancePercentageDecimal,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
if (!storedNetworkFeeCryptoBaseUnit)
|
|
29
|
-
throw new Error('Missing network fee in quote');
|
|
30
|
-
return storedNetworkFeeCryptoBaseUnit;
|
|
31
|
-
}
|
|
32
|
-
};
|