@shapeshiftoss/swapper 18.1.0 → 20.0.0
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/exactOutputFiltering.test.d.ts +1 -0
- package/dist/cjs/exactOutputFiltering.test.js +70 -0
- package/dist/cjs/swapper.d.ts +3 -3
- package/dist/cjs/swapper.js +29 -6
- package/dist/cjs/swappers/AcrossSwapper/constant.js +2 -1
- package/dist/cjs/swappers/AcrossSwapper/endpoints.js +1 -1
- package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +2 -1
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.d.ts +6 -3
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.js +5 -1
- package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +1 -1
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossStepData.d.ts +1 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossStepData.js +2 -2
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +2 -0
- package/dist/cjs/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +3 -1
- package/dist/cjs/swappers/AvnuSwapper/utils/getAvnuTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/AvnuSwapper/utils/getAvnuTradeContext.js +1 -0
- package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +5 -2
- package/dist/cjs/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +2 -1
- package/dist/cjs/swappers/BebopSwapper/types.d.ts +2 -2
- package/dist/cjs/swappers/BebopSwapper/types.js +2 -0
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopStepData.d.ts +1 -0
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopStepData.js +2 -2
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.js +2 -0
- package/dist/cjs/swappers/BebopSwapper/utils/helpers.d.ts +1 -1
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +10 -8
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/ChainflipSwapper/constants.d.ts +1 -0
- package/dist/cjs/swappers/ChainflipSwapper/constants.js +3 -1
- package/dist/cjs/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -0
- package/dist/cjs/swappers/DebridgeSwapper/constant.js +10 -8
- package/dist/cjs/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +1 -0
- package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +2 -2
- package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +5 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +21 -9
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +2 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +14 -9
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +3 -1
- package/dist/cjs/swappers/NearIntentsSwapper/utils/exactOutput.test.d.ts +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/exactOutput.test.js +61 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.d.ts +2 -2
- package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.js +4 -2
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.d.ts +3 -3
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +27 -23
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +11 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.js +3 -3
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +7 -1
- package/dist/cjs/swappers/RelaySwapper/constant.js +4 -3
- package/dist/cjs/swappers/RelaySwapper/endpoints.js +12 -2
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +7 -2
- package/dist/cjs/swappers/RelaySwapper/getTradeRate/getTradeRate.d.ts +2 -1
- package/dist/cjs/swappers/RelaySwapper/getTradeRate/getTradeRate.js +5 -2
- package/dist/cjs/swappers/RelaySwapper/utils/fetchRelayTrade.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.js +3 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayTradeContext.d.ts +2 -2
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayTradeContext.js +22 -10
- package/dist/cjs/swappers/RelaySwapper/utils/helpers.d.ts +2 -2
- package/dist/cjs/swappers/RelaySwapper/utils/notifyTransactionIndexing.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayService.d.ts +6 -3
- package/dist/cjs/swappers/RelaySwapper/utils/relayService.js +3 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +6 -3
- package/dist/cjs/swappers/StonfiSwapper/endpoints.js +40 -14
- package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +2 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.d.ts +1 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.js +2 -2
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTradeContext.js +6 -1
- package/dist/cjs/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +2 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/getLongtailQuote.js +2 -0
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/types.d.ts +1 -1
- package/dist/cjs/swappers/ZrxSwapper/types.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/utils/constants.js +1 -0
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers.js +5 -0
- package/dist/cjs/types.d.ts +22 -2
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/helpers.d.ts +8 -0
- package/dist/cjs/utils/helpers.js +18 -1
- package/dist/cjs/utils/helpers.test.js +17 -0
- package/dist/cjs/utils/test-data/setupSwapQuote.js +1 -0
- package/dist/cjs/utils/thorchain/getThorL1TradeQuote.js +3 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/exactOutputFiltering.test.d.ts +1 -0
- package/dist/esm/exactOutputFiltering.test.js +68 -0
- package/dist/esm/swapper.d.ts +3 -3
- package/dist/esm/swapper.js +29 -6
- package/dist/esm/swappers/AcrossSwapper/constant.js +4 -3
- package/dist/esm/swappers/AcrossSwapper/endpoints.js +2 -2
- package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +2 -1
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.d.ts +6 -3
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.js +3 -0
- package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +2 -2
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossStepData.d.ts +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossStepData.js +2 -2
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.d.ts +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +3 -1
- package/dist/esm/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +3 -1
- package/dist/esm/swappers/AvnuSwapper/utils/getAvnuTradeContext.d.ts +1 -0
- package/dist/esm/swappers/AvnuSwapper/utils/getAvnuTradeContext.js +2 -1
- package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +3 -0
- package/dist/esm/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +2 -1
- package/dist/esm/swappers/BebopSwapper/types.d.ts +2 -2
- package/dist/esm/swappers/BebopSwapper/types.js +2 -0
- package/dist/esm/swappers/BebopSwapper/utils/getBebopStepData.d.ts +1 -0
- package/dist/esm/swappers/BebopSwapper/utils/getBebopStepData.js +2 -2
- package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.d.ts +1 -0
- package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.js +3 -1
- package/dist/esm/swappers/BebopSwapper/utils/helpers.d.ts +1 -1
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +10 -8
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/ChainflipSwapper/constants.d.ts +1 -0
- package/dist/esm/swappers/ChainflipSwapper/constants.js +2 -0
- package/dist/esm/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -0
- package/dist/esm/swappers/DebridgeSwapper/constant.js +11 -9
- package/dist/esm/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +1 -0
- package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +2 -2
- package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +7 -3
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +14 -3
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +2 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +7 -3
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +3 -1
- package/dist/esm/swappers/NearIntentsSwapper/utils/exactOutput.test.d.ts +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/exactOutput.test.js +59 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.d.ts +2 -2
- package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.js +4 -2
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.d.ts +3 -3
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +27 -23
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +12 -1
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.js +3 -3
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +1 -0
- package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +7 -1
- package/dist/esm/swappers/RelaySwapper/constant.js +6 -5
- package/dist/esm/swappers/RelaySwapper/endpoints.js +15 -5
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +5 -1
- package/dist/esm/swappers/RelaySwapper/getTradeRate/getTradeRate.d.ts +2 -1
- package/dist/esm/swappers/RelaySwapper/getTradeRate/getTradeRate.js +3 -1
- package/dist/esm/swappers/RelaySwapper/utils/fetchRelayTrade.js +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.js +3 -1
- package/dist/esm/swappers/RelaySwapper/utils/getRelayTradeContext.d.ts +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayTradeContext.js +23 -11
- package/dist/esm/swappers/RelaySwapper/utils/helpers.d.ts +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/notifyTransactionIndexing.js +2 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayService.d.ts +6 -3
- package/dist/esm/swappers/RelaySwapper/utils/relayService.js +1 -0
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +6 -3
- package/dist/esm/swappers/StonfiSwapper/endpoints.js +41 -15
- package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +2 -0
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +2 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.d.ts +1 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.js +2 -2
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTradeContext.js +6 -1
- package/dist/esm/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +2 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/getLongtailQuote.js +2 -0
- package/dist/esm/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +2 -1
- package/dist/esm/swappers/ZrxSwapper/types.d.ts +1 -1
- package/dist/esm/swappers/ZrxSwapper/types.js +1 -0
- package/dist/esm/swappers/ZrxSwapper/utils/constants.js +1 -0
- package/dist/esm/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
- package/dist/esm/swappers/ZrxSwapper/utils/helpers.js +5 -0
- package/dist/esm/types.d.ts +22 -2
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/helpers.d.ts +8 -0
- package/dist/esm/utils/helpers.js +15 -0
- package/dist/esm/utils/helpers.test.js +18 -1
- package/dist/esm/utils/test-data/setupSwapQuote.js +1 -0
- package/dist/esm/utils/thorchain/getThorL1TradeQuote.js +3 -0
- package/package.json +7 -7
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTradeQuote = void 0;
|
|
3
|
+
exports.getExactOutputTradeQuote = exports.getTradeQuote = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
|
+
const helpers_1 = require("../../../utils/helpers");
|
|
6
7
|
const getRelayStepData_1 = require("../utils/getRelayStepData");
|
|
7
8
|
const getRelayTradeContext_1 = require("../utils/getRelayTradeContext");
|
|
8
|
-
const
|
|
9
|
+
const getQuote = async (input, deps, relayChainMap) => {
|
|
9
10
|
const { accountNumber } = input;
|
|
10
11
|
const addresses = (0, utils_1.assertQuoteAddresses)(input);
|
|
11
12
|
if (addresses.isErr())
|
|
@@ -45,9 +46,13 @@ const getTradeQuote = async (input, deps, relayChainMap) => {
|
|
|
45
46
|
const tradeQuote = {
|
|
46
47
|
...tradeCommon,
|
|
47
48
|
quoteOrRate: 'quote',
|
|
49
|
+
deadline: Date.now() + helpers_1.FALLBACK_QUOTE_DEADLINE_MS,
|
|
48
50
|
receiveAddress,
|
|
49
51
|
steps,
|
|
50
52
|
};
|
|
51
53
|
return (0, monads_1.Ok)([tradeQuote]);
|
|
52
54
|
};
|
|
55
|
+
const getTradeQuote = (input, deps, relayChainMap) => getQuote(input, deps, relayChainMap);
|
|
53
56
|
exports.getTradeQuote = getTradeQuote;
|
|
57
|
+
const getExactOutputTradeQuote = (input, deps, relayChainMap) => getQuote(input, deps, relayChainMap);
|
|
58
|
+
exports.getExactOutputTradeQuote = getExactOutputTradeQuote;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Result } from '@sniptt/monads';
|
|
2
2
|
import type { SwapErrorRight, SwapperDeps, TradeRate } from '../../../types';
|
|
3
3
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant';
|
|
4
|
-
import type { RelayTradeRateInput } from '../utils/types';
|
|
4
|
+
import type { RelayExactOutputTradeRateInput, RelayTradeRateInput } from '../utils/types';
|
|
5
5
|
export declare const getTradeRate: (input: RelayTradeRateInput, deps: SwapperDeps, relayChainMap: typeof relayChainMapImplementation) => Promise<Result<TradeRate[], SwapErrorRight>>;
|
|
6
|
+
export declare const getExactOutputTradeRate: (input: RelayExactOutputTradeRateInput, deps: SwapperDeps, relayChainMap: typeof relayChainMapImplementation) => Promise<Result<TradeRate[], SwapErrorRight>>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTradeRate = void 0;
|
|
3
|
+
exports.getExactOutputTradeRate = exports.getTradeRate = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const getRelayStepData_1 = require("../utils/getRelayStepData");
|
|
6
6
|
const getRelayTradeContext_1 = require("../utils/getRelayTradeContext");
|
|
7
|
-
const
|
|
7
|
+
const getRate = async (input, deps, relayChainMap) => {
|
|
8
8
|
const maybeContext = await (0, getRelayTradeContext_1.getRelayTradeContext)({ input, deps, relayChainMap });
|
|
9
9
|
if (maybeContext.isErr())
|
|
10
10
|
return (0, monads_1.Err)(maybeContext.unwrapErr());
|
|
@@ -39,4 +39,7 @@ const getTradeRate = async (input, deps, relayChainMap) => {
|
|
|
39
39
|
};
|
|
40
40
|
return (0, monads_1.Ok)([tradeRate]);
|
|
41
41
|
};
|
|
42
|
+
const getTradeRate = (input, deps, relayChainMap) => getRate(input, deps, relayChainMap);
|
|
42
43
|
exports.getTradeRate = getTradeRate;
|
|
44
|
+
const getExactOutputTradeRate = (input, deps, relayChainMap) => getRate(input, deps, relayChainMap);
|
|
45
|
+
exports.getExactOutputTradeRate = getExactOutputTradeRate;
|
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fetchRelayTrade = void 0;
|
|
4
4
|
const relayService_1 = require("./relayService");
|
|
5
5
|
const fetchRelayTrade = async (params, config) => {
|
|
6
|
-
return await relayService_1.relayService.post(`${config.VITE_RELAY_API_URL}/quote/v2`, params);
|
|
6
|
+
return await relayService_1.relayService.post(`${config.VITE_RELAY_API_URL}/quote/v2`, params, (0, relayService_1.getRelayRequestConfig)(config));
|
|
7
7
|
};
|
|
8
8
|
exports.fetchRelayTrade = fetchRelayTrade;
|
|
@@ -10,10 +10,12 @@ const getLatestRelayStatusMessage = (status) => {
|
|
|
10
10
|
case statusValue === 'delayed':
|
|
11
11
|
return constant_1.RelayStatusMessage.Retrying;
|
|
12
12
|
case statusValue === 'pending':
|
|
13
|
+
case statusValue === 'depositing':
|
|
14
|
+
case statusValue === 'submitted':
|
|
13
15
|
return constant_1.RelayStatusMessage.DepositDetected;
|
|
14
16
|
case statusValue === 'success':
|
|
15
17
|
return constant_1.RelayStatusMessage.SwapComplete;
|
|
16
|
-
case statusValue === '
|
|
18
|
+
case statusValue === 'failure':
|
|
17
19
|
return constant_1.RelayStatusMessage.SwapFailed;
|
|
18
20
|
default:
|
|
19
21
|
return 'Unknown status';
|
|
@@ -2,7 +2,7 @@ import type { Result } from '@sniptt/monads';
|
|
|
2
2
|
import type { QuoteFeeData, SwapErrorRight, SwapperDeps, TradeCommon, TradeStepCommon } from '../../../types';
|
|
3
3
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant';
|
|
4
4
|
import type { GetRelayStepDataArgs } from './getRelayStepData';
|
|
5
|
-
import type { RelayQuoteItem, RelayTradeQuoteInput, RelayTradeRateInput } from './types';
|
|
5
|
+
import type { RelayExactOutputTradeQuoteInput, RelayExactOutputTradeRateInput, RelayQuoteItem, RelayTradeQuoteInput, RelayTradeRateInput } from './types';
|
|
6
6
|
type RelayTradeContext = {
|
|
7
7
|
tradeCommon: TradeCommon;
|
|
8
8
|
stepCommon: Omit<TradeStepCommon, 'feeData' | 'allowanceContract'>;
|
|
@@ -15,7 +15,7 @@ type RelayTradeContext = {
|
|
|
15
15
|
relayId: string;
|
|
16
16
|
};
|
|
17
17
|
export declare const getRelayTradeContext: ({ input, deps, relayChainMap, }: {
|
|
18
|
-
input: RelayTradeQuoteInput | RelayTradeRateInput;
|
|
18
|
+
input: RelayTradeQuoteInput | RelayTradeRateInput | RelayExactOutputTradeQuoteInput | RelayExactOutputTradeRateInput;
|
|
19
19
|
deps: SwapperDeps;
|
|
20
20
|
relayChainMap: typeof relayChainMapImplementation;
|
|
21
21
|
}) => Promise<Result<RelayTradeContext, SwapErrorRight>>;
|
|
@@ -22,7 +22,9 @@ const fetchRelayTrade_1 = require("./fetchRelayTrade");
|
|
|
22
22
|
const helpers_2 = require("./helpers");
|
|
23
23
|
const types_2 = require("./types");
|
|
24
24
|
const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
25
|
-
const { sellAsset, buyAsset,
|
|
25
|
+
const { sellAsset, buyAsset, affiliateBps } = input;
|
|
26
|
+
const amount = (0, helpers_1.getTradeAmount)(input);
|
|
27
|
+
const isExactOutput = amount.direction === 'exactOut';
|
|
26
28
|
const xpub = 'xpub' in input ? input.xpub : undefined;
|
|
27
29
|
const slippageToleranceBps = input.slippageTolerancePercentageDecimal
|
|
28
30
|
? (0, utils_1.convertDecimalPercentageToBasisPoints)(input.slippageTolerancePercentageDecimal).toFixed()
|
|
@@ -41,8 +43,8 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
41
43
|
originCurrency: (0, getRelayAssetAddress_1.getRelayAssetAddress)(sellAsset),
|
|
42
44
|
destinationChainId: buyRelayChainId,
|
|
43
45
|
destinationCurrency: (0, getRelayAssetAddress_1.getRelayAssetAddress)(buyAsset),
|
|
44
|
-
tradeType: 'EXACT_INPUT',
|
|
45
|
-
amount:
|
|
46
|
+
tradeType: isExactOutput ? 'EXACT_OUTPUT' : 'EXACT_INPUT',
|
|
47
|
+
amount: amount.cryptoBaseUnit,
|
|
46
48
|
recipient,
|
|
47
49
|
user: sendAddress,
|
|
48
50
|
refundTo,
|
|
@@ -84,10 +86,19 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
84
86
|
code: types_1.TradeQuoteError.UnknownError,
|
|
85
87
|
}));
|
|
86
88
|
}
|
|
87
|
-
const { slippageTolerance, currencyOut, timeEstimate } = quote.details;
|
|
88
|
-
const
|
|
89
|
+
const { slippageTolerance, currencyIn, currencyOut, timeEstimate } = quote.details;
|
|
90
|
+
const sellAmountCryptoBaseUnit = currencyIn.amount;
|
|
91
|
+
const buyAmountAfterFeesCryptoBaseUnit = isExactOutput
|
|
92
|
+
? currencyOut.minimumAmount
|
|
93
|
+
: currencyOut.amount;
|
|
94
|
+
if (isExactOutput && !(0, utils_1.bnOrZero)(buyAmountAfterFeesCryptoBaseUnit).eq(amount.cryptoBaseUnit)) {
|
|
95
|
+
return (0, monads_1.Err)((0, utils_2.makeSwapErrorRight)({
|
|
96
|
+
message: `Relay guarantees ${buyAmountAfterFeesCryptoBaseUnit} against a requested exact output of ${amount.cryptoBaseUnit}`,
|
|
97
|
+
code: types_1.TradeQuoteError.InvalidResponse,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
89
100
|
const rate = (0, utils_2.getInputOutputRate)({
|
|
90
|
-
sellAmountCryptoBaseUnit
|
|
101
|
+
sellAmountCryptoBaseUnit,
|
|
91
102
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
92
103
|
sellAsset,
|
|
93
104
|
buyAsset,
|
|
@@ -248,7 +259,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
248
259
|
})();
|
|
249
260
|
// Add back relayer service and gas fees (relayer is including both) since they are downsides,
|
|
250
261
|
// and add appFees — these are quote-level and identical across every step
|
|
251
|
-
const buyAmountBeforeFeesCryptoBaseUnit = (0, utils_1.bnOrZero)(
|
|
262
|
+
const buyAmountBeforeFeesCryptoBaseUnit = (0, utils_1.bnOrZero)(buyAmountAfterFeesCryptoBaseUnit)
|
|
252
263
|
.plus(relayerFeesBuyAssetCryptoBaseUnit)
|
|
253
264
|
.plus(appFeesBaseUnit)
|
|
254
265
|
.toFixed();
|
|
@@ -262,6 +273,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
262
273
|
id: relayId,
|
|
263
274
|
rate,
|
|
264
275
|
swapperName: types_1.SwapperName.Relay,
|
|
276
|
+
isExactOutput,
|
|
265
277
|
affiliateBps,
|
|
266
278
|
slippageTolerancePercentageDecimal,
|
|
267
279
|
},
|
|
@@ -269,7 +281,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
269
281
|
rate,
|
|
270
282
|
buyAmountBeforeFeesCryptoBaseUnit,
|
|
271
283
|
buyAmountAfterFeesCryptoBaseUnit,
|
|
272
|
-
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
284
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmountCryptoBaseUnit,
|
|
273
285
|
buyAsset,
|
|
274
286
|
sellAsset,
|
|
275
287
|
source: types_1.SwapperName.Relay,
|
|
@@ -279,7 +291,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
279
291
|
affiliateBps,
|
|
280
292
|
sellAsset,
|
|
281
293
|
buyAsset,
|
|
282
|
-
sellAmountCryptoBaseUnit
|
|
294
|
+
sellAmountCryptoBaseUnit,
|
|
283
295
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
284
296
|
fixedAssetId: (0, utils_1.chainIdToFeeAssetId)(caip_1.baseChainId),
|
|
285
297
|
fixedAsset: deps.assetsById[(0, utils_1.chainIdToFeeAssetId)(caip_1.baseChainId)],
|
|
@@ -297,7 +309,7 @@ const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
297
309
|
relayStepInputs,
|
|
298
310
|
stepDataArgs: {
|
|
299
311
|
sellAsset,
|
|
300
|
-
sellAmountCryptoBaseUnit
|
|
312
|
+
sellAmountCryptoBaseUnit,
|
|
301
313
|
orderId,
|
|
302
314
|
from: sendAddress,
|
|
303
315
|
xpub,
|
|
@@ -4,7 +4,7 @@ import type { Result } from '@sniptt/monads';
|
|
|
4
4
|
import type { TransactionInstruction } from '@solana/web3.js';
|
|
5
5
|
import type { SwapErrorRight } from '../../../types';
|
|
6
6
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant';
|
|
7
|
-
import type { RelayQuoteItem, RelaySolanaInstruction, RelayTradeQuoteInput, RelayTradeRateInput } from './types';
|
|
7
|
+
import type { RelayExactOutputTradeQuoteInput, RelayExactOutputTradeRateInput, RelayQuoteItem, RelaySolanaInstruction, RelayTradeQuoteInput, RelayTradeRateInput } from './types';
|
|
8
8
|
export declare const assertValidTrade: ({ sellAsset, buyAsset, relayChainMap, }: {
|
|
9
9
|
sellAsset: Asset;
|
|
10
10
|
buyAsset: Asset;
|
|
@@ -14,7 +14,7 @@ export declare const assertValidTrade: ({ sellAsset, buyAsset, relayChainMap, }:
|
|
|
14
14
|
buyRelayChainId: number;
|
|
15
15
|
}, SwapErrorRight>;
|
|
16
16
|
export declare const resolveRelayAddresses: ({ input, sellChainId, buyChainId, }: {
|
|
17
|
-
input: RelayTradeQuoteInput | RelayTradeRateInput;
|
|
17
|
+
input: RelayTradeQuoteInput | RelayTradeRateInput | RelayExactOutputTradeQuoteInput | RelayExactOutputTradeRateInput;
|
|
18
18
|
sellChainId: ChainId;
|
|
19
19
|
buyChainId: ChainId;
|
|
20
20
|
}) => {
|
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.notifyTransactionIndexing = void 0;
|
|
4
4
|
const relayService_1 = require("./relayService");
|
|
5
5
|
const notifyTransactionIndexing = async (params, config) => {
|
|
6
|
-
return await relayService_1.relayService.post(`${config.VITE_RELAY_API_URL}/transactions/single`, params);
|
|
6
|
+
return await relayService_1.relayService.post(`${config.VITE_RELAY_API_URL}/transactions/single`, params, (0, relayService_1.getRelayRequestConfig)(config));
|
|
7
7
|
};
|
|
8
8
|
exports.notifyTransactionIndexing = notifyTransactionIndexing;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { SwapperConfig } from '../../../types';
|
|
1
3
|
export declare const relayService: {
|
|
2
|
-
get: <T = any>(url: string, config?:
|
|
3
|
-
post: <T_1 = any>(url: string, data: any, config?:
|
|
4
|
-
delete: <T_2 = any>(url: string, data: any, config?:
|
|
4
|
+
get: <T = any>(url: string, config?: AxiosRequestConfig<any> | undefined) => Promise<import("@sniptt/monads").Result<import("axios").AxiosResponse<T, any, {}>, import("../../../types").SwapErrorRight>>;
|
|
5
|
+
post: <T_1 = any>(url: string, data: any, config?: AxiosRequestConfig<any> | undefined) => Promise<import("@sniptt/monads").Result<import("axios").AxiosResponse<T_1, any, {}>, import("../../../types").SwapErrorRight>>;
|
|
6
|
+
delete: <T_2 = any>(url: string, data: any, config?: AxiosRequestConfig<any> | undefined) => Promise<import("@sniptt/monads").Result<import("axios").AxiosResponse<T_2, any, {}>, import("../../../types").SwapErrorRight>>;
|
|
5
7
|
};
|
|
8
|
+
export declare const getRelayRequestConfig: (config: SwapperConfig) => AxiosRequestConfig | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.relayService = void 0;
|
|
3
|
+
exports.getRelayRequestConfig = exports.relayService = void 0;
|
|
4
4
|
const utils_1 = require("../../../utils");
|
|
5
5
|
const maxAgeMillis = 15 * 1000;
|
|
6
6
|
const cachedUrls = [];
|
|
@@ -13,3 +13,5 @@ const axiosConfig = {
|
|
|
13
13
|
};
|
|
14
14
|
const relayServiceBase = (0, utils_1.createCache)(maxAgeMillis, cachedUrls, axiosConfig);
|
|
15
15
|
exports.relayService = (0, utils_1.makeSwapperAxiosServiceMonadic)(relayServiceBase);
|
|
16
|
+
const getRelayRequestConfig = (config) => config.VITE_RELAY_API_KEY ? { headers: { 'x-api-key': config.VITE_RELAY_API_KEY } } : undefined;
|
|
17
|
+
exports.getRelayRequestConfig = getRelayRequestConfig;
|
|
@@ -232,6 +232,11 @@ const relayTokenToAssetId = (relayToken) => {
|
|
|
232
232
|
assetReference: caip_1.ASSET_REFERENCE.Abstract,
|
|
233
233
|
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
234
234
|
};
|
|
235
|
+
case caip_1.CHAIN_REFERENCE.RobinhoodMainnet:
|
|
236
|
+
return {
|
|
237
|
+
assetReference: caip_1.ASSET_REFERENCE.Robinhood,
|
|
238
|
+
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
239
|
+
};
|
|
235
240
|
default:
|
|
236
241
|
throw Error(`chainId '${relayToken.chainId}' not supported`);
|
|
237
242
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput } from '../../../types';
|
|
1
|
+
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput, WithExactBuyAmount } from '../../../types';
|
|
2
2
|
export type RelayTradeQuoteInput = GetEvmTradeQuoteInput | GetUtxoTradeQuoteInput | GetSolanaTradeQuoteInput | GetTronTradeQuoteInput;
|
|
3
3
|
export type RelayTradeRateInput = GetEvmTradeRateInput | GetUtxoTradeRateInput | GetSolanaTradeRateInput | GetTronTradeRateInput;
|
|
4
|
+
export type RelayExactOutputTradeQuoteInput = WithExactBuyAmount<RelayTradeQuoteInput>;
|
|
5
|
+
export type RelayExactOutputTradeRateInput = WithExactBuyAmount<RelayTradeRateInput>;
|
|
4
6
|
export type RelayTransactionMetadata = {
|
|
5
7
|
to?: string;
|
|
6
8
|
data?: string;
|
|
@@ -11,11 +13,11 @@ export type RelayMetadata = {
|
|
|
11
13
|
data?: string;
|
|
12
14
|
};
|
|
13
15
|
export type RelayStatus = {
|
|
14
|
-
status: 'success' | '
|
|
16
|
+
status: 'success' | 'failure' | 'pending' | 'submitted' | 'depositing' | 'refund' | 'delayed' | 'waiting';
|
|
15
17
|
details?: string;
|
|
16
18
|
inTxHashes: string[];
|
|
17
19
|
txHashes: string[];
|
|
18
|
-
|
|
20
|
+
updatedAt: number;
|
|
19
21
|
originChainId: number;
|
|
20
22
|
destinationChainId: number;
|
|
21
23
|
};
|
|
@@ -64,6 +66,7 @@ export type RelayFees = {
|
|
|
64
66
|
app: RelayCurrencyData;
|
|
65
67
|
};
|
|
66
68
|
export type QuoteDetails = {
|
|
69
|
+
currencyIn: RelayCurrencyData;
|
|
67
70
|
currencyOut: RelayCurrencyData;
|
|
68
71
|
rate: string;
|
|
69
72
|
slippageTolerance: {
|
|
@@ -100,6 +100,20 @@ exports.stonfiApi = {
|
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
const { quoteId } = (0, utils_1.getSwapMetadata)(swap.metadata.swapperMetadata, 'stonfi');
|
|
103
|
+
// Settlement precedes toncenter's jetton indexer, and confirmed rows are never re-parsed -
|
|
104
|
+
// hold confirmation until the receive leg is visible so the confirmed-time parse and upsert
|
|
105
|
+
// carries both legs of the swap
|
|
106
|
+
const hasVisibleReceiveLeg = async () => {
|
|
107
|
+
const adapter = assertGetTonChainAdapter(swap.sellAsset.chainId);
|
|
108
|
+
const sellAddress = swap.sellAccountId.split(':')[2] ?? '';
|
|
109
|
+
const addresses = new Set([sellAddress, swap.receiveAddress].filter((address) => Boolean(address)));
|
|
110
|
+
for (const address of addresses) {
|
|
111
|
+
const tx = await adapter.parseTx(sellTxHash, address);
|
|
112
|
+
if (tx.transfers.some(transfer => transfer.type === unchained_client_1.TransferType.Receive))
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
};
|
|
103
117
|
try {
|
|
104
118
|
const tradeStatus = await (0, helpers_1.waitForFirstTradeStatus)({
|
|
105
119
|
quoteId,
|
|
@@ -113,14 +127,13 @@ exports.stonfiApi = {
|
|
|
113
127
|
return checkTxStatusViaChainAdapter();
|
|
114
128
|
}
|
|
115
129
|
const statusOneOf = tradeStatus.status;
|
|
130
|
+
// While the trade is in flight the wallet tx may already be confirmed, but the payout leg
|
|
131
|
+
// hasn't landed - confirming here would parse and upsert a trace without the receive, so
|
|
132
|
+
// completion waits for settlement
|
|
116
133
|
if (statusOneOf.awaitingTransfer ||
|
|
117
134
|
statusOneOf.transferring ||
|
|
118
135
|
statusOneOf.swapping ||
|
|
119
136
|
statusOneOf.receivingFunds) {
|
|
120
|
-
const chainStatus = await checkTxStatusViaChainAdapter();
|
|
121
|
-
if (chainStatus.status === unchained_client_1.TxStatus.Confirmed) {
|
|
122
|
-
return chainStatus;
|
|
123
|
-
}
|
|
124
137
|
if (statusOneOf.awaitingTransfer) {
|
|
125
138
|
return {
|
|
126
139
|
status: unchained_client_1.TxStatus.Pending,
|
|
@@ -152,19 +165,32 @@ exports.stonfiApi = {
|
|
|
152
165
|
}
|
|
153
166
|
if (statusOneOf.tradeSettled) {
|
|
154
167
|
const result = statusOneOf.tradeSettled.result;
|
|
155
|
-
if (result === 'TRADE_RESULT_FULLY_FILLED') {
|
|
156
|
-
|
|
157
|
-
status: unchained_client_1.TxStatus.Confirmed,
|
|
158
|
-
buyTxHash: sellTxHash,
|
|
159
|
-
message: undefined,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
if (result === 'TRADE_RESULT_PARTIALLY_FILLED') {
|
|
163
|
-
return {
|
|
168
|
+
if (result === 'TRADE_RESULT_FULLY_FILLED' || result === 'TRADE_RESULT_PARTIALLY_FILLED') {
|
|
169
|
+
const settled = {
|
|
164
170
|
status: unchained_client_1.TxStatus.Confirmed,
|
|
165
171
|
buyTxHash: sellTxHash,
|
|
166
|
-
message: '
|
|
172
|
+
message: result === 'TRADE_RESULT_PARTIALLY_FILLED'
|
|
173
|
+
? 'trade.statuses.partiallyFilled'
|
|
174
|
+
: undefined,
|
|
167
175
|
};
|
|
176
|
+
try {
|
|
177
|
+
if (await hasVisibleReceiveLeg())
|
|
178
|
+
return settled;
|
|
179
|
+
return {
|
|
180
|
+
status: unchained_client_1.TxStatus.Pending,
|
|
181
|
+
buyTxHash: undefined,
|
|
182
|
+
message: 'trade.statuses.receivingFunds',
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
// Indexer/API failure must not block completion
|
|
187
|
+
console.error('[Stonfi] Error verifying settlement receive leg:', {
|
|
188
|
+
sellTxHash,
|
|
189
|
+
result,
|
|
190
|
+
error,
|
|
191
|
+
});
|
|
192
|
+
return settled;
|
|
193
|
+
}
|
|
168
194
|
}
|
|
169
195
|
if (result === 'TRADE_RESULT_ABORTED') {
|
|
170
196
|
return {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getTradeQuote = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
|
+
const helpers_1 = require("../../../utils/helpers");
|
|
6
7
|
const getStonfiStepData_1 = require("../utils/getStonfiStepData");
|
|
7
8
|
const getStonfiTradeContext_1 = require("../utils/getStonfiTradeContext");
|
|
8
9
|
const getTradeQuote = async (input, deps) => {
|
|
@@ -27,6 +28,7 @@ const getTradeQuote = async (input, deps) => {
|
|
|
27
28
|
const tradeQuote = {
|
|
28
29
|
...tradeCommon,
|
|
29
30
|
quoteOrRate: 'quote',
|
|
31
|
+
deadline: (0, helpers_1.normalizeEpochToMs)(stonfiTransactionData.tradeStartDeadline),
|
|
30
32
|
receiveAddress,
|
|
31
33
|
steps: [
|
|
32
34
|
{
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getSunioTradeQuote = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
|
+
const helpers_1 = require("../../../utils/helpers");
|
|
6
7
|
const getSunioStepData_1 = require("../utils/getSunioStepData");
|
|
7
8
|
const getSunioTradeContext_1 = require("../utils/getSunioTradeContext");
|
|
8
9
|
const getSunioTradeQuote = async (input, deps) => {
|
|
@@ -27,6 +28,7 @@ const getSunioTradeQuote = async (input, deps) => {
|
|
|
27
28
|
const tradeQuote = {
|
|
28
29
|
...tradeCommon,
|
|
29
30
|
quoteOrRate: 'quote',
|
|
31
|
+
deadline: Date.now() + helpers_1.FALLBACK_QUOTE_DEADLINE_MS,
|
|
30
32
|
receiveAddress,
|
|
31
33
|
steps: [
|
|
32
34
|
{
|
|
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight } from '../../../types';
|
|
|
3
3
|
import type { SunioRoute, SunioTransactionData } from '../types';
|
|
4
4
|
type BaseArgs = {
|
|
5
5
|
route: SunioRoute;
|
|
6
|
+
sellAmountCryptoBaseUnit: string;
|
|
6
7
|
};
|
|
7
8
|
export type GetSunioStepDataArgs = StepDataArgs<BaseArgs>;
|
|
8
9
|
type SunioRateStepData = {
|
|
@@ -6,12 +6,12 @@ const monads_1 = require("@sniptt/monads");
|
|
|
6
6
|
const utils_2 = require("../../../utils");
|
|
7
7
|
const estimateSunioNetworkFee_1 = require("./estimateSunioNetworkFee");
|
|
8
8
|
async function getSunioStepData(args) {
|
|
9
|
-
const { type, route, sellAsset, from, input, deps } = args;
|
|
9
|
+
const { type, route, sellAsset, sellAmountCryptoBaseUnit, from, input, deps } = args;
|
|
10
10
|
const estimateArgs = {
|
|
11
11
|
rpcUrl: deps.config.VITE_TRON_NODE_URL,
|
|
12
12
|
apiKey: deps.config.VITE_TRON_GRID_API_KEY,
|
|
13
13
|
route,
|
|
14
|
-
sellAmountCryptoBaseUnit
|
|
14
|
+
sellAmountCryptoBaseUnit,
|
|
15
15
|
isSellingNativeTrx: !(0, utils_1.contractAddressOrUndefined)(sellAsset.assetId),
|
|
16
16
|
address: from,
|
|
17
17
|
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
|
|
@@ -83,7 +83,12 @@ const getSunioTradeContext = async ({ input, deps, }) => {
|
|
|
83
83
|
}),
|
|
84
84
|
},
|
|
85
85
|
protocolFees,
|
|
86
|
-
stepDataArgs: {
|
|
86
|
+
stepDataArgs: {
|
|
87
|
+
deps,
|
|
88
|
+
sellAsset,
|
|
89
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
90
|
+
route: bestRoute,
|
|
91
|
+
},
|
|
87
92
|
});
|
|
88
93
|
}
|
|
89
94
|
catch (error) {
|
|
@@ -64,6 +64,7 @@ const expectedQuoteResponse = [
|
|
|
64
64
|
tradeType: thorchain_1.TradeType.L1ToL1,
|
|
65
65
|
slippageTolerancePercentageDecimal: '0.04357',
|
|
66
66
|
expiry: 1713710808,
|
|
67
|
+
deadline: 1713710808000,
|
|
67
68
|
swapperName: types_1.SwapperName.Thorchain,
|
|
68
69
|
steps: [
|
|
69
70
|
{
|
|
@@ -114,6 +115,7 @@ const expectedQuoteResponse = [
|
|
|
114
115
|
tradeType: thorchain_1.TradeType.L1ToL1,
|
|
115
116
|
slippageTolerancePercentageDecimal: undefined,
|
|
116
117
|
expiry: 1713710808,
|
|
118
|
+
deadline: 1713710808000,
|
|
117
119
|
swapperName: types_1.SwapperName.Thorchain,
|
|
118
120
|
steps: [
|
|
119
121
|
{
|
|
@@ -76,6 +76,8 @@ const getLongtailToL1Quote = async (input, deps, streamingInterval, swapperName)
|
|
|
76
76
|
const { data, transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
77
77
|
return (0, monads_1.Ok)({
|
|
78
78
|
...quote,
|
|
79
|
+
// The aggregator swapIn deadline is tighter than the daemon quote expiry
|
|
80
|
+
deadline: Math.min(quote.deadline, Number(deadline) * 1000),
|
|
79
81
|
data: data ?? quote.data,
|
|
80
82
|
// This logic will need to be updated to support multi-hop, if that's ever implemented for THORChain
|
|
81
83
|
steps: quote.steps.map(s => ({
|
|
@@ -3,7 +3,7 @@ import type { Address, TypedData } from 'viem';
|
|
|
3
3
|
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput } from '../../types';
|
|
4
4
|
export type ZrxTradeQuoteInput = GetEvmTradeQuoteInput;
|
|
5
5
|
export type ZrxTradeRateInput = GetEvmTradeRateInput;
|
|
6
|
-
export declare const zrxSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet];
|
|
6
|
+
export declare const zrxSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.RobinhoodMainnet];
|
|
7
7
|
export type ZrxSupportedChainId = (typeof zrxSupportedChainIds)[number];
|
|
8
8
|
type ZrxFee = {
|
|
9
9
|
amount: string;
|
|
@@ -21,6 +21,7 @@ exports.ZRX_SUPPORTED_CHAINIDS = Object.freeze([
|
|
|
21
21
|
types_1.KnownChainIds.PolygonMainnet,
|
|
22
22
|
types_1.KnownChainIds.ArbitrumMainnet,
|
|
23
23
|
types_1.KnownChainIds.BaseMainnet,
|
|
24
|
+
types_1.KnownChainIds.RobinhoodMainnet,
|
|
24
25
|
]);
|
|
25
26
|
// https://0x.org/docs/developer-resources/faqs-and-troubleshooting
|
|
26
27
|
exports.ZRX_NATIVE_ASSET_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
@@ -6,7 +6,7 @@ import type { SwapErrorRight } from '../../../types';
|
|
|
6
6
|
import type { ZrxFees, ZrxPriceResponse } from '../types';
|
|
7
7
|
export declare const assetIdToZrxToken: (assetId: AssetId) => string;
|
|
8
8
|
export declare const zrxTokenToAssetId: (token: string, chainId: ChainId) => AssetId;
|
|
9
|
-
export declare const isSupportedChainId: (chainId: ChainId) => chainId is KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet | KnownChainIds.OptimismMainnet | KnownChainIds.BnbSmartChainMainnet | KnownChainIds.PolygonMainnet | KnownChainIds.ArbitrumMainnet | KnownChainIds.BaseMainnet;
|
|
9
|
+
export declare const isSupportedChainId: (chainId: ChainId) => chainId is KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet | KnownChainIds.OptimismMainnet | KnownChainIds.BnbSmartChainMainnet | KnownChainIds.PolygonMainnet | KnownChainIds.ArbitrumMainnet | KnownChainIds.BaseMainnet | KnownChainIds.RobinhoodMainnet;
|
|
10
10
|
export declare const isWrappedNativeSell: (route: ZrxPriceResponse['route']) => boolean;
|
|
11
11
|
export declare const assertValidTrade: ({ buyAsset, sellAsset, }: {
|
|
12
12
|
buyAsset: Asset;
|
|
@@ -60,6 +60,11 @@ const zrxTokenToAssetId = (token, chainId) => {
|
|
|
60
60
|
assetReference: caip_1.ASSET_REFERENCE.Base,
|
|
61
61
|
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
62
62
|
};
|
|
63
|
+
case types_1.KnownChainIds.RobinhoodMainnet:
|
|
64
|
+
return {
|
|
65
|
+
assetReference: caip_1.ASSET_REFERENCE.Robinhood,
|
|
66
|
+
assetNamespace: caip_1.ASSET_NAMESPACE.slip44,
|
|
67
|
+
};
|
|
63
68
|
default:
|
|
64
69
|
throw Error(`chainId '${chainId}' not supported`);
|
|
65
70
|
}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -49,11 +49,13 @@ export type SwapperConfig = {
|
|
|
49
49
|
VITE_CHAINFLIP_API_URL: string;
|
|
50
50
|
VITE_FEATURE_CHAINFLIP_SWAP_DCA: boolean;
|
|
51
51
|
VITE_RELAY_API_URL: string;
|
|
52
|
+
VITE_RELAY_API_KEY: string;
|
|
52
53
|
VITE_BEBOP_API_KEY: string;
|
|
53
54
|
VITE_NEAR_INTENTS_API_KEY: string;
|
|
54
55
|
VITE_SUI_NODE_URL: string;
|
|
55
56
|
VITE_ACROSS_API_URL: string;
|
|
56
57
|
VITE_ACROSS_INTEGRATOR_ID: string;
|
|
58
|
+
VITE_ACROSS_API_KEY: string;
|
|
57
59
|
VITE_DEBRIDGE_API_URL: string;
|
|
58
60
|
VITE_BOB_GATEWAY_API_KEY: string;
|
|
59
61
|
};
|
|
@@ -91,6 +93,7 @@ export declare enum TradeQuoteError {
|
|
|
91
93
|
NoRouteFound = "NoRouteFound",
|
|
92
94
|
UnsupportedChain = "UnsupportedChain",
|
|
93
95
|
CrossChainNotSupported = "CrossChainNotSupported",
|
|
96
|
+
ExactOutputNotSupported = "ExactOutputNotSupported",
|
|
94
97
|
NetworkFeeEstimationFailed = "NetworkFeeEstimationFailed",
|
|
95
98
|
TradingHalted = "TradingHalted",
|
|
96
99
|
SellAmountBelowMinimum = "SellAmountBelowMinimum",
|
|
@@ -210,17 +213,30 @@ export type GetUtxoTradeRateInput = CommonTradeRateInput & {
|
|
|
210
213
|
export type GetUtxoTradeQuoteInput = GetUtxoTradeQuoteWithWallet;
|
|
211
214
|
export type GetTradeQuoteInput = GetUtxoTradeQuoteInput | GetEvmTradeQuoteInput | GetCosmosSdkTradeQuoteInput | GetTronTradeQuoteInput | GetNearTradeQuoteInput | GetTonTradeQuoteInput | GetSolanaTradeQuoteInput | GetStarknetTradeQuoteInput | GetSuiTradeQuoteInput;
|
|
212
215
|
export type GetTradeRateInput = GetEvmTradeRateInput | GetCosmosSdkTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput | GetNearTradeRateInput | GetTonTradeRateInput | GetSolanaTradeRateInput | GetStarknetTradeRateInput | GetSuiTradeRateInput;
|
|
216
|
+
export type WithExactBuyAmount<T extends {
|
|
217
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: string;
|
|
218
|
+
}> = T extends unknown ? Omit<T, 'sellAmountIncludingProtocolFeesCryptoBaseUnit'> & {
|
|
219
|
+
buyAmountCryptoBaseUnit: string;
|
|
220
|
+
} : never;
|
|
221
|
+
export type GetExactOutputTradeQuoteInput = WithExactBuyAmount<GetTradeQuoteInput>;
|
|
222
|
+
export type GetExactOutputTradeRateInput = WithExactBuyAmount<GetTradeRateInput>;
|
|
223
|
+
export type TradeAmount = {
|
|
224
|
+
direction: 'exactIn' | 'exactOut';
|
|
225
|
+
cryptoBaseUnit: string;
|
|
226
|
+
};
|
|
213
227
|
type StepDataBaseArgs = {
|
|
214
228
|
deps: SwapperDeps;
|
|
215
229
|
sellAsset: Asset;
|
|
216
230
|
};
|
|
231
|
+
type StepDataRateInput = GetTradeRateInput | GetExactOutputTradeRateInput;
|
|
232
|
+
type StepDataQuoteInput = GetTradeQuoteInput | GetExactOutputTradeQuoteInput;
|
|
217
233
|
export type StepDataArgs<Base, Rate = unknown, Quote = unknown> = (StepDataBaseArgs & Base & {
|
|
218
234
|
type: 'rate';
|
|
219
|
-
input:
|
|
235
|
+
input: StepDataRateInput;
|
|
220
236
|
from?: string;
|
|
221
237
|
} & Rate) | (StepDataBaseArgs & Base & {
|
|
222
238
|
type: 'quote';
|
|
223
|
-
input:
|
|
239
|
+
input: StepDataQuoteInput;
|
|
224
240
|
from: string;
|
|
225
241
|
} & Quote);
|
|
226
242
|
export type EvmSwapperDeps = {
|
|
@@ -353,6 +369,7 @@ export type TradeCommon = {
|
|
|
353
369
|
slippageTolerancePercentageDecimal: string | undefined;
|
|
354
370
|
isLongtail?: boolean;
|
|
355
371
|
swapperName: SwapperName;
|
|
372
|
+
isExactOutput?: boolean;
|
|
356
373
|
};
|
|
357
374
|
type TradeQuoteBase = TradeCommon & {
|
|
358
375
|
receiveAddress: string | undefined;
|
|
@@ -439,6 +456,7 @@ export type TradeQuote = TradeQuoteBase & {
|
|
|
439
456
|
} & {
|
|
440
457
|
quoteOrRate: 'quote';
|
|
441
458
|
receiveAddress: string;
|
|
459
|
+
deadline: number;
|
|
442
460
|
};
|
|
443
461
|
export type MultiHopTradeQuote = TradeQuote & {
|
|
444
462
|
steps: MultiHopTradeQuoteSteps;
|
|
@@ -581,6 +599,8 @@ export type SwapperApi = {
|
|
|
581
599
|
checkTradeStatus: (input: CheckTradeStatusInput) => Promise<TradeStatus>;
|
|
582
600
|
getTradeQuote: (input: GetTradeQuoteInput, deps: SwapperDeps) => Promise<TradeQuoteResult>;
|
|
583
601
|
getTradeRate: (input: GetTradeRateInput, deps: SwapperDeps) => Promise<TradeRateResult>;
|
|
602
|
+
getExactOutputTradeQuote?: (input: GetExactOutputTradeQuoteInput, deps: SwapperDeps) => Promise<TradeQuoteResult>;
|
|
603
|
+
getExactOutputTradeRate?: (input: GetExactOutputTradeRateInput, deps: SwapperDeps) => Promise<TradeRateResult>;
|
|
584
604
|
getUnsignedEvmTransaction?: (input: GetUnsignedEvmTransactionArgs) => Promise<SignTx<EvmChainId>>;
|
|
585
605
|
getUnsignedEvmMessage?: (input: GetUnsignedEvmMessageArgs) => Promise<EvmMessageToSign>;
|
|
586
606
|
getUnsignedUtxoTransaction?: (input: GetUnsignedUtxoTransactionArgs) => Promise<SignTx<UtxoChainId>>;
|
package/dist/cjs/types.js
CHANGED
|
@@ -33,6 +33,8 @@ var TradeQuoteError;
|
|
|
33
33
|
TradeQuoteError["UnsupportedChain"] = "UnsupportedChain";
|
|
34
34
|
// the swapper can't swap across chains
|
|
35
35
|
TradeQuoteError["CrossChainNotSupported"] = "CrossChainNotSupported";
|
|
36
|
+
// the swapper can quote this pair, but can't derive a sell amount from an exact buy amount
|
|
37
|
+
TradeQuoteError["ExactOutputNotSupported"] = "ExactOutputNotSupported";
|
|
36
38
|
// the swapper wasn't able to get a network fee estimate
|
|
37
39
|
TradeQuoteError["NetworkFeeEstimationFailed"] = "NetworkFeeEstimationFailed";
|
|
38
40
|
// trading has been halted upstream
|