@shapeshiftoss/swapper 17.6.7 → 17.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/constants.js +42 -24
- package/dist/cjs/cowswap-utils/constants.js +1 -0
- package/dist/cjs/cowswap-utils/index.js +2 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/swappers/AvnuSwapper/AvnuSwapper.d.ts +2 -0
- package/dist/cjs/swappers/AvnuSwapper/AvnuSwapper.js +7 -0
- package/dist/cjs/swappers/AvnuSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/AvnuSwapper/endpoints.js +181 -0
- package/dist/cjs/swappers/AvnuSwapper/index.d.ts +1 -0
- package/dist/cjs/swappers/AvnuSwapper/index.js +5 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +142 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.js +120 -0
- package/dist/cjs/swappers/AvnuSwapper/types.d.ts +2 -0
- package/dist/cjs/swappers/AvnuSwapper/types.js +2 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/constants.d.ts +5 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/constants.js +11 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/helpers.d.ts +7 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/helpers.js +21 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +2 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +4 -0
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/cjs/swappers/CetusSwapper/endpoints.js +33 -27
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getCetusTradeData.d.ts +24 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getCetusTradeData.js +79 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +44 -69
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeRate.js +49 -65
- package/dist/cjs/swappers/CetusSwapper/utils/constants.d.ts +1 -0
- package/dist/cjs/swappers/CetusSwapper/utils/constants.js +2 -1
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.d.ts +6 -11
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.js +41 -96
- package/dist/cjs/swappers/JupiterSwapper/utils/helpers.d.ts +0 -2
- package/dist/cjs/swappers/MayachainSwapper/generated/generatedTradableAssetMap.json +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +2 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +68 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +30 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +53 -5
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.js +8 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +28 -8
- package/dist/cjs/swappers/PortalsSwapper/constants.js +1 -1
- package/dist/cjs/swappers/PortalsSwapper/endpoints.js +92 -1
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +29 -17
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +21 -17
- package/dist/cjs/swappers/PortalsSwapper/types.js +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.d.ts +9 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.js +52 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchPortalsTradeOrder.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchSquidStatus.d.ts +9 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/fetchSquidStatus.js +57 -0
- package/dist/cjs/swappers/RelaySwapper/constant.js +3 -0
- package/dist/cjs/swappers/RelaySwapper/utils/fetchRelayTrade.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +16 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +20 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +13 -4
- package/dist/cjs/swappers/RelaySwapper/utils/types.js +5 -1
- package/dist/cjs/swappers/SunioSwapper/SunioSwapper.d.ts +2 -0
- package/dist/cjs/swappers/SunioSwapper/SunioSwapper.js +7 -0
- package/dist/cjs/swappers/SunioSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +131 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +8 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +8 -0
- package/dist/cjs/swappers/SunioSwapper/index.d.ts +4 -0
- package/dist/cjs/swappers/SunioSwapper/index.js +23 -0
- package/dist/cjs/swappers/SunioSwapper/types.d.ts +22 -0
- package/dist/cjs/swappers/SunioSwapper/types.js +12 -0
- package/dist/cjs/swappers/SunioSwapper/utils/abi.d.ts +48 -0
- package/dist/cjs/swappers/SunioSwapper/utils/abi.js +28 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +14 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +32 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +11 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.js +57 -0
- package/dist/cjs/swappers/SunioSwapper/utils/constants.d.ts +6 -0
- package/dist/cjs/swappers/SunioSwapper/utils/constants.js +16 -0
- package/dist/cjs/swappers/SunioSwapper/utils/fetchFromSunio.d.ts +11 -0
- package/dist/cjs/swappers/SunioSwapper/utils/fetchFromSunio.js +45 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.d.ts +4 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.js +203 -0
- package/dist/cjs/swappers/SunioSwapper/utils/helpers/helpers.d.ts +4 -0
- package/dist/cjs/swappers/SunioSwapper/utils/helpers/helpers.js +22 -0
- package/dist/cjs/swappers/SunioSwapper/utils/sunioService.d.ts +6 -0
- package/dist/cjs/swappers/SunioSwapper/utils/sunioService.js +18 -0
- package/dist/cjs/swappers/ThorchainSwapper/ThorchainSwapper.js +3 -0
- package/dist/cjs/swappers/ThorchainSwapper/endpoints.js +2 -0
- package/dist/cjs/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +2 -2
- package/dist/cjs/swappers/utils/helpers/helpers.js +7 -0
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +80 -3
- package/dist/cjs/thorchain-utils/index.d.ts +1 -0
- package/dist/cjs/thorchain-utils/index.js +2 -1
- package/dist/cjs/thorchain-utils/tron/getThorTxData.d.ts +12 -0
- package/dist/cjs/thorchain-utils/tron/getThorTxData.js +14 -0
- package/dist/cjs/thorchain-utils/tron/getTronTransactionFees.d.ts +2 -0
- package/dist/cjs/thorchain-utils/tron/getTronTransactionFees.js +65 -0
- package/dist/cjs/thorchain-utils/tron/getUnsignedTronTransaction.d.ts +3 -0
- package/dist/cjs/thorchain-utils/tron/getUnsignedTronTransaction.js +35 -0
- package/dist/cjs/thorchain-utils/tron/index.d.ts +3 -0
- package/dist/cjs/thorchain-utils/tron/index.js +19 -0
- package/dist/cjs/types.d.ts +74 -9
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/tenderly/simulate.d.ts +6 -1
- package/dist/cjs/utils/tenderly/simulate.js +22 -2
- package/dist/cjs/utils/tenderly/types.d.ts +21 -0
- package/dist/cjs/utils.d.ts +10 -4
- package/dist/cjs/utils.js +53 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +18 -0
- package/dist/esm/cowswap-utils/constants.js +1 -0
- package/dist/esm/cowswap-utils/index.js +2 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/swappers/AvnuSwapper/AvnuSwapper.d.ts +2 -0
- package/dist/esm/swappers/AvnuSwapper/AvnuSwapper.js +4 -0
- package/dist/esm/swappers/AvnuSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/AvnuSwapper/endpoints.js +178 -0
- package/dist/esm/swappers/AvnuSwapper/index.d.ts +1 -0
- package/dist/esm/swappers/AvnuSwapper/index.js +1 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +138 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.js +116 -0
- package/dist/esm/swappers/AvnuSwapper/types.d.ts +2 -0
- package/dist/esm/swappers/AvnuSwapper/types.js +1 -0
- package/dist/esm/swappers/AvnuSwapper/utils/constants.d.ts +5 -0
- package/dist/esm/swappers/AvnuSwapper/utils/constants.js +7 -0
- package/dist/esm/swappers/AvnuSwapper/utils/helpers.d.ts +7 -0
- package/dist/esm/swappers/AvnuSwapper/utils/helpers.js +17 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +2 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +4 -0
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/esm/swappers/CetusSwapper/endpoints.js +28 -22
- package/dist/esm/swappers/CetusSwapper/swapperApi/getCetusTradeData.d.ts +24 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getCetusTradeData.js +75 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +44 -69
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeRate.js +50 -66
- package/dist/esm/swappers/CetusSwapper/utils/constants.d.ts +1 -0
- package/dist/esm/swappers/CetusSwapper/utils/constants.js +1 -0
- package/dist/esm/swappers/CetusSwapper/utils/helpers.d.ts +6 -11
- package/dist/esm/swappers/CetusSwapper/utils/helpers.js +37 -67
- package/dist/esm/swappers/JupiterSwapper/utils/helpers.d.ts +0 -2
- package/dist/esm/swappers/MayachainSwapper/generated/generatedTradableAssetMap.json +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +3 -1
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +68 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +30 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +54 -6
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.js +8 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +29 -9
- package/dist/esm/swappers/PortalsSwapper/constants.js +1 -1
- package/dist/esm/swappers/PortalsSwapper/endpoints.js +92 -1
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +30 -18
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +21 -17
- package/dist/esm/swappers/PortalsSwapper/types.js +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.d.ts +9 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchAxelarscanStatus.js +47 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchPortalsTradeOrder.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchSquidStatus.d.ts +9 -0
- package/dist/esm/swappers/PortalsSwapper/utils/fetchSquidStatus.js +52 -0
- package/dist/esm/swappers/RelaySwapper/constant.js +5 -2
- package/dist/esm/swappers/RelaySwapper/utils/fetchRelayTrade.js +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +18 -3
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +20 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +13 -4
- package/dist/esm/swappers/RelaySwapper/utils/types.js +3 -0
- package/dist/esm/swappers/SunioSwapper/SunioSwapper.d.ts +2 -0
- package/dist/esm/swappers/SunioSwapper/SunioSwapper.js +4 -0
- package/dist/esm/swappers/SunioSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/SunioSwapper/endpoints.js +128 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +4 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.d.ts +3 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +4 -0
- package/dist/esm/swappers/SunioSwapper/index.d.ts +4 -0
- package/dist/esm/swappers/SunioSwapper/index.js +4 -0
- package/dist/esm/swappers/SunioSwapper/types.d.ts +22 -0
- package/dist/esm/swappers/SunioSwapper/types.js +9 -0
- package/dist/esm/swappers/SunioSwapper/utils/abi.d.ts +48 -0
- package/dist/esm/swappers/SunioSwapper/utils/abi.js +25 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +14 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +28 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +11 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.js +53 -0
- package/dist/esm/swappers/SunioSwapper/utils/constants.d.ts +6 -0
- package/dist/esm/swappers/SunioSwapper/utils/constants.js +13 -0
- package/dist/esm/swappers/SunioSwapper/utils/fetchFromSunio.d.ts +11 -0
- package/dist/esm/swappers/SunioSwapper/utils/fetchFromSunio.js +41 -0
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.d.ts +4 -0
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.js +199 -0
- package/dist/esm/swappers/SunioSwapper/utils/helpers/helpers.d.ts +4 -0
- package/dist/esm/swappers/SunioSwapper/utils/helpers/helpers.js +16 -0
- package/dist/esm/swappers/SunioSwapper/utils/sunioService.d.ts +6 -0
- package/dist/esm/swappers/SunioSwapper/utils/sunioService.js +14 -0
- package/dist/esm/swappers/ThorchainSwapper/ThorchainSwapper.js +3 -0
- package/dist/esm/swappers/ThorchainSwapper/endpoints.js +3 -1
- package/dist/esm/swappers/ThorchainSwapper/generated/generatedTradableAssetMap.json +2 -2
- package/dist/esm/swappers/utils/helpers/helpers.js +9 -2
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +81 -4
- package/dist/esm/thorchain-utils/index.d.ts +1 -0
- package/dist/esm/thorchain-utils/index.js +1 -0
- package/dist/esm/thorchain-utils/tron/getThorTxData.d.ts +12 -0
- package/dist/esm/thorchain-utils/tron/getThorTxData.js +10 -0
- package/dist/esm/thorchain-utils/tron/getTronTransactionFees.d.ts +2 -0
- package/dist/esm/thorchain-utils/tron/getTronTransactionFees.js +61 -0
- package/dist/esm/thorchain-utils/tron/getUnsignedTronTransaction.d.ts +3 -0
- package/dist/esm/thorchain-utils/tron/getUnsignedTronTransaction.js +31 -0
- package/dist/esm/thorchain-utils/tron/index.d.ts +3 -0
- package/dist/esm/thorchain-utils/tron/index.js +3 -0
- package/dist/esm/types.d.ts +74 -9
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/tenderly/simulate.d.ts +6 -1
- package/dist/esm/utils/tenderly/simulate.js +20 -1
- package/dist/esm/utils/tenderly/types.d.ts +21 -0
- package/dist/esm/utils.d.ts +10 -4
- package/dist/esm/utils.js +50 -1
- package/package.json +5 -4
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { bnOrZero, contractAddressOrUndefined } from '@shapeshiftoss/utils';
|
|
2
|
+
import { TronWeb } from 'tronweb';
|
|
3
|
+
import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils.js';
|
|
4
|
+
import { getThorTxData } from './getThorTxData.js';
|
|
5
|
+
const getChainPrices = async (rpcUrl) => {
|
|
6
|
+
try {
|
|
7
|
+
const tronWeb = new TronWeb({ fullHost: rpcUrl });
|
|
8
|
+
const params = await tronWeb.trx.getChainParameters();
|
|
9
|
+
const bandwidthPrice = params.find(p => p.key === 'getTransactionFee')?.value ?? 1000;
|
|
10
|
+
const energyPrice = params.find(p => p.key === 'getEnergyFee')?.value ?? 420;
|
|
11
|
+
return { bandwidthPrice, energyPrice };
|
|
12
|
+
}
|
|
13
|
+
catch (_err) {
|
|
14
|
+
return { bandwidthPrice: 1000, energyPrice: 420 };
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const getTronTransactionFees = async (args, swapperName) => {
|
|
18
|
+
const { tradeQuote, stepIndex, config, from } = args;
|
|
19
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
20
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
21
|
+
const { memo } = tradeQuote;
|
|
22
|
+
if (!memo)
|
|
23
|
+
throw new Error('Memo is required');
|
|
24
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
25
|
+
const { sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit } = step;
|
|
26
|
+
const { vault } = await getThorTxData({ sellAsset, config, swapperName });
|
|
27
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
28
|
+
const rpcUrl = config.VITE_TRON_NODE_URL;
|
|
29
|
+
try {
|
|
30
|
+
const tronWeb = new TronWeb({ fullHost: rpcUrl });
|
|
31
|
+
if (contractAddress) {
|
|
32
|
+
// TRC20 transfer - estimate energy cost
|
|
33
|
+
const { energyPrice } = await getChainPrices(rpcUrl);
|
|
34
|
+
const result = await tronWeb.transactionBuilder.triggerConstantContract(contractAddress, 'transfer(address,uint256)', {}, [
|
|
35
|
+
{ type: 'address', value: vault },
|
|
36
|
+
{ type: 'uint256', value: sellAmountIncludingProtocolFeesCryptoBaseUnit },
|
|
37
|
+
], from);
|
|
38
|
+
const energyUsed = result.energy_used ?? 65000; // Conservative default for TRC20 transfer
|
|
39
|
+
const feeInSun = energyUsed * energyPrice;
|
|
40
|
+
return String(feeInSun);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// TRX transfer with memo - build transaction to get accurate size
|
|
44
|
+
const { bandwidthPrice } = await getChainPrices(rpcUrl);
|
|
45
|
+
let tx = await tronWeb.transactionBuilder.sendTrx(vault, bnOrZero(sellAmountIncludingProtocolFeesCryptoBaseUnit).toNumber(), from);
|
|
46
|
+
// Add memo to get accurate size with memo overhead
|
|
47
|
+
const txWithMemo = await tronWeb.transactionBuilder.addUpdateData(tx, memo, 'utf8');
|
|
48
|
+
// Calculate bandwidth fee from transaction size
|
|
49
|
+
const rawDataBytes = txWithMemo.raw_data_hex ? txWithMemo.raw_data_hex.length / 2 : 268;
|
|
50
|
+
const signatureBytes = 65;
|
|
51
|
+
const totalBytes = rawDataBytes + signatureBytes;
|
|
52
|
+
const feeInSun = totalBytes * bandwidthPrice;
|
|
53
|
+
return String(feeInSun);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
// Fallback to conservative estimate if fee estimation fails
|
|
58
|
+
// TRX transfer: ~1 TRX, TRC20: ~10 TRX
|
|
59
|
+
return contractAddress ? '10000000' : '1000000';
|
|
60
|
+
}
|
|
61
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import type { GetUnsignedTronTransactionArgs, SwapperName } from '../../types.js';
|
|
3
|
+
export declare const getUnsignedTronTransaction: (args: GetUnsignedTronTransactionArgs, swapperName: SwapperName) => Promise<tron.TronSignTx>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { contractAddressOrUndefined } from '@shapeshiftoss/utils';
|
|
2
|
+
import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils.js';
|
|
3
|
+
import { getThorTxData } from './getThorTxData.js';
|
|
4
|
+
export const getUnsignedTronTransaction = async (args, swapperName) => {
|
|
5
|
+
const { tradeQuote, stepIndex, from, assertGetTronChainAdapter, config } = args;
|
|
6
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
7
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
8
|
+
const { memo } = tradeQuote;
|
|
9
|
+
if (!memo)
|
|
10
|
+
throw new Error('Memo is required');
|
|
11
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
12
|
+
const { accountNumber, sellAmountIncludingProtocolFeesCryptoBaseUnit, sellAsset } = step;
|
|
13
|
+
const { vault } = await getThorTxData({
|
|
14
|
+
sellAsset,
|
|
15
|
+
config,
|
|
16
|
+
swapperName,
|
|
17
|
+
});
|
|
18
|
+
const adapter = assertGetTronChainAdapter(sellAsset.chainId);
|
|
19
|
+
// For TRC20 tokens, extract contract address
|
|
20
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
21
|
+
return adapter.buildSendApiTransaction({
|
|
22
|
+
to: vault,
|
|
23
|
+
from,
|
|
24
|
+
value: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
25
|
+
accountNumber,
|
|
26
|
+
chainSpecific: {
|
|
27
|
+
contractAddress,
|
|
28
|
+
memo,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
};
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { QuoteResponse } from '@jup-ag/api';
|
|
2
2
|
import type { AccountId, AssetId, ChainId, Nominal } from '@shapeshiftoss/caip';
|
|
3
|
-
import type { ChainAdapter, CosmosSdkChainAdapter, EvmChainAdapter, SignTx, solana, sui, tron, UtxoChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
4
|
-
import type { HDWallet, SolanaSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
5
|
-
import type { AccountMetadata, Asset, AssetsByIdPartial, CosmosSdkChainId, EvmChainId, KnownChainIds, OrderQuoteResponse, PartialRecord, TronChainId, UtxoAccountType, UtxoChainId } from '@shapeshiftoss/types';
|
|
3
|
+
import type { ChainAdapter, CosmosSdkChainAdapter, EvmChainAdapter, near, SignTx, solana, starknet, sui, tron, UtxoChainAdapter } from '@shapeshiftoss/chain-adapters';
|
|
4
|
+
import type { HDWallet, SolanaSignTx, StarknetSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
5
|
+
import type { AccountMetadata, Asset, AssetsByIdPartial, CosmosSdkChainId, EvmChainId, KnownChainIds, NearChainId, OrderQuoteResponse, PartialRecord, TronChainId, UtxoAccountType, UtxoChainId } from '@shapeshiftoss/types';
|
|
6
6
|
import type { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
7
7
|
import type { Result } from '@sniptt/monads';
|
|
8
8
|
import type { TransactionInstruction } from '@solana/web3.js';
|
|
@@ -20,6 +20,7 @@ export type SwapperConfig = {
|
|
|
20
20
|
VITE_UNCHAINED_COSMOS_HTTP_URL: string;
|
|
21
21
|
VITE_THORCHAIN_NODE_URL: string;
|
|
22
22
|
VITE_MAYACHAIN_NODE_URL: string;
|
|
23
|
+
VITE_TRON_NODE_URL: string;
|
|
23
24
|
VITE_FEATURE_THORCHAINSWAP_LONGTAIL: boolean;
|
|
24
25
|
VITE_FEATURE_THORCHAINSWAP_L1_TO_LONGTAIL: boolean;
|
|
25
26
|
VITE_THORCHAIN_MIDGARD_URL: string;
|
|
@@ -45,6 +46,7 @@ export type SwapperConfig = {
|
|
|
45
46
|
VITE_TENDERLY_API_KEY: string;
|
|
46
47
|
VITE_TENDERLY_ACCOUNT_SLUG: string;
|
|
47
48
|
VITE_TENDERLY_PROJECT_SLUG: string;
|
|
49
|
+
VITE_SUI_NODE_URL: string;
|
|
48
50
|
};
|
|
49
51
|
export declare enum SwapperName {
|
|
50
52
|
Thorchain = "THORChain",
|
|
@@ -60,7 +62,9 @@ export declare enum SwapperName {
|
|
|
60
62
|
ButterSwap = "ButterSwap",
|
|
61
63
|
Bebop = "Bebop",
|
|
62
64
|
NearIntents = "NEAR Intents",
|
|
63
|
-
Cetus = "Cetus"
|
|
65
|
+
Cetus = "Cetus",
|
|
66
|
+
Sunio = "Sun.io",
|
|
67
|
+
Avnu = "AVNU"
|
|
64
68
|
}
|
|
65
69
|
export type SwapSource = SwapperName | `${SwapperName} • ${string}`;
|
|
66
70
|
export type SwapErrorRight = {
|
|
@@ -170,6 +174,15 @@ export type GetCosmosSdkTradeRateInput = CommonTradeRateInput & {
|
|
|
170
174
|
export type GetTronTradeRateInput = CommonTradeRateInput & {
|
|
171
175
|
chainId: TronChainId;
|
|
172
176
|
};
|
|
177
|
+
export type GetNearTradeQuoteInputBase = CommonTradeInput & {
|
|
178
|
+
chainId: NearChainId;
|
|
179
|
+
};
|
|
180
|
+
export type GetNearTradeQuoteInput = CommonTradeInput & {
|
|
181
|
+
chainId: NearChainId;
|
|
182
|
+
};
|
|
183
|
+
export type GetNearTradeRateInput = CommonTradeRateInput & {
|
|
184
|
+
chainId: NearChainId;
|
|
185
|
+
};
|
|
173
186
|
type GetUtxoTradeQuoteWithWallet = CommonTradeQuoteInput & {
|
|
174
187
|
chainId: UtxoChainId;
|
|
175
188
|
accountType: UtxoAccountType;
|
|
@@ -183,9 +196,9 @@ export type GetUtxoTradeRateInput = CommonTradeRateInput & {
|
|
|
183
196
|
xpub: string | undefined;
|
|
184
197
|
};
|
|
185
198
|
export type GetUtxoTradeQuoteInput = GetUtxoTradeQuoteWithWallet;
|
|
186
|
-
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput;
|
|
187
|
-
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput;
|
|
188
|
-
export type GetTradeQuoteInputWithWallet = GetUtxoTradeQuoteWithWallet | GetEvmTradeQuoteInputBase | GetCosmosSdkTradeQuoteInputBase | GetTronTradeQuoteInputBase;
|
|
199
|
+
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput | GetNearTradeQuoteInput;
|
|
200
|
+
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput | GetNearTradeRateInput;
|
|
201
|
+
export type GetTradeQuoteInputWithWallet = GetUtxoTradeQuoteWithWallet | GetEvmTradeQuoteInputBase | GetCosmosSdkTradeQuoteInputBase | GetTronTradeQuoteInputBase | GetNearTradeQuoteInputBase;
|
|
189
202
|
export type EvmSwapperDeps = {
|
|
190
203
|
assertGetEvmChainAdapter: (chainId: ChainId) => EvmChainAdapter;
|
|
191
204
|
fetchIsSmartContractAddressQuery: (userAddress: string, chainId: ChainId) => Promise<boolean>;
|
|
@@ -205,12 +218,18 @@ export type TronSwapperDeps = {
|
|
|
205
218
|
export type SuiSwapperDeps = {
|
|
206
219
|
assertGetSuiChainAdapter: (chainId: ChainId) => sui.ChainAdapter;
|
|
207
220
|
};
|
|
221
|
+
export type NearSwapperDeps = {
|
|
222
|
+
assertGetNearChainAdapter: (chainId: ChainId) => near.ChainAdapter;
|
|
223
|
+
};
|
|
224
|
+
export type StarknetSwapperDeps = {
|
|
225
|
+
assertGetStarknetChainAdapter: (chainId: ChainId) => starknet.ChainAdapter;
|
|
226
|
+
};
|
|
208
227
|
export type SwapperDeps = {
|
|
209
228
|
assetsById: AssetsByIdPartial;
|
|
210
229
|
config: SwapperConfig;
|
|
211
230
|
mixPanel: Mixpanel | undefined;
|
|
212
231
|
assertGetChainAdapter: (chainId: ChainId) => ChainAdapter<KnownChainIds>;
|
|
213
|
-
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps;
|
|
232
|
+
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps;
|
|
214
233
|
export type TradeQuoteStep = {
|
|
215
234
|
buyAmountBeforeFeesCryptoBaseUnit: string;
|
|
216
235
|
buyAmountAfterFeesCryptoBaseUnit: string;
|
|
@@ -238,6 +257,11 @@ export type TradeQuoteStep = {
|
|
|
238
257
|
data: string;
|
|
239
258
|
value: string;
|
|
240
259
|
gasLimit: string;
|
|
260
|
+
isCrossChain?: boolean;
|
|
261
|
+
buyAssetChainId?: ChainId;
|
|
262
|
+
expiry?: number;
|
|
263
|
+
steps?: string[];
|
|
264
|
+
route?: string[];
|
|
241
265
|
};
|
|
242
266
|
bebopTransactionMetadata?: {
|
|
243
267
|
to: Address;
|
|
@@ -274,6 +298,25 @@ export type TradeQuoteStep = {
|
|
|
274
298
|
value: Hex;
|
|
275
299
|
gasLimit: string;
|
|
276
300
|
};
|
|
301
|
+
sunioTransactionMetadata?: {
|
|
302
|
+
route: {
|
|
303
|
+
amountIn: string;
|
|
304
|
+
amountOut: string;
|
|
305
|
+
inUsd: string;
|
|
306
|
+
outUsd: string;
|
|
307
|
+
impact: string;
|
|
308
|
+
fee: string;
|
|
309
|
+
tokens: string[];
|
|
310
|
+
symbols: string[];
|
|
311
|
+
poolFees: string[];
|
|
312
|
+
poolVersions: string[];
|
|
313
|
+
stepAmountsOut: string[];
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
avnuSpecific?: {
|
|
317
|
+
quoteId: string;
|
|
318
|
+
routes: any[];
|
|
319
|
+
};
|
|
277
320
|
};
|
|
278
321
|
export type TradeRateStep = Omit<TradeQuoteStep, 'accountNumber'> & {
|
|
279
322
|
accountNumber: undefined;
|
|
@@ -426,6 +469,12 @@ export type TronTransactionExecutionProps = {
|
|
|
426
469
|
export type SuiTransactionExecutionProps = {
|
|
427
470
|
signAndBroadcastTransaction: (txToSign: SuiSignTx) => Promise<string>;
|
|
428
471
|
};
|
|
472
|
+
export type NearTransactionExecutionProps = {
|
|
473
|
+
signAndBroadcastTransaction: (txToSign: near.NearSignTx) => Promise<string>;
|
|
474
|
+
};
|
|
475
|
+
export type StarknetTransactionExecutionProps = {
|
|
476
|
+
signAndBroadcastTransaction: (txToSign: StarknetSignTx) => Promise<string>;
|
|
477
|
+
};
|
|
429
478
|
type EvmAccountMetadata = {
|
|
430
479
|
from: string;
|
|
431
480
|
};
|
|
@@ -438,6 +487,12 @@ type TronAccountMetadata = {
|
|
|
438
487
|
type SuiAccountMetadata = {
|
|
439
488
|
from: string;
|
|
440
489
|
};
|
|
490
|
+
type NearAccountMetadata = {
|
|
491
|
+
from: string;
|
|
492
|
+
};
|
|
493
|
+
type StarknetAccountMetadata = {
|
|
494
|
+
from: string;
|
|
495
|
+
};
|
|
441
496
|
type UtxoAccountMetadata = {
|
|
442
497
|
senderAddress: string;
|
|
443
498
|
xpub: string;
|
|
@@ -460,6 +515,8 @@ export type GetUnsignedEvmTransactionArgs = CommonGetUnsignedTransactionArgs & E
|
|
|
460
515
|
export type GetUnsignedSolanaTransactionArgs = CommonGetUnsignedTransactionArgs & SolanaAccountMetadata & SolanaSwapperDeps;
|
|
461
516
|
export type GetUnsignedTronTransactionArgs = CommonGetUnsignedTransactionArgs & TronAccountMetadata & TronSwapperDeps;
|
|
462
517
|
export type GetUnsignedSuiTransactionArgs = CommonGetUnsignedTransactionArgs & SuiAccountMetadata & SuiSwapperDeps;
|
|
518
|
+
export type GetUnsignedNearTransactionArgs = CommonGetUnsignedTransactionArgs & NearAccountMetadata & NearSwapperDeps;
|
|
519
|
+
export type GetUnsignedStarknetTransactionArgs = CommonGetUnsignedTransactionArgs & StarknetAccountMetadata & StarknetSwapperDeps;
|
|
463
520
|
export type GetUnsignedEvmMessageArgs = CommonGetUnsignedTransactionArgs & EvmAccountMetadata & Omit<EvmSwapperDeps, 'fetchIsSmartContractAddressQuery'>;
|
|
464
521
|
export type GetUnsignedUtxoTransactionArgs = CommonGetUnsignedTransactionArgs & UtxoAccountMetadata & UtxoSwapperDeps;
|
|
465
522
|
export type GetUnsignedCosmosSdkTransactionArgs = CommonGetUnsignedTransactionArgs & CosmosSdkAccountMetadata & CosmosSdkSwapperDeps;
|
|
@@ -478,7 +535,7 @@ export type CheckTradeStatusInput = {
|
|
|
478
535
|
stepIndex: SupportedTradeQuoteStepIndex;
|
|
479
536
|
config: SwapperConfig;
|
|
480
537
|
swap: Swap | undefined;
|
|
481
|
-
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & SuiSwapperDeps;
|
|
538
|
+
} & EvmSwapperDeps & UtxoSwapperDeps & CosmosSdkSwapperDeps & SolanaSwapperDeps & TronSwapperDeps & SuiSwapperDeps & NearSwapperDeps & StarknetSwapperDeps;
|
|
482
539
|
export type TradeStatus = {
|
|
483
540
|
status: TxStatus;
|
|
484
541
|
buyTxHash: string | undefined;
|
|
@@ -499,6 +556,8 @@ export type Swapper = {
|
|
|
499
556
|
executeSolanaTransaction?: (txToSign: SolanaSignTx, callbacks: SolanaTransactionExecutionProps) => Promise<string>;
|
|
500
557
|
executeTronTransaction?: (txToSign: tron.TronSignTx, callbacks: TronTransactionExecutionProps) => Promise<string>;
|
|
501
558
|
executeSuiTransaction?: (txToSign: SuiSignTx, callbacks: SuiTransactionExecutionProps) => Promise<string>;
|
|
559
|
+
executeNearTransaction?: (txToSign: near.NearSignTx, callbacks: NearTransactionExecutionProps) => Promise<string>;
|
|
560
|
+
executeStarknetTransaction?: (txToSign: StarknetSignTx, callbacks: StarknetTransactionExecutionProps) => Promise<string>;
|
|
502
561
|
};
|
|
503
562
|
export type SwapperApi = {
|
|
504
563
|
checkTradeStatus: (input: CheckTradeStatusInput) => Promise<TradeStatus>;
|
|
@@ -512,12 +571,16 @@ export type SwapperApi = {
|
|
|
512
571
|
getUnsignedSolanaTransaction?: (input: GetUnsignedSolanaTransactionArgs) => Promise<SolanaSignTx>;
|
|
513
572
|
getUnsignedTronTransaction?: (input: GetUnsignedTronTransactionArgs) => Promise<tron.TronSignTx>;
|
|
514
573
|
getUnsignedSuiTransaction?: (input: GetUnsignedSuiTransactionArgs) => Promise<SuiSignTx>;
|
|
574
|
+
getUnsignedNearTransaction?: (input: GetUnsignedNearTransactionArgs) => Promise<near.NearSignTx>;
|
|
575
|
+
getUnsignedStarknetTransaction?: (input: GetUnsignedStarknetTransactionArgs) => Promise<StarknetSignTx>;
|
|
515
576
|
getEvmTransactionFees?: (input: GetUnsignedEvmTransactionArgs) => Promise<string>;
|
|
516
577
|
getSolanaTransactionFees?: (input: GetUnsignedSolanaTransactionArgs) => Promise<string>;
|
|
517
578
|
getSuiTransactionFees?: (input: GetUnsignedSuiTransactionArgs) => Promise<string>;
|
|
518
579
|
getUtxoTransactionFees?: (input: GetUnsignedUtxoTransactionArgs) => Promise<string>;
|
|
519
580
|
getCosmosSdkTransactionFees?: (input: GetUnsignedCosmosSdkTransactionArgs) => Promise<string>;
|
|
520
581
|
getTronTransactionFees?: (input: GetUnsignedTronTransactionArgs) => Promise<string>;
|
|
582
|
+
getNearTransactionFees?: (input: GetUnsignedNearTransactionArgs) => Promise<string>;
|
|
583
|
+
getStarknetTransactionFees?: (input: GetUnsignedStarknetTransactionArgs) => Promise<string>;
|
|
521
584
|
};
|
|
522
585
|
export type QuoteResult = Result<TradeQuote[], SwapErrorRight> & {
|
|
523
586
|
swapperName: SwapperName;
|
|
@@ -542,6 +605,8 @@ export type CosmosSdkTransactionExecutionInput = CommonTradeExecutionInput & Cos
|
|
|
542
605
|
export type SolanaTransactionExecutionInput = CommonTradeExecutionInput & SolanaTransactionExecutionProps & SolanaAccountMetadata;
|
|
543
606
|
export type TronTransactionExecutionInput = CommonTradeExecutionInput & TronTransactionExecutionProps & TronAccountMetadata;
|
|
544
607
|
export type SuiTransactionExecutionInput = CommonTradeExecutionInput & SuiTransactionExecutionProps & SuiAccountMetadata;
|
|
608
|
+
export type NearTransactionExecutionInput = CommonTradeExecutionInput & NearTransactionExecutionProps & NearAccountMetadata;
|
|
609
|
+
export type StarknetTransactionExecutionInput = CommonTradeExecutionInput & StarknetTransactionExecutionProps & StarknetAccountMetadata;
|
|
545
610
|
export declare enum TradeExecutionEvent {
|
|
546
611
|
SellTxHash = "sellTxHash",
|
|
547
612
|
RelayerTxHash = "relayerTxHash",
|
package/dist/esm/types.js
CHANGED
|
@@ -14,6 +14,8 @@ export var SwapperName;
|
|
|
14
14
|
SwapperName["Bebop"] = "Bebop";
|
|
15
15
|
SwapperName["NearIntents"] = "NEAR Intents";
|
|
16
16
|
SwapperName["Cetus"] = "Cetus";
|
|
17
|
+
SwapperName["Sunio"] = "Sun.io";
|
|
18
|
+
SwapperName["Avnu"] = "AVNU";
|
|
17
19
|
})(SwapperName || (SwapperName = {}));
|
|
18
20
|
export var TradeQuoteError;
|
|
19
21
|
(function (TradeQuoteError) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import type { Asset } from '@shapeshiftoss/types';
|
|
3
3
|
import type { Address, Hex } from 'viem';
|
|
4
|
-
import type { TenderlyConfig } from './types.js';
|
|
4
|
+
import type { TenderlyConfig, TenderlyInternalTransaction } from './types.js';
|
|
5
5
|
export type SimulationResult = {
|
|
6
6
|
success: boolean;
|
|
7
7
|
gasUsed: bigint;
|
|
@@ -16,5 +16,10 @@ export type SimulateTransactionParams = {
|
|
|
16
16
|
value?: string | bigint;
|
|
17
17
|
sellAsset: Asset;
|
|
18
18
|
spenderAddress?: Address;
|
|
19
|
+
gas?: number;
|
|
19
20
|
};
|
|
20
21
|
export declare const simulateWithStateOverrides: (params: SimulateTransactionParams, config: TenderlyConfig) => Promise<SimulationResult>;
|
|
22
|
+
export declare const fetchInternalTransactions: (params: {
|
|
23
|
+
chainId: ChainId;
|
|
24
|
+
txHash: string;
|
|
25
|
+
}, config: TenderlyConfig) => Promise<TenderlyInternalTransaction[]>;
|
|
@@ -5,7 +5,7 @@ import { isAddress, maxUint256, parseEther, toHex } from 'viem';
|
|
|
5
5
|
import { isNativeEvmAsset } from '../../swappers/utils/helpers/helpers.js';
|
|
6
6
|
import { getAllowanceStorageSlot, getBalanceStorageSlot, getMaxBalanceValue, getTokenAllowanceSlot, getTokenBalanceSlot, } from './storageSlots.js';
|
|
7
7
|
export const simulateWithStateOverrides = async (params, config) => {
|
|
8
|
-
const { chainId, from, to, data, value, sellAsset, spenderAddress } = params;
|
|
8
|
+
const { chainId, from, to, data, value, sellAsset, spenderAddress, gas } = params;
|
|
9
9
|
try {
|
|
10
10
|
if (!isAddress(from))
|
|
11
11
|
throw new Error(`Invalid from address: ${from}`);
|
|
@@ -23,6 +23,7 @@ export const simulateWithStateOverrides = async (params, config) => {
|
|
|
23
23
|
from: from.toLowerCase(),
|
|
24
24
|
to: to.toLowerCase(),
|
|
25
25
|
input: data,
|
|
26
|
+
gas,
|
|
26
27
|
value: value ? toHex(BigInt(value)) : '0x0',
|
|
27
28
|
save: false,
|
|
28
29
|
state_objects: stateOverrides,
|
|
@@ -62,6 +63,24 @@ export const simulateWithStateOverrides = async (params, config) => {
|
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
};
|
|
66
|
+
export const fetchInternalTransactions = async (params, config) => {
|
|
67
|
+
const { chainId, txHash } = params;
|
|
68
|
+
try {
|
|
69
|
+
const evmNetworkId = Number(fromChainId(chainId).chainReference);
|
|
70
|
+
const url = `https://api.tenderly.co/api/v1/account/${config.accountSlug}/project/${config.projectSlug}/transactions/by-hash/${evmNetworkId}/${txHash}`;
|
|
71
|
+
const response = await axios.get(url, {
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
'X-Access-Key': config.apiKey,
|
|
75
|
+
},
|
|
76
|
+
timeout: 10000,
|
|
77
|
+
});
|
|
78
|
+
return response.data.transaction.internal_transactions ?? [];
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
};
|
|
65
84
|
const buildStateOverrides = (params) => {
|
|
66
85
|
const { from, spender, sellAsset } = params;
|
|
67
86
|
// Large native balance for gas (1B is overkill but guarantees success on all chains)
|
|
@@ -54,3 +54,24 @@ export type TenderlyConfig = {
|
|
|
54
54
|
accountSlug: string;
|
|
55
55
|
projectSlug: string;
|
|
56
56
|
};
|
|
57
|
+
export type TenderlyInternalTransaction = {
|
|
58
|
+
from: Address;
|
|
59
|
+
to: Address;
|
|
60
|
+
value: string;
|
|
61
|
+
};
|
|
62
|
+
export type TenderlyTransactionResponse = {
|
|
63
|
+
transaction: {
|
|
64
|
+
hash: string;
|
|
65
|
+
block_number: number;
|
|
66
|
+
from: Address;
|
|
67
|
+
to: Address;
|
|
68
|
+
input: string;
|
|
69
|
+
value: string;
|
|
70
|
+
gas: number;
|
|
71
|
+
gas_used: number;
|
|
72
|
+
gas_price: string;
|
|
73
|
+
status: boolean;
|
|
74
|
+
error_message?: string;
|
|
75
|
+
internal_transactions?: TenderlyInternalTransaction[];
|
|
76
|
+
};
|
|
77
|
+
};
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import type { EvmChainAdapter, SignTx, solana, sui } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import type { SolanaSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
2
|
+
import type { EvmChainAdapter, near, SignTx, solana, starknet, sui } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import type { SolanaSignTx, StarknetSignTx, SuiSignTx } from '@shapeshiftoss/hdwallet-core';
|
|
4
4
|
import type { Asset, EvmChainId } from '@shapeshiftoss/types';
|
|
5
5
|
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
6
6
|
import type { Result } from '@sniptt/monads';
|
|
7
7
|
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
8
|
-
import type { TronSignTx } from '
|
|
9
|
-
import type { EvmTransactionExecutionProps, ExecutableTradeStep, SolanaTransactionExecutionProps, SuiTransactionExecutionProps, SupportedTradeQuoteStepIndex, SwapErrorRight, TradeQuote, TradeQuoteStep, TradeRate, TradeStatus, TronTransactionExecutionProps } from './types.js';
|
|
8
|
+
import type { TronSignTx } from '@shapeshiftoss/chain-adapters/src/tron/types';
|
|
9
|
+
import type { EvmTransactionExecutionProps, ExecutableTradeStep, NearTransactionExecutionProps, SolanaTransactionExecutionProps, StarknetTransactionExecutionProps, SuiTransactionExecutionProps, SupportedTradeQuoteStepIndex, SwapErrorRight, TradeQuote, TradeQuoteStep, TradeRate, TradeStatus, TronTransactionExecutionProps } from './types.js';
|
|
10
10
|
import { TradeQuoteError } from './types.js';
|
|
11
11
|
export declare const makeSwapErrorRight: ({ details, cause, code, message, }: {
|
|
12
12
|
message: string;
|
|
@@ -30,6 +30,8 @@ export declare const executeEvmTransaction: (txToSign: SignTx<EvmChainId>, callb
|
|
|
30
30
|
export declare const executeSolanaTransaction: (txToSign: SolanaSignTx, callbacks: SolanaTransactionExecutionProps) => Promise<string>;
|
|
31
31
|
export declare const executeTronTransaction: (txToSign: TronSignTx, callbacks: TronTransactionExecutionProps) => Promise<string>;
|
|
32
32
|
export declare const executeSuiTransaction: (txToSign: SuiSignTx, callbacks: SuiTransactionExecutionProps) => Promise<string>;
|
|
33
|
+
export declare const executeNearTransaction: (txToSign: near.NearSignTx, callbacks: NearTransactionExecutionProps) => Promise<string>;
|
|
34
|
+
export declare const executeStarknetTransaction: (txToSign: StarknetSignTx, callbacks: StarknetTransactionExecutionProps) => Promise<string>;
|
|
33
35
|
export declare const createDefaultStatusResponse: (buyTxHash?: string) => {
|
|
34
36
|
status: TxStatus;
|
|
35
37
|
buyTxHash: string | undefined;
|
|
@@ -68,3 +70,7 @@ export declare const checkSuiSwapStatus: ({ txHash, address, assertGetSuiChainAd
|
|
|
68
70
|
address: string | undefined;
|
|
69
71
|
assertGetSuiChainAdapter: (chainId: ChainId) => sui.ChainAdapter;
|
|
70
72
|
}) => Promise<TradeStatus>;
|
|
73
|
+
export declare const checkStarknetSwapStatus: ({ txHash, assertGetStarknetChainAdapter, }: {
|
|
74
|
+
txHash: string;
|
|
75
|
+
assertGetStarknetChainAdapter: (chainId: ChainId) => starknet.ChainAdapter;
|
|
76
|
+
}) => Promise<TradeStatus>;
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { solanaChainId, suiChainId } from '@shapeshiftoss/caip';
|
|
1
|
+
import { solanaChainId, starknetChainId, suiChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { evm, TxStatus } from '@shapeshiftoss/unchained-client';
|
|
3
3
|
import { bn, fromBaseUnit } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
@@ -89,6 +89,12 @@ export const executeTronTransaction = (txToSign, callbacks) => {
|
|
|
89
89
|
export const executeSuiTransaction = (txToSign, callbacks) => {
|
|
90
90
|
return callbacks.signAndBroadcastTransaction(txToSign);
|
|
91
91
|
};
|
|
92
|
+
export const executeNearTransaction = (txToSign, callbacks) => {
|
|
93
|
+
return callbacks.signAndBroadcastTransaction(txToSign);
|
|
94
|
+
};
|
|
95
|
+
export const executeStarknetTransaction = (txToSign, callbacks) => {
|
|
96
|
+
return callbacks.signAndBroadcastTransaction(txToSign);
|
|
97
|
+
};
|
|
92
98
|
export const createDefaultStatusResponse = (buyTxHash) => ({
|
|
93
99
|
status: TxStatus.Unknown,
|
|
94
100
|
buyTxHash,
|
|
@@ -197,9 +203,52 @@ export const checkSuiSwapStatus = async ({ txHash, address, assertGetSuiChainAda
|
|
|
197
203
|
digest: txHash,
|
|
198
204
|
options: {
|
|
199
205
|
showEffects: true,
|
|
206
|
+
showBalanceChanges: true,
|
|
200
207
|
},
|
|
201
208
|
});
|
|
202
209
|
const status = txResponse.effects?.status?.status === 'success' ? TxStatus.Confirmed : TxStatus.Failed;
|
|
210
|
+
// Extract actual buy amount from balance changes
|
|
211
|
+
let actualBuyAmountCryptoBaseUnit;
|
|
212
|
+
if (txResponse.balanceChanges) {
|
|
213
|
+
// Balance changes show the net effect on the user's balances
|
|
214
|
+
// Positive amounts are received, negative are sent
|
|
215
|
+
const receivedChanges = txResponse.balanceChanges.filter(change => {
|
|
216
|
+
// The owner field is a discriminated union - check for AddressOwner variant
|
|
217
|
+
// Handle both object and string cases
|
|
218
|
+
const ownerAddress = change.owner && typeof change.owner === 'object' && 'AddressOwner' in change.owner
|
|
219
|
+
? change.owner.AddressOwner
|
|
220
|
+
: change.owner && typeof change.owner === 'object' && 'ObjectOwner' in change.owner
|
|
221
|
+
? change.owner.ObjectOwner
|
|
222
|
+
: null;
|
|
223
|
+
return ownerAddress === address && Number(change.amount) > 0;
|
|
224
|
+
});
|
|
225
|
+
if (receivedChanges.length > 0) {
|
|
226
|
+
// For swaps, we expect exactly one positive balance change (the buy asset)
|
|
227
|
+
actualBuyAmountCryptoBaseUnit = receivedChanges[0].amount;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
status,
|
|
232
|
+
buyTxHash: txHash,
|
|
233
|
+
message: undefined,
|
|
234
|
+
actualBuyAmountCryptoBaseUnit,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
console.error(e);
|
|
239
|
+
return createDefaultStatusResponse(txHash);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
export const checkStarknetSwapStatus = async ({ txHash, assertGetStarknetChainAdapter, }) => {
|
|
243
|
+
try {
|
|
244
|
+
const adapter = assertGetStarknetChainAdapter(starknetChainId);
|
|
245
|
+
const provider = adapter.getStarknetProvider();
|
|
246
|
+
const receipt = await provider.getTransactionReceipt(txHash);
|
|
247
|
+
const status = receipt.execution_status === 'SUCCEEDED'
|
|
248
|
+
? TxStatus.Confirmed
|
|
249
|
+
: receipt.execution_status === 'REVERTED'
|
|
250
|
+
? TxStatus.Failed
|
|
251
|
+
: TxStatus.Pending;
|
|
203
252
|
return {
|
|
204
253
|
status,
|
|
205
254
|
buyTxHash: txHash,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swapper",
|
|
3
|
-
"version": "17.6.
|
|
3
|
+
"version": "17.6.9",
|
|
4
4
|
"packageManager": "yarn@3.5.0",
|
|
5
5
|
"repository": "https://github.com/shapeshift/web",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@arbitrum/sdk": "^4.0.1",
|
|
34
|
+
"@avnu/avnu-sdk": "^4.0.1",
|
|
34
35
|
"@coral-xyz/anchor": "0.29.0",
|
|
35
36
|
"@cowprotocol/app-data": "^2.3.0",
|
|
36
37
|
"@defuse-protocol/one-click-sdk-typescript": "^0.1.1-0.2",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"@shapeshiftoss/caip": "^8.16.5",
|
|
40
41
|
"@shapeshiftoss/chain-adapters": "^11.3.6",
|
|
41
42
|
"@shapeshiftoss/contracts": "^1.0.4",
|
|
42
|
-
"@shapeshiftoss/hdwallet-core": "1.62.
|
|
43
|
+
"@shapeshiftoss/hdwallet-core": "1.62.39",
|
|
43
44
|
"@shapeshiftoss/types": "^8.6.5",
|
|
44
45
|
"@shapeshiftoss/unchained-client": "^10.14.8",
|
|
45
46
|
"@shapeshiftoss/utils": "^1.0.4",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"@uniswap/sdk-core": "^5.3.1",
|
|
49
50
|
"@uniswap/v3-sdk": "^3.13.1",
|
|
50
51
|
"axios": "^1.13.0",
|
|
51
|
-
"axios-cache-interceptor": "^1.
|
|
52
|
+
"axios-cache-interceptor": "^1.11.1",
|
|
52
53
|
"bignumber.js": "^9.3.1",
|
|
53
54
|
"eip-712": "^1.0.0",
|
|
54
55
|
"ethers": "6.11.1",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"mixpanel-browser": "^2.67.0",
|
|
58
59
|
"node-polyglot": "^2.4.0",
|
|
59
60
|
"pretty-ms": "7.0.1",
|
|
60
|
-
"qs": "^6.
|
|
61
|
+
"qs": "^6.14.1",
|
|
61
62
|
"retry-axios": "^2.6.0",
|
|
62
63
|
"uuid": "^9.0.0",
|
|
63
64
|
"viem": "^2.40.3"
|