@shapeshiftoss/swapper 17.6.7 → 17.6.8
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 +9 -3
- 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 +9 -3
- package/dist/esm/utils.js +50 -1
- package/package.json +9 -8
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Err, Ok } from '@sniptt/monads';
|
|
2
|
+
import { makeSwapErrorRight } from '../../../utils.js';
|
|
3
|
+
export const fetchAxelarscanBridgeStatus = async (sourceTxHash) => {
|
|
4
|
+
try {
|
|
5
|
+
const response = await fetch(`https://api.axelarscan.io/gmp/searchGMP?txHash=${sourceTxHash}`);
|
|
6
|
+
if (!response.ok) {
|
|
7
|
+
return Err(makeSwapErrorRight({
|
|
8
|
+
message: `Axelarscan API error: ${response.statusText}`,
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
const data = await response.json();
|
|
12
|
+
if (!data.data || data.data.length === 0) {
|
|
13
|
+
return Ok(undefined);
|
|
14
|
+
}
|
|
15
|
+
const bridgeData = data.data[0];
|
|
16
|
+
const destinationTxHash = bridgeData.call?.transaction_hash ||
|
|
17
|
+
bridgeData.executed?.transaction_hash ||
|
|
18
|
+
bridgeData.express_executed?.transactionHash;
|
|
19
|
+
const isCompleted = bridgeData.status === 'executed' ||
|
|
20
|
+
bridgeData.status === 'destination_executed' ||
|
|
21
|
+
bridgeData.status === 'express_executed' ||
|
|
22
|
+
bridgeData.simplified_status === 'received' ||
|
|
23
|
+
!!destinationTxHash;
|
|
24
|
+
if (isCompleted) {
|
|
25
|
+
return Ok({
|
|
26
|
+
status: 'confirmed',
|
|
27
|
+
destinationTxHash,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (bridgeData.status === 'error') {
|
|
31
|
+
return Ok({
|
|
32
|
+
status: 'failed',
|
|
33
|
+
errorMessage: bridgeData.error?.message || 'Bridge failed',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return Ok({
|
|
37
|
+
status: 'pending',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return Err(makeSwapErrorRight({
|
|
42
|
+
message: 'Failed to fetch Axelarscan bridge status',
|
|
43
|
+
cause: error,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
export const getAxelarscanTrackingLink = (sourceTxHash) => `https://axelarscan.io/gmp/${sourceTxHash}`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import type { Result } from '@sniptt/monads';
|
|
3
|
+
import type { SwapErrorRight } from '../../../types.js';
|
|
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,52 @@
|
|
|
1
|
+
import { fromChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { Err, Ok } from '@sniptt/monads';
|
|
3
|
+
import { makeSwapErrorRight } from '../../../utils.js';
|
|
4
|
+
export const fetchSquidBridgeStatus = async (sourceTxHash, sourceChainId, destinationChainId) => {
|
|
5
|
+
try {
|
|
6
|
+
const fromChain = fromChainId(sourceChainId).chainReference;
|
|
7
|
+
const toChain = fromChainId(destinationChainId).chainReference;
|
|
8
|
+
const url = new URL('https://v2.api.squidrouter.com/v2/status');
|
|
9
|
+
url.searchParams.set('transactionId', sourceTxHash);
|
|
10
|
+
url.searchParams.set('fromChainId', fromChain);
|
|
11
|
+
url.searchParams.set('toChainId', toChain);
|
|
12
|
+
const response = await fetch(url.toString(), {
|
|
13
|
+
headers: {
|
|
14
|
+
'x-integrator-id': 'squid-swap-widget',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
return Err(makeSwapErrorRight({
|
|
19
|
+
message: `Squid API error: ${response.statusText}`,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
const data = await response.json();
|
|
23
|
+
const destinationTxHash = data.toChain?.transactionId;
|
|
24
|
+
if (data.squidTransactionStatus === 'success') {
|
|
25
|
+
return Ok({
|
|
26
|
+
status: 'confirmed',
|
|
27
|
+
destinationTxHash,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (data.squidTransactionStatus === 'partial_success' ||
|
|
31
|
+
data.squidTransactionStatus === 'needs_gas') {
|
|
32
|
+
return Ok({
|
|
33
|
+
status: 'failed',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return Ok({
|
|
37
|
+
status: 'pending',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return Err(makeSwapErrorRight({
|
|
42
|
+
message: 'Failed to fetch Squid bridge status',
|
|
43
|
+
cause: error,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
export const getSquidTrackingLink = (sourceTxHash, squidStatus, sellAssetExplorerTxLink, buyAssetExplorerTxLink) => {
|
|
48
|
+
if (squidStatus.status === 'confirmed' && squidStatus.destinationTxHash) {
|
|
49
|
+
return `${buyAssetExplorerTxLink}${squidStatus.destinationTxHash}`;
|
|
50
|
+
}
|
|
51
|
+
return `${sellAssetExplorerTxLink}${sourceTxHash}`;
|
|
52
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { arbitrumChainId, avalancheChainId, baseChainId, bscChainId, btcChainId, ethChainId, gnosisChainId, monadChainId, optimismChainId, polygonChainId, solanaChainId, tronChainId, } from '@shapeshiftoss/caip';
|
|
1
|
+
import { arbitrumChainId, avalancheChainId, baseChainId, bscChainId, btcChainId, ethChainId, gnosisChainId, hyperEvmChainId, katanaChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, solanaChainId, tronChainId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import invert from 'lodash/invert';
|
|
3
3
|
import { zeroAddress } from 'viem';
|
|
4
|
-
import { arbitrum, avalanche, base, bsc, gnosis, mainnet as ethereum, monad, optimism, polygon, } from 'viem/chains';
|
|
4
|
+
import { arbitrum, avalanche, base, bsc, gnosis, hyperEvm, katana, mainnet as ethereum, monad, optimism, plasma, polygon, } from 'viem/chains';
|
|
5
5
|
import { TradeQuoteError } from '../../types.js';
|
|
6
6
|
import { RelayErrorCode } from './utils/types.js';
|
|
7
7
|
export const chainIdToRelayChainId = {
|
|
@@ -19,6 +19,9 @@ export const chainIdToRelayChainId = {
|
|
|
19
19
|
[bscChainId]: bsc.id,
|
|
20
20
|
[tronChainId]: 728126428,
|
|
21
21
|
[monadChainId]: monad.id,
|
|
22
|
+
[hyperEvmChainId]: hyperEvm.id,
|
|
23
|
+
[plasmaChainId]: plasma.id,
|
|
24
|
+
[katanaChainId]: katana.id,
|
|
22
25
|
};
|
|
23
26
|
export var RelayStatusMessage;
|
|
24
27
|
(function (RelayStatusMessage) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { relayService } from './relayService.js';
|
|
2
2
|
export const fetchRelayTrade = async (params, config) => {
|
|
3
|
-
return await relayService.post(`${config.VITE_RELAY_API_URL}/quote`, params);
|
|
3
|
+
return await relayService.post(`${config.VITE_RELAY_API_URL}/quote/v2`, params);
|
|
4
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { btcChainId, fromChainId, solanaChainId, tronChainId } from '@shapeshiftoss/caip';
|
|
1
|
+
import { btcChainId, fromChainId, monadChainId, solanaChainId, tronChainId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import { evm, isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
3
3
|
import { bnOrZero, convertBasisPointsToPercentage, convertDecimalPercentageToBasisPoints, convertPrecision, DAO_TREASURY_BASE, } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
@@ -13,7 +13,7 @@ import { MAXIMUM_SUPPORTED_RELAY_STEPS, relayErrorCodeToTradeQuoteError } from '
|
|
|
13
13
|
import { getRelayAssetAddress } from '../utils/getRelayAssetAddress.js';
|
|
14
14
|
import { relayTokenToAsset } from '../utils/relayTokenToAsset.js';
|
|
15
15
|
import { relayTokenToAssetId } from '../utils/relayTokenToAssetId.js';
|
|
16
|
-
import { isRelayError, isRelayQuoteEvmItemData, isRelayQuoteSolanaItemData, isRelayQuoteUtxoItemData, } from '../utils/types.js';
|
|
16
|
+
import { isRelayError, isRelayQuoteEvmItemData, isRelayQuoteSolanaItemData, isRelayQuoteTronItemData, isRelayQuoteUtxoItemData, } from '../utils/types.js';
|
|
17
17
|
import { fetchRelayTrade } from './fetchRelayTrade.js';
|
|
18
18
|
import { getRelayDefaultUserAddress } from './getRelayDefaultUserAddress.js';
|
|
19
19
|
import { getRelayPsbtRelayer } from './getRelayPsbtRelayer.js';
|
|
@@ -353,6 +353,10 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
353
353
|
data: (selectedItem.data.data ?? '0x'),
|
|
354
354
|
value: selectedItem.data.value ?? '0',
|
|
355
355
|
sellAsset,
|
|
356
|
+
// Pass Relay's gas limit to Tenderly for Monad as tenderly return crazy gas
|
|
357
|
+
gas: selectedItem.data.gas && sellAsset.chainId === monadChainId
|
|
358
|
+
? Number(selectedItem.data.gas)
|
|
359
|
+
: undefined,
|
|
356
360
|
}, {
|
|
357
361
|
apiKey: deps.config.VITE_TENDERLY_API_KEY,
|
|
358
362
|
accountSlug: deps.config.VITE_TENDERLY_ACCOUNT_SLUG,
|
|
@@ -414,7 +418,8 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
414
418
|
relayTransactionMetadata: {
|
|
415
419
|
from: sendAddress,
|
|
416
420
|
to: selectedItem.data?.to,
|
|
417
|
-
value
|
|
421
|
+
// v2 API may return value as undefined or empty object for ERC-20 swaps - default to '0'
|
|
422
|
+
value: typeof selectedItem.data?.value === 'string' ? selectedItem.data.value : '0',
|
|
418
423
|
data: selectedItem.data?.data,
|
|
419
424
|
// gas is not documented in the relay docs but refers to gasLimit
|
|
420
425
|
gasLimit: selectedItem.data?.gas,
|
|
@@ -436,6 +441,16 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
436
441
|
},
|
|
437
442
|
};
|
|
438
443
|
}
|
|
444
|
+
if (isRelayQuoteTronItemData(selectedItem.data)) {
|
|
445
|
+
return {
|
|
446
|
+
allowanceContract: '',
|
|
447
|
+
solanaTransactionMetadata: undefined,
|
|
448
|
+
relayTransactionMetadata: {
|
|
449
|
+
relayId: quote.steps[0].requestId,
|
|
450
|
+
to: selectedItem.data?.parameter?.contract_address,
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
}
|
|
439
454
|
throw new Error('Relay quote step contains no data');
|
|
440
455
|
})();
|
|
441
456
|
return {
|
|
@@ -74,6 +74,11 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
74
74
|
assetReference: ASSET_REFERENCE.Base,
|
|
75
75
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
76
76
|
};
|
|
77
|
+
case CHAIN_REFERENCE.BnbSmartChainMainnet:
|
|
78
|
+
return {
|
|
79
|
+
assetReference: ASSET_REFERENCE.BnbSmartChain,
|
|
80
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
81
|
+
};
|
|
77
82
|
case CHAIN_REFERENCE.BitcoinMainnet:
|
|
78
83
|
return {
|
|
79
84
|
assetReference: ASSET_REFERENCE.Bitcoin,
|
|
@@ -94,6 +99,21 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
94
99
|
assetReference: ASSET_REFERENCE.Monad,
|
|
95
100
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
96
101
|
};
|
|
102
|
+
case CHAIN_REFERENCE.HyperEvmMainnet:
|
|
103
|
+
return {
|
|
104
|
+
assetReference: ASSET_REFERENCE.HyperEvm,
|
|
105
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
106
|
+
};
|
|
107
|
+
case CHAIN_REFERENCE.PlasmaMainnet:
|
|
108
|
+
return {
|
|
109
|
+
assetReference: ASSET_REFERENCE.Plasma,
|
|
110
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
111
|
+
};
|
|
112
|
+
case CHAIN_REFERENCE.KatanaMainnet:
|
|
113
|
+
return {
|
|
114
|
+
assetReference: ASSET_REFERENCE.Katana,
|
|
115
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
116
|
+
};
|
|
97
117
|
default:
|
|
98
118
|
throw Error(`chainId '${relayToken.chainId}' not supported`);
|
|
99
119
|
}
|
|
@@ -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;
|
|
@@ -7,6 +7,9 @@ export const isRelayQuoteEvmItemData = (item) => {
|
|
|
7
7
|
export const isRelayQuoteSolanaItemData = (item) => {
|
|
8
8
|
return 'instructions' in item;
|
|
9
9
|
};
|
|
10
|
+
export const isRelayQuoteTronItemData = (item) => {
|
|
11
|
+
return 'type' in item && 'parameter' in item;
|
|
12
|
+
};
|
|
10
13
|
export var RelayErrorCode;
|
|
11
14
|
(function (RelayErrorCode) {
|
|
12
15
|
RelayErrorCode["AmountTooLow"] = "AMOUNT_TOO_LOW";
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { tronAssetId, tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { toAddressNList } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
4
|
+
import { TronWeb } from 'tronweb';
|
|
5
|
+
import { getTronTransactionFees } from '../../tron-utils/getTronTransactionFees.js';
|
|
6
|
+
import { createDefaultStatusResponse, getExecutableTradeStep, isExecutableTradeQuote, } from '../../utils.js';
|
|
7
|
+
import { getSunioTradeQuote } from './getSunioTradeQuote/getSunioTradeQuote.js';
|
|
8
|
+
import { getSunioTradeRate } from './getSunioTradeRate/getSunioTradeRate.js';
|
|
9
|
+
import { buildSwapRouteParameters } from './utils/buildSwapRouteParameters.js';
|
|
10
|
+
import { SUNIO_SMART_ROUTER_CONTRACT } from './utils/constants.js';
|
|
11
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
12
|
+
const convertAddressesToEvmFormat = (value) => {
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
return value.map(v => convertAddressesToEvmFormat(v));
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === 'string' && value.startsWith('T') && TronWeb.isAddress(value)) {
|
|
17
|
+
const hex = TronWeb.address.toHex(value);
|
|
18
|
+
return hex.replace(/^41/, '0x');
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
export const sunioApi = {
|
|
23
|
+
getTradeQuote: async (input, deps) => {
|
|
24
|
+
const maybeTradeQuote = await getSunioTradeQuote(input, deps);
|
|
25
|
+
return maybeTradeQuote.map(quote => [quote]);
|
|
26
|
+
},
|
|
27
|
+
getTradeRate: async (input, deps) => {
|
|
28
|
+
const maybeTradeRate = await getSunioTradeRate(input, deps);
|
|
29
|
+
return maybeTradeRate.map(rate => [rate]);
|
|
30
|
+
},
|
|
31
|
+
getUnsignedTronTransaction: async (args) => {
|
|
32
|
+
const { tradeQuote, stepIndex, from, slippageTolerancePercentageDecimal, assertGetTronChainAdapter, } = args;
|
|
33
|
+
if (!isExecutableTradeQuote(tradeQuote)) {
|
|
34
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
35
|
+
}
|
|
36
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
37
|
+
const adapter = assertGetTronChainAdapter(tronChainId);
|
|
38
|
+
const sunioMetadata = step.sunioTransactionMetadata;
|
|
39
|
+
if (!sunioMetadata) {
|
|
40
|
+
throw new Error('[Sun.io] Missing transaction metadata in quote');
|
|
41
|
+
}
|
|
42
|
+
const rpcUrl = adapter.httpProvider.getRpcUrl();
|
|
43
|
+
const tronWeb = new TronWeb({
|
|
44
|
+
fullHost: rpcUrl,
|
|
45
|
+
});
|
|
46
|
+
const routeParams = buildSwapRouteParameters(sunioMetadata.route, step.sellAmountIncludingProtocolFeesCryptoBaseUnit, step.buyAmountAfterFeesCryptoBaseUnit, from, slippageTolerancePercentageDecimal);
|
|
47
|
+
const parameters = [
|
|
48
|
+
{ type: 'address[]', value: routeParams.path },
|
|
49
|
+
{ type: 'string[]', value: routeParams.poolVersion },
|
|
50
|
+
{ type: 'uint256[]', value: routeParams.versionLen },
|
|
51
|
+
{ type: 'uint24[]', value: routeParams.fees },
|
|
52
|
+
{
|
|
53
|
+
type: 'tuple(uint256,uint256,address,uint256)',
|
|
54
|
+
value: convertAddressesToEvmFormat([
|
|
55
|
+
routeParams.swapData.amountIn,
|
|
56
|
+
routeParams.swapData.amountOutMin,
|
|
57
|
+
routeParams.swapData.recipient,
|
|
58
|
+
routeParams.swapData.deadline,
|
|
59
|
+
]),
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
const functionSelector = 'swapExactInput(address[],string[],uint256[],uint24[],(uint256,uint256,address,uint256))';
|
|
63
|
+
const isSellingNativeTrx = step.sellAsset.assetId === tronAssetId;
|
|
64
|
+
const callValue = isSellingNativeTrx
|
|
65
|
+
? Number(step.sellAmountIncludingProtocolFeesCryptoBaseUnit)
|
|
66
|
+
: 0;
|
|
67
|
+
const options = {
|
|
68
|
+
feeLimit: 100_000_000,
|
|
69
|
+
callValue,
|
|
70
|
+
};
|
|
71
|
+
const txData = await tronWeb.transactionBuilder.triggerSmartContract(SUNIO_SMART_ROUTER_CONTRACT, functionSelector, options, parameters, from);
|
|
72
|
+
if (!txData.result || !txData.result.result) {
|
|
73
|
+
throw new Error('[Sun.io] Failed to build swap transaction');
|
|
74
|
+
}
|
|
75
|
+
const transaction = txData.transaction;
|
|
76
|
+
const rawDataHex = typeof transaction.raw_data_hex === 'string'
|
|
77
|
+
? transaction.raw_data_hex
|
|
78
|
+
: Buffer.isBuffer(transaction.raw_data_hex)
|
|
79
|
+
? transaction.raw_data_hex.toString('hex')
|
|
80
|
+
: Array.isArray(transaction.raw_data_hex)
|
|
81
|
+
? Buffer.from(transaction.raw_data_hex).toString('hex')
|
|
82
|
+
: (() => {
|
|
83
|
+
throw new Error(`Unexpected raw_data_hex type: ${typeof transaction.raw_data_hex}`);
|
|
84
|
+
})();
|
|
85
|
+
if (!/^[0-9a-fA-F]+$/.test(rawDataHex)) {
|
|
86
|
+
throw new Error(`Invalid raw_data_hex format: ${rawDataHex.slice(0, 100)}`);
|
|
87
|
+
}
|
|
88
|
+
const accountNumber = step.accountNumber;
|
|
89
|
+
if (accountNumber === undefined) {
|
|
90
|
+
throw new Error('[Sun.io] accountNumber is required for execution');
|
|
91
|
+
}
|
|
92
|
+
const bip44Params = adapter.getBip44Params({ accountNumber });
|
|
93
|
+
const addressNList = toAddressNList(bip44Params);
|
|
94
|
+
return {
|
|
95
|
+
addressNList,
|
|
96
|
+
rawDataHex,
|
|
97
|
+
transaction,
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
getTronTransactionFees,
|
|
101
|
+
checkTradeStatus: async ({ txHash, assertGetTronChainAdapter }) => {
|
|
102
|
+
try {
|
|
103
|
+
// Wait for TronGrid indexing to avoid false "REVERT"
|
|
104
|
+
await sleep(2000);
|
|
105
|
+
const adapter = assertGetTronChainAdapter(tronChainId);
|
|
106
|
+
const tx = await adapter.httpProvider.getTransaction({ txid: txHash });
|
|
107
|
+
if (!tx) {
|
|
108
|
+
return createDefaultStatusResponse(txHash);
|
|
109
|
+
}
|
|
110
|
+
const contractRet = tx.ret?.[0]?.contractRet;
|
|
111
|
+
// Only mark as confirmed if SUCCESS AND has confirmations (in a block)
|
|
112
|
+
const status = contractRet === 'SUCCESS' && tx.confirmations > 0
|
|
113
|
+
? TxStatus.Confirmed
|
|
114
|
+
: contractRet === 'REVERT'
|
|
115
|
+
? TxStatus.Failed
|
|
116
|
+
: TxStatus.Pending;
|
|
117
|
+
return {
|
|
118
|
+
status,
|
|
119
|
+
buyTxHash: txHash,
|
|
120
|
+
message: undefined,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error('[Sun.io] Error checking trade status:', error);
|
|
125
|
+
return createDefaultStatusResponse(txHash);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { CommonTradeQuoteInput, GetTronTradeQuoteInput, SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types.js';
|
|
3
|
+
export declare const getSunioTradeQuote: (input: GetTronTradeQuoteInput | CommonTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote, SwapErrorRight>>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { GetTradeRateInput, SwapErrorRight, SwapperDeps, TradeRate } from '../../../types.js';
|
|
3
|
+
export declare const getSunioTradeRate: (input: GetTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate, SwapErrorRight>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
export type SunioSupportedChainId = typeof tronChainId;
|
|
3
|
+
export type SunioRoute = {
|
|
4
|
+
amountIn: string;
|
|
5
|
+
amountOut: string;
|
|
6
|
+
inUsd: string;
|
|
7
|
+
outUsd: string;
|
|
8
|
+
impact: string;
|
|
9
|
+
fee: string;
|
|
10
|
+
tokens: string[];
|
|
11
|
+
symbols: string[];
|
|
12
|
+
poolFees: string[];
|
|
13
|
+
poolVersions: string[];
|
|
14
|
+
stepAmountsOut: string[];
|
|
15
|
+
};
|
|
16
|
+
export type SunioQuoteResponse = {
|
|
17
|
+
code: number;
|
|
18
|
+
message: string;
|
|
19
|
+
data: SunioRoute[];
|
|
20
|
+
};
|
|
21
|
+
export declare const SUNIO_SUPPORTED_DEX_TYPES: readonly ["SUNSWAP_V1", "SUNSWAP_V2", "SUNSWAP_V3", "PSM", "CURVE", "CURVE_COMBINATION", "WTRX"];
|
|
22
|
+
export type SunioDexType = (typeof SUNIO_SUPPORTED_DEX_TYPES)[number];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const SUNSWAP_ROUTER_ABI: readonly [{
|
|
2
|
+
readonly name: "swapExactInput";
|
|
3
|
+
readonly type: "function";
|
|
4
|
+
readonly stateMutability: "payable";
|
|
5
|
+
readonly inputs: readonly [{
|
|
6
|
+
readonly internalType: "address[]";
|
|
7
|
+
readonly name: "path";
|
|
8
|
+
readonly type: "address[]";
|
|
9
|
+
}, {
|
|
10
|
+
readonly internalType: "string[]";
|
|
11
|
+
readonly name: "poolVersion";
|
|
12
|
+
readonly type: "string[]";
|
|
13
|
+
}, {
|
|
14
|
+
readonly internalType: "uint256[]";
|
|
15
|
+
readonly name: "versionLen";
|
|
16
|
+
readonly type: "uint256[]";
|
|
17
|
+
}, {
|
|
18
|
+
readonly internalType: "uint24[]";
|
|
19
|
+
readonly name: "fees";
|
|
20
|
+
readonly type: "uint24[]";
|
|
21
|
+
}, {
|
|
22
|
+
readonly internalType: "struct SwapData";
|
|
23
|
+
readonly name: "data";
|
|
24
|
+
readonly type: "tuple";
|
|
25
|
+
readonly components: readonly [{
|
|
26
|
+
readonly internalType: "uint256";
|
|
27
|
+
readonly name: "amountIn";
|
|
28
|
+
readonly type: "uint256";
|
|
29
|
+
}, {
|
|
30
|
+
readonly internalType: "uint256";
|
|
31
|
+
readonly name: "amountOutMin";
|
|
32
|
+
readonly type: "uint256";
|
|
33
|
+
}, {
|
|
34
|
+
readonly internalType: "address";
|
|
35
|
+
readonly name: "to";
|
|
36
|
+
readonly type: "address";
|
|
37
|
+
}, {
|
|
38
|
+
readonly internalType: "uint256";
|
|
39
|
+
readonly name: "deadline";
|
|
40
|
+
readonly type: "uint256";
|
|
41
|
+
}];
|
|
42
|
+
}];
|
|
43
|
+
readonly outputs: readonly [{
|
|
44
|
+
readonly internalType: "uint256[]";
|
|
45
|
+
readonly name: "amountsOut";
|
|
46
|
+
readonly type: "uint256[]";
|
|
47
|
+
}];
|
|
48
|
+
}];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const SUNSWAP_ROUTER_ABI = [
|
|
2
|
+
{
|
|
3
|
+
name: 'swapExactInput',
|
|
4
|
+
type: 'function',
|
|
5
|
+
stateMutability: 'payable',
|
|
6
|
+
inputs: [
|
|
7
|
+
{ internalType: 'address[]', name: 'path', type: 'address[]' },
|
|
8
|
+
{ internalType: 'string[]', name: 'poolVersion', type: 'string[]' },
|
|
9
|
+
{ internalType: 'uint256[]', name: 'versionLen', type: 'uint256[]' },
|
|
10
|
+
{ internalType: 'uint24[]', name: 'fees', type: 'uint24[]' },
|
|
11
|
+
{
|
|
12
|
+
internalType: 'struct SwapData',
|
|
13
|
+
name: 'data',
|
|
14
|
+
type: 'tuple',
|
|
15
|
+
components: [
|
|
16
|
+
{ internalType: 'uint256', name: 'amountIn', type: 'uint256' },
|
|
17
|
+
{ internalType: 'uint256', name: 'amountOutMin', type: 'uint256' },
|
|
18
|
+
{ internalType: 'address', name: 'to', type: 'address' },
|
|
19
|
+
{ internalType: 'uint256', name: 'deadline', type: 'uint256' },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
outputs: [{ internalType: 'uint256[]', name: 'amountsOut', type: 'uint256[]' }],
|
|
24
|
+
},
|
|
25
|
+
];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SunioRoute } from '../types.js';
|
|
2
|
+
export type SwapRouteParameters = {
|
|
3
|
+
path: string[];
|
|
4
|
+
poolVersion: string[];
|
|
5
|
+
versionLen: number[];
|
|
6
|
+
fees: number[];
|
|
7
|
+
swapData: {
|
|
8
|
+
amountIn: string;
|
|
9
|
+
amountOutMin: string;
|
|
10
|
+
recipient: string;
|
|
11
|
+
deadline: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const buildSwapRouteParameters: (route: SunioRoute, sellAmountCryptoBaseUnit: string, minBuyAmountCryptoBaseUnit: string, recipient: string, slippageTolerancePercentageDecimal: string) => SwapRouteParameters;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { bn } from '@shapeshiftoss/utils';
|
|
2
|
+
export const buildSwapRouteParameters = (route, sellAmountCryptoBaseUnit, minBuyAmountCryptoBaseUnit, recipient, slippageTolerancePercentageDecimal) => {
|
|
3
|
+
const path = route.tokens;
|
|
4
|
+
const poolVersion = route.poolVersions;
|
|
5
|
+
const versionLen = poolVersion.map((_, index) => {
|
|
6
|
+
if (index === poolVersion.length - 1) {
|
|
7
|
+
return path.length - index;
|
|
8
|
+
}
|
|
9
|
+
return 2;
|
|
10
|
+
});
|
|
11
|
+
const fees = route.poolFees.map(fee => Number(fee));
|
|
12
|
+
const amountOutWithSlippage = bn(minBuyAmountCryptoBaseUnit)
|
|
13
|
+
.times(bn(1).minus(slippageTolerancePercentageDecimal))
|
|
14
|
+
.toFixed(0);
|
|
15
|
+
const swapData = {
|
|
16
|
+
amountIn: sellAmountCryptoBaseUnit,
|
|
17
|
+
amountOutMin: amountOutWithSlippage,
|
|
18
|
+
recipient,
|
|
19
|
+
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
path,
|
|
23
|
+
poolVersion,
|
|
24
|
+
versionLen,
|
|
25
|
+
fees,
|
|
26
|
+
swapData,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SunioRoute } from '../types.js';
|
|
2
|
+
export type BuildSwapTransactionArgs = {
|
|
3
|
+
route: SunioRoute;
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
sellAmountCryptoBaseUnit: string;
|
|
7
|
+
minBuyAmountCryptoBaseUnit: string;
|
|
8
|
+
rpcUrl: string;
|
|
9
|
+
deadline?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const buildSunioSwapTransaction: (args: BuildSwapTransactionArgs) => Promise<any>;
|