@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
|
@@ -2,7 +2,6 @@ import { getEvmTransactionFees, getUnsignedEvmTransaction } from '../../utils/ev
|
|
|
2
2
|
import { getSolanaTransactionFees } from '../../utils/solana/getSolanaTransactionFees.js';
|
|
3
3
|
import { getUnsignedSolanaTransaction } from '../../utils/solana/getUnsignedSolanaTransaction.js';
|
|
4
4
|
import { getTronTransactionFees, getUnsignedTronTransaction } from '../../utils/tron/index.js';
|
|
5
|
-
import { getUnsignedUtxoTransaction, getUtxoTransactionFees } from '../../utils/utxo/index.js';
|
|
6
5
|
import { checkTradeStatus } from './swapperApi/checkTradeStatus.js';
|
|
7
6
|
import { getTradeQuote } from './swapperApi/getTradeQuote.js';
|
|
8
7
|
import { getTradeRate } from './swapperApi/getTradeRate.js';
|
|
@@ -12,8 +11,6 @@ export const butterSwapApi = {
|
|
|
12
11
|
checkTradeStatus,
|
|
13
12
|
getEvmTransactionFees,
|
|
14
13
|
getUnsignedEvmTransaction,
|
|
15
|
-
getUnsignedUtxoTransaction,
|
|
16
|
-
getUtxoTransactionFees,
|
|
17
14
|
getUnsignedSolanaTransaction,
|
|
18
15
|
getSolanaTransactionFees,
|
|
19
16
|
getTronTransactionFees,
|
|
@@ -56,7 +56,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
56
56
|
});
|
|
57
57
|
if (maybeStepData.isErr())
|
|
58
58
|
return Err(maybeStepData.unwrapErr());
|
|
59
|
-
const { networkFeeCryptoBaseUnit, transactionData
|
|
59
|
+
const { networkFeeCryptoBaseUnit, transactionData } = maybeStepData.unwrap();
|
|
60
60
|
const tradeQuote = {
|
|
61
61
|
...tradeCommon,
|
|
62
62
|
quoteOrRate: 'quote',
|
|
@@ -66,10 +66,9 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
66
66
|
{
|
|
67
67
|
...stepCommon,
|
|
68
68
|
accountNumber,
|
|
69
|
-
// Tron
|
|
69
|
+
// Tron routes pull the sell token from the buildTx target
|
|
70
70
|
allowanceContract: sellAsset.chainId === tronChainId ? buildTx.to : stepCommon.allowanceContract,
|
|
71
71
|
transactionData,
|
|
72
|
-
butterSwapTransactionMetadata,
|
|
73
72
|
feeData: { networkFeeCryptoBaseUnit, protocolFees },
|
|
74
73
|
},
|
|
75
74
|
],
|
|
@@ -2,8 +2,7 @@ import { KnownChainIds } from '@shapeshiftoss/types';
|
|
|
2
2
|
import { bn } from '@shapeshiftoss/utils';
|
|
3
3
|
import { Ok } from '@sniptt/monads';
|
|
4
4
|
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
-
import {
|
|
6
|
-
import ethBtcRoute from '../test-data/eth-btc.json';
|
|
5
|
+
import { ETH, USDC_MAINNET, WETH } from '../../../utils/test-data/assets.js';
|
|
7
6
|
import { ROUTE_QUOTE } from '../test-data/routeQuote.js';
|
|
8
7
|
import { butterService } from '../utils/butterSwapService.js';
|
|
9
8
|
import { getTradeRate } from './getTradeRate.js';
|
|
@@ -59,51 +58,4 @@ describe('getTradeRate', () => {
|
|
|
59
58
|
const tradeRate = result.unwrap();
|
|
60
59
|
expect(tradeRate[0].rate).toBe('2296.409699');
|
|
61
60
|
});
|
|
62
|
-
it('should return a correct trade rate and steps for a multi-hop ETH->BTC route', async () => {
|
|
63
|
-
const deps = {
|
|
64
|
-
assetsById: { [ETH.assetId]: ETH, [BTC.assetId]: BTC },
|
|
65
|
-
assertGetChainAdapter: () => vi.fn(),
|
|
66
|
-
assertGetEvmChainAdapter: () => mockEvmChainAdapter,
|
|
67
|
-
assertGetUtxoChainAdapter: () => vi.fn(),
|
|
68
|
-
assertGetCosmosSdkChainAdapter: () => vi.fn(),
|
|
69
|
-
assertGetSolanaChainAdapter: () => vi.fn(),
|
|
70
|
-
assertGetTronChainAdapter: () => vi.fn(),
|
|
71
|
-
assertGetSuiChainAdapter: () => vi.fn(),
|
|
72
|
-
assertGetNearChainAdapter: () => vi.fn(),
|
|
73
|
-
assertGetStarknetChainAdapter: () => vi.fn(),
|
|
74
|
-
assertGetTonChainAdapter: () => vi.fn(),
|
|
75
|
-
config: {
|
|
76
|
-
VITE_BUTTERSWAP_CLIENT_ID: 'test',
|
|
77
|
-
},
|
|
78
|
-
mixPanel: undefined,
|
|
79
|
-
fetchIsSmartContractAddressQuery: vi.fn(),
|
|
80
|
-
};
|
|
81
|
-
const input = {
|
|
82
|
-
sellAsset: ETH,
|
|
83
|
-
buyAsset: BTC,
|
|
84
|
-
sellAmountIncludingProtocolFeesCryptoBaseUnit: bn(1).shiftedBy(18).toString(),
|
|
85
|
-
affiliateBps: '0',
|
|
86
|
-
allowMultiHop: true,
|
|
87
|
-
receiveAddress: '0x123',
|
|
88
|
-
accountNumber: undefined,
|
|
89
|
-
quoteOrRate: 'rate',
|
|
90
|
-
chainId: KnownChainIds.EthereumMainnet,
|
|
91
|
-
supportsEIP1559: false,
|
|
92
|
-
};
|
|
93
|
-
// Use the first route in the eth-btc.json data
|
|
94
|
-
vi.mocked(butterService.get).mockResolvedValue(Ok({ data: ethBtcRoute }));
|
|
95
|
-
const result = await getTradeRate(input, deps);
|
|
96
|
-
expect(result.isOk()).toBe(true);
|
|
97
|
-
const tradeRate = result.unwrap()[0];
|
|
98
|
-
expect(tradeRate).toBeDefined();
|
|
99
|
-
// The expected rate is dstChain.totalAmountOut / srcChain.totalAmountIn
|
|
100
|
-
expect(tradeRate.rate).toBe('0.02284418');
|
|
101
|
-
// Should have a single step
|
|
102
|
-
expect(tradeRate.steps).toBeDefined();
|
|
103
|
-
expect(tradeRate.steps.length).toBe(1);
|
|
104
|
-
// The step should have the correct rate
|
|
105
|
-
expect(tradeRate.steps[0]?.rate).toBe('0.02284418');
|
|
106
|
-
// The buyAmountAfterFeesCryptoBaseUnit of the step should match the output in base units
|
|
107
|
-
expect(tradeRate.steps[0]?.buyAmountAfterFeesCryptoBaseUnit).toBe('2284418'); // 0.02284418 BTC in base units
|
|
108
|
-
});
|
|
109
61
|
});
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import type { Hex } from 'viem';
|
|
2
|
-
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput
|
|
3
|
-
export type ButterSwapTradeQuoteInput = GetEvmTradeQuoteInput |
|
|
4
|
-
export type ButterSwapTradeRateInput = GetEvmTradeRateInput |
|
|
5
|
-
export type ButterSwapTransactionMetadata = {
|
|
6
|
-
to: string;
|
|
7
|
-
data: string;
|
|
8
|
-
value: Hex;
|
|
9
|
-
method?: string;
|
|
10
|
-
args?: {
|
|
11
|
-
type: string;
|
|
12
|
-
value: unknown;
|
|
13
|
-
}[];
|
|
14
|
-
memo?: string;
|
|
15
|
-
};
|
|
2
|
+
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput } from '../../types.js';
|
|
3
|
+
export type ButterSwapTradeQuoteInput = GetEvmTradeQuoteInput | GetSolanaTradeQuoteInput | GetTronTradeQuoteInput;
|
|
4
|
+
export type ButterSwapTradeRateInput = GetEvmTradeRateInput | GetSolanaTradeRateInput | GetTronTradeRateInput;
|
|
16
5
|
export type ErrorType = {
|
|
17
6
|
errno: number;
|
|
18
7
|
message: string;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { bnOrZero } from '@shapeshiftoss/utils';
|
|
2
2
|
const BUTTERSWAP_AFFILIATE = 'shapeshift';
|
|
3
|
+
// The router's total energy per swap, before its deployer's share comes off
|
|
4
|
+
export const BUTTERSWAP_TRON_FALLBACK_SWAP_ENERGY = '1000000';
|
|
5
|
+
export const BUTTERSWAP_TRON_DEFAULT_BANDWIDTH_BYTES = 2400;
|
|
3
6
|
// Format is `<nickname>[:rate]`, where rate is in basis points (e.g. `shapeshift:60` = 0.6%).
|
|
4
7
|
export const makeButterSwapAffiliate = (affiliateBps) => {
|
|
5
8
|
if (bnOrZero(affiliateBps).lte(0))
|
|
@@ -2,7 +2,7 @@ import type { Asset } from '@shapeshiftoss/types';
|
|
|
2
2
|
import type { Result } from '@sniptt/monads';
|
|
3
3
|
import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types.js';
|
|
4
4
|
import type { SolanaComputeBudgetOptions } from '../../../utils/solana/index.js';
|
|
5
|
-
import type { BuildTxSuccessItem,
|
|
5
|
+
import type { BuildTxSuccessItem, RouteSuccessItem } from '../types.js';
|
|
6
6
|
export declare const BUTTERSWAP_SOLANA_COMPUTE_BUDGET: SolanaComputeBudgetOptions;
|
|
7
7
|
type BaseArgs = {
|
|
8
8
|
route: RouteSuccessItem;
|
|
@@ -19,8 +19,7 @@ type ButterSwapRateStepData = {
|
|
|
19
19
|
networkFeeCryptoBaseUnit: string;
|
|
20
20
|
};
|
|
21
21
|
type ButterSwapQuoteStepData = {
|
|
22
|
-
transactionData
|
|
23
|
-
butterSwapTransactionMetadata?: ButterSwapTransactionMetadata;
|
|
22
|
+
transactionData: TxBuildData;
|
|
24
23
|
networkFeeCryptoBaseUnit: string;
|
|
25
24
|
};
|
|
26
25
|
export declare function getButterSwapStepData(args: Extract<GetButterSwapStepDataArgs, {
|
|
@@ -7,7 +7,8 @@ import { TradeQuoteError } from '../../../types.js';
|
|
|
7
7
|
import { makeNetworkFeeEstimationFailedErr, makeSwapErrorRight, makeTradeStepBuildFailedErr, } from '../../../utils/index.js';
|
|
8
8
|
import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
|
|
9
9
|
import { getSolanaNetworkFeeCryptoBaseUnit, omitComputeBudgetInstructions, withComputeUnitLimit, } from '../../../utils/solana/index.js';
|
|
10
|
-
import {
|
|
10
|
+
import { getTronContractCallFallbackFeeCryptoBaseUnit, getTronContractCallNetworkFeeCryptoBaseUnit, } from '../../../utils/tron/index.js';
|
|
11
|
+
import { BUTTERSWAP_TRON_DEFAULT_BANDWIDTH_BYTES, BUTTERSWAP_TRON_FALLBACK_SWAP_ENERGY, } from './constants.js';
|
|
11
12
|
import { getProviderNetworkFeeCryptoBaseUnit } from './helpers.js';
|
|
12
13
|
// Jupiter swap legs can consume more units than simulated when pool state moves between
|
|
13
14
|
// simulation and landing (CLMM tick crossings), 1.4 matches Jupiter's dynamicComputeUnitLimit margin
|
|
@@ -66,56 +67,6 @@ export async function getButterSwapStepData(args) {
|
|
|
66
67
|
return Err(makeNetworkFeeEstimationFailedErr('getButterSwapStepData', error));
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
case CHAIN_NAMESPACE.Utxo: {
|
|
70
|
-
const adapter = deps.assertGetUtxoChainAdapter(sellAsset.chainId);
|
|
71
|
-
const pubkey = 'xpub' in input ? input.xpub : undefined;
|
|
72
|
-
if (args.type === 'rate') {
|
|
73
|
-
const networkFeeCryptoBaseUnit = await (async () => {
|
|
74
|
-
try {
|
|
75
|
-
const { networkFeeCryptoBaseUnit } = await getUtxoNetworkFeeCryptoBaseUnit({
|
|
76
|
-
adapter,
|
|
77
|
-
pubkey,
|
|
78
|
-
to: input.sendAddress ?? UTXO_PLACEHOLDER_ADDRESS,
|
|
79
|
-
value: sellAmountCryptoBaseUnit,
|
|
80
|
-
});
|
|
81
|
-
return networkFeeCryptoBaseUnit;
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
return getProviderNetworkFeeCryptoBaseUnit({ route, feeAsset });
|
|
85
|
-
}
|
|
86
|
-
})();
|
|
87
|
-
const stepData = { networkFeeCryptoBaseUnit };
|
|
88
|
-
return Ok(stepData);
|
|
89
|
-
}
|
|
90
|
-
const { buildTx } = args;
|
|
91
|
-
// opReturnData routes the bridge for BTC deposits
|
|
92
|
-
if (!buildTx.memo) {
|
|
93
|
-
return Err(makeSwapErrorRight({
|
|
94
|
-
message: '[getButterSwapStepData] Missing memo (opReturnData)',
|
|
95
|
-
code: TradeQuoteError.InvalidResponse,
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
const transactionData = {
|
|
99
|
-
type: 'utxo',
|
|
100
|
-
to: buildTx.to,
|
|
101
|
-
opReturnData: buildTx.memo,
|
|
102
|
-
value: sellAmountCryptoBaseUnit,
|
|
103
|
-
};
|
|
104
|
-
try {
|
|
105
|
-
const { networkFeeCryptoBaseUnit } = await getUtxoNetworkFeeCryptoBaseUnit({
|
|
106
|
-
adapter,
|
|
107
|
-
pubkey,
|
|
108
|
-
to: transactionData.to,
|
|
109
|
-
value: transactionData.value,
|
|
110
|
-
opReturnData: transactionData.opReturnData,
|
|
111
|
-
});
|
|
112
|
-
const stepData = { transactionData, networkFeeCryptoBaseUnit };
|
|
113
|
-
return Ok(stepData);
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
return Err(makeNetworkFeeEstimationFailedErr('getButterSwapStepData', error));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
70
|
case CHAIN_NAMESPACE.Solana: {
|
|
120
71
|
const adapter = deps.assertGetSolanaChainAdapter(sellAsset.chainId);
|
|
121
72
|
if (args.type === 'rate') {
|
|
@@ -165,26 +116,52 @@ export async function getButterSwapStepData(args) {
|
|
|
165
116
|
return Err(makeTradeStepBuildFailedErr('getButterSwapStepData', error));
|
|
166
117
|
}
|
|
167
118
|
}
|
|
168
|
-
// Not yet migrated to a TxBuildData variant - exec still builds from legacy metadata
|
|
169
119
|
case CHAIN_NAMESPACE.Tron: {
|
|
170
|
-
const
|
|
120
|
+
const adapter = deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
171
121
|
if (args.type === 'rate') {
|
|
122
|
+
// Butter's gasFee is a fraction of what the router burns, so rates price the measured swap at the router's share
|
|
123
|
+
const networkFeeCryptoBaseUnit = await (async () => {
|
|
124
|
+
if (!route.contract)
|
|
125
|
+
return getProviderNetworkFeeCryptoBaseUnit({ route, feeAsset });
|
|
126
|
+
try {
|
|
127
|
+
return await getTronContractCallFallbackFeeCryptoBaseUnit({
|
|
128
|
+
adapter,
|
|
129
|
+
energy: BUTTERSWAP_TRON_FALLBACK_SWAP_ENERGY,
|
|
130
|
+
bandwidthBytes: BUTTERSWAP_TRON_DEFAULT_BANDWIDTH_BYTES,
|
|
131
|
+
contractAddress: route.contract,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return getProviderNetworkFeeCryptoBaseUnit({ route, feeAsset });
|
|
136
|
+
}
|
|
137
|
+
})();
|
|
172
138
|
const stepData = { networkFeeCryptoBaseUnit };
|
|
173
139
|
return Ok(stepData);
|
|
174
140
|
}
|
|
175
|
-
const { buildTx } = args;
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
value: buildTx.value,
|
|
181
|
-
method: buildTx.method,
|
|
182
|
-
args: buildTx.args,
|
|
183
|
-
memo: buildTx.memo,
|
|
184
|
-
},
|
|
185
|
-
networkFeeCryptoBaseUnit,
|
|
141
|
+
const { buildTx, from } = args;
|
|
142
|
+
const call = {
|
|
143
|
+
to: buildTx.to,
|
|
144
|
+
data: buildTx.data,
|
|
145
|
+
value: fromHex(buildTx.value, 'bigint').toString(),
|
|
186
146
|
};
|
|
187
|
-
|
|
147
|
+
try {
|
|
148
|
+
const stepData = {
|
|
149
|
+
transactionData: { type: 'tron', ...call },
|
|
150
|
+
networkFeeCryptoBaseUnit: await getTronContractCallNetworkFeeCryptoBaseUnit({
|
|
151
|
+
adapter,
|
|
152
|
+
transactionData: call,
|
|
153
|
+
from,
|
|
154
|
+
sellAsset,
|
|
155
|
+
sellAmountCryptoBaseUnit,
|
|
156
|
+
spenderAddress: buildTx.to,
|
|
157
|
+
fallbackEnergy: BUTTERSWAP_TRON_FALLBACK_SWAP_ENERGY,
|
|
158
|
+
}),
|
|
159
|
+
};
|
|
160
|
+
return Ok(stepData);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
return Err(makeNetworkFeeEstimationFailedErr('getButterSwapStepData', error));
|
|
164
|
+
}
|
|
188
165
|
}
|
|
189
166
|
default:
|
|
190
167
|
return Err(makeSwapErrorRight({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { solanaChainId, tronChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest';
|
|
3
3
|
import { TradeQuoteError } from '../../../types.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ETH, RUNE, WETH } from '../../../utils/test-data/assets.js';
|
|
5
5
|
import { ROUTE_QUOTE } from '../test-data/routeQuote.js';
|
|
6
6
|
import { getButterSwapStepData } from './getButterSwapStepData.js';
|
|
7
7
|
// The override path reads live chain state - resolve to no override so estimation exercises the
|
|
@@ -15,6 +15,11 @@ const route = ROUTE_QUOTE.data[0];
|
|
|
15
15
|
const PROVIDER_GAS_FEE_BASE_UNIT = '1333043669759539'; // 0.001333043669759539 ETH
|
|
16
16
|
const SOL = { ...ETH, assetId: `${solanaChainId}/slip44:501`, chainId: solanaChainId };
|
|
17
17
|
const TRX = { ...ETH, assetId: `${tronChainId}/slip44:195`, chainId: tronChainId };
|
|
18
|
+
const USDT_TRON = {
|
|
19
|
+
...ETH,
|
|
20
|
+
assetId: `${tronChainId}/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t`,
|
|
21
|
+
chainId: tronChainId,
|
|
22
|
+
};
|
|
18
23
|
const evmBuildTx = {
|
|
19
24
|
to: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
|
|
20
25
|
data: '0xdeadbeef',
|
|
@@ -25,6 +30,7 @@ const makeDeps = (adapters) => ({
|
|
|
25
30
|
assertGetEvmChainAdapter: () => adapters.evm,
|
|
26
31
|
assertGetUtxoChainAdapter: () => adapters.utxo,
|
|
27
32
|
assertGetSolanaChainAdapter: () => adapters.solana,
|
|
33
|
+
assertGetTronChainAdapter: () => adapters.tron,
|
|
28
34
|
});
|
|
29
35
|
const evmAdapter = ({ gasPrice = '1000000000', estimatedGasLimit = '500000', throwOnGasFeeData = false, throwOnFeeData = false, } = {}) => ({
|
|
30
36
|
getGasFeeData: () => {
|
|
@@ -134,116 +140,152 @@ describe('getButterSwapStepData', () => {
|
|
|
134
140
|
expect(actual.unwrapErr().code).toBe(TradeQuoteError.NetworkFeeEstimationFailed);
|
|
135
141
|
});
|
|
136
142
|
});
|
|
137
|
-
describe('
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
httpProvider: {
|
|
141
|
-
getNetworkFees: () => Promise.resolve({ fast: { satsPerKiloByte: 10000 } }),
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
it('estimates off the default vsize for a rate with no pubkey', async () => {
|
|
143
|
+
describe('solana', () => {
|
|
144
|
+
it('uses the provider fee for a rate, since swap instructions do not exist yet', async () => {
|
|
145
|
+
const assertGetSolanaChainAdapter = vi.fn();
|
|
145
146
|
const actual = await getButterSwapStepData({
|
|
146
147
|
type: 'rate',
|
|
147
148
|
input: {},
|
|
148
|
-
deps:
|
|
149
|
+
deps: { assertGetSolanaChainAdapter },
|
|
149
150
|
route,
|
|
150
|
-
sellAsset:
|
|
151
|
-
feeAsset:
|
|
152
|
-
sellAmountCryptoBaseUnit: '
|
|
151
|
+
sellAsset: SOL,
|
|
152
|
+
feeAsset: SOL,
|
|
153
|
+
sellAmountCryptoBaseUnit: '1000000000',
|
|
153
154
|
spenderAddress: '',
|
|
154
155
|
});
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
expect(actual.unwrap()).toEqual({
|
|
157
|
+
networkFeeCryptoBaseUnit: PROVIDER_GAS_FEE_BASE_UNIT,
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe('tron', () => {
|
|
162
|
+
const tronBuildTx = { ...evmBuildTx, to: 'TRouterAddress' };
|
|
163
|
+
const tronAdapter = ({ txFee = '9000000', allowance = '0' } = {}) => ({
|
|
164
|
+
getFeeData: vi.fn().mockResolvedValue({ fast: { txFee } }),
|
|
165
|
+
httpProvider: {
|
|
166
|
+
getChainPrices: () => Promise.resolve({ energyPrice: 100, bandwidthPrice: 1000 }),
|
|
167
|
+
getTrc20Allowance: vi.fn().mockResolvedValue(allowance),
|
|
168
|
+
getTrc20Balance: vi.fn().mockResolvedValue('100000000'),
|
|
169
|
+
getContractEnergyShare: vi.fn().mockResolvedValue({
|
|
170
|
+
callerPercent: 100,
|
|
171
|
+
originEnergyLimit: 0,
|
|
172
|
+
originEnergyAvailable: 0,
|
|
173
|
+
}),
|
|
174
|
+
},
|
|
157
175
|
});
|
|
158
|
-
it('
|
|
176
|
+
it('carries the router call as transactionData and simulates it', async () => {
|
|
177
|
+
const adapter = tronAdapter();
|
|
159
178
|
const actual = await getButterSwapStepData({
|
|
160
179
|
type: 'quote',
|
|
161
|
-
input: {
|
|
162
|
-
from: '
|
|
163
|
-
buildTx:
|
|
164
|
-
deps: makeDeps({
|
|
180
|
+
input: {},
|
|
181
|
+
from: 'TSenderAddress',
|
|
182
|
+
buildTx: tronBuildTx,
|
|
183
|
+
deps: makeDeps({ tron: adapter }),
|
|
165
184
|
route,
|
|
166
|
-
sellAsset:
|
|
167
|
-
feeAsset:
|
|
168
|
-
sellAmountCryptoBaseUnit: '
|
|
185
|
+
sellAsset: TRX,
|
|
186
|
+
feeAsset: TRX,
|
|
187
|
+
sellAmountCryptoBaseUnit: '1000000',
|
|
169
188
|
spenderAddress: '',
|
|
170
189
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
190
|
+
// Butter's value is the native amount to send: the sell amount for a native sell, 0 for a token
|
|
191
|
+
const transactionData = {
|
|
192
|
+
type: 'tron',
|
|
193
|
+
to: 'TRouterAddress',
|
|
194
|
+
data: evmBuildTx.data,
|
|
195
|
+
value: '100000000000000000',
|
|
196
|
+
};
|
|
197
|
+
expect(actual.unwrap()).toEqual({ transactionData, networkFeeCryptoBaseUnit: '9000000' });
|
|
198
|
+
expect(adapter.getFeeData).toHaveBeenCalledWith({
|
|
199
|
+
to: 'TRouterAddress',
|
|
200
|
+
value: '100000000000000000',
|
|
201
|
+
chainSpecific: { from: 'TSenderAddress', data: evmBuildTx.data, requireEnergyShare: true },
|
|
179
202
|
});
|
|
180
203
|
});
|
|
181
|
-
it('
|
|
204
|
+
it('uses the provider value for a token sell', async () => {
|
|
182
205
|
const actual = await getButterSwapStepData({
|
|
183
206
|
type: 'quote',
|
|
184
|
-
input: {
|
|
185
|
-
from: '
|
|
186
|
-
buildTx: { ...
|
|
187
|
-
deps: makeDeps({
|
|
207
|
+
input: {},
|
|
208
|
+
from: 'TSenderAddress',
|
|
209
|
+
buildTx: { ...tronBuildTx, value: '0x00' },
|
|
210
|
+
deps: makeDeps({ tron: tronAdapter() }),
|
|
188
211
|
route,
|
|
189
|
-
sellAsset:
|
|
190
|
-
feeAsset:
|
|
191
|
-
sellAmountCryptoBaseUnit: '
|
|
212
|
+
sellAsset: USDT_TRON,
|
|
213
|
+
feeAsset: TRX,
|
|
214
|
+
sellAmountCryptoBaseUnit: '1000000',
|
|
192
215
|
spenderAddress: '',
|
|
193
216
|
});
|
|
194
|
-
expect(actual.
|
|
195
|
-
expect(actual.unwrapErr().code).toBe(TradeQuoteError.InvalidResponse);
|
|
217
|
+
expect(actual.unwrap().transactionData).toMatchObject({ value: '0' });
|
|
196
218
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const assertGetSolanaChainAdapter = vi.fn();
|
|
219
|
+
it('fails a native quote when the simulation fails', async () => {
|
|
220
|
+
const adapter = tronAdapter();
|
|
221
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
201
222
|
const actual = await getButterSwapStepData({
|
|
202
|
-
type: '
|
|
223
|
+
type: 'quote',
|
|
203
224
|
input: {},
|
|
204
|
-
|
|
225
|
+
from: 'TSenderAddress',
|
|
226
|
+
buildTx: tronBuildTx,
|
|
227
|
+
deps: makeDeps({ tron: adapter }),
|
|
205
228
|
route,
|
|
206
|
-
sellAsset:
|
|
207
|
-
feeAsset:
|
|
208
|
-
sellAmountCryptoBaseUnit: '
|
|
229
|
+
sellAsset: TRX,
|
|
230
|
+
feeAsset: TRX,
|
|
231
|
+
sellAmountCryptoBaseUnit: '1000000',
|
|
209
232
|
spenderAddress: '',
|
|
210
233
|
});
|
|
211
|
-
expect(actual.
|
|
212
|
-
networkFeeCryptoBaseUnit: PROVIDER_GAS_FEE_BASE_UNIT,
|
|
213
|
-
});
|
|
234
|
+
expect(actual.isErr()).toBe(true);
|
|
214
235
|
});
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const buildTx = {
|
|
219
|
-
...evmBuildTx,
|
|
220
|
-
to: 'TRouterAddress',
|
|
221
|
-
method: 'swapAndCall',
|
|
222
|
-
args: [{ type: 'address', value: 'TSpender' }],
|
|
223
|
-
};
|
|
236
|
+
it('prices the measured worst case when a token allowance is not granted yet', async () => {
|
|
237
|
+
const adapter = tronAdapter({ allowance: '0' });
|
|
238
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
224
239
|
const actual = await getButterSwapStepData({
|
|
225
240
|
type: 'quote',
|
|
226
241
|
input: {},
|
|
227
242
|
from: 'TSenderAddress',
|
|
228
|
-
buildTx,
|
|
229
|
-
deps: {},
|
|
243
|
+
buildTx: { ...tronBuildTx, value: '0x00' },
|
|
244
|
+
deps: makeDeps({ tron: adapter }),
|
|
230
245
|
route,
|
|
246
|
+
sellAsset: USDT_TRON,
|
|
247
|
+
feeAsset: TRX,
|
|
248
|
+
sellAmountCryptoBaseUnit: '1000000',
|
|
249
|
+
spenderAddress: '',
|
|
250
|
+
});
|
|
251
|
+
// 1000000 energy * 1.2 margin * 100 sun + (4 calldata + 279 envelope) bytes * 1000 sun
|
|
252
|
+
expect(actual.unwrap().networkFeeCryptoBaseUnit).toBe('120283000');
|
|
253
|
+
});
|
|
254
|
+
it('rates price the measured swap at the router share', async () => {
|
|
255
|
+
const adapter = tronAdapter();
|
|
256
|
+
adapter.httpProvider.getContractEnergyShare.mockResolvedValue({
|
|
257
|
+
callerPercent: 5,
|
|
258
|
+
originEnergyLimit: 10_000_000,
|
|
259
|
+
originEnergyAvailable: 5_000_000,
|
|
260
|
+
});
|
|
261
|
+
const actual = await getButterSwapStepData({
|
|
262
|
+
type: 'rate',
|
|
263
|
+
input: {},
|
|
264
|
+
deps: makeDeps({ tron: adapter }),
|
|
265
|
+
route: { ...route, contract: 'TRouterAddress' },
|
|
231
266
|
sellAsset: TRX,
|
|
232
267
|
feeAsset: TRX,
|
|
233
268
|
sellAmountCryptoBaseUnit: '1000000',
|
|
234
269
|
spenderAddress: '',
|
|
235
270
|
});
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
},
|
|
271
|
+
// 1000000 * 5% caller energy * 1.2 margin * 100 sun + 2400 bytes * 1000 sun
|
|
272
|
+
expect(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '8400000' });
|
|
273
|
+
expect(adapter.httpProvider.getContractEnergyShare).toHaveBeenCalledWith('TRouterAddress');
|
|
274
|
+
});
|
|
275
|
+
it('rates fall back to the provider fee when the worst case cannot be priced', async () => {
|
|
276
|
+
const adapter = tronAdapter();
|
|
277
|
+
adapter.httpProvider.getContractEnergyShare.mockRejectedValue(new Error('429'));
|
|
278
|
+
const actual = await getButterSwapStepData({
|
|
279
|
+
type: 'rate',
|
|
280
|
+
input: {},
|
|
281
|
+
deps: makeDeps({ tron: adapter }),
|
|
282
|
+
route: { ...route, contract: 'TRouterAddress' },
|
|
283
|
+
sellAsset: TRX,
|
|
284
|
+
feeAsset: TRX,
|
|
285
|
+
sellAmountCryptoBaseUnit: '1000000',
|
|
286
|
+
spenderAddress: '',
|
|
246
287
|
});
|
|
288
|
+
expect(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: PROVIDER_GAS_FEE_BASE_UNIT });
|
|
247
289
|
});
|
|
248
290
|
});
|
|
249
291
|
it('errors on an unsupported chain namespace', async () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { solanaChainId, tronChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
3
3
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
4
4
|
import { BigAmount, bnOrZero } from '@shapeshiftoss/utils';
|
|
@@ -17,7 +17,6 @@ const BUTTERSWAP_CHAIN_ID_TO_CHAIN_ID = {
|
|
|
17
17
|
[avalanche.id]: KnownChainIds.AvalancheMainnet,
|
|
18
18
|
[robinhood.id]: KnownChainIds.RobinhoodMainnet,
|
|
19
19
|
1360108768460801: KnownChainIds.SolanaMainnet,
|
|
20
|
-
1360095883558913: KnownChainIds.BitcoinMainnet,
|
|
21
20
|
[tron.id]: KnownChainIds.TronMainnet,
|
|
22
21
|
};
|
|
23
22
|
const CHAIN_ID_TO_BUTTERSWAP_CHAIN_ID = Object.entries(BUTTERSWAP_CHAIN_ID_TO_CHAIN_ID).reduce((acc, [butterSwapChainId, chainId]) => {
|
|
@@ -32,7 +31,6 @@ export const chainIdToButterSwapChainId = (chainId) => {
|
|
|
32
31
|
};
|
|
33
32
|
export const assertValidTrade = ({ sellAsset, }) => {
|
|
34
33
|
if (!isEvmChainId(sellAsset.chainId) &&
|
|
35
|
-
sellAsset.chainId !== btcChainId &&
|
|
36
34
|
sellAsset.chainId !== solanaChainId &&
|
|
37
35
|
sellAsset.chainId !== tronChainId) {
|
|
38
36
|
return Err(makeSwapErrorRight({
|
|
@@ -42,8 +40,7 @@ export const assertValidTrade = ({ sellAsset, }) => {
|
|
|
42
40
|
}
|
|
43
41
|
return Ok(undefined);
|
|
44
42
|
};
|
|
45
|
-
// Provider reported network fee - the
|
|
46
|
-
// un-migrated tron quote path (exec computes the real fee at execution)
|
|
43
|
+
// Provider reported network fee - the fallback when estimation fails
|
|
47
44
|
export const getProviderNetworkFeeCryptoBaseUnit = ({ route, feeAsset, }) => {
|
|
48
45
|
if (bnOrZero(route.gasFee?.amount).lte(0))
|
|
49
46
|
return '0';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fromAssetId, solanaChainId, tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
3
|
import { chainIdToFeeAssetId } from '@shapeshiftoss/utils';
|
|
3
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
4
5
|
import { zeroAddress } from 'viem';
|
|
@@ -20,7 +21,6 @@ export var ButterSwapErrorCode;
|
|
|
20
21
|
ButterSwapErrorCode[ButterSwapErrorCode["InvalidAddress"] = 2007] = "InvalidAddress";
|
|
21
22
|
})(ButterSwapErrorCode || (ButterSwapErrorCode = {}));
|
|
22
23
|
const SOLANA_NATIVE_ADDRESS = 'So11111111111111111111111111111111111111112';
|
|
23
|
-
const TRON_NATIVE_ADDRESS = 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb';
|
|
24
24
|
export const getButterRoute = async ({ sellAsset, buyAsset, sellAmountCryptoPrecision, slippage, affiliate, }) => {
|
|
25
25
|
const butterFromChainId = chainIdToButterSwapChainId(sellAsset.chainId);
|
|
26
26
|
const butterToChainId = chainIdToButterSwapChainId(buyAsset.chainId);
|
|
@@ -39,7 +39,7 @@ export const getButterRoute = async ({ sellAsset, buyAsset, sellAmountCryptoPrec
|
|
|
39
39
|
if (sellAsset.chainId === solanaChainId && sellAssetIsNative)
|
|
40
40
|
return SOLANA_NATIVE_ADDRESS;
|
|
41
41
|
if (sellAsset.chainId === tronChainId && sellAssetIsNative)
|
|
42
|
-
return
|
|
42
|
+
return tron.TRON_ZERO_ADDRESS;
|
|
43
43
|
if (sellAssetIsNative)
|
|
44
44
|
return zeroAddress;
|
|
45
45
|
return sellAssetAddressRaw;
|
|
@@ -48,7 +48,7 @@ export const getButterRoute = async ({ sellAsset, buyAsset, sellAmountCryptoPrec
|
|
|
48
48
|
if (buyAsset.chainId === solanaChainId && buyAssetIsNative)
|
|
49
49
|
return SOLANA_NATIVE_ADDRESS;
|
|
50
50
|
if (buyAsset.chainId === tronChainId && buyAssetIsNative)
|
|
51
|
-
return
|
|
51
|
+
return tron.TRON_ZERO_ADDRESS;
|
|
52
52
|
if (buyAssetIsNative)
|
|
53
53
|
return zeroAddress;
|
|
54
54
|
return buyAssetAddressRaw;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
2
|
-
import {
|
|
3
|
-
import { getExecutableTradeStep, getSwapMetadata, isExecutableTradeQuote } from '../../utils/index.js';
|
|
2
|
+
import { getSwapMetadata } from '../../utils/index.js';
|
|
4
3
|
import { getEvmTransactionFees, getUnsignedEvmTransaction } from '../../utils/evm/index.js';
|
|
5
4
|
import { getSolanaTransactionFees, getUnsignedSolanaTransaction } from '../../utils/solana/index.js';
|
|
6
|
-
import { getTronTransactionFees } from '../../utils/tron/index.js';
|
|
5
|
+
import { getTronTransactionFees, getUnsignedTronTransaction } from '../../utils/tron/index.js';
|
|
7
6
|
import { getUnsignedUtxoTransaction, getUtxoTransactionFees } from '../../utils/utxo/index.js';
|
|
8
7
|
import { ChainflipStatusMessage } from './constants.js';
|
|
9
8
|
import { getTradeQuote } from './swapperApi/getTradeQuote.js';
|
|
@@ -19,22 +18,7 @@ export const chainflipApi = {
|
|
|
19
18
|
getUtxoTransactionFees,
|
|
20
19
|
getUnsignedSolanaTransaction,
|
|
21
20
|
getSolanaTransactionFees,
|
|
22
|
-
getUnsignedTronTransaction
|
|
23
|
-
if (!isExecutableTradeQuote(tradeQuote))
|
|
24
|
-
throw new Error('Unable to execute a trade rate quote');
|
|
25
|
-
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
26
|
-
const { accountNumber, chainflipSpecific, sellAsset } = step;
|
|
27
|
-
if (!chainflipSpecific?.depositAddress)
|
|
28
|
-
throw Error('Missing deposit address');
|
|
29
|
-
const adapter = assertGetTronChainAdapter(sellAsset.chainId);
|
|
30
|
-
return adapter.buildSendApiTransaction({
|
|
31
|
-
to: chainflipSpecific.depositAddress,
|
|
32
|
-
from,
|
|
33
|
-
value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
34
|
-
accountNumber,
|
|
35
|
-
chainSpecific: { contractAddress: contractAddressOrUndefined(sellAsset.assetId) },
|
|
36
|
-
});
|
|
37
|
-
},
|
|
21
|
+
getUnsignedTronTransaction,
|
|
38
22
|
getTronTransactionFees,
|
|
39
23
|
checkTradeStatus: async ({ config, swap }) => {
|
|
40
24
|
if (!swap)
|