@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,5 @@
|
|
|
1
|
+
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
export declare const AVNU_SUPPORTED_CHAIN_IDS: readonly ChainId[];
|
|
3
|
+
export declare const isSupportedChainId: (chainId: ChainId) => chainId is ChainId;
|
|
4
|
+
export declare const DEFAULT_SLIPPAGE_PERCENTAGE = "0.005";
|
|
5
|
+
export declare const AVNU_API_BASE_URL = "https://starknet.api.avnu.fi";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AVNU_API_BASE_URL = exports.DEFAULT_SLIPPAGE_PERCENTAGE = exports.isSupportedChainId = exports.AVNU_SUPPORTED_CHAIN_IDS = void 0;
|
|
4
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
5
|
+
exports.AVNU_SUPPORTED_CHAIN_IDS = [types_1.KnownChainIds.StarknetMainnet];
|
|
6
|
+
const isSupportedChainId = (chainId) => {
|
|
7
|
+
return exports.AVNU_SUPPORTED_CHAIN_IDS.includes(chainId);
|
|
8
|
+
};
|
|
9
|
+
exports.isSupportedChainId = isSupportedChainId;
|
|
10
|
+
exports.DEFAULT_SLIPPAGE_PERCENTAGE = '0.005';
|
|
11
|
+
exports.AVNU_API_BASE_URL = 'https://starknet.api.avnu.fi';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Asset } from '@shapeshiftoss/types';
|
|
2
|
+
/**
|
|
3
|
+
* Get the token address for AVNU swaps
|
|
4
|
+
* For native STRK token (slip44 namespace), returns the STRK contract address
|
|
5
|
+
* For other tokens, returns the token contract address from assetReference
|
|
6
|
+
*/
|
|
7
|
+
export declare const getTokenAddress: (asset: Asset) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenAddress = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
// STRK native token contract address on Starknet
|
|
6
|
+
const AVNU_STRK_NATIVE_ADDRESS = '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d';
|
|
7
|
+
/**
|
|
8
|
+
* Get the token address for AVNU swaps
|
|
9
|
+
* For native STRK token (slip44 namespace), returns the STRK contract address
|
|
10
|
+
* For other tokens, returns the token contract address from assetReference
|
|
11
|
+
*/
|
|
12
|
+
const getTokenAddress = (asset) => {
|
|
13
|
+
const { assetReference, assetNamespace } = (0, caip_1.fromAssetId)(asset.assetId);
|
|
14
|
+
// For native STRK token, the assetReference is 'slip44:9004' but AVNU expects the STRK contract address
|
|
15
|
+
if (assetNamespace === 'slip44') {
|
|
16
|
+
return AVNU_STRK_NATIVE_ADDRESS;
|
|
17
|
+
}
|
|
18
|
+
// For other tokens, the assetReference should be the token contract address
|
|
19
|
+
return assetReference;
|
|
20
|
+
};
|
|
21
|
+
exports.getTokenAddress = getTokenAddress;
|
|
@@ -34,6 +34,8 @@ vitest_1.vi.mock('../xhr', () => ({
|
|
|
34
34
|
assertGetSolanaChainAdapter: () => vitest_1.vi.fn(),
|
|
35
35
|
assertGetTronChainAdapter: () => vitest_1.vi.fn(),
|
|
36
36
|
assertGetSuiChainAdapter: () => vitest_1.vi.fn(),
|
|
37
|
+
assertGetNearChainAdapter: () => vitest_1.vi.fn(),
|
|
38
|
+
assertGetStarknetChainAdapter: () => vitest_1.vi.fn(),
|
|
37
39
|
config: {
|
|
38
40
|
VITE_BUTTERSWAP_CLIENT_ID: 'test',
|
|
39
41
|
},
|
|
@@ -28,6 +28,8 @@ vitest_1.vi.mock('../utils/butterSwapService', () => ({
|
|
|
28
28
|
assertGetSolanaChainAdapter: () => vitest_1.vi.fn(),
|
|
29
29
|
assertGetTronChainAdapter: () => vitest_1.vi.fn(),
|
|
30
30
|
assertGetSuiChainAdapter: () => vitest_1.vi.fn(),
|
|
31
|
+
assertGetNearChainAdapter: () => vitest_1.vi.fn(),
|
|
32
|
+
assertGetStarknetChainAdapter: () => vitest_1.vi.fn(),
|
|
31
33
|
config: {
|
|
32
34
|
VITE_BUTTERSWAP_CLIENT_ID: 'test',
|
|
33
35
|
},
|
|
@@ -62,6 +64,8 @@ vitest_1.vi.mock('../utils/butterSwapService', () => ({
|
|
|
62
64
|
assertGetSolanaChainAdapter: () => vitest_1.vi.fn(),
|
|
63
65
|
assertGetTronChainAdapter: () => vitest_1.vi.fn(),
|
|
64
66
|
assertGetSuiChainAdapter: () => vitest_1.vi.fn(),
|
|
67
|
+
assertGetNearChainAdapter: () => vitest_1.vi.fn(),
|
|
68
|
+
assertGetStarknetChainAdapter: () => vitest_1.vi.fn(),
|
|
65
69
|
config: {
|
|
66
70
|
VITE_BUTTERSWAP_CLIENT_ID: 'test',
|
|
67
71
|
},
|
|
@@ -10,6 +10,7 @@ const BUTTERSWAP_CHAIN_ID_TO_CHAIN_ID = {
|
|
|
10
10
|
42161: types_1.KnownChainIds.ArbitrumMainnet,
|
|
11
11
|
10: types_1.KnownChainIds.OptimismMainnet,
|
|
12
12
|
8453: types_1.KnownChainIds.BaseMainnet,
|
|
13
|
+
43114: types_1.KnownChainIds.AvalancheMainnet,
|
|
13
14
|
1360108768460801: types_1.KnownChainIds.SolanaMainnet,
|
|
14
15
|
1360095883558913: types_1.KnownChainIds.BitcoinMainnet,
|
|
15
16
|
};
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cetusApi = void 0;
|
|
4
|
+
const aggregator_sdk_1 = require("@cetusprotocol/aggregator-sdk");
|
|
5
|
+
const transactions_1 = require("@cetusprotocol/aggregator-sdk/node_modules/@mysten/sui/transactions");
|
|
4
6
|
const unchained_client_1 = require("@shapeshiftoss/unchained-client");
|
|
5
|
-
const utils_1 = require("
|
|
7
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
8
|
+
const constants_1 = require("../../constants");
|
|
9
|
+
const types_1 = require("../../types");
|
|
10
|
+
const utils_2 = require("../../utils");
|
|
6
11
|
const getTradeQuote_1 = require("./swapperApi/getTradeQuote");
|
|
7
12
|
const getTradeRate_1 = require("./swapperApi/getTradeRate");
|
|
13
|
+
const constants_2 = require("./utils/constants");
|
|
8
14
|
const helpers_1 = require("./utils/helpers");
|
|
9
15
|
exports.cetusApi = {
|
|
10
16
|
getTradeQuote: (input, deps) => {
|
|
@@ -13,36 +19,35 @@ exports.cetusApi = {
|
|
|
13
19
|
getTradeRate: (input, deps) => {
|
|
14
20
|
return (0, getTradeRate_1.getTradeRate)(input, deps);
|
|
15
21
|
},
|
|
16
|
-
getUnsignedSuiTransaction: async ({ stepIndex, tradeQuote, from, assertGetSuiChainAdapter, }) => {
|
|
17
|
-
if (!(0,
|
|
22
|
+
getUnsignedSuiTransaction: async ({ stepIndex, tradeQuote, from, assertGetSuiChainAdapter, config, }) => {
|
|
23
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
18
24
|
throw new Error('Unable to execute a trade rate quote');
|
|
19
|
-
const step = (0,
|
|
25
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
20
26
|
const { accountNumber, sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit } = step;
|
|
21
27
|
const adapter = assertGetSuiChainAdapter(sellAsset.chainId);
|
|
22
|
-
const
|
|
23
|
-
|
|
28
|
+
const rpcUrl = config.VITE_SUI_NODE_URL;
|
|
29
|
+
const client = (0, helpers_1.getAggregatorClient)(rpcUrl);
|
|
30
|
+
const suiClient = (0, helpers_1.getSuiClient)(rpcUrl);
|
|
24
31
|
const sellCoinType = (0, helpers_1.getCoinType)(sellAsset);
|
|
25
32
|
const buyCoinType = (0, helpers_1.getCoinType)(buyAsset);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
// Exclude Pyth-dependent providers to avoid oracle failures
|
|
34
|
+
const providersWithoutPyth = (0, aggregator_sdk_1.getProvidersExcluding)(constants_2.PYTH_DEPENDENT_PROVIDERS);
|
|
35
|
+
const routerData = await (0, helpers_1.findBestRoute)(client, sellCoinType, buyCoinType, sellAmountIncludingProtocolFeesCryptoBaseUnit, providersWithoutPyth);
|
|
36
|
+
if (!routerData) {
|
|
37
|
+
throw new Error(`No route found for ${sellAsset.symbol}/${buyAsset.symbol}`);
|
|
29
38
|
}
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
coinTypeB: pool.coinTypeB,
|
|
40
|
-
a2b,
|
|
41
|
-
by_amount_in: true,
|
|
42
|
-
amount: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
43
|
-
amount_limit: amountLimit,
|
|
39
|
+
const slippage = (0, utils_1.bnOrZero)(tradeQuote.slippageTolerancePercentageDecimal ??
|
|
40
|
+
(0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.Cetus)).toNumber();
|
|
41
|
+
const txb = new transactions_1.Transaction();
|
|
42
|
+
txb.setSender(from);
|
|
43
|
+
await client.fastRouterSwap({
|
|
44
|
+
router: routerData,
|
|
45
|
+
slippage,
|
|
46
|
+
txb,
|
|
47
|
+
refreshAllCoins: true,
|
|
44
48
|
});
|
|
45
|
-
const
|
|
49
|
+
const transactionJson = await txb.toJSON({ client: suiClient });
|
|
50
|
+
const transactionBytes = await txb.build({ client: suiClient });
|
|
46
51
|
const intentMessage = new Uint8Array(3 + transactionBytes.length);
|
|
47
52
|
intentMessage[0] = 0;
|
|
48
53
|
intentMessage[1] = 0;
|
|
@@ -59,12 +64,13 @@ exports.cetusApi = {
|
|
|
59
64
|
return {
|
|
60
65
|
addressNList,
|
|
61
66
|
intentMessageBytes: intentMessage,
|
|
67
|
+
transactionJson,
|
|
62
68
|
};
|
|
63
69
|
},
|
|
64
70
|
getSuiTransactionFees: ({ tradeQuote, stepIndex }) => {
|
|
65
|
-
if (!(0,
|
|
71
|
+
if (!(0, utils_2.isExecutableTradeQuote)(tradeQuote))
|
|
66
72
|
throw new Error('Unable to execute a trade rate quote');
|
|
67
|
-
const step = (0,
|
|
73
|
+
const step = (0, utils_2.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
68
74
|
if (!step.feeData.networkFeeCryptoBaseUnit) {
|
|
69
75
|
throw new Error('Missing network fee in quote');
|
|
70
76
|
}
|
|
@@ -78,7 +84,7 @@ exports.cetusApi = {
|
|
|
78
84
|
message: undefined,
|
|
79
85
|
});
|
|
80
86
|
}
|
|
81
|
-
return (0,
|
|
87
|
+
return (0, utils_2.checkSuiSwapStatus)({
|
|
82
88
|
txHash: swap.sellTxHash,
|
|
83
89
|
address: swap.receiveAddress,
|
|
84
90
|
assertGetSuiChainAdapter,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
|
|
2
|
+
import type { AssetId } from '@shapeshiftoss/caip';
|
|
3
|
+
import type { Asset } from '@shapeshiftoss/types';
|
|
4
|
+
import type { Result } from '@sniptt/monads';
|
|
5
|
+
import type { ProtocolFee, SwapErrorRight, SwapperDeps } from '../../../types';
|
|
6
|
+
type CetusTradeDataInput = {
|
|
7
|
+
sellAsset: Asset;
|
|
8
|
+
buyAsset: Asset;
|
|
9
|
+
receiveAddress: string | undefined;
|
|
10
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: string;
|
|
11
|
+
};
|
|
12
|
+
type CetusTradeData = {
|
|
13
|
+
buyAmountAfterFeesCryptoBaseUnit: string;
|
|
14
|
+
rate: string;
|
|
15
|
+
addressForFeeEstimate: string;
|
|
16
|
+
sellCoinType: string;
|
|
17
|
+
buyCoinType: string;
|
|
18
|
+
routerData: RouterDataV3;
|
|
19
|
+
protocolFees: Record<AssetId, ProtocolFee>;
|
|
20
|
+
adapter: ReturnType<SwapperDeps['assertGetSuiChainAdapter']>;
|
|
21
|
+
rpcUrl: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const getCetusTradeData: (input: CetusTradeDataInput, deps: SwapperDeps) => Promise<Result<CetusTradeData, SwapErrorRight>>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCetusTradeData = void 0;
|
|
4
|
+
const aggregator_sdk_1 = require("@cetusprotocol/aggregator-sdk");
|
|
5
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
6
|
+
const monads_1 = require("@sniptt/monads");
|
|
7
|
+
const types_1 = require("../../../types");
|
|
8
|
+
const utils_1 = require("../../../utils");
|
|
9
|
+
const constants_1 = require("../utils/constants");
|
|
10
|
+
const helpers_1 = require("../utils/helpers");
|
|
11
|
+
const getCetusTradeData = async (input, deps) => {
|
|
12
|
+
const { sellAsset, buyAsset, receiveAddress, sellAmountIncludingProtocolFeesCryptoBaseUnit } = input;
|
|
13
|
+
const { assetsById } = deps;
|
|
14
|
+
if (!(0, constants_1.isSupportedChainId)(sellAsset.chainId)) {
|
|
15
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
16
|
+
message: `unsupported chainId`,
|
|
17
|
+
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
18
|
+
details: { chainId: sellAsset.chainId },
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
if (!(0, constants_1.isSupportedChainId)(buyAsset.chainId)) {
|
|
22
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
23
|
+
message: `unsupported chainId`,
|
|
24
|
+
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
25
|
+
details: { chainId: buyAsset.chainId },
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
const suiAsset = assetsById[caip_1.suiAssetId];
|
|
29
|
+
if (!suiAsset) {
|
|
30
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
31
|
+
message: `suiAsset is required`,
|
|
32
|
+
code: types_1.TradeQuoteError.InternalError,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const adapter = deps.assertGetSuiChainAdapter(sellAsset.chainId);
|
|
37
|
+
const rpcUrl = deps.config.VITE_SUI_NODE_URL;
|
|
38
|
+
const client = (0, helpers_1.getAggregatorClient)(rpcUrl);
|
|
39
|
+
const sellCoinType = (0, helpers_1.getCoinType)(sellAsset);
|
|
40
|
+
const buyCoinType = (0, helpers_1.getCoinType)(buyAsset);
|
|
41
|
+
// Exclude Pyth-dependent providers to avoid oracle failures
|
|
42
|
+
const providersWithoutPyth = (0, aggregator_sdk_1.getProvidersExcluding)(constants_1.PYTH_DEPENDENT_PROVIDERS);
|
|
43
|
+
const routerData = await (0, helpers_1.findBestRoute)(client, sellCoinType, buyCoinType, sellAmountIncludingProtocolFeesCryptoBaseUnit, providersWithoutPyth);
|
|
44
|
+
if (!routerData) {
|
|
45
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
46
|
+
message: `No route found for ${sellAsset.symbol}/${buyAsset.symbol}`,
|
|
47
|
+
code: types_1.TradeQuoteError.NoRouteFound,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
const buyAmountAfterFeesCryptoBaseUnit = routerData.amountOut.toString();
|
|
51
|
+
const rate = (0, utils_1.getInputOutputRate)({
|
|
52
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
53
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
54
|
+
sellAsset,
|
|
55
|
+
buyAsset,
|
|
56
|
+
});
|
|
57
|
+
const dummyAddress = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
58
|
+
const addressForFeeEstimate = receiveAddress ?? dummyAddress;
|
|
59
|
+
const protocolFees = {};
|
|
60
|
+
return (0, monads_1.Ok)({
|
|
61
|
+
buyAmountAfterFeesCryptoBaseUnit,
|
|
62
|
+
rate,
|
|
63
|
+
addressForFeeEstimate,
|
|
64
|
+
sellCoinType,
|
|
65
|
+
buyCoinType,
|
|
66
|
+
routerData,
|
|
67
|
+
protocolFees,
|
|
68
|
+
adapter,
|
|
69
|
+
rpcUrl,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
74
|
+
message: error instanceof Error ? error.message : 'Unknown error getting Cetus data',
|
|
75
|
+
code: types_1.TradeQuoteError.QueryFailed,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.getCetusTradeData = getCetusTradeData;
|
|
@@ -1,82 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTradeQuote = void 0;
|
|
4
|
-
const
|
|
4
|
+
const transactions_1 = require("@cetusprotocol/aggregator-sdk/node_modules/@mysten/sui/transactions");
|
|
5
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
6
|
const monads_1 = require("@sniptt/monads");
|
|
6
7
|
const uuid_1 = require("uuid");
|
|
8
|
+
const constants_1 = require("../../../constants");
|
|
7
9
|
const types_1 = require("../../../types");
|
|
8
|
-
const
|
|
9
|
-
const constants_1 = require("../utils/constants");
|
|
10
|
+
const utils_2 = require("../../../utils");
|
|
10
11
|
const helpers_1 = require("../utils/helpers");
|
|
12
|
+
const getCetusTradeData_1 = require("./getCetusTradeData");
|
|
11
13
|
const getTradeQuote = async (input, deps) => {
|
|
12
14
|
const { sellAsset, buyAsset, receiveAddress, accountNumber, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, affiliateBps, slippageTolerancePercentageDecimal, } = input;
|
|
13
|
-
const { assetsById } = deps;
|
|
14
15
|
if (accountNumber === undefined) {
|
|
15
|
-
return (0, monads_1.Err)((0,
|
|
16
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
16
17
|
message: `accountNumber is required`,
|
|
17
18
|
code: types_1.TradeQuoteError.InternalError,
|
|
18
19
|
}));
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
message: `unsupported chainId`,
|
|
30
|
-
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
31
|
-
details: { chainId: buyAsset.chainId },
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
const suiAsset = assetsById[caip_1.suiAssetId];
|
|
35
|
-
if (!suiAsset) {
|
|
36
|
-
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
37
|
-
message: `suiAsset is required`,
|
|
38
|
-
code: types_1.TradeQuoteError.InternalError,
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
21
|
+
const tradeDataResult = await (0, getCetusTradeData_1.getCetusTradeData)({
|
|
22
|
+
sellAsset,
|
|
23
|
+
buyAsset,
|
|
24
|
+
receiveAddress,
|
|
25
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount,
|
|
26
|
+
}, deps);
|
|
27
|
+
if (tradeDataResult.isErr())
|
|
28
|
+
return (0, monads_1.Err)(tradeDataResult.unwrapErr());
|
|
29
|
+
const { buyAmountAfterFeesCryptoBaseUnit, rate, addressForFeeEstimate, routerData, protocolFees, rpcUrl, } = tradeDataResult.unwrap();
|
|
41
30
|
try {
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
55
|
-
message: `Failed to calculate swap for ${sellAsset.symbol}/${buyAsset.symbol}`,
|
|
56
|
-
code: types_1.TradeQuoteError.QueryFailed,
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
const buyAmountAfterFeesCryptoBaseUnit = swapResult.estimatedAmountOut;
|
|
60
|
-
const rate = (0, utils_1.getInputOutputRate)({
|
|
61
|
-
sellAmountCryptoBaseUnit: sellAmount,
|
|
62
|
-
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
63
|
-
sellAsset,
|
|
64
|
-
buyAsset,
|
|
31
|
+
// Build the actual Cetus swap transaction to get accurate gas estimation
|
|
32
|
+
const client = (0, helpers_1.getAggregatorClient)(rpcUrl);
|
|
33
|
+
const suiClient = (0, helpers_1.getSuiClient)(rpcUrl);
|
|
34
|
+
const slippage = (0, utils_1.bnOrZero)(slippageTolerancePercentageDecimal ??
|
|
35
|
+
(0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.Cetus)).toNumber();
|
|
36
|
+
const txb = new transactions_1.Transaction();
|
|
37
|
+
txb.setSender(addressForFeeEstimate);
|
|
38
|
+
await client.fastRouterSwap({
|
|
39
|
+
router: routerData,
|
|
40
|
+
slippage,
|
|
41
|
+
txb,
|
|
42
|
+
refreshAllCoins: true,
|
|
65
43
|
});
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const protocolFees = {};
|
|
79
|
-
const quotes = [];
|
|
44
|
+
const transactionBytes = await txb.build({ client: suiClient });
|
|
45
|
+
const dryRunResult = await suiClient.dryRunTransactionBlock({
|
|
46
|
+
transactionBlock: transactionBytes,
|
|
47
|
+
});
|
|
48
|
+
const computationCost = BigInt(dryRunResult.effects.gasUsed.computationCost);
|
|
49
|
+
const storageCost = BigInt(dryRunResult.effects.gasUsed.storageCost);
|
|
50
|
+
const storageRebate = BigInt(dryRunResult.effects.gasUsed.storageRebate);
|
|
51
|
+
const netStorageCost = storageCost > storageRebate ? storageCost - storageRebate : 0n;
|
|
52
|
+
const estimatedGas = computationCost + netStorageCost;
|
|
53
|
+
const txFee = estimatedGas.toString();
|
|
54
|
+
const gasBudget = ((estimatedGas * 120n) / 100n).toString();
|
|
55
|
+
const gasPrice = await suiClient.getReferenceGasPrice();
|
|
80
56
|
const tradeQuote = {
|
|
81
57
|
id: (0, uuid_1.v4)(),
|
|
82
58
|
quoteOrRate: 'quote',
|
|
@@ -93,10 +69,10 @@ const getTradeQuote = async (input, deps) => {
|
|
|
93
69
|
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount,
|
|
94
70
|
feeData: {
|
|
95
71
|
protocolFees,
|
|
96
|
-
networkFeeCryptoBaseUnit:
|
|
72
|
+
networkFeeCryptoBaseUnit: txFee,
|
|
97
73
|
chainSpecific: {
|
|
98
|
-
gasBudget
|
|
99
|
-
gasPrice:
|
|
74
|
+
gasBudget,
|
|
75
|
+
gasPrice: gasPrice.toString(),
|
|
100
76
|
},
|
|
101
77
|
},
|
|
102
78
|
rate,
|
|
@@ -108,12 +84,11 @@ const getTradeQuote = async (input, deps) => {
|
|
|
108
84
|
},
|
|
109
85
|
],
|
|
110
86
|
};
|
|
111
|
-
|
|
112
|
-
return (0, monads_1.Ok)(quotes);
|
|
87
|
+
return tradeDataResult.map(() => [tradeQuote]);
|
|
113
88
|
}
|
|
114
89
|
catch (error) {
|
|
115
90
|
console.error(error);
|
|
116
|
-
return (0, monads_1.Err)((0,
|
|
91
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
117
92
|
message: error instanceof Error ? error.message : 'Unknown error getting Cetus quote',
|
|
118
93
|
code: types_1.TradeQuoteError.QueryFailed,
|
|
119
94
|
}));
|
|
@@ -1,75 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTradeRate = void 0;
|
|
4
|
-
const
|
|
4
|
+
const transactions_1 = require("@cetusprotocol/aggregator-sdk/node_modules/@mysten/sui/transactions");
|
|
5
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
6
|
const monads_1 = require("@sniptt/monads");
|
|
6
7
|
const uuid_1 = require("uuid");
|
|
8
|
+
const constants_1 = require("../../../constants");
|
|
7
9
|
const types_1 = require("../../../types");
|
|
8
|
-
const
|
|
9
|
-
const constants_1 = require("../utils/constants");
|
|
10
|
+
const utils_2 = require("../../../utils");
|
|
10
11
|
const helpers_1 = require("../utils/helpers");
|
|
12
|
+
const getCetusTradeData_1 = require("./getCetusTradeData");
|
|
11
13
|
const getTradeRate = async (input, deps) => {
|
|
12
14
|
const { sellAsset, buyAsset, receiveAddress, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, affiliateBps, slippageTolerancePercentageDecimal, } = input;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
23
|
-
message: `unsupported chainId`,
|
|
24
|
-
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
25
|
-
details: { chainId: buyAsset.chainId },
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
const suiAsset = assetsById[caip_1.suiAssetId];
|
|
29
|
-
if (!suiAsset) {
|
|
30
|
-
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
31
|
-
message: `suiAsset is required`,
|
|
32
|
-
code: types_1.TradeQuoteError.UnknownError,
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
15
|
+
const tradeDataResult = await (0, getCetusTradeData_1.getCetusTradeData)({
|
|
16
|
+
sellAsset,
|
|
17
|
+
buyAsset,
|
|
18
|
+
receiveAddress,
|
|
19
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount,
|
|
20
|
+
}, deps);
|
|
21
|
+
if (tradeDataResult.isErr())
|
|
22
|
+
return (0, monads_1.Err)(tradeDataResult.unwrapErr());
|
|
23
|
+
const { buyAmountAfterFeesCryptoBaseUnit, rate, addressForFeeEstimate, routerData, protocolFees, rpcUrl, } = tradeDataResult.unwrap();
|
|
35
24
|
try {
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
49
|
-
message: `Failed to calculate swap for ${sellAsset.symbol}/${buyAsset.symbol}`,
|
|
50
|
-
code: types_1.TradeQuoteError.QueryFailed,
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
const buyAmountAfterFeesCryptoBaseUnit = swapResult.estimatedAmountOut;
|
|
54
|
-
const rate = (0, utils_1.getInputOutputRate)({
|
|
55
|
-
sellAmountCryptoBaseUnit: sellAmount,
|
|
56
|
-
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
57
|
-
sellAsset,
|
|
58
|
-
buyAsset,
|
|
59
|
-
});
|
|
60
|
-
const adapter = deps.assertGetSuiChainAdapter(sellAsset.chainId);
|
|
61
|
-
const dummyAddress = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
62
|
-
const addressForFeeEstimate = receiveAddress ?? dummyAddress;
|
|
63
|
-
const { fast: feeDataFast } = await adapter.getFeeData({
|
|
64
|
-
to: addressForFeeEstimate,
|
|
65
|
-
value: sellAmount,
|
|
66
|
-
chainSpecific: {
|
|
67
|
-
from: addressForFeeEstimate,
|
|
68
|
-
tokenId: (0, helpers_1.getCoinType)(sellAsset),
|
|
69
|
-
},
|
|
25
|
+
// Build the actual Cetus swap transaction to get accurate gas estimation
|
|
26
|
+
const client = (0, helpers_1.getAggregatorClient)(rpcUrl);
|
|
27
|
+
const suiClient = (0, helpers_1.getSuiClient)(rpcUrl);
|
|
28
|
+
const slippage = (0, utils_1.bnOrZero)(slippageTolerancePercentageDecimal ??
|
|
29
|
+
(0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.Cetus)).toNumber();
|
|
30
|
+
const txb = new transactions_1.Transaction();
|
|
31
|
+
txb.setSender(addressForFeeEstimate);
|
|
32
|
+
await client.fastRouterSwap({
|
|
33
|
+
router: routerData,
|
|
34
|
+
slippage,
|
|
35
|
+
txb,
|
|
36
|
+
refreshAllCoins: true,
|
|
70
37
|
});
|
|
71
|
-
const
|
|
72
|
-
|
|
38
|
+
const txFee = await (async () => {
|
|
39
|
+
try {
|
|
40
|
+
const transactionBytes = await txb.build({ client: suiClient });
|
|
41
|
+
const dryRunResult = await suiClient.dryRunTransactionBlock({
|
|
42
|
+
transactionBlock: transactionBytes,
|
|
43
|
+
});
|
|
44
|
+
const computationCost = BigInt(dryRunResult.effects.gasUsed.computationCost);
|
|
45
|
+
const storageCost = BigInt(dryRunResult.effects.gasUsed.storageCost);
|
|
46
|
+
const storageRebate = BigInt(dryRunResult.effects.gasUsed.storageRebate);
|
|
47
|
+
const netStorageCost = storageCost > storageRebate ? storageCost - storageRebate : 0n;
|
|
48
|
+
const estimatedGas = computationCost + netStorageCost;
|
|
49
|
+
return estimatedGas.toString();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error instanceof Error && error.message.includes('Not enough coins of type')) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
73
58
|
const tradeRate = {
|
|
74
59
|
id: (0, uuid_1.v4)(),
|
|
75
60
|
quoteOrRate: 'rate',
|
|
@@ -86,7 +71,7 @@ const getTradeRate = async (input, deps) => {
|
|
|
86
71
|
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount,
|
|
87
72
|
feeData: {
|
|
88
73
|
protocolFees,
|
|
89
|
-
networkFeeCryptoBaseUnit:
|
|
74
|
+
networkFeeCryptoBaseUnit: txFee,
|
|
90
75
|
},
|
|
91
76
|
rate,
|
|
92
77
|
source: types_1.SwapperName.Cetus,
|
|
@@ -97,11 +82,10 @@ const getTradeRate = async (input, deps) => {
|
|
|
97
82
|
},
|
|
98
83
|
],
|
|
99
84
|
};
|
|
100
|
-
|
|
101
|
-
return (0, monads_1.Ok)(rates);
|
|
85
|
+
return tradeDataResult.map(() => [tradeRate]);
|
|
102
86
|
}
|
|
103
87
|
catch (error) {
|
|
104
|
-
return (0, monads_1.Err)((0,
|
|
88
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
105
89
|
message: error instanceof Error ? error.message : 'Unknown error getting Cetus rate',
|
|
106
90
|
code: types_1.TradeQuoteError.QueryFailed,
|
|
107
91
|
}));
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSupportedChainId = exports.SUPPORTED_CETUS_CHAIN_IDS = void 0;
|
|
3
|
+
exports.PYTH_DEPENDENT_PROVIDERS = exports.isSupportedChainId = exports.SUPPORTED_CETUS_CHAIN_IDS = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
exports.SUPPORTED_CETUS_CHAIN_IDS = [caip_1.suiChainId];
|
|
6
6
|
const isSupportedChainId = (chainId) => {
|
|
7
7
|
return exports.SUPPORTED_CETUS_CHAIN_IDS.includes(chainId);
|
|
8
8
|
};
|
|
9
9
|
exports.isSupportedChainId = isSupportedChainId;
|
|
10
|
+
exports.PYTH_DEPENDENT_PROVIDERS = ['HAEDALPMM', 'HAEDALHMMV2', 'METASTABLE'];
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
|
|
2
|
+
import { AggregatorClient } from '@cetusprotocol/aggregator-sdk';
|
|
3
|
+
import { SuiClient } from '@cetusprotocol/aggregator-sdk/node_modules/@mysten/sui/client';
|
|
2
4
|
import type { Asset } from '@shapeshiftoss/types';
|
|
3
|
-
export declare const
|
|
5
|
+
export declare const getAggregatorClient: (rpcUrl: string) => AggregatorClient;
|
|
6
|
+
export declare const getSuiClient: (rpcUrl: string) => SuiClient;
|
|
4
7
|
export declare const getCoinType: (asset: Asset) => string;
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const calculateAmountLimit: (estimatedAmount: string, slippageTolerancePercentageDecimal: string | undefined, isBuyAmount: boolean) => string;
|
|
7
|
-
export declare const findBestPool: (sdk: CetusClmmSDK, sellCoinType: string, buyCoinType: string) => Promise<Pool | undefined>;
|
|
8
|
-
export type CalculateSwapResult = {
|
|
9
|
-
estimatedAmountOut: string;
|
|
10
|
-
estimatedAmountIn: string;
|
|
11
|
-
estimatedFeeAmount: string;
|
|
12
|
-
};
|
|
13
|
-
export declare const calculateSwapAmounts: (sdk: CetusClmmSDK, pool: Pool, sellAsset: Asset, buyAsset: Asset, sellAmount: string) => Promise<CalculateSwapResult | undefined>;
|
|
8
|
+
export declare const findBestRoute: (client: AggregatorClient, sellCoinType: string, buyCoinType: string, sellAmountCryptoBaseUnit: string, providers?: string[]) => Promise<RouterDataV3 | undefined>;
|