@shapeshiftoss/swapper 17.6.9 → 17.6.10
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 +61 -43
- package/dist/cjs/swappers/AcrossSwapper/AcrossSwapper.d.ts +2 -0
- package/dist/cjs/swappers/AcrossSwapper/AcrossSwapper.js +8 -0
- package/dist/cjs/swappers/AcrossSwapper/constant.d.ts +9 -0
- package/dist/cjs/swappers/AcrossSwapper/constant.js +48 -0
- package/dist/cjs/swappers/AcrossSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/AcrossSwapper/endpoints.js +113 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +31 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeRate/getTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/AcrossSwapper/getTradeRate/getTradeRate.js +19 -0
- package/dist/cjs/swappers/AcrossSwapper/index.d.ts +1 -0
- package/dist/cjs/swappers/AcrossSwapper/index.js +5 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.d.ts +5 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.js +17 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.d.ts +19 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +27 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getTrade.d.ts +11 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getTrade.js +335 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/types.d.ts +177 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/types.js +17 -0
- package/dist/cjs/swappers/AvnuSwapper/endpoints.js +42 -14
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +10 -5
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeRate.js +8 -4
- package/dist/cjs/swappers/BebopSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/cjs/swappers/ButterSwap/ButterSwap.js +1 -0
- package/dist/cjs/swappers/ButterSwap/endpoints.js +56 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/checkTradeStatus.js +19 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +27 -14
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +1 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.js +23 -16
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +2 -0
- package/dist/cjs/swappers/ButterSwap/types.d.ts +1 -0
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/cjs/swappers/ButterSwap/xhr.d.ts +2 -2
- package/dist/cjs/swappers/ButterSwap/xhr.js +7 -2
- package/dist/cjs/swappers/CetusSwapper/endpoints.js +3 -8
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +1 -1
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeRate.js +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +11 -5
- package/dist/cjs/swappers/ChainflipSwapper/utils/helpers.js +8 -2
- package/dist/cjs/swappers/CowSwapper/CowSwapper.js +1 -1
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -1
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.test.js +5 -5
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +1 -1
- package/dist/cjs/swappers/CowSwapper/utils/helpers/helpers.js +8 -2
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +31 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +36 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +61 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/NearIntentsSwapper/types.js +6 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +23 -4
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +8 -3
- package/dist/cjs/swappers/RelaySwapper/constant.js +26 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +13 -2
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +100 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +15 -0
- package/dist/cjs/swappers/StonfiSwapper/StonfiSwapper.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/StonfiSwapper.js +8 -0
- package/dist/cjs/swappers/StonfiSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/endpoints.js +227 -0
- package/dist/cjs/swappers/StonfiSwapper/index.d.ts +4 -0
- package/dist/cjs/swappers/StonfiSwapper/index.js +25 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +119 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeRate.d.ts +2 -0
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeRate.js +105 -0
- package/dist/cjs/swappers/StonfiSwapper/types.d.ts +60 -0
- package/dist/cjs/swappers/StonfiSwapper/types.js +5 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/constants.d.ts +5 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/constants.js +8 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/helpers.d.ts +11 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/helpers.js +135 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/omnistonManager.d.ts +5 -0
- package/dist/cjs/swappers/StonfiSwapper/utils/omnistonManager.js +20 -0
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +1 -1
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.js +4 -3
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/cjs/swappers/utils/filterBuyAssetsBySellAssetId/filterBuyAssetsBySellAssetId.js +2 -5
- package/dist/cjs/swappers/utils/helpers/helpers.js +3 -0
- package/dist/cjs/thorchain-utils/getCallDataFromQuote.d.ts +1 -1
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +30 -5
- package/dist/cjs/thorchain-utils/getQuote.js +8 -2
- package/dist/cjs/tron-utils/getUnsignedTronTransaction.js +22 -2
- package/dist/cjs/types.d.ts +79 -8
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils.d.ts +4 -3
- package/dist/cjs/utils.js +35 -7
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +31 -13
- package/dist/esm/swappers/AcrossSwapper/AcrossSwapper.d.ts +2 -0
- package/dist/esm/swappers/AcrossSwapper/AcrossSwapper.js +5 -0
- package/dist/esm/swappers/AcrossSwapper/constant.d.ts +9 -0
- package/dist/esm/swappers/AcrossSwapper/constant.js +42 -0
- package/dist/esm/swappers/AcrossSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/AcrossSwapper/endpoints.js +107 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +27 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeRate/getTradeRate.d.ts +3 -0
- package/dist/esm/swappers/AcrossSwapper/getTradeRate/getTradeRate.js +15 -0
- package/dist/esm/swappers/AcrossSwapper/index.d.ts +1 -0
- package/dist/esm/swappers/AcrossSwapper/index.js +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.d.ts +5 -0
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.js +11 -0
- package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.d.ts +19 -0
- package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +23 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getTrade.d.ts +11 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getTrade.js +328 -0
- package/dist/esm/swappers/AcrossSwapper/utils/types.d.ts +177 -0
- package/dist/esm/swappers/AcrossSwapper/utils/types.js +13 -0
- package/dist/esm/swappers/AvnuSwapper/endpoints.js +43 -15
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +10 -5
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeRate.js +8 -4
- package/dist/esm/swappers/BebopSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/esm/swappers/ButterSwap/ButterSwap.js +2 -1
- package/dist/esm/swappers/ButterSwap/endpoints.js +56 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/checkTradeStatus.js +20 -1
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +29 -16
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +1 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.js +25 -18
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +2 -0
- package/dist/esm/swappers/ButterSwap/types.d.ts +1 -0
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +1 -0
- package/dist/esm/swappers/ButterSwap/xhr.d.ts +2 -2
- package/dist/esm/swappers/ButterSwap/xhr.js +8 -3
- package/dist/esm/swappers/CetusSwapper/endpoints.js +3 -8
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +1 -1
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeRate.js +1 -1
- package/dist/esm/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +12 -6
- package/dist/esm/swappers/ChainflipSwapper/utils/helpers.js +9 -3
- package/dist/esm/swappers/CowSwapper/CowSwapper.js +1 -1
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -1
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.test.js +5 -5
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +1 -1
- package/dist/esm/swappers/CowSwapper/utils/helpers/helpers.js +9 -3
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +31 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +36 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +61 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/NearIntentsSwapper/types.js +6 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +23 -4
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +8 -3
- package/dist/esm/swappers/RelaySwapper/constant.js +28 -3
- package/dist/esm/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +13 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +100 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +15 -0
- package/dist/esm/swappers/StonfiSwapper/StonfiSwapper.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/StonfiSwapper.js +5 -0
- package/dist/esm/swappers/StonfiSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/endpoints.js +224 -0
- package/dist/esm/swappers/StonfiSwapper/index.d.ts +4 -0
- package/dist/esm/swappers/StonfiSwapper/index.js +4 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +115 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeRate.d.ts +2 -0
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeRate.js +101 -0
- package/dist/esm/swappers/StonfiSwapper/types.d.ts +60 -0
- package/dist/esm/swappers/StonfiSwapper/types.js +2 -0
- package/dist/esm/swappers/StonfiSwapper/utils/constants.d.ts +5 -0
- package/dist/esm/swappers/StonfiSwapper/utils/constants.js +5 -0
- package/dist/esm/swappers/StonfiSwapper/utils/helpers.d.ts +11 -0
- package/dist/esm/swappers/StonfiSwapper/utils/helpers.js +124 -0
- package/dist/esm/swappers/StonfiSwapper/utils/omnistonManager.d.ts +5 -0
- package/dist/esm/swappers/StonfiSwapper/utils/omnistonManager.js +17 -0
- package/dist/esm/swappers/SunioSwapper/endpoints.js +1 -1
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.js +5 -4
- package/dist/esm/swappers/ZrxSwapper/utils/helpers/helpers.d.ts +1 -1
- package/dist/esm/swappers/utils/filterBuyAssetsBySellAssetId/filterBuyAssetsBySellAssetId.js +2 -5
- package/dist/esm/swappers/utils/helpers/helpers.js +4 -1
- package/dist/esm/thorchain-utils/getCallDataFromQuote.d.ts +1 -1
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +31 -6
- package/dist/esm/thorchain-utils/getQuote.js +9 -3
- package/dist/esm/tron-utils/getUnsignedTronTransaction.js +22 -2
- package/dist/esm/types.d.ts +79 -8
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils.d.ts +4 -3
- package/dist/esm/utils.js +34 -7
- package/package.json +17 -15
|
@@ -4,11 +4,12 @@ exports.getTradeRate = void 0;
|
|
|
4
4
|
const avnu_sdk_1 = require("@avnu/avnu-sdk");
|
|
5
5
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
6
|
const monads_1 = require("@sniptt/monads");
|
|
7
|
-
const
|
|
7
|
+
const starknet_1 = require("starknet");
|
|
8
8
|
const uuid_1 = require("uuid");
|
|
9
9
|
const constants_1 = require("../../../constants");
|
|
10
10
|
const types_1 = require("../../../types");
|
|
11
11
|
const utils_2 = require("../../../utils");
|
|
12
|
+
const helpers_1 = require("../../utils/helpers/helpers");
|
|
12
13
|
const constants_2 = require("../utils/constants");
|
|
13
14
|
const helpers_2 = require("../utils/helpers");
|
|
14
15
|
const getTradeRate = async (input, deps) => {
|
|
@@ -28,6 +29,9 @@ const getTradeRate = async (input, deps) => {
|
|
|
28
29
|
try {
|
|
29
30
|
const sellTokenAddress = (0, helpers_2.getTokenAddress)(sellAsset);
|
|
30
31
|
const buyTokenAddress = (0, helpers_2.getTokenAddress)(buyAsset);
|
|
32
|
+
// Normalize receive address if provided (for fee estimation)
|
|
33
|
+
// Rate quotes may not have a receive address, so this is optional
|
|
34
|
+
const normalizedReceiveAddress = receiveAddress ? (0, starknet_1.validateAndParseAddress)(receiveAddress) : '';
|
|
31
35
|
const quotes = await (0, avnu_sdk_1.getQuotes)({
|
|
32
36
|
sellTokenAddress,
|
|
33
37
|
buyTokenAddress,
|
|
@@ -53,10 +57,10 @@ const getTradeRate = async (input, deps) => {
|
|
|
53
57
|
const sellAdapter = deps.assertGetStarknetChainAdapter(sellAsset.chainId);
|
|
54
58
|
// For rate quotes, use receiveAddress as a dummy from/to for fee estimation
|
|
55
59
|
const feeData = await sellAdapter.getFeeData({
|
|
56
|
-
to:
|
|
60
|
+
to: normalizedReceiveAddress,
|
|
57
61
|
value: sellAmount,
|
|
58
62
|
chainSpecific: {
|
|
59
|
-
from:
|
|
63
|
+
from: normalizedReceiveAddress,
|
|
60
64
|
tokenContractAddress: sellTokenAddress,
|
|
61
65
|
},
|
|
62
66
|
sendMax: false,
|
|
@@ -81,7 +85,7 @@ const getTradeRate = async (input, deps) => {
|
|
|
81
85
|
: {};
|
|
82
86
|
const tradeRate = {
|
|
83
87
|
id: (0, uuid_1.v4)(),
|
|
84
|
-
receiveAddress,
|
|
88
|
+
receiveAddress: normalizedReceiveAddress || receiveAddress,
|
|
85
89
|
affiliateBps,
|
|
86
90
|
rate,
|
|
87
91
|
slippageTolerancePercentageDecimal: slippageTolerancePercentageDecimal ??
|
|
@@ -5,7 +5,7 @@ export declare const isSupportedChainId: (chainId: ChainId) => chainId is import
|
|
|
5
5
|
export declare const assertValidTrade: ({ buyAsset, sellAsset, }: {
|
|
6
6
|
buyAsset: Asset;
|
|
7
7
|
sellAsset: Asset;
|
|
8
|
-
}) => import("@sniptt/monads/build/result/result").
|
|
8
|
+
}) => import("@sniptt/monads/build/result/result").ResErr<unknown, import("../../../../types").SwapErrorRight> | import("@sniptt/monads/build/result/result").ResOk<boolean, never>;
|
|
9
9
|
export declare const calculateRate: ({ buyAmount, sellAmount, buyAsset, sellAsset, }: {
|
|
10
10
|
buyAmount: string;
|
|
11
11
|
sellAmount: string;
|
|
@@ -5,6 +5,7 @@ const utils_1 = require("../../utils");
|
|
|
5
5
|
exports.butterSwap = {
|
|
6
6
|
executeEvmTransaction: utils_1.executeEvmTransaction,
|
|
7
7
|
executeSolanaTransaction: utils_1.executeSolanaTransaction,
|
|
8
|
+
executeTronTransaction: utils_1.executeTronTransaction,
|
|
8
9
|
executeUtxoTransaction: (txToSign, { signAndBroadcastTransaction }) => {
|
|
9
10
|
return signAndBroadcastTransaction(txToSign);
|
|
10
11
|
},
|
|
@@ -8,6 +8,8 @@ const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
|
8
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
9
|
const getSolanaTransactionFees_1 = require("../../solana-utils/getSolanaTransactionFees");
|
|
10
10
|
const getUnsignedSolanaTransaction_1 = require("../../solana-utils/getUnsignedSolanaTransaction");
|
|
11
|
+
const getTronTransactionFees_1 = require("../../tron-utils/getTronTransactionFees");
|
|
12
|
+
const getUnsignedTronTransaction_1 = require("../../tron-utils/getUnsignedTronTransaction");
|
|
11
13
|
const utils_1 = require("../../utils");
|
|
12
14
|
const checkTradeStatus_1 = require("./swapperApi/checkTradeStatus");
|
|
13
15
|
const getTradeQuote_1 = require("./swapperApi/getTradeQuote");
|
|
@@ -70,6 +72,60 @@ exports.butterSwapApi = {
|
|
|
70
72
|
gasLimit: bignumber_js_1.default.max(feeData.gasLimit, gasLimit).toFixed(),
|
|
71
73
|
});
|
|
72
74
|
},
|
|
75
|
+
getUnsignedUtxoTransaction: async ({ stepIndex, tradeQuote, xpub, accountType, assertGetUtxoChainAdapter, }) => {
|
|
76
|
+
if (!(0, utils_1.isExecutableTradeQuote)(tradeQuote))
|
|
77
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
78
|
+
const step = (0, utils_1.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
79
|
+
const { accountNumber, sellAsset, butterSwapTransactionMetadata } = step;
|
|
80
|
+
if (!butterSwapTransactionMetadata)
|
|
81
|
+
throw new Error('Transaction metadata is required');
|
|
82
|
+
const { to, memo } = butterSwapTransactionMetadata;
|
|
83
|
+
if (!to)
|
|
84
|
+
throw new Error('Missing deposit address');
|
|
85
|
+
if (!memo)
|
|
86
|
+
throw new Error('Missing memo (opReturnData)');
|
|
87
|
+
const adapter = assertGetUtxoChainAdapter(sellAsset.chainId);
|
|
88
|
+
const { fast } = await adapter.getFeeData({
|
|
89
|
+
to,
|
|
90
|
+
value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
91
|
+
chainSpecific: { pubkey: xpub, opReturnData: memo },
|
|
92
|
+
sendMax: false,
|
|
93
|
+
});
|
|
94
|
+
return adapter.buildSendApiTransaction({
|
|
95
|
+
value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
96
|
+
xpub,
|
|
97
|
+
to,
|
|
98
|
+
accountNumber,
|
|
99
|
+
chainSpecific: {
|
|
100
|
+
accountType,
|
|
101
|
+
opReturnData: memo,
|
|
102
|
+
satoshiPerByte: fast.chainSpecific.satoshiPerByte,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
getUtxoTransactionFees: async ({ stepIndex, tradeQuote, xpub, assertGetUtxoChainAdapter }) => {
|
|
107
|
+
if (!(0, utils_1.isExecutableTradeQuote)(tradeQuote))
|
|
108
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
109
|
+
const step = (0, utils_1.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
110
|
+
const { sellAsset, butterSwapTransactionMetadata } = step;
|
|
111
|
+
if (!butterSwapTransactionMetadata)
|
|
112
|
+
throw new Error('Transaction metadata is required');
|
|
113
|
+
const { to, memo } = butterSwapTransactionMetadata;
|
|
114
|
+
if (!to)
|
|
115
|
+
throw new Error('Missing deposit address');
|
|
116
|
+
if (!memo)
|
|
117
|
+
throw new Error('Missing memo (opReturnData)');
|
|
118
|
+
const adapter = assertGetUtxoChainAdapter(sellAsset.chainId);
|
|
119
|
+
const { fast } = await adapter.getFeeData({
|
|
120
|
+
to,
|
|
121
|
+
value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
122
|
+
chainSpecific: { pubkey: xpub, opReturnData: memo },
|
|
123
|
+
sendMax: false,
|
|
124
|
+
});
|
|
125
|
+
return fast.txFee;
|
|
126
|
+
},
|
|
73
127
|
getUnsignedSolanaTransaction: getUnsignedSolanaTransaction_1.getUnsignedSolanaTransaction,
|
|
74
128
|
getSolanaTransactionFees: getSolanaTransactionFees_1.getSolanaTransactionFees,
|
|
129
|
+
getTronTransactionFees: getTronTransactionFees_1.getTronTransactionFees,
|
|
130
|
+
getUnsignedTronTransaction: getUnsignedTronTransaction_1.getUnsignedTronTransaction,
|
|
75
131
|
};
|
|
@@ -36,6 +36,25 @@ const checkTradeStatus = async (input) => {
|
|
|
36
36
|
fetchIsSmartContractAddressQuery,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
+
if (sellChainId === caip_1.tronChainId) {
|
|
40
|
+
const adapter = input.assertGetTronChainAdapter(caip_1.tronChainId);
|
|
41
|
+
const tx = await adapter.httpProvider.getTransaction({ txid: txHash });
|
|
42
|
+
if (!tx) {
|
|
43
|
+
return (0, utils_1.createDefaultStatusResponse)(txHash);
|
|
44
|
+
}
|
|
45
|
+
const contractRet = tx.ret?.[0]?.contractRet;
|
|
46
|
+
// Only mark as confirmed if SUCCESS AND has confirmations (in a block)
|
|
47
|
+
const status = contractRet === 'SUCCESS' && tx.confirmations > 0
|
|
48
|
+
? unchained_client_1.TxStatus.Confirmed
|
|
49
|
+
: contractRet === 'REVERT'
|
|
50
|
+
? unchained_client_1.TxStatus.Failed
|
|
51
|
+
: unchained_client_1.TxStatus.Pending;
|
|
52
|
+
return {
|
|
53
|
+
status,
|
|
54
|
+
buyTxHash: txHash,
|
|
55
|
+
message: undefined,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
39
58
|
// Fallback: unknown same-chain type (should never happen for Butter, but just in case). Avoid bridge polling.
|
|
40
59
|
return (0, utils_1.createDefaultStatusResponse)(txHash);
|
|
41
60
|
}
|
|
@@ -15,19 +15,14 @@ const getTradeQuote = async (input, _deps) => {
|
|
|
15
15
|
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, receiveAddress, sendAddress, slippageTolerancePercentageDecimal, accountNumber, affiliateBps, } = input;
|
|
16
16
|
if (!(0, chain_adapters_1.isEvmChainId)(sellAsset.chainId) &&
|
|
17
17
|
sellAsset.chainId !== caip_1.btcChainId &&
|
|
18
|
-
sellAsset.chainId !== caip_1.solanaChainId
|
|
18
|
+
sellAsset.chainId !== caip_1.solanaChainId &&
|
|
19
|
+
sellAsset.chainId !== caip_1.tronChainId) {
|
|
19
20
|
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
20
21
|
message: `Unsupported chain`,
|
|
21
22
|
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
22
23
|
}));
|
|
23
24
|
}
|
|
24
|
-
//
|
|
25
|
-
if (sellAsset.assetId === caip_1.btcAssetId) {
|
|
26
|
-
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
27
|
-
message: `BTC sells are currently unsupported`,
|
|
28
|
-
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
25
|
+
// TODO: Debug why same-chain Tron swaps revert (swapAndCall method works on EVM but 0 successful on Tron)
|
|
31
26
|
if (!sendAddress) {
|
|
32
27
|
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
33
28
|
message: '[getTradeQuote] sendAddress is required for ButterSwap',
|
|
@@ -41,7 +36,10 @@ const getTradeQuote = async (input, _deps) => {
|
|
|
41
36
|
const routeResult = await (0, xhr_1.getButterRoute)({
|
|
42
37
|
sellAsset,
|
|
43
38
|
buyAsset,
|
|
44
|
-
|
|
39
|
+
sellAmountCryptoPrecision: utils_1.BigAmount.fromBaseUnit({
|
|
40
|
+
value: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
41
|
+
precision: sellAsset.precision,
|
|
42
|
+
}).toPrecision(),
|
|
45
43
|
slippage,
|
|
46
44
|
affiliate: (0, constants_2.makeButterSwapAffiliate)(affiliateBps),
|
|
47
45
|
});
|
|
@@ -50,7 +48,10 @@ const getTradeQuote = async (input, _deps) => {
|
|
|
50
48
|
const routeResponse = routeResult.unwrap();
|
|
51
49
|
if (!(0, xhr_1.isRouteSuccess)(routeResponse)) {
|
|
52
50
|
if (routeResponse.errno === xhr_1.ButterSwapErrorCode.InsufficientAmount) {
|
|
53
|
-
const minAmountCryptoBaseUnit =
|
|
51
|
+
const minAmountCryptoBaseUnit = utils_1.BigAmount.fromPrecision({
|
|
52
|
+
value: routeResponse.minAmount,
|
|
53
|
+
precision: sellAsset.precision,
|
|
54
|
+
}).toBaseUnit();
|
|
54
55
|
return (0, monads_1.Err)((0, utils_2.createTradeAmountTooSmallErr)({
|
|
55
56
|
minAmountCryptoBaseUnit,
|
|
56
57
|
assetId: sellAsset.assetId,
|
|
@@ -100,13 +101,19 @@ const getTradeQuote = async (input, _deps) => {
|
|
|
100
101
|
}));
|
|
101
102
|
}
|
|
102
103
|
// Map gasFee.amount to networkFeeCryptoBaseUnit using fee asset precision
|
|
103
|
-
const networkFeeCryptoBaseUnit =
|
|
104
|
+
const networkFeeCryptoBaseUnit = utils_1.BigAmount.fromPrecision({
|
|
105
|
+
value: (0, utils_1.bnOrZero)(route.gasFee?.amount),
|
|
106
|
+
precision: feeAsset.precision,
|
|
107
|
+
}).toBaseUnit();
|
|
104
108
|
// Use destination receive amount as a priority if present and defined
|
|
105
109
|
// It won't for same-chain swaps, so we fall back to the source chain receive amount (i.e source chain *is* the destination chain)
|
|
106
110
|
const outputAmount = route.dstChain?.totalAmountOut ?? route.srcChain.totalAmountOut;
|
|
107
111
|
// TODO: affiliate fees not yet here, gut feel is that Butter won't do the swap output - fees logic for us here
|
|
108
112
|
// Sanity check me when affiliates are implemented, and do the math ourselves if needed
|
|
109
|
-
const buyAmountAfterFeesCryptoBaseUnit =
|
|
113
|
+
const buyAmountAfterFeesCryptoBaseUnit = utils_1.BigAmount.fromPrecision({
|
|
114
|
+
value: outputAmount,
|
|
115
|
+
precision: buyAsset.precision,
|
|
116
|
+
}).toBaseUnit();
|
|
110
117
|
const rate = (0, utils_2.getInputOutputRate)({
|
|
111
118
|
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
112
119
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
@@ -151,7 +158,10 @@ const getTradeQuote = async (input, _deps) => {
|
|
|
151
158
|
}
|
|
152
159
|
const solanaTransactionMetadata = maybeSolanaTransactionMetadata?.unwrap();
|
|
153
160
|
const step = {
|
|
154
|
-
buyAmountBeforeFeesCryptoBaseUnit:
|
|
161
|
+
buyAmountBeforeFeesCryptoBaseUnit: utils_1.BigAmount.fromPrecision({
|
|
162
|
+
value: outputAmount,
|
|
163
|
+
precision: buyAsset.precision,
|
|
164
|
+
}).toBaseUnit(),
|
|
155
165
|
buyAmountAfterFeesCryptoBaseUnit,
|
|
156
166
|
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
157
167
|
feeData: {
|
|
@@ -163,13 +173,16 @@ const getTradeQuote = async (input, _deps) => {
|
|
|
163
173
|
buyAsset,
|
|
164
174
|
sellAsset,
|
|
165
175
|
accountNumber,
|
|
166
|
-
allowanceContract: route.contract ?? '0x0',
|
|
176
|
+
allowanceContract: sellAsset.chainId === caip_1.tronChainId ? buildTx.to : route.contract ?? '0x0',
|
|
167
177
|
estimatedExecutionTimeMs: route.timeEstimated * 1000,
|
|
168
178
|
butterSwapTransactionMetadata: {
|
|
169
179
|
to: buildTx.to,
|
|
170
180
|
data: buildTx.data,
|
|
171
181
|
value: buildTx.value,
|
|
172
182
|
gasLimit: (0, utils_1.bnOrZero)(route.gasEstimatedTarget).toFixed(),
|
|
183
|
+
method: buildTx.method,
|
|
184
|
+
args: buildTx.args,
|
|
185
|
+
memo: buildTx.memo,
|
|
173
186
|
},
|
|
174
187
|
...(solanaTransactionMetadata && {
|
|
175
188
|
solanaTransactionMetadata,
|
|
@@ -36,6 +36,7 @@ vitest_1.vi.mock('../xhr', () => ({
|
|
|
36
36
|
assertGetSuiChainAdapter: () => vitest_1.vi.fn(),
|
|
37
37
|
assertGetNearChainAdapter: () => vitest_1.vi.fn(),
|
|
38
38
|
assertGetStarknetChainAdapter: () => vitest_1.vi.fn(),
|
|
39
|
+
assertGetTonChainAdapter: () => vitest_1.vi.fn(),
|
|
39
40
|
config: {
|
|
40
41
|
VITE_BUTTERSWAP_CLIENT_ID: 'test',
|
|
41
42
|
},
|
|
@@ -14,29 +14,24 @@ const getTradeRate = async (input, _deps) => {
|
|
|
14
14
|
const { sellAsset, buyAsset, affiliateBps, accountNumber, receiveAddress, sellAmountIncludingProtocolFeesCryptoBaseUnit, } = input;
|
|
15
15
|
if (!(0, chain_adapters_1.isEvmChainId)(sellAsset.chainId) &&
|
|
16
16
|
sellAsset.chainId !== caip_1.btcChainId &&
|
|
17
|
-
sellAsset.chainId !== caip_1.solanaChainId
|
|
17
|
+
sellAsset.chainId !== caip_1.solanaChainId &&
|
|
18
|
+
sellAsset.chainId !== caip_1.tronChainId) {
|
|
18
19
|
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
19
20
|
message: `Unsupported chain`,
|
|
20
21
|
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
21
22
|
}));
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
const amount = (0, utils_1.bn)(sellAmountIncludingProtocolFeesCryptoBaseUnit)
|
|
31
|
-
.shiftedBy(-sellAsset.precision)
|
|
32
|
-
.toString();
|
|
24
|
+
const amount = utils_1.BigAmount.fromBaseUnit({
|
|
25
|
+
value: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
26
|
+
precision: sellAsset.precision,
|
|
27
|
+
}).toPrecision();
|
|
33
28
|
const feeAssetId = (0, utils_1.chainIdToFeeAssetId)(sellAsset.chainId);
|
|
34
29
|
const slippageTolerancePercentageDecimal = (0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.ButterSwap);
|
|
35
30
|
const slippage = (0, utils_1.convertDecimalPercentageToBasisPoints)(slippageTolerancePercentageDecimal).toString();
|
|
36
31
|
const result = await (0, xhr_1.getButterRoute)({
|
|
37
32
|
sellAsset,
|
|
38
33
|
buyAsset,
|
|
39
|
-
|
|
34
|
+
sellAmountCryptoPrecision: amount,
|
|
40
35
|
slippage,
|
|
41
36
|
affiliate: (0, constants_2.makeButterSwapAffiliate)(affiliateBps),
|
|
42
37
|
});
|
|
@@ -46,7 +41,10 @@ const getTradeRate = async (input, _deps) => {
|
|
|
46
41
|
const routeResponse = result.unwrap();
|
|
47
42
|
if (!(0, xhr_1.isRouteSuccess)(routeResponse)) {
|
|
48
43
|
if (routeResponse.errno === xhr_1.ButterSwapErrorCode.InsufficientAmount) {
|
|
49
|
-
const minAmountCryptoBaseUnit =
|
|
44
|
+
const minAmountCryptoBaseUnit = utils_1.BigAmount.fromPrecision({
|
|
45
|
+
value: routeResponse.minAmount,
|
|
46
|
+
precision: sellAsset.precision,
|
|
47
|
+
}).toBaseUnit();
|
|
50
48
|
return (0, monads_1.Err)((0, utils_2.createTradeAmountTooSmallErr)({
|
|
51
49
|
minAmountCryptoBaseUnit,
|
|
52
50
|
assetId: sellAsset.assetId,
|
|
@@ -69,7 +67,10 @@ const getTradeRate = async (input, _deps) => {
|
|
|
69
67
|
const outputAmount = route.dstChain?.totalAmountOut ?? route.srcChain.totalAmountOut;
|
|
70
68
|
// TODO: affiliate fees not yet here, gut feel is that Butter won't do the swap output - fees logic for us here
|
|
71
69
|
// Sanity check me when affiliates are implemented, and do the math ourselves if needed
|
|
72
|
-
const buyAmountAfterFeesCryptoBaseUnit =
|
|
70
|
+
const buyAmountAfterFeesCryptoBaseUnit = utils_1.BigAmount.fromPrecision({
|
|
71
|
+
value: outputAmount,
|
|
72
|
+
precision: buyAsset.precision,
|
|
73
|
+
}).toBaseUnit();
|
|
73
74
|
const rate = (0, utils_2.getInputOutputRate)({
|
|
74
75
|
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
75
76
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
@@ -85,12 +86,18 @@ const getTradeRate = async (input, _deps) => {
|
|
|
85
86
|
}
|
|
86
87
|
// Map gasFee.amount to networkFeeCryptoBaseUnit using fee asset precision
|
|
87
88
|
const networkFeeCryptoBaseUnit = (0, utils_1.bnOrZero)(route.gasFee?.amount).gt(0)
|
|
88
|
-
?
|
|
89
|
+
? utils_1.BigAmount.fromPrecision({
|
|
90
|
+
value: route.gasFee.amount,
|
|
91
|
+
precision: feeAsset.precision,
|
|
92
|
+
}).toBaseUnit()
|
|
89
93
|
: '0';
|
|
90
94
|
// Always a single step
|
|
91
95
|
const step = {
|
|
92
96
|
rate,
|
|
93
|
-
buyAmountBeforeFeesCryptoBaseUnit:
|
|
97
|
+
buyAmountBeforeFeesCryptoBaseUnit: utils_1.BigAmount.fromPrecision({
|
|
98
|
+
value: outputAmount,
|
|
99
|
+
precision: buyAsset.precision,
|
|
100
|
+
}).toBaseUnit(),
|
|
94
101
|
buyAmountAfterFeesCryptoBaseUnit,
|
|
95
102
|
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
96
103
|
feeData: {
|
|
@@ -30,6 +30,7 @@ vitest_1.vi.mock('../utils/butterSwapService', () => ({
|
|
|
30
30
|
assertGetSuiChainAdapter: () => vitest_1.vi.fn(),
|
|
31
31
|
assertGetNearChainAdapter: () => vitest_1.vi.fn(),
|
|
32
32
|
assertGetStarknetChainAdapter: () => vitest_1.vi.fn(),
|
|
33
|
+
assertGetTonChainAdapter: () => vitest_1.vi.fn(),
|
|
33
34
|
config: {
|
|
34
35
|
VITE_BUTTERSWAP_CLIENT_ID: 'test',
|
|
35
36
|
},
|
|
@@ -66,6 +67,7 @@ vitest_1.vi.mock('../utils/butterSwapService', () => ({
|
|
|
66
67
|
assertGetSuiChainAdapter: () => vitest_1.vi.fn(),
|
|
67
68
|
assertGetNearChainAdapter: () => vitest_1.vi.fn(),
|
|
68
69
|
assertGetStarknetChainAdapter: () => vitest_1.vi.fn(),
|
|
70
|
+
assertGetTonChainAdapter: () => vitest_1.vi.fn(),
|
|
69
71
|
config: {
|
|
70
72
|
VITE_BUTTERSWAP_CLIENT_ID: 'test',
|
|
71
73
|
},
|
|
@@ -13,6 +13,7 @@ const BUTTERSWAP_CHAIN_ID_TO_CHAIN_ID = {
|
|
|
13
13
|
43114: types_1.KnownChainIds.AvalancheMainnet,
|
|
14
14
|
1360108768460801: types_1.KnownChainIds.SolanaMainnet,
|
|
15
15
|
1360095883558913: types_1.KnownChainIds.BitcoinMainnet,
|
|
16
|
+
728126428: types_1.KnownChainIds.TronMainnet,
|
|
16
17
|
};
|
|
17
18
|
const CHAIN_ID_TO_BUTTERSWAP_CHAIN_ID = Object.entries(BUTTERSWAP_CHAIN_ID_TO_CHAIN_ID).reduce((acc, [butterSwapChainId, chainId]) => {
|
|
18
19
|
acc[chainId] = Number(butterSwapChainId);
|
|
@@ -20,11 +20,11 @@ type ButterSwapPromise<T> = Promise<Result<T, SwapErrorRight>>;
|
|
|
20
20
|
export type GetButterRouteArgs = {
|
|
21
21
|
sellAsset: Asset;
|
|
22
22
|
buyAsset: Asset;
|
|
23
|
-
|
|
23
|
+
sellAmountCryptoPrecision: string;
|
|
24
24
|
slippage: string;
|
|
25
25
|
affiliate?: string;
|
|
26
26
|
};
|
|
27
|
-
export declare const getButterRoute: ({ sellAsset, buyAsset,
|
|
27
|
+
export declare const getButterRoute: ({ sellAsset, buyAsset, sellAmountCryptoPrecision, slippage, affiliate, }: GetButterRouteArgs) => ButterSwapPromise<RouteResponse>;
|
|
28
28
|
export type ButterBuildTxArgs = {
|
|
29
29
|
hash: string;
|
|
30
30
|
slippage: string;
|
|
@@ -23,7 +23,8 @@ var ButterSwapErrorCode;
|
|
|
23
23
|
ButterSwapErrorCode[ButterSwapErrorCode["InvalidAddress"] = 2007] = "InvalidAddress";
|
|
24
24
|
})(ButterSwapErrorCode || (exports.ButterSwapErrorCode = ButterSwapErrorCode = {}));
|
|
25
25
|
const SOLANA_NATIVE_ADDRESS = 'So11111111111111111111111111111111111111112';
|
|
26
|
-
const
|
|
26
|
+
const TRON_NATIVE_ADDRESS = 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb';
|
|
27
|
+
const getButterRoute = async ({ sellAsset, buyAsset, sellAmountCryptoPrecision, slippage, affiliate, }) => {
|
|
27
28
|
const butterFromChainId = (0, helpers_2.chainIdToButterSwapChainId)(sellAsset.chainId);
|
|
28
29
|
const butterToChainId = (0, helpers_2.chainIdToButterSwapChainId)(buyAsset.chainId);
|
|
29
30
|
if (!butterFromChainId || !butterToChainId) {
|
|
@@ -40,6 +41,8 @@ const getButterRoute = async ({ sellAsset, buyAsset, sellAmountCryptoBaseUnit, s
|
|
|
40
41
|
const sellAssetAddress = (() => {
|
|
41
42
|
if (sellAsset.chainId === caip_1.solanaChainId && sellAssetIsNative)
|
|
42
43
|
return SOLANA_NATIVE_ADDRESS;
|
|
44
|
+
if (sellAsset.chainId === caip_1.tronChainId && sellAssetIsNative)
|
|
45
|
+
return TRON_NATIVE_ADDRESS;
|
|
43
46
|
if (sellAssetIsNative)
|
|
44
47
|
return viem_1.zeroAddress;
|
|
45
48
|
return sellAssetAddressRaw;
|
|
@@ -47,6 +50,8 @@ const getButterRoute = async ({ sellAsset, buyAsset, sellAmountCryptoBaseUnit, s
|
|
|
47
50
|
const buyAssetAddress = (() => {
|
|
48
51
|
if (buyAsset.chainId === caip_1.solanaChainId && buyAssetIsNative)
|
|
49
52
|
return SOLANA_NATIVE_ADDRESS;
|
|
53
|
+
if (buyAsset.chainId === caip_1.tronChainId && buyAssetIsNative)
|
|
54
|
+
return TRON_NATIVE_ADDRESS;
|
|
50
55
|
if (buyAssetIsNative)
|
|
51
56
|
return viem_1.zeroAddress;
|
|
52
57
|
return buyAssetAddressRaw;
|
|
@@ -57,7 +62,7 @@ const getButterRoute = async ({ sellAsset, buyAsset, sellAmountCryptoBaseUnit, s
|
|
|
57
62
|
tokenInAddress: sellAssetAddress,
|
|
58
63
|
toChainId: butterToChainId,
|
|
59
64
|
tokenOutAddress: buyAssetAddress,
|
|
60
|
-
amount:
|
|
65
|
+
amount: sellAmountCryptoPrecision,
|
|
61
66
|
type: 'exactIn',
|
|
62
67
|
slippage,
|
|
63
68
|
entrance: 'shapeshift',
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cetusApi = void 0;
|
|
4
4
|
const aggregator_sdk_1 = require("@cetusprotocol/aggregator-sdk");
|
|
5
|
-
const transactions_1 = require("@
|
|
5
|
+
const transactions_1 = require("@mysten/sui/transactions");
|
|
6
|
+
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
6
7
|
const unchained_client_1 = require("@shapeshiftoss/unchained-client");
|
|
7
8
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
8
9
|
const constants_1 = require("../../constants");
|
|
@@ -54,13 +55,7 @@ exports.cetusApi = {
|
|
|
54
55
|
intentMessage[2] = 0;
|
|
55
56
|
intentMessage.set(transactionBytes, 3);
|
|
56
57
|
const bip44Params = adapter.getBip44Params({ accountNumber });
|
|
57
|
-
const addressNList =
|
|
58
|
-
bip44Params.purpose,
|
|
59
|
-
bip44Params.coinType,
|
|
60
|
-
bip44Params.accountNumber,
|
|
61
|
-
...(bip44Params.isChange !== undefined ? [bip44Params.isChange ? 1 : 0] : []),
|
|
62
|
-
...(bip44Params.addressIndex !== undefined ? [bip44Params.addressIndex] : []),
|
|
63
|
-
];
|
|
58
|
+
const addressNList = (0, chain_adapters_1.toAddressNList)(bip44Params);
|
|
64
59
|
return {
|
|
65
60
|
addressNList,
|
|
66
61
|
intentMessageBytes: intentMessage,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTradeQuote = void 0;
|
|
4
|
-
const transactions_1 = require("@
|
|
4
|
+
const transactions_1 = require("@mysten/sui/transactions");
|
|
5
5
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
6
|
const monads_1 = require("@sniptt/monads");
|
|
7
7
|
const uuid_1 = require("uuid");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTradeRate = void 0;
|
|
4
|
-
const transactions_1 = require("@
|
|
4
|
+
const transactions_1 = require("@mysten/sui/transactions");
|
|
5
5
|
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
6
|
const monads_1 = require("@sniptt/monads");
|
|
7
7
|
const uuid_1 = require("uuid");
|
|
@@ -69,11 +69,11 @@ const getQuoteOrRate = async (input, deps) => {
|
|
|
69
69
|
if (maybeQuoteResponse.isErr()) {
|
|
70
70
|
const error = maybeQuoteResponse.unwrapErr();
|
|
71
71
|
const cause = error.cause;
|
|
72
|
-
if (cause
|
|
73
|
-
cause
|
|
72
|
+
if (cause?.message?.includes('code 400') &&
|
|
73
|
+
cause?.response?.data?.detail?.includes('Amount outside asset bounds')) {
|
|
74
74
|
return (0, monads_1.Err)((0, utils_2.createTradeAmountTooSmallErr)({
|
|
75
75
|
assetId: sellAsset.assetId,
|
|
76
|
-
minAmountCryptoBaseUnit: cause.response?.data
|
|
76
|
+
minAmountCryptoBaseUnit: cause.response?.data?.errors?.minimalAmountNative?.[0],
|
|
77
77
|
}));
|
|
78
78
|
}
|
|
79
79
|
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
@@ -202,7 +202,10 @@ const getQuoteOrRate = async (input, deps) => {
|
|
|
202
202
|
const boostRate = getChainflipQuoteRate(singleQuoteResponse.boostQuote.ingressAmountNative, singleQuoteResponse.boostQuote.egressAmountNative);
|
|
203
203
|
// This is not really a buyAmount before fees but rather an input/output calculation to get the sell amount
|
|
204
204
|
// prorated to the buy asset price to determine price impact
|
|
205
|
-
const buyAmountBeforeFeesCryptoBaseUnit =
|
|
205
|
+
const buyAmountBeforeFeesCryptoBaseUnit = utils_1.BigAmount.fromPrecision({
|
|
206
|
+
value: (0, utils_1.bnOrZero)(singleQuoteResponse.boostQuote.ingressAmount).times((0, utils_1.bnOrZero)(singleQuoteResponse.estimatedPrice)),
|
|
207
|
+
precision: buyAsset.precision,
|
|
208
|
+
}).toBaseUnit();
|
|
206
209
|
const boostTradeRateOrQuote = {
|
|
207
210
|
id: (0, uuid_1.v4)(),
|
|
208
211
|
rate: boostRate,
|
|
@@ -249,7 +252,10 @@ const getQuoteOrRate = async (input, deps) => {
|
|
|
249
252
|
: '0';
|
|
250
253
|
// This is not really a buyAmount before fees but rather an input/output calculation to get the sell amount
|
|
251
254
|
// prorated to the buy asset price to determine price impact
|
|
252
|
-
const buyAmountBeforeFeesCryptoBaseUnit =
|
|
255
|
+
const buyAmountBeforeFeesCryptoBaseUnit = utils_1.BigAmount.fromPrecision({
|
|
256
|
+
value: (0, utils_1.bnOrZero)(singleQuoteResponse.ingressAmount).times((0, utils_1.bnOrZero)(singleQuoteResponse.estimatedPrice)),
|
|
257
|
+
precision: buyAsset.precision,
|
|
258
|
+
}).toBaseUnit();
|
|
253
259
|
const tradeRateOrQuote = {
|
|
254
260
|
id: (0, uuid_1.v4)(),
|
|
255
261
|
rate,
|
|
@@ -20,8 +20,14 @@ const isSupportedAssetId = (chainId, assetId) => {
|
|
|
20
20
|
};
|
|
21
21
|
exports.isSupportedAssetId = isSupportedAssetId;
|
|
22
22
|
const calculateChainflipMinPrice = ({ sellAmountIncludingProtocolFeesCryptoBaseUnit, buyAmountAfterFeesCryptoBaseUnit, slippageTolerancePercentageDecimal, sellAsset, buyAsset, }) => {
|
|
23
|
-
const sellAmountCryptoPrecision =
|
|
24
|
-
|
|
23
|
+
const sellAmountCryptoPrecision = utils_1.BigAmount.fromBaseUnit({
|
|
24
|
+
value: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
25
|
+
precision: sellAsset.precision,
|
|
26
|
+
}).toPrecision();
|
|
27
|
+
const buyAmountCryptoPrecision = utils_1.BigAmount.fromBaseUnit({
|
|
28
|
+
value: buyAmountAfterFeesCryptoBaseUnit,
|
|
29
|
+
precision: buyAsset.precision,
|
|
30
|
+
}).toPrecision();
|
|
25
31
|
const estimatedPrice = (0, utils_1.bn)(buyAmountCryptoPrecision).div(sellAmountCryptoPrecision);
|
|
26
32
|
// This is called minimumPrice upstream but this really is a rate, let's not honour confusing terminology
|
|
27
33
|
const minimumRate = estimatedPrice
|
|
@@ -12,7 +12,7 @@ exports.cowSwapper = {
|
|
|
12
12
|
throw Error('Missing appDataHash');
|
|
13
13
|
const signature = await (0, cowswap_utils_1.signCowOrder)(orderToSign, chainId, signMessage);
|
|
14
14
|
const network = (0, cowswap_utils_1.assertGetCowNetwork)(chainId);
|
|
15
|
-
const maybeOrdersResponse = await cowService_1.cowService.post(`${config.VITE_COWSWAP_BASE_URL}/${network}/api/v1/orders
|
|
15
|
+
const maybeOrdersResponse = await cowService_1.cowService.post(`${config.VITE_COWSWAP_BASE_URL}/${network}/api/v1/orders`, {
|
|
16
16
|
...orderToSign,
|
|
17
17
|
signingScheme: types_1.SigningScheme.EIP712,
|
|
18
18
|
signature,
|
|
@@ -42,7 +42,7 @@ async function getCowSwapTradeQuote(input, config) {
|
|
|
42
42
|
});
|
|
43
43
|
const { appData, appDataHash } = await (0, cowswap_utils_1.getFullAppData)(slippageTolerancePercentageDecimal, affiliateAppDataFragment, 'market');
|
|
44
44
|
// https://api.cow.fi/docs/#/default/post_api_v1_quote
|
|
45
|
-
const maybeQuoteResponse = await cowService_1.cowService.post(`${config.VITE_COWSWAP_BASE_URL}/${network}/api/v1/quote
|
|
45
|
+
const maybeQuoteResponse = await cowService_1.cowService.post(`${config.VITE_COWSWAP_BASE_URL}/${network}/api/v1/quote`, {
|
|
46
46
|
sellToken: (0, caip_1.fromAssetId)(sellAsset.assetId).assetReference,
|
|
47
47
|
buyToken,
|
|
48
48
|
receiver: receiveAddress,
|
|
@@ -385,7 +385,7 @@ const expectedTradeQuoteSmallAmountWethToFox = {
|
|
|
385
385
|
const maybeTradeQuote = await (0, getCowSwapTradeQuote_1.getCowSwapTradeQuote)(input, MOCK_COWSWAP_CONFIG);
|
|
386
386
|
(0, vitest_1.expect)(maybeTradeQuote.isOk()).toBe(true);
|
|
387
387
|
(0, vitest_1.expect)(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteWethToFox);
|
|
388
|
-
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote
|
|
388
|
+
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote', expectedApiInputWethToFox);
|
|
389
389
|
});
|
|
390
390
|
(0, vitest_1.it)('should call cowService with correct parameters, handle the fees and return the correct trade quote when buying ETH', async () => {
|
|
391
391
|
const input = {
|
|
@@ -418,7 +418,7 @@ const expectedTradeQuoteSmallAmountWethToFox = {
|
|
|
418
418
|
const maybeTradeQuote = await (0, getCowSwapTradeQuote_1.getCowSwapTradeQuote)(input, MOCK_COWSWAP_CONFIG);
|
|
419
419
|
(0, vitest_1.expect)(maybeTradeQuote.isOk()).toBe(true);
|
|
420
420
|
(0, vitest_1.expect)(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteFoxToEth);
|
|
421
|
-
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote
|
|
421
|
+
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote', expectedApiInputFoxToEth);
|
|
422
422
|
});
|
|
423
423
|
(0, vitest_1.it)('should call cowService with correct parameters, handle the fees and return the correct trade quote when buying XDAI', async () => {
|
|
424
424
|
const input = {
|
|
@@ -451,7 +451,7 @@ const expectedTradeQuoteSmallAmountWethToFox = {
|
|
|
451
451
|
const maybeTradeQuote = await (0, getCowSwapTradeQuote_1.getCowSwapTradeQuote)(input, MOCK_COWSWAP_CONFIG);
|
|
452
452
|
(0, vitest_1.expect)(maybeTradeQuote.isOk()).toBe(true);
|
|
453
453
|
(0, vitest_1.expect)(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteUsdcToXdai);
|
|
454
|
-
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/xdai/api/v1/quote
|
|
454
|
+
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/xdai/api/v1/quote', expectedApiInputUsdcGnosisToXdai);
|
|
455
455
|
});
|
|
456
456
|
(0, vitest_1.it)('should call cowService with correct parameters, handle the fees and return the correct trade quote when buying ETH on Arbitrum', async () => {
|
|
457
457
|
const input = {
|
|
@@ -484,7 +484,7 @@ const expectedTradeQuoteSmallAmountWethToFox = {
|
|
|
484
484
|
const maybeTradeQuote = await (0, getCowSwapTradeQuote_1.getCowSwapTradeQuote)(input, MOCK_COWSWAP_CONFIG);
|
|
485
485
|
(0, vitest_1.expect)(maybeTradeQuote.isOk()).toBe(true);
|
|
486
486
|
(0, vitest_1.expect)(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteUsdcToEthArbitrum);
|
|
487
|
-
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/arbitrum_one/api/v1/quote
|
|
487
|
+
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/arbitrum_one/api/v1/quote', expectedApiInputUsdcToEthArbitrum);
|
|
488
488
|
});
|
|
489
489
|
(0, vitest_1.it)('should call cowService with correct parameters and return quote with original sellAmount when selling a very small amount of WETH', async () => {
|
|
490
490
|
const input = {
|
|
@@ -517,6 +517,6 @@ const expectedTradeQuoteSmallAmountWethToFox = {
|
|
|
517
517
|
const maybeTradeQuote = await (0, getCowSwapTradeQuote_1.getCowSwapTradeQuote)(input, MOCK_COWSWAP_CONFIG);
|
|
518
518
|
(0, vitest_1.expect)(maybeTradeQuote.isErr()).toBe(false);
|
|
519
519
|
(0, vitest_1.expect)(maybeTradeQuote.unwrap()).toEqual(expectedTradeQuoteSmallAmountWethToFox);
|
|
520
|
-
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote
|
|
520
|
+
(0, vitest_1.expect)(cowService_1.cowService.post).toHaveBeenCalledWith('https://api.cow.fi/mainnet/api/v1/quote', expectedApiInputSmallAmountWethToFox);
|
|
521
521
|
});
|
|
522
522
|
});
|
|
@@ -42,7 +42,7 @@ async function getCowSwapTradeRate(input, config) {
|
|
|
42
42
|
});
|
|
43
43
|
const { appData, appDataHash } = await (0, cowswap_utils_1.getFullAppData)(slippageTolerancePercentageDecimal, affiliateAppDataFragment, 'market');
|
|
44
44
|
// https://api.cow.fi/docs/#/default/post_api_v1_quote
|
|
45
|
-
const maybeQuoteResponse = await cowService_1.cowService.post(`${config.VITE_COWSWAP_BASE_URL}/${network}/api/v1/quote
|
|
45
|
+
const maybeQuoteResponse = await cowService_1.cowService.post(`${config.VITE_COWSWAP_BASE_URL}/${network}/api/v1/quote`, {
|
|
46
46
|
sellToken: (0, caip_1.fromAssetId)(sellAsset.assetId).assetReference,
|
|
47
47
|
buyToken,
|
|
48
48
|
receiver: receiveAddress,
|