@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
package/dist/cjs/constants.js
CHANGED
|
@@ -4,29 +4,33 @@ exports.isAutoSlippageSupportedBySwapper = exports.getDefaultSlippageDecimalPerc
|
|
|
4
4
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
5
|
const ArbitrumBridgeSwapper_1 = require("./swappers/ArbitrumBridgeSwapper/ArbitrumBridgeSwapper");
|
|
6
6
|
const endpoints_1 = require("./swappers/ArbitrumBridgeSwapper/endpoints");
|
|
7
|
+
const AvnuSwapper_1 = require("./swappers/AvnuSwapper/AvnuSwapper");
|
|
8
|
+
const endpoints_2 = require("./swappers/AvnuSwapper/endpoints");
|
|
7
9
|
const BebopSwapper_1 = require("./swappers/BebopSwapper/BebopSwapper");
|
|
8
|
-
const
|
|
10
|
+
const endpoints_3 = require("./swappers/BebopSwapper/endpoints");
|
|
9
11
|
const ButterSwap_1 = require("./swappers/ButterSwap/ButterSwap");
|
|
10
|
-
const
|
|
12
|
+
const endpoints_4 = require("./swappers/ButterSwap/endpoints");
|
|
11
13
|
const CetusSwapper_1 = require("./swappers/CetusSwapper/CetusSwapper");
|
|
12
|
-
const
|
|
14
|
+
const endpoints_5 = require("./swappers/CetusSwapper/endpoints");
|
|
13
15
|
const ChainflipSwapper_1 = require("./swappers/ChainflipSwapper/ChainflipSwapper");
|
|
14
|
-
const
|
|
16
|
+
const endpoints_6 = require("./swappers/ChainflipSwapper/endpoints");
|
|
15
17
|
const CowSwapper_1 = require("./swappers/CowSwapper/CowSwapper");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
+
const endpoints_7 = require("./swappers/CowSwapper/endpoints");
|
|
19
|
+
const endpoints_8 = require("./swappers/JupiterSwapper/endpoints");
|
|
18
20
|
const JupiterSwapper_1 = require("./swappers/JupiterSwapper/JupiterSwapper");
|
|
19
|
-
const
|
|
21
|
+
const endpoints_9 = require("./swappers/MayachainSwapper/endpoints");
|
|
20
22
|
const MayachainSwapper_1 = require("./swappers/MayachainSwapper/MayachainSwapper");
|
|
21
|
-
const
|
|
23
|
+
const endpoints_10 = require("./swappers/NearIntentsSwapper/endpoints");
|
|
22
24
|
const NearIntentsSwapper_1 = require("./swappers/NearIntentsSwapper/NearIntentsSwapper");
|
|
23
|
-
const
|
|
25
|
+
const endpoints_11 = require("./swappers/PortalsSwapper/endpoints");
|
|
24
26
|
const PortalsSwapper_1 = require("./swappers/PortalsSwapper/PortalsSwapper");
|
|
25
27
|
const RelaySwapper_1 = require("./swappers/RelaySwapper");
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
+
const endpoints_12 = require("./swappers/RelaySwapper/endpoints");
|
|
29
|
+
const endpoints_13 = require("./swappers/SunioSwapper/endpoints");
|
|
30
|
+
const SunioSwapper_1 = require("./swappers/SunioSwapper/SunioSwapper");
|
|
31
|
+
const endpoints_14 = require("./swappers/ThorchainSwapper/endpoints");
|
|
28
32
|
const ThorchainSwapper_1 = require("./swappers/ThorchainSwapper/ThorchainSwapper");
|
|
29
|
-
const
|
|
33
|
+
const endpoints_15 = require("./swappers/ZrxSwapper/endpoints");
|
|
30
34
|
const ZrxSwapper_1 = require("./swappers/ZrxSwapper/ZrxSwapper");
|
|
31
35
|
const types_1 = require("./types");
|
|
32
36
|
const utils_2 = require("./utils");
|
|
@@ -40,19 +44,19 @@ exports.QUOTE_TIMEOUT_ERROR = (0, utils_2.makeSwapErrorRight)({
|
|
|
40
44
|
exports.swappers = {
|
|
41
45
|
[types_1.SwapperName.Thorchain]: {
|
|
42
46
|
...ThorchainSwapper_1.thorchainSwapper,
|
|
43
|
-
...
|
|
47
|
+
...endpoints_14.thorchainApi,
|
|
44
48
|
},
|
|
45
49
|
[types_1.SwapperName.Mayachain]: {
|
|
46
50
|
...MayachainSwapper_1.mayachainSwapper,
|
|
47
|
-
...
|
|
51
|
+
...endpoints_9.mayachainApi,
|
|
48
52
|
},
|
|
49
53
|
[types_1.SwapperName.Zrx]: {
|
|
50
54
|
...ZrxSwapper_1.zrxSwapper,
|
|
51
|
-
...
|
|
55
|
+
...endpoints_15.zrxApi,
|
|
52
56
|
},
|
|
53
57
|
[types_1.SwapperName.CowSwap]: {
|
|
54
58
|
...CowSwapper_1.cowSwapper,
|
|
55
|
-
...
|
|
59
|
+
...endpoints_7.cowApi,
|
|
56
60
|
},
|
|
57
61
|
[types_1.SwapperName.ArbitrumBridge]: {
|
|
58
62
|
...ArbitrumBridgeSwapper_1.arbitrumBridgeSwapper,
|
|
@@ -60,35 +64,43 @@ exports.swappers = {
|
|
|
60
64
|
},
|
|
61
65
|
[types_1.SwapperName.Portals]: {
|
|
62
66
|
...PortalsSwapper_1.portalsSwapper,
|
|
63
|
-
...
|
|
67
|
+
...endpoints_11.portalsApi,
|
|
64
68
|
},
|
|
65
69
|
[types_1.SwapperName.Chainflip]: {
|
|
66
70
|
...ChainflipSwapper_1.chainflipSwapper,
|
|
67
|
-
...
|
|
71
|
+
...endpoints_6.chainflipApi,
|
|
68
72
|
},
|
|
69
73
|
[types_1.SwapperName.Jupiter]: {
|
|
70
74
|
...JupiterSwapper_1.jupiterSwapper,
|
|
71
|
-
...
|
|
75
|
+
...endpoints_8.jupiterApi,
|
|
72
76
|
},
|
|
73
77
|
[types_1.SwapperName.Relay]: {
|
|
74
78
|
...RelaySwapper_1.relaySwapper,
|
|
75
|
-
...
|
|
79
|
+
...endpoints_12.relayApi,
|
|
76
80
|
},
|
|
77
81
|
[types_1.SwapperName.ButterSwap]: {
|
|
78
82
|
...ButterSwap_1.butterSwap,
|
|
79
|
-
...
|
|
83
|
+
...endpoints_4.butterSwapApi,
|
|
80
84
|
},
|
|
81
85
|
[types_1.SwapperName.Bebop]: {
|
|
82
86
|
...BebopSwapper_1.bebopSwapper,
|
|
83
|
-
...
|
|
87
|
+
...endpoints_3.bebopApi,
|
|
84
88
|
},
|
|
85
89
|
[types_1.SwapperName.NearIntents]: {
|
|
86
90
|
...NearIntentsSwapper_1.nearIntentsSwapper,
|
|
87
|
-
...
|
|
91
|
+
...endpoints_10.nearIntentsApi,
|
|
88
92
|
},
|
|
89
93
|
[types_1.SwapperName.Cetus]: {
|
|
90
94
|
...CetusSwapper_1.cetusSwapper,
|
|
91
|
-
...
|
|
95
|
+
...endpoints_5.cetusApi,
|
|
96
|
+
},
|
|
97
|
+
[types_1.SwapperName.Sunio]: {
|
|
98
|
+
...SunioSwapper_1.sunioSwapper,
|
|
99
|
+
...endpoints_13.sunioApi,
|
|
100
|
+
},
|
|
101
|
+
[types_1.SwapperName.Avnu]: {
|
|
102
|
+
...AvnuSwapper_1.avnuSwapper,
|
|
103
|
+
...endpoints_2.avnuApi,
|
|
92
104
|
},
|
|
93
105
|
[types_1.SwapperName.Test]: undefined,
|
|
94
106
|
};
|
|
@@ -103,6 +115,8 @@ const DEFAULT_ARBITRUM_BRIDGE_SLIPPAGE_DECIMAL_PERCENTAGE = '0'; // no slippage
|
|
|
103
115
|
const DEFAULT_CHAINFLIP_SLIPPAGE_DECIMAL_PERCENTAGE = '0.02'; // 2%
|
|
104
116
|
const DEFAULT_BUTTERSWAP_SLIPPAGE_DECIMAL_PERCENTAGE = '0.015'; // 1.5%
|
|
105
117
|
const DEFAULT_CETUS_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005'; // .5%
|
|
118
|
+
const DEFAULT_SUNIO_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005'; // .5%
|
|
119
|
+
const DEFAULT_AVNU_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005'; // .5%
|
|
106
120
|
const getDefaultSlippageDecimalPercentageForSwapper = (swapperName) => {
|
|
107
121
|
if (swapperName === undefined)
|
|
108
122
|
return DEFAULT_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
@@ -133,6 +147,10 @@ const getDefaultSlippageDecimalPercentageForSwapper = (swapperName) => {
|
|
|
133
147
|
return DEFAULT_NEAR_INTENTS_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
134
148
|
case types_1.SwapperName.Cetus:
|
|
135
149
|
return DEFAULT_CETUS_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
150
|
+
case types_1.SwapperName.Sunio:
|
|
151
|
+
return DEFAULT_SUNIO_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
152
|
+
case types_1.SwapperName.Avnu:
|
|
153
|
+
return DEFAULT_AVNU_SLIPPAGE_DECIMAL_PERCENTAGE;
|
|
136
154
|
default:
|
|
137
155
|
return (0, utils_1.assertUnreachable)(swapperName);
|
|
138
156
|
}
|
|
@@ -26,6 +26,7 @@ exports.SUPPORTED_CHAIN_IDS = [
|
|
|
26
26
|
types_1.KnownChainIds.BaseMainnet,
|
|
27
27
|
types_1.KnownChainIds.AvalancheMainnet,
|
|
28
28
|
types_1.KnownChainIds.PolygonMainnet,
|
|
29
|
+
types_1.KnownChainIds.BnbSmartChainMainnet,
|
|
29
30
|
];
|
|
30
31
|
exports.COW_SWAP_VAULT_RELAYER_ADDRESS = '0xc92e8bdf79f0507f65a392b0ab4667716bfe0110';
|
|
31
32
|
exports.COW_SWAP_SETTLEMENT_ADDRESS = '0x9008D19f58AAbD9eD0D60971565AA8510560ab41';
|
|
@@ -39,6 +39,8 @@ const getCowNetwork = (chainId) => {
|
|
|
39
39
|
return types_1.CowNetwork.Avalanche;
|
|
40
40
|
case types_1.KnownChainIds.PolygonMainnet:
|
|
41
41
|
return types_1.CowNetwork.Polygon;
|
|
42
|
+
case types_1.KnownChainIds.BnbSmartChainMainnet:
|
|
43
|
+
return types_1.CowNetwork.Bnb;
|
|
42
44
|
default:
|
|
43
45
|
return;
|
|
44
46
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ export * from './cowswap-utils';
|
|
|
3
3
|
export * from './safe-utils';
|
|
4
4
|
export * from './swapper';
|
|
5
5
|
export * from './swappers/ArbitrumBridgeSwapper';
|
|
6
|
+
export * from './swappers/AvnuSwapper';
|
|
6
7
|
export * from './swappers/BebopSwapper';
|
|
7
8
|
export * from './swappers/CetusSwapper';
|
|
8
9
|
export * from './swappers/ChainflipSwapper';
|
|
10
|
+
export * from './swappers/SunioSwapper';
|
|
9
11
|
export * from './swappers/CowSwapper';
|
|
10
12
|
export * from './swappers/JupiterSwapper';
|
|
11
13
|
export * from './swappers/PortalsSwapper';
|
package/dist/cjs/index.js
CHANGED
|
@@ -32,9 +32,11 @@ __exportStar(require("./cowswap-utils"), exports);
|
|
|
32
32
|
__exportStar(require("./safe-utils"), exports);
|
|
33
33
|
__exportStar(require("./swapper"), exports);
|
|
34
34
|
__exportStar(require("./swappers/ArbitrumBridgeSwapper"), exports);
|
|
35
|
+
__exportStar(require("./swappers/AvnuSwapper"), exports);
|
|
35
36
|
__exportStar(require("./swappers/BebopSwapper"), exports);
|
|
36
37
|
__exportStar(require("./swappers/CetusSwapper"), exports);
|
|
37
38
|
__exportStar(require("./swappers/ChainflipSwapper"), exports);
|
|
39
|
+
__exportStar(require("./swappers/SunioSwapper"), exports);
|
|
38
40
|
__exportStar(require("./swappers/CowSwapper"), exports);
|
|
39
41
|
__exportStar(require("./swappers/JupiterSwapper"), exports);
|
|
40
42
|
__exportStar(require("./swappers/PortalsSwapper"), exports);
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.avnuApi = void 0;
|
|
4
|
+
const avnu_sdk_1 = require("@avnu/avnu-sdk");
|
|
5
|
+
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
6
|
+
const starknet_1 = require("starknet");
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const getTradeQuote_1 = require("./swapperApi/getTradeQuote");
|
|
9
|
+
const getTradeRate_1 = require("./swapperApi/getTradeRate");
|
|
10
|
+
exports.avnuApi = {
|
|
11
|
+
getTradeQuote: getTradeQuote_1.getTradeQuote,
|
|
12
|
+
getTradeRate: (input, deps) => {
|
|
13
|
+
return (0, getTradeRate_1.getTradeRate)(input, deps);
|
|
14
|
+
},
|
|
15
|
+
getUnsignedStarknetTransaction: async ({ stepIndex, tradeQuote, from, slippageTolerancePercentageDecimal, assertGetStarknetChainAdapter, }) => {
|
|
16
|
+
if (!(0, utils_1.isExecutableTradeQuote)(tradeQuote))
|
|
17
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
18
|
+
const step = (0, utils_1.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
19
|
+
const { accountNumber, sellAsset, avnuSpecific } = step;
|
|
20
|
+
if (!avnuSpecific)
|
|
21
|
+
throw new Error('avnuSpecific is required');
|
|
22
|
+
if (!avnuSpecific.quoteId)
|
|
23
|
+
throw new Error('quoteId is required in avnuSpecific');
|
|
24
|
+
const adapter = assertGetStarknetChainAdapter(sellAsset.chainId);
|
|
25
|
+
// Convert slippage from decimal percentage string to number for AVNU format (e.g., "0.01" = 1%)
|
|
26
|
+
const slippage = slippageTolerancePercentageDecimal
|
|
27
|
+
? parseFloat(slippageTolerancePercentageDecimal)
|
|
28
|
+
: 0.01;
|
|
29
|
+
// Get the swap calls from AVNU SDK
|
|
30
|
+
const { calls: avnuCalls } = await (0, avnu_sdk_1.quoteToCalls)({
|
|
31
|
+
quoteId: avnuSpecific.quoteId,
|
|
32
|
+
slippage,
|
|
33
|
+
takerAddress: from,
|
|
34
|
+
});
|
|
35
|
+
// Build the full invoke transaction calldata from AVNU calls
|
|
36
|
+
// Format: [call_array_length, contract1, selector1, calldata_len1, ...calldata1, ...]
|
|
37
|
+
const fullCalldata = [avnuCalls.length.toString()];
|
|
38
|
+
for (const call of avnuCalls) {
|
|
39
|
+
const rawCalldata = call.calldata ?? [];
|
|
40
|
+
const calldataArray = Array.isArray(rawCalldata) ? rawCalldata : starknet_1.CallData.compile(rawCalldata);
|
|
41
|
+
const selector = starknet_1.hash.getSelectorFromName(call.entrypoint);
|
|
42
|
+
fullCalldata.push(call.contractAddress, selector, calldataArray.length.toString(), ...calldataArray.map(cd => cd.toString()));
|
|
43
|
+
}
|
|
44
|
+
// Format calldata for RPC (convert numbers to hex)
|
|
45
|
+
const formattedCalldata = fullCalldata.map(data => {
|
|
46
|
+
if (!data.startsWith('0x')) {
|
|
47
|
+
return starknet_1.num.toHex(data);
|
|
48
|
+
}
|
|
49
|
+
return data;
|
|
50
|
+
});
|
|
51
|
+
// Get nonce using adapter method (checks deployment status and returns appropriate nonce)
|
|
52
|
+
const chainIdHex = await adapter.getStarknetProvider().getChainId();
|
|
53
|
+
const nonce = await adapter.getNonce(from);
|
|
54
|
+
// Estimate fees for the multi-call swap transaction
|
|
55
|
+
const version = '0x3';
|
|
56
|
+
const estimateTx = {
|
|
57
|
+
type: 'INVOKE',
|
|
58
|
+
version,
|
|
59
|
+
sender_address: from,
|
|
60
|
+
calldata: formattedCalldata,
|
|
61
|
+
signature: [],
|
|
62
|
+
nonce,
|
|
63
|
+
resource_bounds: {
|
|
64
|
+
l1_gas: { max_amount: '0x186a0', max_price_per_unit: '0x5f5e100' },
|
|
65
|
+
l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
|
|
66
|
+
l1_data_gas: { max_amount: '0x186a0', max_price_per_unit: '0x1' },
|
|
67
|
+
},
|
|
68
|
+
tip: '0x0',
|
|
69
|
+
paymaster_data: [],
|
|
70
|
+
account_deployment_data: [],
|
|
71
|
+
nonce_data_availability_mode: 'L1',
|
|
72
|
+
fee_data_availability_mode: 'L1',
|
|
73
|
+
};
|
|
74
|
+
const estimateResponse = await adapter
|
|
75
|
+
.getStarknetProvider()
|
|
76
|
+
.fetch('starknet_estimateFee', [[estimateTx], ['SKIP_VALIDATE'], 'latest']);
|
|
77
|
+
const estimateResult = await estimateResponse.json();
|
|
78
|
+
if (estimateResult.error) {
|
|
79
|
+
throw new Error(`Fee estimation failed: ${JSON.stringify(estimateResult.error)}`);
|
|
80
|
+
}
|
|
81
|
+
const feeEstimate = estimateResult.result?.[0];
|
|
82
|
+
if (!feeEstimate) {
|
|
83
|
+
throw new Error('Fee estimation failed: no estimate returned');
|
|
84
|
+
}
|
|
85
|
+
// Calculate resource bounds with buffer (5x gas amount, 2x gas price)
|
|
86
|
+
const l1GasConsumed = feeEstimate.l1_gas_consumed
|
|
87
|
+
? BigInt(feeEstimate.l1_gas_consumed)
|
|
88
|
+
: BigInt('0x186a0');
|
|
89
|
+
const l1GasPrice = feeEstimate.l1_gas_price
|
|
90
|
+
? BigInt(feeEstimate.l1_gas_price)
|
|
91
|
+
: BigInt('0x5f5e100');
|
|
92
|
+
const l2GasConsumed = feeEstimate.l2_gas_consumed
|
|
93
|
+
? BigInt(feeEstimate.l2_gas_consumed)
|
|
94
|
+
: BigInt('0x0');
|
|
95
|
+
const l2GasPrice = feeEstimate.l2_gas_price ? BigInt(feeEstimate.l2_gas_price) : BigInt('0x0');
|
|
96
|
+
const l1DataGasConsumed = feeEstimate.l1_data_gas_consumed
|
|
97
|
+
? BigInt(feeEstimate.l1_data_gas_consumed)
|
|
98
|
+
: BigInt('0x186a0');
|
|
99
|
+
const l1DataGasPrice = feeEstimate.l1_data_gas_price
|
|
100
|
+
? BigInt(feeEstimate.l1_data_gas_price)
|
|
101
|
+
: BigInt('0x1');
|
|
102
|
+
const resourceBounds = {
|
|
103
|
+
l1_gas: {
|
|
104
|
+
max_amount: (l1GasConsumed * BigInt(500)) / BigInt(100),
|
|
105
|
+
max_price_per_unit: (l1GasPrice * BigInt(200)) / BigInt(100),
|
|
106
|
+
},
|
|
107
|
+
l2_gas: {
|
|
108
|
+
max_amount: (l2GasConsumed * BigInt(500)) / BigInt(100),
|
|
109
|
+
max_price_per_unit: (l2GasPrice * BigInt(200)) / BigInt(100),
|
|
110
|
+
},
|
|
111
|
+
l1_data_gas: {
|
|
112
|
+
max_amount: (l1DataGasConsumed * BigInt(500)) / BigInt(100),
|
|
113
|
+
max_price_per_unit: (l1DataGasPrice * BigInt(200)) / BigInt(100),
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
// Calculate transaction hash for signing
|
|
117
|
+
const invokeHashInputs = {
|
|
118
|
+
senderAddress: from,
|
|
119
|
+
version,
|
|
120
|
+
compiledCalldata: formattedCalldata,
|
|
121
|
+
chainId: chainIdHex,
|
|
122
|
+
nonce,
|
|
123
|
+
nonceDataAvailabilityMode: 0,
|
|
124
|
+
feeDataAvailabilityMode: 0,
|
|
125
|
+
resourceBounds: {
|
|
126
|
+
l1_gas: {
|
|
127
|
+
max_amount: resourceBounds.l1_gas.max_amount,
|
|
128
|
+
max_price_per_unit: resourceBounds.l1_gas.max_price_per_unit,
|
|
129
|
+
},
|
|
130
|
+
l2_gas: {
|
|
131
|
+
max_amount: resourceBounds.l2_gas.max_amount,
|
|
132
|
+
max_price_per_unit: resourceBounds.l2_gas.max_price_per_unit,
|
|
133
|
+
},
|
|
134
|
+
l1_data_gas: {
|
|
135
|
+
max_amount: resourceBounds.l1_data_gas.max_amount,
|
|
136
|
+
max_price_per_unit: resourceBounds.l1_data_gas.max_price_per_unit,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
tip: '0x0',
|
|
140
|
+
paymasterData: [],
|
|
141
|
+
accountDeploymentData: [],
|
|
142
|
+
};
|
|
143
|
+
const txHash = starknet_1.hash.calculateInvokeTransactionHash(invokeHashInputs);
|
|
144
|
+
// Return transaction ready for signing
|
|
145
|
+
return {
|
|
146
|
+
addressNList: (0, chain_adapters_1.toAddressNList)(adapter.getBip44Params({ accountNumber })),
|
|
147
|
+
txHash,
|
|
148
|
+
_txDetails: {
|
|
149
|
+
fromAddress: from,
|
|
150
|
+
calldata: formattedCalldata,
|
|
151
|
+
nonce,
|
|
152
|
+
version,
|
|
153
|
+
resourceBounds,
|
|
154
|
+
chainId: chainIdHex,
|
|
155
|
+
nonceDataAvailabilityMode: 0,
|
|
156
|
+
feeDataAvailabilityMode: 0,
|
|
157
|
+
tip: '0x0',
|
|
158
|
+
paymasterData: [],
|
|
159
|
+
accountDeploymentData: [],
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
getStarknetTransactionFees: ({ tradeQuote, stepIndex }) => {
|
|
164
|
+
if (!(0, utils_1.isExecutableTradeQuote)(tradeQuote))
|
|
165
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
166
|
+
const step = (0, utils_1.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
167
|
+
if (!step.feeData.networkFeeCryptoBaseUnit) {
|
|
168
|
+
throw new Error('Missing network fee in quote');
|
|
169
|
+
}
|
|
170
|
+
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
171
|
+
},
|
|
172
|
+
checkTradeStatus: ({ swap, assertGetStarknetChainAdapter }) => {
|
|
173
|
+
if (!swap?.sellTxHash) {
|
|
174
|
+
return Promise.resolve((0, utils_1.createDefaultStatusResponse)());
|
|
175
|
+
}
|
|
176
|
+
return (0, utils_1.checkStarknetSwapStatus)({
|
|
177
|
+
txHash: swap.sellTxHash,
|
|
178
|
+
assertGetStarknetChainAdapter,
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AVNU_SUPPORTED_CHAIN_IDS } from './utils/constants';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AVNU_SUPPORTED_CHAIN_IDS = void 0;
|
|
4
|
+
var constants_1 = require("./utils/constants");
|
|
5
|
+
Object.defineProperty(exports, "AVNU_SUPPORTED_CHAIN_IDS", { enumerable: true, get: function () { return constants_1.AVNU_SUPPORTED_CHAIN_IDS; } });
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { CommonTradeQuoteInput, SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types';
|
|
3
|
+
export declare const getTradeQuote: (input: CommonTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote[], SwapErrorRight>>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTradeQuote = void 0;
|
|
4
|
+
const avnu_sdk_1 = require("@avnu/avnu-sdk");
|
|
5
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
|
+
const monads_1 = require("@sniptt/monads");
|
|
7
|
+
const helpers_1 = require("packages/swapper/src/swappers/utils/helpers/helpers");
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const constants_1 = require("../../../constants");
|
|
10
|
+
const types_1 = require("../../../types");
|
|
11
|
+
const utils_2 = require("../../../utils");
|
|
12
|
+
const constants_2 = require("../utils/constants");
|
|
13
|
+
const helpers_2 = require("../utils/helpers");
|
|
14
|
+
const getTradeQuote = async (input, deps) => {
|
|
15
|
+
const { sellAsset, buyAsset, accountNumber, sendAddress, receiveAddress, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, slippageTolerancePercentageDecimal, affiliateBps, } = input;
|
|
16
|
+
if (!constants_2.AVNU_SUPPORTED_CHAIN_IDS.includes(sellAsset.chainId)) {
|
|
17
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
18
|
+
message: `Chain ${sellAsset.chainId} is not supported by AVNU`,
|
|
19
|
+
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
if (!constants_2.AVNU_SUPPORTED_CHAIN_IDS.includes(buyAsset.chainId)) {
|
|
23
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
24
|
+
message: `Chain ${buyAsset.chainId} is not supported by AVNU`,
|
|
25
|
+
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
if (accountNumber === undefined) {
|
|
29
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
30
|
+
message: `accountNumber is required`,
|
|
31
|
+
code: types_1.TradeQuoteError.UnknownError,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
if (sendAddress === undefined) {
|
|
35
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
36
|
+
message: `sendAddress is required`,
|
|
37
|
+
code: types_1.TradeQuoteError.UnknownError,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
if (receiveAddress === undefined) {
|
|
41
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
42
|
+
message: `receiveAddress is required`,
|
|
43
|
+
code: types_1.TradeQuoteError.UnknownError,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const sellTokenAddress = (0, helpers_2.getTokenAddress)(sellAsset);
|
|
48
|
+
const buyTokenAddress = (0, helpers_2.getTokenAddress)(buyAsset);
|
|
49
|
+
const quotes = await (0, avnu_sdk_1.getQuotes)({
|
|
50
|
+
sellTokenAddress,
|
|
51
|
+
buyTokenAddress,
|
|
52
|
+
sellAmount: BigInt(sellAmount),
|
|
53
|
+
takerAddress: sendAddress,
|
|
54
|
+
size: 1,
|
|
55
|
+
integratorFees: affiliateBps ? BigInt(affiliateBps) : undefined,
|
|
56
|
+
integratorFeeRecipient: (0, helpers_1.getTreasuryAddressFromChainId)(sellAsset.chainId),
|
|
57
|
+
});
|
|
58
|
+
if (!quotes || quotes.length === 0) {
|
|
59
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
60
|
+
message: 'No quotes available for this trade pair',
|
|
61
|
+
code: types_1.TradeQuoteError.NoRouteFound,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
const bestQuote = quotes[0];
|
|
65
|
+
if (!bestQuote) {
|
|
66
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
67
|
+
message: 'No valid quote returned from AVNU',
|
|
68
|
+
code: types_1.TradeQuoteError.QueryFailed,
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
const buyAmountAfterFeesCryptoBaseUnit = bestQuote.buyAmount.toString();
|
|
72
|
+
const sellAdapter = deps.assertGetStarknetChainAdapter(sellAsset.chainId);
|
|
73
|
+
const feeData = await sellAdapter.getFeeData({
|
|
74
|
+
to: receiveAddress,
|
|
75
|
+
value: sellAmount,
|
|
76
|
+
chainSpecific: {
|
|
77
|
+
from: sendAddress,
|
|
78
|
+
tokenContractAddress: sellTokenAddress,
|
|
79
|
+
},
|
|
80
|
+
sendMax: false,
|
|
81
|
+
});
|
|
82
|
+
const rate = (0, utils_2.getInputOutputRate)({
|
|
83
|
+
sellAmountCryptoBaseUnit: sellAmount,
|
|
84
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
85
|
+
sellAsset,
|
|
86
|
+
buyAsset,
|
|
87
|
+
});
|
|
88
|
+
const protocolFees = affiliateBps
|
|
89
|
+
? {
|
|
90
|
+
[buyAsset.assetId]: {
|
|
91
|
+
amountCryptoBaseUnit: (0, utils_1.bn)(buyAmountAfterFeesCryptoBaseUnit)
|
|
92
|
+
.times(affiliateBps)
|
|
93
|
+
.div(10000)
|
|
94
|
+
.toFixed(0),
|
|
95
|
+
requiresBalance: false,
|
|
96
|
+
asset: buyAsset,
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
: {};
|
|
100
|
+
const tradeQuote = {
|
|
101
|
+
id: (0, uuid_1.v4)(),
|
|
102
|
+
receiveAddress,
|
|
103
|
+
affiliateBps,
|
|
104
|
+
rate,
|
|
105
|
+
slippageTolerancePercentageDecimal: slippageTolerancePercentageDecimal ??
|
|
106
|
+
(0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.Avnu),
|
|
107
|
+
quoteOrRate: 'quote',
|
|
108
|
+
swapperName: types_1.SwapperName.Avnu,
|
|
109
|
+
steps: [
|
|
110
|
+
{
|
|
111
|
+
accountNumber,
|
|
112
|
+
allowanceContract: '0x0',
|
|
113
|
+
buyAmountBeforeFeesCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
114
|
+
buyAmountAfterFeesCryptoBaseUnit,
|
|
115
|
+
buyAsset,
|
|
116
|
+
feeData: {
|
|
117
|
+
protocolFees,
|
|
118
|
+
networkFeeCryptoBaseUnit: feeData.fast.txFee,
|
|
119
|
+
},
|
|
120
|
+
rate,
|
|
121
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount,
|
|
122
|
+
sellAsset,
|
|
123
|
+
source: types_1.SwapperName.Avnu,
|
|
124
|
+
estimatedExecutionTimeMs: undefined,
|
|
125
|
+
avnuSpecific: {
|
|
126
|
+
quoteId: bestQuote.quoteId,
|
|
127
|
+
routes: bestQuote.routes,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
return (0, monads_1.Ok)([tradeQuote]);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
136
|
+
message: error instanceof Error ? error.message : 'Unknown error getting AVNU quote',
|
|
137
|
+
code: types_1.TradeQuoteError.QueryFailed,
|
|
138
|
+
cause: error,
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
exports.getTradeQuote = getTradeQuote;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { GetTradeRateInput, SwapErrorRight, SwapperDeps, TradeRate } from '../../../types';
|
|
3
|
+
export declare const getTradeRate: (input: GetTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate[], SwapErrorRight>>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTradeRate = void 0;
|
|
4
|
+
const avnu_sdk_1 = require("@avnu/avnu-sdk");
|
|
5
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
|
+
const monads_1 = require("@sniptt/monads");
|
|
7
|
+
const helpers_1 = require("packages/swapper/src/swappers/utils/helpers/helpers");
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const constants_1 = require("../../../constants");
|
|
10
|
+
const types_1 = require("../../../types");
|
|
11
|
+
const utils_2 = require("../../../utils");
|
|
12
|
+
const constants_2 = require("../utils/constants");
|
|
13
|
+
const helpers_2 = require("../utils/helpers");
|
|
14
|
+
const getTradeRate = async (input, deps) => {
|
|
15
|
+
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, slippageTolerancePercentageDecimal, affiliateBps, receiveAddress, } = input;
|
|
16
|
+
if (!constants_2.AVNU_SUPPORTED_CHAIN_IDS.includes(sellAsset.chainId)) {
|
|
17
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
18
|
+
message: `Chain ${sellAsset.chainId} is not supported by AVNU`,
|
|
19
|
+
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
if (!constants_2.AVNU_SUPPORTED_CHAIN_IDS.includes(buyAsset.chainId)) {
|
|
23
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
24
|
+
message: `Chain ${buyAsset.chainId} is not supported by AVNU`,
|
|
25
|
+
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const sellTokenAddress = (0, helpers_2.getTokenAddress)(sellAsset);
|
|
30
|
+
const buyTokenAddress = (0, helpers_2.getTokenAddress)(buyAsset);
|
|
31
|
+
const quotes = await (0, avnu_sdk_1.getQuotes)({
|
|
32
|
+
sellTokenAddress,
|
|
33
|
+
buyTokenAddress,
|
|
34
|
+
sellAmount: BigInt(sellAmount),
|
|
35
|
+
size: 1,
|
|
36
|
+
integratorFees: affiliateBps ? BigInt(affiliateBps) : undefined,
|
|
37
|
+
integratorFeeRecipient: (0, helpers_1.getTreasuryAddressFromChainId)(sellAsset.chainId),
|
|
38
|
+
});
|
|
39
|
+
if (!quotes || quotes.length === 0) {
|
|
40
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
41
|
+
message: 'No quotes available for this trade pair',
|
|
42
|
+
code: types_1.TradeQuoteError.NoRouteFound,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
const bestQuote = quotes[0];
|
|
46
|
+
if (!bestQuote) {
|
|
47
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
48
|
+
message: 'No valid quote returned from AVNU',
|
|
49
|
+
code: types_1.TradeQuoteError.QueryFailed,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
const buyAmountAfterFeesCryptoBaseUnit = bestQuote.buyAmount.toString();
|
|
53
|
+
const sellAdapter = deps.assertGetStarknetChainAdapter(sellAsset.chainId);
|
|
54
|
+
// For rate quotes, use receiveAddress as a dummy from/to for fee estimation
|
|
55
|
+
const feeData = await sellAdapter.getFeeData({
|
|
56
|
+
to: receiveAddress ?? '',
|
|
57
|
+
value: sellAmount,
|
|
58
|
+
chainSpecific: {
|
|
59
|
+
from: receiveAddress ?? '',
|
|
60
|
+
tokenContractAddress: sellTokenAddress,
|
|
61
|
+
},
|
|
62
|
+
sendMax: false,
|
|
63
|
+
});
|
|
64
|
+
const rate = (0, utils_2.getInputOutputRate)({
|
|
65
|
+
sellAmountCryptoBaseUnit: sellAmount,
|
|
66
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
67
|
+
sellAsset,
|
|
68
|
+
buyAsset,
|
|
69
|
+
});
|
|
70
|
+
const protocolFees = affiliateBps
|
|
71
|
+
? {
|
|
72
|
+
[buyAsset.assetId]: {
|
|
73
|
+
amountCryptoBaseUnit: (0, utils_1.bn)(buyAmountAfterFeesCryptoBaseUnit)
|
|
74
|
+
.times(affiliateBps)
|
|
75
|
+
.div(10000)
|
|
76
|
+
.toFixed(0),
|
|
77
|
+
requiresBalance: false,
|
|
78
|
+
asset: buyAsset,
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
: {};
|
|
82
|
+
const tradeRate = {
|
|
83
|
+
id: (0, uuid_1.v4)(),
|
|
84
|
+
receiveAddress,
|
|
85
|
+
affiliateBps,
|
|
86
|
+
rate,
|
|
87
|
+
slippageTolerancePercentageDecimal: slippageTolerancePercentageDecimal ??
|
|
88
|
+
(0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.Avnu),
|
|
89
|
+
quoteOrRate: 'rate',
|
|
90
|
+
swapperName: types_1.SwapperName.Avnu,
|
|
91
|
+
steps: [
|
|
92
|
+
{
|
|
93
|
+
accountNumber: undefined,
|
|
94
|
+
allowanceContract: '0x0',
|
|
95
|
+
buyAmountBeforeFeesCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
96
|
+
buyAmountAfterFeesCryptoBaseUnit,
|
|
97
|
+
buyAsset,
|
|
98
|
+
feeData: {
|
|
99
|
+
protocolFees,
|
|
100
|
+
networkFeeCryptoBaseUnit: feeData.fast.txFee,
|
|
101
|
+
},
|
|
102
|
+
rate,
|
|
103
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount,
|
|
104
|
+
sellAsset,
|
|
105
|
+
source: types_1.SwapperName.Avnu,
|
|
106
|
+
estimatedExecutionTimeMs: undefined,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
return (0, monads_1.Ok)([tradeRate]);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
114
|
+
message: error instanceof Error ? error.message : 'Unknown error getting AVNU rate',
|
|
115
|
+
code: types_1.TradeQuoteError.QueryFailed,
|
|
116
|
+
cause: error,
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
exports.getTradeRate = getTradeRate;
|