@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
|
@@ -28,16 +28,10 @@ async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swapperConf
|
|
|
28
28
|
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
29
29
|
message: `unsupported chainId`,
|
|
30
30
|
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
31
|
-
details: { chainId:
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
if (sellAssetChainId !== buyAssetChainId) {
|
|
35
|
-
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
36
|
-
message: `cross-chain not supported - both assets must be on chainId ${sellAsset.chainId}`,
|
|
37
|
-
code: types_1.TradeQuoteError.CrossChainNotSupported,
|
|
38
|
-
details: { buyAsset, sellAsset },
|
|
31
|
+
details: { chainId: buyAsset.chainId },
|
|
39
32
|
}));
|
|
40
33
|
}
|
|
34
|
+
const isCrossChain = sellAssetChainId !== buyAssetChainId;
|
|
41
35
|
// Not a decimal percentage, just a good ol' percentage e.g 1 for 1%
|
|
42
36
|
const affiliateBpsPercentage = (0, utils_1.convertBasisPointsToDecimalPercentage)(affiliateBps)
|
|
43
37
|
.times(100)
|
|
@@ -49,12 +43,20 @@ async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swapperConf
|
|
|
49
43
|
.toNumber();
|
|
50
44
|
if (!sendAddress)
|
|
51
45
|
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({ message: 'missing sendAddress' }));
|
|
52
|
-
const
|
|
53
|
-
|
|
46
|
+
const sellPortalsNetwork = constants_1.chainIdToPortalsNetwork[sellAssetChainId];
|
|
47
|
+
const buyPortalsNetwork = constants_1.chainIdToPortalsNetwork[buyAssetChainId];
|
|
48
|
+
if (!sellPortalsNetwork) {
|
|
49
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
50
|
+
message: `unsupported ChainId`,
|
|
51
|
+
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
52
|
+
details: { chainId: sellAssetChainId },
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
if (!buyPortalsNetwork) {
|
|
54
56
|
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
55
57
|
message: `unsupported ChainId`,
|
|
56
58
|
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
57
|
-
details: { chainId:
|
|
59
|
+
details: { chainId: buyAssetChainId },
|
|
58
60
|
}));
|
|
59
61
|
}
|
|
60
62
|
const sellAssetAddress = (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId)
|
|
@@ -63,8 +65,8 @@ async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swapperConf
|
|
|
63
65
|
const buyAssetAddress = (0, helpers_1.isNativeEvmAsset)(buyAsset.assetId)
|
|
64
66
|
? viem_1.zeroAddress
|
|
65
67
|
: (0, caip_1.fromAssetId)(buyAsset.assetId).assetReference;
|
|
66
|
-
const inputToken = `${
|
|
67
|
-
const outputToken = `${
|
|
68
|
+
const inputToken = `${sellPortalsNetwork}:${sellAssetAddress}`;
|
|
69
|
+
const outputToken = `${buyPortalsNetwork}:${buyAssetAddress}`;
|
|
68
70
|
try {
|
|
69
71
|
const maybePortalsTradeOrderResponse = await (0, fetchPortalsTradeOrder_1.fetchPortalsTradeOrder)({
|
|
70
72
|
sender: sendAddress,
|
|
@@ -130,7 +132,9 @@ async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swapperConf
|
|
|
130
132
|
if (maybePortalsTradeOrderResponse.isErr())
|
|
131
133
|
return (0, monads_1.Err)(maybePortalsTradeOrderResponse.unwrapErr());
|
|
132
134
|
const portalsTradeOrderResponse = maybePortalsTradeOrderResponse.unwrap();
|
|
133
|
-
const { context: { orderId, outputAmount
|
|
135
|
+
const { context: { orderId, outputAmount, minOutputAmount, target, feeAmount, gasLimit, feeToken }, tx, } = portalsTradeOrderResponse;
|
|
136
|
+
const allowanceContract = isCrossChain ? target : (0, helpers_2.getPortalsRouterAddressByChainId)(chainId);
|
|
137
|
+
const buyAmountAfterFeesCryptoBaseUnit = isCrossChain ? minOutputAmount : outputAmount;
|
|
134
138
|
const protocolFeeAsset = feeToken === inputToken ? sellAsset : buyAsset;
|
|
135
139
|
if (!tx)
|
|
136
140
|
throw new Error('Portals Tx simulation failed upstream');
|
|
@@ -189,9 +193,17 @@ async function getPortalsTradeQuote(input, assertGetEvmChainAdapter, swapperConf
|
|
|
189
193
|
},
|
|
190
194
|
},
|
|
191
195
|
source: types_1.SwapperName.Portals,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
196
|
+
estimatedExecutionTimeMs: isCrossChain ? 300000 : 0,
|
|
197
|
+
portalsTransactionMetadata: {
|
|
198
|
+
...tx,
|
|
199
|
+
isCrossChain,
|
|
200
|
+
buyAssetChainId: isCrossChain ? buyAssetChainId : undefined,
|
|
201
|
+
expiry: portalsTradeOrderResponse.context.expiry
|
|
202
|
+
? Number(portalsTradeOrderResponse.context.expiry)
|
|
203
|
+
: undefined,
|
|
204
|
+
steps: portalsTradeOrderResponse.context.steps,
|
|
205
|
+
route: portalsTradeOrderResponse.context.route,
|
|
206
|
+
},
|
|
195
207
|
},
|
|
196
208
|
],
|
|
197
209
|
};
|
|
@@ -34,22 +34,24 @@ async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapperConfi
|
|
|
34
34
|
details: { chainId: sellAsset.chainId },
|
|
35
35
|
}));
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
39
|
-
message: `cross-chain not supported - both assets must be on chainId ${sellAsset.chainId}`,
|
|
40
|
-
code: types_1.TradeQuoteError.CrossChainNotSupported,
|
|
41
|
-
details: { buyAsset, sellAsset },
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
37
|
+
const isCrossChain = sellAssetChainId !== buyAssetChainId;
|
|
44
38
|
try {
|
|
45
39
|
if (!(0, helpers_2.isSupportedChainId)(chainId))
|
|
46
40
|
throw new Error(`Unsupported chainId ${sellAsset.chainId}`);
|
|
47
|
-
const
|
|
48
|
-
|
|
41
|
+
const sellPortalsNetwork = constants_1.chainIdToPortalsNetwork[sellAssetChainId];
|
|
42
|
+
const buyPortalsNetwork = constants_1.chainIdToPortalsNetwork[buyAssetChainId];
|
|
43
|
+
if (!sellPortalsNetwork) {
|
|
44
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
45
|
+
message: `unsupported ChainId`,
|
|
46
|
+
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
47
|
+
details: { chainId: sellAssetChainId },
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
if (!buyPortalsNetwork) {
|
|
49
51
|
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
50
52
|
message: `unsupported ChainId`,
|
|
51
53
|
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
52
|
-
details: { chainId:
|
|
54
|
+
details: { chainId: buyAssetChainId },
|
|
53
55
|
}));
|
|
54
56
|
}
|
|
55
57
|
const sellAssetAddress = (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId)
|
|
@@ -58,8 +60,8 @@ async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapperConfi
|
|
|
58
60
|
const buyAssetAddress = (0, helpers_1.isNativeEvmAsset)(buyAsset.assetId)
|
|
59
61
|
? viem_1.zeroAddress
|
|
60
62
|
: (0, caip_1.fromAssetId)(buyAsset.assetId).assetReference;
|
|
61
|
-
const inputToken = `${
|
|
62
|
-
const outputToken = `${
|
|
63
|
+
const inputToken = `${sellPortalsNetwork}:${sellAssetAddress}`;
|
|
64
|
+
const outputToken = `${buyPortalsNetwork}:${buyAssetAddress}`;
|
|
63
65
|
const userSlippageTolerancePercentageDecimalOrDefault = input.slippageTolerancePercentageDecimal
|
|
64
66
|
? (0, utils_1.bnOrZero)(input.slippageTolerancePercentageDecimal).times(100).toNumber()
|
|
65
67
|
: (0, utils_1.bnOrZero)((0, __1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.Portals))
|
|
@@ -89,15 +91,18 @@ async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapperConfi
|
|
|
89
91
|
throw new Error('Portals quote response missing transaction data');
|
|
90
92
|
}
|
|
91
93
|
const { context, tx } = quoteResponse;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
const buyAmountAfterFeesCryptoBaseUnit = isCrossChain
|
|
95
|
+
? context.minOutputAmount
|
|
96
|
+
: context.outputAmount;
|
|
94
97
|
const inputOutputRate = (0, utils_2.getInputOutputRate)({
|
|
95
98
|
sellAmountCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
96
99
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
97
100
|
sellAsset,
|
|
98
101
|
buyAsset,
|
|
99
102
|
});
|
|
100
|
-
const allowanceContract =
|
|
103
|
+
const allowanceContract = isCrossChain
|
|
104
|
+
? context.target
|
|
105
|
+
: (0, helpers_2.getPortalsRouterAddressByChainId)(chainId);
|
|
101
106
|
// Don't use Portals' slippageTolerancePercentage field (it's a price indicator, not actual buffer)
|
|
102
107
|
// Instead, calculate the actual buffer Portals applied from the amounts
|
|
103
108
|
const actualBufferDecimal = (0, utils_1.bnOrZero)(context.outputAmount)
|
|
@@ -153,8 +158,7 @@ async function getPortalsTradeRate(input, assertGetEvmChainAdapter, swapperConfi
|
|
|
153
158
|
swapperName: types_1.SwapperName.Portals,
|
|
154
159
|
steps: [
|
|
155
160
|
{
|
|
156
|
-
|
|
157
|
-
estimatedExecutionTimeMs: 0,
|
|
161
|
+
estimatedExecutionTimeMs: isCrossChain ? 300000 : 0,
|
|
158
162
|
allowanceContract,
|
|
159
163
|
accountNumber,
|
|
160
164
|
rate: inputOutputRate,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { SwapErrorRight } from '../../../types';
|
|
3
|
+
export type AxelarscanBridgeStatus = {
|
|
4
|
+
status: 'pending' | 'confirmed' | 'failed';
|
|
5
|
+
destinationTxHash?: string;
|
|
6
|
+
errorMessage?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const fetchAxelarscanBridgeStatus: (sourceTxHash: string) => Promise<Result<AxelarscanBridgeStatus | undefined, SwapErrorRight>>;
|
|
9
|
+
export declare const getAxelarscanTrackingLink: (sourceTxHash: string) => string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAxelarscanTrackingLink = exports.fetchAxelarscanBridgeStatus = void 0;
|
|
4
|
+
const monads_1 = require("@sniptt/monads");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
const fetchAxelarscanBridgeStatus = async (sourceTxHash) => {
|
|
7
|
+
try {
|
|
8
|
+
const response = await fetch(`https://api.axelarscan.io/gmp/searchGMP?txHash=${sourceTxHash}`);
|
|
9
|
+
if (!response.ok) {
|
|
10
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
11
|
+
message: `Axelarscan API error: ${response.statusText}`,
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
const data = await response.json();
|
|
15
|
+
if (!data.data || data.data.length === 0) {
|
|
16
|
+
return (0, monads_1.Ok)(undefined);
|
|
17
|
+
}
|
|
18
|
+
const bridgeData = data.data[0];
|
|
19
|
+
const destinationTxHash = bridgeData.call?.transaction_hash ||
|
|
20
|
+
bridgeData.executed?.transaction_hash ||
|
|
21
|
+
bridgeData.express_executed?.transactionHash;
|
|
22
|
+
const isCompleted = bridgeData.status === 'executed' ||
|
|
23
|
+
bridgeData.status === 'destination_executed' ||
|
|
24
|
+
bridgeData.status === 'express_executed' ||
|
|
25
|
+
bridgeData.simplified_status === 'received' ||
|
|
26
|
+
!!destinationTxHash;
|
|
27
|
+
if (isCompleted) {
|
|
28
|
+
return (0, monads_1.Ok)({
|
|
29
|
+
status: 'confirmed',
|
|
30
|
+
destinationTxHash,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (bridgeData.status === 'error') {
|
|
34
|
+
return (0, monads_1.Ok)({
|
|
35
|
+
status: 'failed',
|
|
36
|
+
errorMessage: bridgeData.error?.message || 'Bridge failed',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return (0, monads_1.Ok)({
|
|
40
|
+
status: 'pending',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
45
|
+
message: 'Failed to fetch Axelarscan bridge status',
|
|
46
|
+
cause: error,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.fetchAxelarscanBridgeStatus = fetchAxelarscanBridgeStatus;
|
|
51
|
+
const getAxelarscanTrackingLink = (sourceTxHash) => `https://axelarscan.io/gmp/${sourceTxHash}`;
|
|
52
|
+
exports.getAxelarscanTrackingLink = getAxelarscanTrackingLink;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import type { Result } from '@sniptt/monads';
|
|
3
|
+
import type { SwapErrorRight } from '../../../types';
|
|
4
|
+
export type SquidBridgeStatus = {
|
|
5
|
+
status: 'pending' | 'confirmed' | 'failed';
|
|
6
|
+
destinationTxHash?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const fetchSquidBridgeStatus: (sourceTxHash: string, sourceChainId: ChainId, destinationChainId: ChainId) => Promise<Result<SquidBridgeStatus, SwapErrorRight>>;
|
|
9
|
+
export declare const getSquidTrackingLink: (sourceTxHash: string, squidStatus: SquidBridgeStatus, sellAssetExplorerTxLink: string, buyAssetExplorerTxLink: string) => string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSquidTrackingLink = exports.fetchSquidBridgeStatus = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const monads_1 = require("@sniptt/monads");
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const fetchSquidBridgeStatus = async (sourceTxHash, sourceChainId, destinationChainId) => {
|
|
8
|
+
try {
|
|
9
|
+
const fromChain = (0, caip_1.fromChainId)(sourceChainId).chainReference;
|
|
10
|
+
const toChain = (0, caip_1.fromChainId)(destinationChainId).chainReference;
|
|
11
|
+
const url = new URL('https://v2.api.squidrouter.com/v2/status');
|
|
12
|
+
url.searchParams.set('transactionId', sourceTxHash);
|
|
13
|
+
url.searchParams.set('fromChainId', fromChain);
|
|
14
|
+
url.searchParams.set('toChainId', toChain);
|
|
15
|
+
const response = await fetch(url.toString(), {
|
|
16
|
+
headers: {
|
|
17
|
+
'x-integrator-id': 'squid-swap-widget',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
22
|
+
message: `Squid API error: ${response.statusText}`,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
const data = await response.json();
|
|
26
|
+
const destinationTxHash = data.toChain?.transactionId;
|
|
27
|
+
if (data.squidTransactionStatus === 'success') {
|
|
28
|
+
return (0, monads_1.Ok)({
|
|
29
|
+
status: 'confirmed',
|
|
30
|
+
destinationTxHash,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (data.squidTransactionStatus === 'partial_success' ||
|
|
34
|
+
data.squidTransactionStatus === 'needs_gas') {
|
|
35
|
+
return (0, monads_1.Ok)({
|
|
36
|
+
status: 'failed',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return (0, monads_1.Ok)({
|
|
40
|
+
status: 'pending',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
45
|
+
message: 'Failed to fetch Squid bridge status',
|
|
46
|
+
cause: error,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.fetchSquidBridgeStatus = fetchSquidBridgeStatus;
|
|
51
|
+
const getSquidTrackingLink = (sourceTxHash, squidStatus, sellAssetExplorerTxLink, buyAssetExplorerTxLink) => {
|
|
52
|
+
if (squidStatus.status === 'confirmed' && squidStatus.destinationTxHash) {
|
|
53
|
+
return `${buyAssetExplorerTxLink}${squidStatus.destinationTxHash}`;
|
|
54
|
+
}
|
|
55
|
+
return `${sellAssetExplorerTxLink}${sourceTxHash}`;
|
|
56
|
+
};
|
|
57
|
+
exports.getSquidTrackingLink = getSquidTrackingLink;
|
|
@@ -25,6 +25,9 @@ exports.chainIdToRelayChainId = {
|
|
|
25
25
|
[caip_1.bscChainId]: chains_1.bsc.id,
|
|
26
26
|
[caip_1.tronChainId]: 728126428,
|
|
27
27
|
[caip_1.monadChainId]: chains_1.monad.id,
|
|
28
|
+
[caip_1.hyperEvmChainId]: chains_1.hyperEvm.id,
|
|
29
|
+
[caip_1.plasmaChainId]: chains_1.plasma.id,
|
|
30
|
+
[caip_1.katanaChainId]: chains_1.katana.id,
|
|
28
31
|
};
|
|
29
32
|
var RelayStatusMessage;
|
|
30
33
|
(function (RelayStatusMessage) {
|
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fetchRelayTrade = void 0;
|
|
4
4
|
const relayService_1 = require("./relayService");
|
|
5
5
|
const fetchRelayTrade = async (params, config) => {
|
|
6
|
-
return await relayService_1.relayService.post(`${config.VITE_RELAY_API_URL}/quote`, params);
|
|
6
|
+
return await relayService_1.relayService.post(`${config.VITE_RELAY_API_URL}/quote/v2`, params);
|
|
7
7
|
};
|
|
8
8
|
exports.fetchRelayTrade = fetchRelayTrade;
|
|
@@ -359,6 +359,10 @@ async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
359
359
|
data: (selectedItem.data.data ?? '0x'),
|
|
360
360
|
value: selectedItem.data.value ?? '0',
|
|
361
361
|
sellAsset,
|
|
362
|
+
// Pass Relay's gas limit to Tenderly for Monad as tenderly return crazy gas
|
|
363
|
+
gas: selectedItem.data.gas && sellAsset.chainId === caip_1.monadChainId
|
|
364
|
+
? Number(selectedItem.data.gas)
|
|
365
|
+
: undefined,
|
|
362
366
|
}, {
|
|
363
367
|
apiKey: deps.config.VITE_TENDERLY_API_KEY,
|
|
364
368
|
accountSlug: deps.config.VITE_TENDERLY_ACCOUNT_SLUG,
|
|
@@ -420,7 +424,8 @@ async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
420
424
|
relayTransactionMetadata: {
|
|
421
425
|
from: sendAddress,
|
|
422
426
|
to: selectedItem.data?.to,
|
|
423
|
-
value
|
|
427
|
+
// v2 API may return value as undefined or empty object for ERC-20 swaps - default to '0'
|
|
428
|
+
value: typeof selectedItem.data?.value === 'string' ? selectedItem.data.value : '0',
|
|
424
429
|
data: selectedItem.data?.data,
|
|
425
430
|
// gas is not documented in the relay docs but refers to gasLimit
|
|
426
431
|
gasLimit: selectedItem.data?.gas,
|
|
@@ -442,6 +447,16 @@ async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
442
447
|
},
|
|
443
448
|
};
|
|
444
449
|
}
|
|
450
|
+
if ((0, types_2.isRelayQuoteTronItemData)(selectedItem.data)) {
|
|
451
|
+
return {
|
|
452
|
+
allowanceContract: '',
|
|
453
|
+
solanaTransactionMetadata: undefined,
|
|
454
|
+
relayTransactionMetadata: {
|
|
455
|
+
relayId: quote.steps[0].requestId,
|
|
456
|
+
to: selectedItem.data?.parameter?.contract_address,
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
}
|
|
445
460
|
throw new Error('Relay quote step contains no data');
|
|
446
461
|
})();
|
|
447
462
|
return {
|
|
@@ -77,6 +77,11 @@ const relayTokenToAssetId = (relayToken) => {
|
|
|
77
77
|
assetReference: caip_1.ASSET_REFERENCE.Base,
|
|
78
78
|
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
79
79
|
};
|
|
80
|
+
case caip_1.CHAIN_REFERENCE.BnbSmartChainMainnet:
|
|
81
|
+
return {
|
|
82
|
+
assetReference: caip_1.ASSET_REFERENCE.BnbSmartChain,
|
|
83
|
+
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
84
|
+
};
|
|
80
85
|
case caip_1.CHAIN_REFERENCE.BitcoinMainnet:
|
|
81
86
|
return {
|
|
82
87
|
assetReference: caip_1.ASSET_REFERENCE.Bitcoin,
|
|
@@ -97,6 +102,21 @@ const relayTokenToAssetId = (relayToken) => {
|
|
|
97
102
|
assetReference: caip_1.ASSET_REFERENCE.Monad,
|
|
98
103
|
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
99
104
|
};
|
|
105
|
+
case caip_1.CHAIN_REFERENCE.HyperEvmMainnet:
|
|
106
|
+
return {
|
|
107
|
+
assetReference: caip_1.ASSET_REFERENCE.HyperEvm,
|
|
108
|
+
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
109
|
+
};
|
|
110
|
+
case caip_1.CHAIN_REFERENCE.PlasmaMainnet:
|
|
111
|
+
return {
|
|
112
|
+
assetReference: caip_1.ASSET_REFERENCE.Plasma,
|
|
113
|
+
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
114
|
+
};
|
|
115
|
+
case caip_1.CHAIN_REFERENCE.KatanaMainnet:
|
|
116
|
+
return {
|
|
117
|
+
assetReference: caip_1.ASSET_REFERENCE.Katana,
|
|
118
|
+
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
119
|
+
};
|
|
100
120
|
default:
|
|
101
121
|
throw Error(`chainId '${relayToken.chainId}' not supported`);
|
|
102
122
|
}
|
|
@@ -104,8 +104,16 @@ export type RelayQuoteSolanaItemData = {
|
|
|
104
104
|
instructions: RelaySolanaInstruction[];
|
|
105
105
|
addressLookupTableAddresses: string[];
|
|
106
106
|
};
|
|
107
|
+
export type RelayQuoteTronItemData = {
|
|
108
|
+
type?: string;
|
|
109
|
+
parameter?: {
|
|
110
|
+
owner_address?: string;
|
|
111
|
+
contract_address?: string;
|
|
112
|
+
data?: string;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
107
115
|
export type RelayQuoteItem = {
|
|
108
|
-
data?: RelayQuoteEvmItemData | RelayQuoteUtxoItemData | RelayQuoteSolanaItemData;
|
|
116
|
+
data?: RelayQuoteEvmItemData | RelayQuoteUtxoItemData | RelayQuoteSolanaItemData | RelayQuoteTronItemData;
|
|
109
117
|
};
|
|
110
118
|
export type RelayQuoteStep = {
|
|
111
119
|
id: string;
|
|
@@ -117,9 +125,10 @@ export type RelayQuote = {
|
|
|
117
125
|
details: QuoteDetails;
|
|
118
126
|
steps: RelayQuoteStep[];
|
|
119
127
|
};
|
|
120
|
-
export declare const isRelayQuoteUtxoItemData: (item: RelayQuoteUtxoItemData | RelayQuoteEvmItemData | RelayQuoteSolanaItemData) => item is RelayQuoteUtxoItemData;
|
|
121
|
-
export declare const isRelayQuoteEvmItemData: (item: RelayQuoteUtxoItemData | RelayQuoteEvmItemData | RelayQuoteSolanaItemData) => item is RelayQuoteEvmItemData;
|
|
122
|
-
export declare const isRelayQuoteSolanaItemData: (item: RelayQuoteUtxoItemData | RelayQuoteEvmItemData | RelayQuoteSolanaItemData) => item is RelayQuoteSolanaItemData;
|
|
128
|
+
export declare const isRelayQuoteUtxoItemData: (item: RelayQuoteUtxoItemData | RelayQuoteEvmItemData | RelayQuoteSolanaItemData | RelayQuoteTronItemData) => item is RelayQuoteUtxoItemData;
|
|
129
|
+
export declare const isRelayQuoteEvmItemData: (item: RelayQuoteUtxoItemData | RelayQuoteEvmItemData | RelayQuoteSolanaItemData | RelayQuoteTronItemData) => item is RelayQuoteEvmItemData;
|
|
130
|
+
export declare const isRelayQuoteSolanaItemData: (item: RelayQuoteUtxoItemData | RelayQuoteEvmItemData | RelayQuoteSolanaItemData | RelayQuoteTronItemData) => item is RelayQuoteSolanaItemData;
|
|
131
|
+
export declare const isRelayQuoteTronItemData: (item: RelayQuoteUtxoItemData | RelayQuoteEvmItemData | RelayQuoteSolanaItemData | RelayQuoteTronItemData) => item is RelayQuoteTronItemData;
|
|
123
132
|
export type RelaySolanaInstruction = {
|
|
124
133
|
keys: {
|
|
125
134
|
pubkey: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRelayError = exports.RelayErrorCode = exports.isRelayQuoteSolanaItemData = exports.isRelayQuoteEvmItemData = exports.isRelayQuoteUtxoItemData = void 0;
|
|
3
|
+
exports.isRelayError = exports.RelayErrorCode = exports.isRelayQuoteTronItemData = exports.isRelayQuoteSolanaItemData = exports.isRelayQuoteEvmItemData = exports.isRelayQuoteUtxoItemData = void 0;
|
|
4
4
|
const isRelayQuoteUtxoItemData = (item) => {
|
|
5
5
|
return 'psbt' in item;
|
|
6
6
|
};
|
|
@@ -13,6 +13,10 @@ const isRelayQuoteSolanaItemData = (item) => {
|
|
|
13
13
|
return 'instructions' in item;
|
|
14
14
|
};
|
|
15
15
|
exports.isRelayQuoteSolanaItemData = isRelayQuoteSolanaItemData;
|
|
16
|
+
const isRelayQuoteTronItemData = (item) => {
|
|
17
|
+
return 'type' in item && 'parameter' in item;
|
|
18
|
+
};
|
|
19
|
+
exports.isRelayQuoteTronItemData = isRelayQuoteTronItemData;
|
|
16
20
|
var RelayErrorCode;
|
|
17
21
|
(function (RelayErrorCode) {
|
|
18
22
|
RelayErrorCode["AmountTooLow"] = "AMOUNT_TOO_LOW";
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sunioApi = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
6
|
+
const unchained_client_1 = require("@shapeshiftoss/unchained-client");
|
|
7
|
+
const tronweb_1 = require("tronweb");
|
|
8
|
+
const getTronTransactionFees_1 = require("../../tron-utils/getTronTransactionFees");
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
10
|
+
const getSunioTradeQuote_1 = require("./getSunioTradeQuote/getSunioTradeQuote");
|
|
11
|
+
const getSunioTradeRate_1 = require("./getSunioTradeRate/getSunioTradeRate");
|
|
12
|
+
const buildSwapRouteParameters_1 = require("./utils/buildSwapRouteParameters");
|
|
13
|
+
const constants_1 = require("./utils/constants");
|
|
14
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
15
|
+
const convertAddressesToEvmFormat = (value) => {
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
return value.map(v => convertAddressesToEvmFormat(v));
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === 'string' && value.startsWith('T') && tronweb_1.TronWeb.isAddress(value)) {
|
|
20
|
+
const hex = tronweb_1.TronWeb.address.toHex(value);
|
|
21
|
+
return hex.replace(/^41/, '0x');
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
exports.sunioApi = {
|
|
26
|
+
getTradeQuote: async (input, deps) => {
|
|
27
|
+
const maybeTradeQuote = await (0, getSunioTradeQuote_1.getSunioTradeQuote)(input, deps);
|
|
28
|
+
return maybeTradeQuote.map(quote => [quote]);
|
|
29
|
+
},
|
|
30
|
+
getTradeRate: async (input, deps) => {
|
|
31
|
+
const maybeTradeRate = await (0, getSunioTradeRate_1.getSunioTradeRate)(input, deps);
|
|
32
|
+
return maybeTradeRate.map(rate => [rate]);
|
|
33
|
+
},
|
|
34
|
+
getUnsignedTronTransaction: async (args) => {
|
|
35
|
+
const { tradeQuote, stepIndex, from, slippageTolerancePercentageDecimal, assertGetTronChainAdapter, } = args;
|
|
36
|
+
if (!(0, utils_1.isExecutableTradeQuote)(tradeQuote)) {
|
|
37
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
38
|
+
}
|
|
39
|
+
const step = (0, utils_1.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
40
|
+
const adapter = assertGetTronChainAdapter(caip_1.tronChainId);
|
|
41
|
+
const sunioMetadata = step.sunioTransactionMetadata;
|
|
42
|
+
if (!sunioMetadata) {
|
|
43
|
+
throw new Error('[Sun.io] Missing transaction metadata in quote');
|
|
44
|
+
}
|
|
45
|
+
const rpcUrl = adapter.httpProvider.getRpcUrl();
|
|
46
|
+
const tronWeb = new tronweb_1.TronWeb({
|
|
47
|
+
fullHost: rpcUrl,
|
|
48
|
+
});
|
|
49
|
+
const routeParams = (0, buildSwapRouteParameters_1.buildSwapRouteParameters)(sunioMetadata.route, step.sellAmountIncludingProtocolFeesCryptoBaseUnit, step.buyAmountAfterFeesCryptoBaseUnit, from, slippageTolerancePercentageDecimal);
|
|
50
|
+
const parameters = [
|
|
51
|
+
{ type: 'address[]', value: routeParams.path },
|
|
52
|
+
{ type: 'string[]', value: routeParams.poolVersion },
|
|
53
|
+
{ type: 'uint256[]', value: routeParams.versionLen },
|
|
54
|
+
{ type: 'uint24[]', value: routeParams.fees },
|
|
55
|
+
{
|
|
56
|
+
type: 'tuple(uint256,uint256,address,uint256)',
|
|
57
|
+
value: convertAddressesToEvmFormat([
|
|
58
|
+
routeParams.swapData.amountIn,
|
|
59
|
+
routeParams.swapData.amountOutMin,
|
|
60
|
+
routeParams.swapData.recipient,
|
|
61
|
+
routeParams.swapData.deadline,
|
|
62
|
+
]),
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
const functionSelector = 'swapExactInput(address[],string[],uint256[],uint24[],(uint256,uint256,address,uint256))';
|
|
66
|
+
const isSellingNativeTrx = step.sellAsset.assetId === caip_1.tronAssetId;
|
|
67
|
+
const callValue = isSellingNativeTrx
|
|
68
|
+
? Number(step.sellAmountIncludingProtocolFeesCryptoBaseUnit)
|
|
69
|
+
: 0;
|
|
70
|
+
const options = {
|
|
71
|
+
feeLimit: 100_000_000,
|
|
72
|
+
callValue,
|
|
73
|
+
};
|
|
74
|
+
const txData = await tronWeb.transactionBuilder.triggerSmartContract(constants_1.SUNIO_SMART_ROUTER_CONTRACT, functionSelector, options, parameters, from);
|
|
75
|
+
if (!txData.result || !txData.result.result) {
|
|
76
|
+
throw new Error('[Sun.io] Failed to build swap transaction');
|
|
77
|
+
}
|
|
78
|
+
const transaction = txData.transaction;
|
|
79
|
+
const rawDataHex = typeof transaction.raw_data_hex === 'string'
|
|
80
|
+
? transaction.raw_data_hex
|
|
81
|
+
: Buffer.isBuffer(transaction.raw_data_hex)
|
|
82
|
+
? transaction.raw_data_hex.toString('hex')
|
|
83
|
+
: Array.isArray(transaction.raw_data_hex)
|
|
84
|
+
? Buffer.from(transaction.raw_data_hex).toString('hex')
|
|
85
|
+
: (() => {
|
|
86
|
+
throw new Error(`Unexpected raw_data_hex type: ${typeof transaction.raw_data_hex}`);
|
|
87
|
+
})();
|
|
88
|
+
if (!/^[0-9a-fA-F]+$/.test(rawDataHex)) {
|
|
89
|
+
throw new Error(`Invalid raw_data_hex format: ${rawDataHex.slice(0, 100)}`);
|
|
90
|
+
}
|
|
91
|
+
const accountNumber = step.accountNumber;
|
|
92
|
+
if (accountNumber === undefined) {
|
|
93
|
+
throw new Error('[Sun.io] accountNumber is required for execution');
|
|
94
|
+
}
|
|
95
|
+
const bip44Params = adapter.getBip44Params({ accountNumber });
|
|
96
|
+
const addressNList = (0, chain_adapters_1.toAddressNList)(bip44Params);
|
|
97
|
+
return {
|
|
98
|
+
addressNList,
|
|
99
|
+
rawDataHex,
|
|
100
|
+
transaction,
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
getTronTransactionFees: getTronTransactionFees_1.getTronTransactionFees,
|
|
104
|
+
checkTradeStatus: async ({ txHash, assertGetTronChainAdapter }) => {
|
|
105
|
+
try {
|
|
106
|
+
// Wait for TronGrid indexing to avoid false "REVERT"
|
|
107
|
+
await sleep(2000);
|
|
108
|
+
const adapter = assertGetTronChainAdapter(caip_1.tronChainId);
|
|
109
|
+
const tx = await adapter.httpProvider.getTransaction({ txid: txHash });
|
|
110
|
+
if (!tx) {
|
|
111
|
+
return (0, utils_1.createDefaultStatusResponse)(txHash);
|
|
112
|
+
}
|
|
113
|
+
const contractRet = tx.ret?.[0]?.contractRet;
|
|
114
|
+
// Only mark as confirmed if SUCCESS AND has confirmations (in a block)
|
|
115
|
+
const status = contractRet === 'SUCCESS' && tx.confirmations > 0
|
|
116
|
+
? unchained_client_1.TxStatus.Confirmed
|
|
117
|
+
: contractRet === 'REVERT'
|
|
118
|
+
? unchained_client_1.TxStatus.Failed
|
|
119
|
+
: unchained_client_1.TxStatus.Pending;
|
|
120
|
+
return {
|
|
121
|
+
status,
|
|
122
|
+
buyTxHash: txHash,
|
|
123
|
+
message: undefined,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error('[Sun.io] Error checking trade status:', error);
|
|
128
|
+
return (0, utils_1.createDefaultStatusResponse)(txHash);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { CommonTradeQuoteInput, GetTronTradeQuoteInput, SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types';
|
|
3
|
+
export declare const getSunioTradeQuote: (input: GetTronTradeQuoteInput | CommonTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote, SwapErrorRight>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSunioTradeQuote = void 0;
|
|
4
|
+
const getQuoteOrRate_1 = require("../utils/getQuoteOrRate");
|
|
5
|
+
const getSunioTradeQuote = (input, deps) => {
|
|
6
|
+
return (0, getQuoteOrRate_1.getQuoteOrRate)(input, deps);
|
|
7
|
+
};
|
|
8
|
+
exports.getSunioTradeQuote = getSunioTradeQuote;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { GetTradeRateInput, SwapErrorRight, SwapperDeps, TradeRate } from '../../../types';
|
|
3
|
+
export declare const getSunioTradeRate: (input: GetTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate, SwapErrorRight>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSunioTradeRate = void 0;
|
|
4
|
+
const getQuoteOrRate_1 = require("../utils/getQuoteOrRate");
|
|
5
|
+
const getSunioTradeRate = (input, deps) => {
|
|
6
|
+
return (0, getQuoteOrRate_1.getQuoteOrRate)(input, deps);
|
|
7
|
+
};
|
|
8
|
+
exports.getSunioTradeRate = getSunioTradeRate;
|