@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,8 +1,9 @@
|
|
|
1
1
|
import { Err, Ok } from '@sniptt/monads';
|
|
2
2
|
import { assertQuoteAddresses } from '../../../utils/index.js';
|
|
3
|
+
import { FALLBACK_QUOTE_DEADLINE_MS } from '../../../utils/helpers.js';
|
|
3
4
|
import { getRelayStepData } from '../utils/getRelayStepData.js';
|
|
4
5
|
import { getRelayTradeContext } from '../utils/getRelayTradeContext.js';
|
|
5
|
-
|
|
6
|
+
const getQuote = async (input, deps, relayChainMap) => {
|
|
6
7
|
const { accountNumber } = input;
|
|
7
8
|
const addresses = assertQuoteAddresses(input);
|
|
8
9
|
if (addresses.isErr())
|
|
@@ -42,8 +43,11 @@ export const getTradeQuote = async (input, deps, relayChainMap) => {
|
|
|
42
43
|
const tradeQuote = {
|
|
43
44
|
...tradeCommon,
|
|
44
45
|
quoteOrRate: 'quote',
|
|
46
|
+
deadline: Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
45
47
|
receiveAddress,
|
|
46
48
|
steps,
|
|
47
49
|
};
|
|
48
50
|
return Ok([tradeQuote]);
|
|
49
51
|
};
|
|
52
|
+
export const getTradeQuote = (input, deps, relayChainMap) => getQuote(input, deps, relayChainMap);
|
|
53
|
+
export const getExactOutputTradeQuote = (input, deps, relayChainMap) => getQuote(input, deps, relayChainMap);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Result } from '@sniptt/monads';
|
|
2
2
|
import type { SwapErrorRight, SwapperDeps, TradeRate } from '../../../types.js';
|
|
3
3
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant.js';
|
|
4
|
-
import type { RelayTradeRateInput } from '../utils/types.js';
|
|
4
|
+
import type { RelayExactOutputTradeRateInput, RelayTradeRateInput } from '../utils/types.js';
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import { Err, Ok } from '@sniptt/monads';
|
|
2
2
|
import { getRelayStepData } from '../utils/getRelayStepData.js';
|
|
3
3
|
import { getRelayTradeContext } from '../utils/getRelayTradeContext.js';
|
|
4
|
-
|
|
4
|
+
const getRate = async (input, deps, relayChainMap) => {
|
|
5
5
|
const maybeContext = await getRelayTradeContext({ input, deps, relayChainMap });
|
|
6
6
|
if (maybeContext.isErr())
|
|
7
7
|
return Err(maybeContext.unwrapErr());
|
|
@@ -36,3 +36,5 @@ export const getTradeRate = async (input, deps, relayChainMap) => {
|
|
|
36
36
|
};
|
|
37
37
|
return Ok([tradeRate]);
|
|
38
38
|
};
|
|
39
|
+
export const getTradeRate = (input, deps, relayChainMap) => getRate(input, deps, relayChainMap);
|
|
40
|
+
export const getExactOutputTradeRate = (input, deps, relayChainMap) => getRate(input, deps, relayChainMap);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { relayService } from './relayService.js';
|
|
1
|
+
import { getRelayRequestConfig, relayService } from './relayService.js';
|
|
2
2
|
export const fetchRelayTrade = async (params, config) => {
|
|
3
|
-
return await relayService.post(`${config.VITE_RELAY_API_URL}/quote/v2`, params);
|
|
3
|
+
return await relayService.post(`${config.VITE_RELAY_API_URL}/quote/v2`, params, getRelayRequestConfig(config));
|
|
4
4
|
};
|
|
@@ -7,10 +7,12 @@ export const getLatestRelayStatusMessage = (status) => {
|
|
|
7
7
|
case statusValue === 'delayed':
|
|
8
8
|
return RelayStatusMessage.Retrying;
|
|
9
9
|
case statusValue === 'pending':
|
|
10
|
+
case statusValue === 'depositing':
|
|
11
|
+
case statusValue === 'submitted':
|
|
10
12
|
return RelayStatusMessage.DepositDetected;
|
|
11
13
|
case statusValue === 'success':
|
|
12
14
|
return RelayStatusMessage.SwapComplete;
|
|
13
|
-
case statusValue === '
|
|
15
|
+
case statusValue === 'failure':
|
|
14
16
|
return RelayStatusMessage.SwapFailed;
|
|
15
17
|
default:
|
|
16
18
|
return 'Unknown status';
|
|
@@ -2,7 +2,7 @@ import type { Result } from '@sniptt/monads';
|
|
|
2
2
|
import type { QuoteFeeData, SwapErrorRight, SwapperDeps, TradeCommon, TradeStepCommon } from '../../../types.js';
|
|
3
3
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant.js';
|
|
4
4
|
import type { GetRelayStepDataArgs } from './getRelayStepData.js';
|
|
5
|
-
import type { RelayQuoteItem, RelayTradeQuoteInput, RelayTradeRateInput } from './types.js';
|
|
5
|
+
import type { RelayExactOutputTradeQuoteInput, RelayExactOutputTradeRateInput, RelayQuoteItem, RelayTradeQuoteInput, RelayTradeRateInput } from './types.js';
|
|
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>>;
|
|
@@ -7,7 +7,7 @@ import { zeroAddress } from 'viem';
|
|
|
7
7
|
import { MixPanelEvent, SwapperName, TradeQuoteError } from '../../../types.js';
|
|
8
8
|
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils/index.js';
|
|
9
9
|
import { buildAffiliateFee } from '../../../utils/affiliateFee.js';
|
|
10
|
-
import { isNativeEvmAsset } from '../../../utils/helpers.js';
|
|
10
|
+
import { getTradeAmount, isNativeEvmAsset } from '../../../utils/helpers.js';
|
|
11
11
|
import { MAXIMUM_SUPPORTED_RELAY_STEPS, relayErrorCodeToTradeQuoteError } from '../constant.js';
|
|
12
12
|
import { getRelayAssetAddress } from '../utils/getRelayAssetAddress.js';
|
|
13
13
|
import { relayTokenToAsset } from '../utils/relayTokenToAsset.js';
|
|
@@ -16,7 +16,9 @@ import { fetchRelayTrade } from './fetchRelayTrade.js';
|
|
|
16
16
|
import { assertValidTrade, getRelayAllowanceContract, resolveRelayAddresses } from './helpers.js';
|
|
17
17
|
import { isRelayError } from './types.js';
|
|
18
18
|
export const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
19
|
-
const { sellAsset, buyAsset,
|
|
19
|
+
const { sellAsset, buyAsset, affiliateBps } = input;
|
|
20
|
+
const amount = getTradeAmount(input);
|
|
21
|
+
const isExactOutput = amount.direction === 'exactOut';
|
|
20
22
|
const xpub = 'xpub' in input ? input.xpub : undefined;
|
|
21
23
|
const slippageToleranceBps = input.slippageTolerancePercentageDecimal
|
|
22
24
|
? convertDecimalPercentageToBasisPoints(input.slippageTolerancePercentageDecimal).toFixed()
|
|
@@ -35,8 +37,8 @@ export const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
35
37
|
originCurrency: getRelayAssetAddress(sellAsset),
|
|
36
38
|
destinationChainId: buyRelayChainId,
|
|
37
39
|
destinationCurrency: getRelayAssetAddress(buyAsset),
|
|
38
|
-
tradeType: 'EXACT_INPUT',
|
|
39
|
-
amount:
|
|
40
|
+
tradeType: isExactOutput ? 'EXACT_OUTPUT' : 'EXACT_INPUT',
|
|
41
|
+
amount: amount.cryptoBaseUnit,
|
|
40
42
|
recipient,
|
|
41
43
|
user: sendAddress,
|
|
42
44
|
refundTo,
|
|
@@ -78,10 +80,19 @@ export const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
78
80
|
code: TradeQuoteError.UnknownError,
|
|
79
81
|
}));
|
|
80
82
|
}
|
|
81
|
-
const { slippageTolerance, currencyOut, timeEstimate } = quote.details;
|
|
82
|
-
const
|
|
83
|
+
const { slippageTolerance, currencyIn, currencyOut, timeEstimate } = quote.details;
|
|
84
|
+
const sellAmountCryptoBaseUnit = currencyIn.amount;
|
|
85
|
+
const buyAmountAfterFeesCryptoBaseUnit = isExactOutput
|
|
86
|
+
? currencyOut.minimumAmount
|
|
87
|
+
: currencyOut.amount;
|
|
88
|
+
if (isExactOutput && !bnOrZero(buyAmountAfterFeesCryptoBaseUnit).eq(amount.cryptoBaseUnit)) {
|
|
89
|
+
return Err(makeSwapErrorRight({
|
|
90
|
+
message: `Relay guarantees ${buyAmountAfterFeesCryptoBaseUnit} against a requested exact output of ${amount.cryptoBaseUnit}`,
|
|
91
|
+
code: TradeQuoteError.InvalidResponse,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
83
94
|
const rate = getInputOutputRate({
|
|
84
|
-
sellAmountCryptoBaseUnit
|
|
95
|
+
sellAmountCryptoBaseUnit,
|
|
85
96
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
86
97
|
sellAsset,
|
|
87
98
|
buyAsset,
|
|
@@ -242,7 +253,7 @@ export const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
242
253
|
})();
|
|
243
254
|
// Add back relayer service and gas fees (relayer is including both) since they are downsides,
|
|
244
255
|
// and add appFees — these are quote-level and identical across every step
|
|
245
|
-
const buyAmountBeforeFeesCryptoBaseUnit = bnOrZero(
|
|
256
|
+
const buyAmountBeforeFeesCryptoBaseUnit = bnOrZero(buyAmountAfterFeesCryptoBaseUnit)
|
|
246
257
|
.plus(relayerFeesBuyAssetCryptoBaseUnit)
|
|
247
258
|
.plus(appFeesBaseUnit)
|
|
248
259
|
.toFixed();
|
|
@@ -256,6 +267,7 @@ export const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
256
267
|
id: relayId,
|
|
257
268
|
rate,
|
|
258
269
|
swapperName: SwapperName.Relay,
|
|
270
|
+
isExactOutput,
|
|
259
271
|
affiliateBps,
|
|
260
272
|
slippageTolerancePercentageDecimal,
|
|
261
273
|
},
|
|
@@ -263,7 +275,7 @@ export const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
263
275
|
rate,
|
|
264
276
|
buyAmountBeforeFeesCryptoBaseUnit,
|
|
265
277
|
buyAmountAfterFeesCryptoBaseUnit,
|
|
266
|
-
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
278
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmountCryptoBaseUnit,
|
|
267
279
|
buyAsset,
|
|
268
280
|
sellAsset,
|
|
269
281
|
source: SwapperName.Relay,
|
|
@@ -273,7 +285,7 @@ export const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
273
285
|
affiliateBps,
|
|
274
286
|
sellAsset,
|
|
275
287
|
buyAsset,
|
|
276
|
-
sellAmountCryptoBaseUnit
|
|
288
|
+
sellAmountCryptoBaseUnit,
|
|
277
289
|
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
278
290
|
fixedAssetId: chainIdToFeeAssetId(baseChainId),
|
|
279
291
|
fixedAsset: deps.assetsById[chainIdToFeeAssetId(baseChainId)],
|
|
@@ -291,7 +303,7 @@ export const getRelayTradeContext = async ({ input, deps, relayChainMap, }) => {
|
|
|
291
303
|
relayStepInputs,
|
|
292
304
|
stepDataArgs: {
|
|
293
305
|
sellAsset,
|
|
294
|
-
sellAmountCryptoBaseUnit
|
|
306
|
+
sellAmountCryptoBaseUnit,
|
|
295
307
|
orderId,
|
|
296
308
|
from: sendAddress,
|
|
297
309
|
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.js';
|
|
6
6
|
import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant.js';
|
|
7
|
-
import type { RelayQuoteItem, RelaySolanaInstruction, RelayTradeQuoteInput, RelayTradeRateInput } from './types.js';
|
|
7
|
+
import type { RelayExactOutputTradeQuoteInput, RelayExactOutputTradeRateInput, RelayQuoteItem, RelaySolanaInstruction, RelayTradeQuoteInput, RelayTradeRateInput } from './types.js';
|
|
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
|
}) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { relayService } from './relayService.js';
|
|
1
|
+
import { getRelayRequestConfig, relayService } from './relayService.js';
|
|
2
2
|
export const notifyTransactionIndexing = async (params, config) => {
|
|
3
|
-
return await relayService.post(`${config.VITE_RELAY_API_URL}/transactions/single`, params);
|
|
3
|
+
return await relayService.post(`${config.VITE_RELAY_API_URL}/transactions/single`, params, getRelayRequestConfig(config));
|
|
4
4
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { SwapperConfig } from '../../../types.js';
|
|
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.js").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.js").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.js").SwapErrorRight>>;
|
|
5
7
|
};
|
|
8
|
+
export declare const getRelayRequestConfig: (config: SwapperConfig) => AxiosRequestConfig | undefined;
|
|
@@ -10,3 +10,4 @@ const axiosConfig = {
|
|
|
10
10
|
};
|
|
11
11
|
const relayServiceBase = createCache(maxAgeMillis, cachedUrls, axiosConfig);
|
|
12
12
|
export const relayService = makeSwapperAxiosServiceMonadic(relayServiceBase);
|
|
13
|
+
export const getRelayRequestConfig = (config) => config.VITE_RELAY_API_KEY ? { headers: { 'x-api-key': config.VITE_RELAY_API_KEY } } : undefined;
|
|
@@ -229,6 +229,11 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
229
229
|
assetReference: ASSET_REFERENCE.Abstract,
|
|
230
230
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
231
231
|
};
|
|
232
|
+
case CHAIN_REFERENCE.RobinhoodMainnet:
|
|
233
|
+
return {
|
|
234
|
+
assetReference: ASSET_REFERENCE.Robinhood,
|
|
235
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
236
|
+
};
|
|
232
237
|
default:
|
|
233
238
|
throw Error(`chainId '${relayToken.chainId}' not supported`);
|
|
234
239
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput } from '../../../types.js';
|
|
1
|
+
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput, WithExactBuyAmount } from '../../../types.js';
|
|
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: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toAddressNList } from '@shapeshiftoss/chain-adapters';
|
|
2
|
-
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
2
|
+
import { TransferType, TxStatus } from '@shapeshiftoss/unchained-client';
|
|
3
3
|
import { Blockchain } from '@ston-fi/omniston-sdk';
|
|
4
4
|
import { createDefaultStatusResponse, getExecutableTradeStep, getSwapMetadata, isExecutableTradeQuote, } from '../../utils/index.js';
|
|
5
5
|
import { getTradeQuote } from './swapperApi/getTradeQuote.js';
|
|
@@ -97,6 +97,20 @@ export const stonfiApi = {
|
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
const { quoteId } = getSwapMetadata(swap.metadata.swapperMetadata, 'stonfi');
|
|
100
|
+
// Settlement precedes toncenter's jetton indexer, and confirmed rows are never re-parsed -
|
|
101
|
+
// hold confirmation until the receive leg is visible so the confirmed-time parse and upsert
|
|
102
|
+
// carries both legs of the swap
|
|
103
|
+
const hasVisibleReceiveLeg = async () => {
|
|
104
|
+
const adapter = assertGetTonChainAdapter(swap.sellAsset.chainId);
|
|
105
|
+
const sellAddress = swap.sellAccountId.split(':')[2] ?? '';
|
|
106
|
+
const addresses = new Set([sellAddress, swap.receiveAddress].filter((address) => Boolean(address)));
|
|
107
|
+
for (const address of addresses) {
|
|
108
|
+
const tx = await adapter.parseTx(sellTxHash, address);
|
|
109
|
+
if (tx.transfers.some(transfer => transfer.type === TransferType.Receive))
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
};
|
|
100
114
|
try {
|
|
101
115
|
const tradeStatus = await waitForFirstTradeStatus({
|
|
102
116
|
quoteId,
|
|
@@ -110,14 +124,13 @@ export const stonfiApi = {
|
|
|
110
124
|
return checkTxStatusViaChainAdapter();
|
|
111
125
|
}
|
|
112
126
|
const statusOneOf = tradeStatus.status;
|
|
127
|
+
// While the trade is in flight the wallet tx may already be confirmed, but the payout leg
|
|
128
|
+
// hasn't landed - confirming here would parse and upsert a trace without the receive, so
|
|
129
|
+
// completion waits for settlement
|
|
113
130
|
if (statusOneOf.awaitingTransfer ||
|
|
114
131
|
statusOneOf.transferring ||
|
|
115
132
|
statusOneOf.swapping ||
|
|
116
133
|
statusOneOf.receivingFunds) {
|
|
117
|
-
const chainStatus = await checkTxStatusViaChainAdapter();
|
|
118
|
-
if (chainStatus.status === TxStatus.Confirmed) {
|
|
119
|
-
return chainStatus;
|
|
120
|
-
}
|
|
121
134
|
if (statusOneOf.awaitingTransfer) {
|
|
122
135
|
return {
|
|
123
136
|
status: TxStatus.Pending,
|
|
@@ -149,19 +162,32 @@ export const stonfiApi = {
|
|
|
149
162
|
}
|
|
150
163
|
if (statusOneOf.tradeSettled) {
|
|
151
164
|
const result = statusOneOf.tradeSettled.result;
|
|
152
|
-
if (result === 'TRADE_RESULT_FULLY_FILLED') {
|
|
153
|
-
|
|
154
|
-
status: TxStatus.Confirmed,
|
|
155
|
-
buyTxHash: sellTxHash,
|
|
156
|
-
message: undefined,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (result === 'TRADE_RESULT_PARTIALLY_FILLED') {
|
|
160
|
-
return {
|
|
165
|
+
if (result === 'TRADE_RESULT_FULLY_FILLED' || result === 'TRADE_RESULT_PARTIALLY_FILLED') {
|
|
166
|
+
const settled = {
|
|
161
167
|
status: TxStatus.Confirmed,
|
|
162
168
|
buyTxHash: sellTxHash,
|
|
163
|
-
message: '
|
|
169
|
+
message: result === 'TRADE_RESULT_PARTIALLY_FILLED'
|
|
170
|
+
? 'trade.statuses.partiallyFilled'
|
|
171
|
+
: undefined,
|
|
164
172
|
};
|
|
173
|
+
try {
|
|
174
|
+
if (await hasVisibleReceiveLeg())
|
|
175
|
+
return settled;
|
|
176
|
+
return {
|
|
177
|
+
status: TxStatus.Pending,
|
|
178
|
+
buyTxHash: undefined,
|
|
179
|
+
message: 'trade.statuses.receivingFunds',
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
// Indexer/API failure must not block completion
|
|
184
|
+
console.error('[Stonfi] Error verifying settlement receive leg:', {
|
|
185
|
+
sellTxHash,
|
|
186
|
+
result,
|
|
187
|
+
error,
|
|
188
|
+
});
|
|
189
|
+
return settled;
|
|
190
|
+
}
|
|
165
191
|
}
|
|
166
192
|
if (result === 'TRADE_RESULT_ABORTED') {
|
|
167
193
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Err, Ok } from '@sniptt/monads';
|
|
2
2
|
import { assertQuoteAddresses } from '../../../utils/index.js';
|
|
3
|
+
import { normalizeEpochToMs } from '../../../utils/helpers.js';
|
|
3
4
|
import { getStonfiStepData } from '../utils/getStonfiStepData.js';
|
|
4
5
|
import { getStonfiTradeContext } from '../utils/getStonfiTradeContext.js';
|
|
5
6
|
export const getTradeQuote = async (input, deps) => {
|
|
@@ -24,6 +25,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
24
25
|
const tradeQuote = {
|
|
25
26
|
...tradeCommon,
|
|
26
27
|
quoteOrRate: 'quote',
|
|
28
|
+
deadline: normalizeEpochToMs(stonfiTransactionData.tradeStartDeadline),
|
|
27
29
|
receiveAddress,
|
|
28
30
|
steps: [
|
|
29
31
|
{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Err, Ok } from '@sniptt/monads';
|
|
2
2
|
import { assertQuoteAddresses } from '../../../utils/index.js';
|
|
3
|
+
import { FALLBACK_QUOTE_DEADLINE_MS } from '../../../utils/helpers.js';
|
|
3
4
|
import { getSunioStepData } from '../utils/getSunioStepData.js';
|
|
4
5
|
import { getSunioTradeContext } from '../utils/getSunioTradeContext.js';
|
|
5
6
|
export const getSunioTradeQuote = async (input, deps) => {
|
|
@@ -24,6 +25,7 @@ export const getSunioTradeQuote = async (input, deps) => {
|
|
|
24
25
|
const tradeQuote = {
|
|
25
26
|
...tradeCommon,
|
|
26
27
|
quoteOrRate: 'quote',
|
|
28
|
+
deadline: Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
27
29
|
receiveAddress,
|
|
28
30
|
steps: [
|
|
29
31
|
{
|
|
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight } from '../../../types.js';
|
|
|
3
3
|
import type { SunioRoute, SunioTransactionData } from '../types.js';
|
|
4
4
|
type BaseArgs = {
|
|
5
5
|
route: SunioRoute;
|
|
6
|
+
sellAmountCryptoBaseUnit: string;
|
|
6
7
|
};
|
|
7
8
|
export type GetSunioStepDataArgs = StepDataArgs<BaseArgs>;
|
|
8
9
|
type SunioRateStepData = {
|
|
@@ -3,12 +3,12 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
3
3
|
import { makeNetworkFeeEstimationFailedErr } from '../../../utils/index.js';
|
|
4
4
|
import { estimateSunioNetworkFeeCryptoBaseUnit } from './estimateSunioNetworkFee.js';
|
|
5
5
|
export async function getSunioStepData(args) {
|
|
6
|
-
const { type, route, sellAsset, from, input, deps } = args;
|
|
6
|
+
const { type, route, sellAsset, sellAmountCryptoBaseUnit, from, input, deps } = args;
|
|
7
7
|
const estimateArgs = {
|
|
8
8
|
rpcUrl: deps.config.VITE_TRON_NODE_URL,
|
|
9
9
|
apiKey: deps.config.VITE_TRON_GRID_API_KEY,
|
|
10
10
|
route,
|
|
11
|
-
sellAmountCryptoBaseUnit
|
|
11
|
+
sellAmountCryptoBaseUnit,
|
|
12
12
|
isSellingNativeTrx: !contractAddressOrUndefined(sellAsset.assetId),
|
|
13
13
|
address: from,
|
|
14
14
|
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
|
|
@@ -80,7 +80,12 @@ export const getSunioTradeContext = async ({ input, deps, }) => {
|
|
|
80
80
|
}),
|
|
81
81
|
},
|
|
82
82
|
protocolFees,
|
|
83
|
-
stepDataArgs: {
|
|
83
|
+
stepDataArgs: {
|
|
84
|
+
deps,
|
|
85
|
+
sellAsset,
|
|
86
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
87
|
+
route: bestRoute,
|
|
88
|
+
},
|
|
84
89
|
});
|
|
85
90
|
}
|
|
86
91
|
catch (error) {
|
|
@@ -62,6 +62,7 @@ const expectedQuoteResponse = [
|
|
|
62
62
|
tradeType: TradeType.L1ToL1,
|
|
63
63
|
slippageTolerancePercentageDecimal: '0.04357',
|
|
64
64
|
expiry: 1713710808,
|
|
65
|
+
deadline: 1713710808000,
|
|
65
66
|
swapperName: SwapperName.Thorchain,
|
|
66
67
|
steps: [
|
|
67
68
|
{
|
|
@@ -112,6 +113,7 @@ const expectedQuoteResponse = [
|
|
|
112
113
|
tradeType: TradeType.L1ToL1,
|
|
113
114
|
slippageTolerancePercentageDecimal: undefined,
|
|
114
115
|
expiry: 1713710808,
|
|
116
|
+
deadline: 1713710808000,
|
|
115
117
|
swapperName: SwapperName.Thorchain,
|
|
116
118
|
steps: [
|
|
117
119
|
{
|
|
@@ -73,6 +73,8 @@ export const getLongtailToL1Quote = async (input, deps, streamingInterval, swapp
|
|
|
73
73
|
const { data, transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
74
74
|
return Ok({
|
|
75
75
|
...quote,
|
|
76
|
+
// The aggregator swapIn deadline is tighter than the daemon quote expiry
|
|
77
|
+
deadline: Math.min(quote.deadline, Number(deadline) * 1000),
|
|
76
78
|
data: data ?? quote.data,
|
|
77
79
|
// This logic will need to be updated to support multi-hop, if that's ever implemented for THORChain
|
|
78
80
|
steps: quote.steps.map(s => ({
|
|
@@ -2,7 +2,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
2
2
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
3
3
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
4
4
|
import { assertQuoteAddresses, makeSwapErrorRight } from '../../../utils/index.js';
|
|
5
|
-
import { isNativeEvmAsset } from '../../../utils/helpers.js';
|
|
5
|
+
import { FALLBACK_QUOTE_DEADLINE_MS, isNativeEvmAsset } from '../../../utils/helpers.js';
|
|
6
6
|
import { fetchZrxQuote } from '../utils/fetchFromZrx.js';
|
|
7
7
|
import { getZrxStepData } from '../utils/getZrxStepData.js';
|
|
8
8
|
import { getZrxTradeContext } from '../utils/getZrxTradeContext.js';
|
|
@@ -76,6 +76,7 @@ export const getZrxTradeQuote = async (input, deps) => {
|
|
|
76
76
|
const tradeQuote = {
|
|
77
77
|
...tradeCommon,
|
|
78
78
|
quoteOrRate: 'quote',
|
|
79
|
+
deadline: Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
79
80
|
receiveAddress,
|
|
80
81
|
steps: [
|
|
81
82
|
{
|
|
@@ -3,7 +3,7 @@ import type { Address, TypedData } from 'viem';
|
|
|
3
3
|
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput } from '../../types.js';
|
|
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;
|
|
@@ -18,6 +18,7 @@ export const ZRX_SUPPORTED_CHAINIDS = Object.freeze([
|
|
|
18
18
|
KnownChainIds.PolygonMainnet,
|
|
19
19
|
KnownChainIds.ArbitrumMainnet,
|
|
20
20
|
KnownChainIds.BaseMainnet,
|
|
21
|
+
KnownChainIds.RobinhoodMainnet,
|
|
21
22
|
]);
|
|
22
23
|
// https://0x.org/docs/developer-resources/faqs-and-troubleshooting
|
|
23
24
|
export const ZRX_NATIVE_ASSET_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
@@ -6,7 +6,7 @@ import type { SwapErrorRight } from '../../../types.js';
|
|
|
6
6
|
import type { ZrxFees, ZrxPriceResponse } from '../types.js';
|
|
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;
|
|
@@ -56,6 +56,11 @@ export const zrxTokenToAssetId = (token, chainId) => {
|
|
|
56
56
|
assetReference: ASSET_REFERENCE.Base,
|
|
57
57
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
58
58
|
};
|
|
59
|
+
case KnownChainIds.RobinhoodMainnet:
|
|
60
|
+
return {
|
|
61
|
+
assetReference: ASSET_REFERENCE.Robinhood,
|
|
62
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
63
|
+
};
|
|
59
64
|
default:
|
|
60
65
|
throw Error(`chainId '${chainId}' not supported`);
|
|
61
66
|
}
|
package/dist/esm/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/esm/types.js
CHANGED
|
@@ -30,6 +30,8 @@ export var TradeQuoteError;
|
|
|
30
30
|
TradeQuoteError["UnsupportedChain"] = "UnsupportedChain";
|
|
31
31
|
// the swapper can't swap across chains
|
|
32
32
|
TradeQuoteError["CrossChainNotSupported"] = "CrossChainNotSupported";
|
|
33
|
+
// the swapper can quote this pair, but can't derive a sell amount from an exact buy amount
|
|
34
|
+
TradeQuoteError["ExactOutputNotSupported"] = "ExactOutputNotSupported";
|
|
33
35
|
// the swapper wasn't able to get a network fee estimate
|
|
34
36
|
TradeQuoteError["NetworkFeeEstimationFailed"] = "NetworkFeeEstimationFailed";
|
|
35
37
|
// trading has been halted upstream
|