@shapeshiftoss/swapper 18.1.0 → 19.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/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/getAcrossTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +1 -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/getBebopTradeContext.d.ts +1 -0
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.js +1 -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/NearIntentsSwapper/endpoints.js +3 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +7 -0
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +11 -0
- package/dist/cjs/swappers/RelaySwapper/constant.js +4 -3
- package/dist/cjs/swappers/RelaySwapper/endpoints.js +6 -2
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +2 -0
- 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/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 +2 -2
- 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/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 +3 -0
- package/dist/cjs/utils/helpers.d.ts +2 -0
- package/dist/cjs/utils/helpers.js +14 -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/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/getAcrossTradeContext.d.ts +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +2 -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/getBebopTradeContext.d.ts +1 -0
- package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.js +2 -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/NearIntentsSwapper/endpoints.js +3 -1
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +7 -0
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +12 -1
- package/dist/esm/swappers/RelaySwapper/constant.js +6 -5
- package/dist/esm/swappers/RelaySwapper/endpoints.js +7 -3
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +2 -0
- 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/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 +2 -2
- 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/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 +3 -0
- package/dist/esm/utils/helpers.d.ts +2 -0
- package/dist/esm/utils/helpers.js +12 -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 +5 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { arbitrumChainId, baseChainId, blastChainId, bscChainId, ethChainId, hyperEvmChainId, inkChainId, lineaChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, scrollChainId, solanaChainId, soneiumChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
1
|
+
import { arbitrumChainId, baseChainId, blastChainId, bscChainId, ethChainId, hyperEvmChainId, inkChainId, lineaChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, robinhoodChainId, scrollChainId, solanaChainId, soneiumChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import invert from 'lodash/invert';
|
|
3
3
|
import { zeroAddress } from 'viem';
|
|
4
|
-
import { arbitrum, base, blast, bsc, hyperEvm, ink, linea, mainnet as ethereum, mode, monad, optimism, plasma, polygon, scroll, soneium, unichain, worldchain, zksync, } from 'viem/chains';
|
|
4
|
+
import { arbitrum, base, blast, bsc, hyperEvm, ink, linea, mainnet as ethereum, megaeth, mode, monad, optimism, plasma, polygon, robinhood, scroll, soneium, unichain, worldchain, zksync, } from 'viem/chains';
|
|
5
5
|
import { TradeQuoteError } from '../../types.js';
|
|
6
6
|
import { AcrossErrorCode } from './utils/types.js';
|
|
7
7
|
export const chainIdToAcrossChainId = {
|
|
@@ -25,7 +25,8 @@ export const chainIdToAcrossChainId = {
|
|
|
25
25
|
// Across uses a custom Solana chain ID
|
|
26
26
|
[solanaChainId]: 34268394551451,
|
|
27
27
|
[scrollChainId]: scroll.id,
|
|
28
|
-
[megaethChainId]:
|
|
28
|
+
[megaethChainId]: megaeth.id,
|
|
29
|
+
[robinhoodChainId]: robinhood.id,
|
|
29
30
|
};
|
|
30
31
|
export const acrossChainIdToChainId = invert(chainIdToAcrossChainId);
|
|
31
32
|
export const ACROSS_SUPPORTED_CHAIN_IDS = Object.keys(chainIdToAcrossChainId);
|
|
@@ -4,7 +4,7 @@ import { checkEvmSwapStatus, getExecutableTradeStep, isExecutableTradeQuote } fr
|
|
|
4
4
|
import { getEvmTransactionFees, getUnsignedEvmTransaction } from '../../utils/evm/index.js';
|
|
5
5
|
import { getTradeQuote } from './getTradeQuote/getTradeQuote.js';
|
|
6
6
|
import { getTradeRate } from './getTradeRate/getTradeRate.js';
|
|
7
|
-
import { acrossService } from './utils/acrossService.js';
|
|
7
|
+
import { acrossService, getAcrossRequestConfig } from './utils/acrossService.js';
|
|
8
8
|
export const acrossApi = {
|
|
9
9
|
getTradeQuote: (input, deps) => getTradeQuote(input, deps),
|
|
10
10
|
getTradeRate: (input, deps) => getTradeRate(input, deps),
|
|
@@ -33,7 +33,7 @@ export const acrossApi = {
|
|
|
33
33
|
return sourceTxStatus;
|
|
34
34
|
txHash = sourceTxStatus.buyTxHash ?? txHash;
|
|
35
35
|
}
|
|
36
|
-
const maybeStatusResponse = await acrossService.get(`${config.VITE_ACROSS_API_URL}/deposit/status?depositTxnRef=${txHash}
|
|
36
|
+
const maybeStatusResponse = await acrossService.get(`${config.VITE_ACROSS_API_URL}/deposit/status?depositTxnRef=${txHash}`, getAcrossRequestConfig(config));
|
|
37
37
|
if (maybeStatusResponse.isErr()) {
|
|
38
38
|
return {
|
|
39
39
|
buyTxHash: undefined,
|
|
@@ -16,7 +16,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
16
16
|
});
|
|
17
17
|
if (maybeContext.isErr())
|
|
18
18
|
return Err(maybeContext.unwrapErr());
|
|
19
|
-
const { tradeCommon, stepCommon, protocolFees, stepDataArgs } = maybeContext.unwrap();
|
|
19
|
+
const { tradeCommon, stepCommon, protocolFees, stepDataArgs, deadline } = maybeContext.unwrap();
|
|
20
20
|
const maybeStepData = await getAcrossStepData({ ...stepDataArgs, type: 'quote', input });
|
|
21
21
|
if (maybeStepData.isErr())
|
|
22
22
|
return Err(maybeStepData.unwrapErr());
|
|
@@ -24,6 +24,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
24
24
|
const tradeQuote = {
|
|
25
25
|
...tradeCommon,
|
|
26
26
|
quoteOrRate: 'quote',
|
|
27
|
+
deadline,
|
|
27
28
|
receiveAddress,
|
|
28
29
|
steps: [
|
|
29
30
|
{
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { SwapperConfig } from '../../../types.js';
|
|
1
3
|
export declare const acrossService: {
|
|
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 getAcrossRequestConfig: (config: SwapperConfig) => AxiosRequestConfig | undefined;
|
|
@@ -9,3 +9,6 @@ const axiosConfig = {
|
|
|
9
9
|
};
|
|
10
10
|
const acrossServiceBase = axios.create(axiosConfig);
|
|
11
11
|
export const acrossService = makeSwapperAxiosServiceMonadic(acrossServiceBase);
|
|
12
|
+
export const getAcrossRequestConfig = (config) => config.VITE_ACROSS_API_KEY
|
|
13
|
+
? { headers: { Authorization: `Bearer ${config.VITE_ACROSS_API_KEY}` } }
|
|
14
|
+
: undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { acrossService } from './acrossService.js';
|
|
1
|
+
import { acrossService, getAcrossRequestConfig } from './acrossService.js';
|
|
2
2
|
export const fetchAcrossTrade = (params, config) => {
|
|
3
3
|
const searchParams = new URLSearchParams();
|
|
4
4
|
searchParams.set('tradeType', params.tradeType);
|
|
@@ -19,5 +19,5 @@ export const fetchAcrossTrade = (params, config) => {
|
|
|
19
19
|
if (params.slippage)
|
|
20
20
|
searchParams.set('slippage', params.slippage);
|
|
21
21
|
const url = `${config.VITE_ACROSS_API_URL}/swap/approval?${searchParams.toString()}`;
|
|
22
|
-
return acrossService.get(url);
|
|
22
|
+
return acrossService.get(url, getAcrossRequestConfig(config));
|
|
23
23
|
};
|
|
@@ -7,6 +7,7 @@ type AcrossTradeContext = {
|
|
|
7
7
|
stepCommon: Omit<TradeStepCommon, 'feeData'>;
|
|
8
8
|
protocolFees: QuoteFeeData['protocolFees'];
|
|
9
9
|
stepDataArgs: Omit<GetAcrossStepDataArgs, 'type' | 'input'>;
|
|
10
|
+
deadline: number;
|
|
10
11
|
};
|
|
11
12
|
export declare const getAcrossTradeContext: ({ input, deps, depositor, recipient, }: {
|
|
12
13
|
input: AcrossTradeQuoteInput | AcrossTradeRateInput;
|
|
@@ -7,7 +7,7 @@ import { zeroAddress } from 'viem';
|
|
|
7
7
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
8
8
|
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils/index.js';
|
|
9
9
|
import { buildAffiliateFee } from '../../../utils/affiliateFee.js';
|
|
10
|
-
import { getTreasuryAddressFromChainId } from '../../../utils/helpers.js';
|
|
10
|
+
import { getTreasuryAddressFromChainId, normalizeEpochToMs } from '../../../utils/helpers.js';
|
|
11
11
|
import { acrossChainIdToChainId, acrossErrorCodeToTradeQuoteError } from '../constant.js';
|
|
12
12
|
import { fetchAcrossTrade } from './fetchAcrossTrade.js';
|
|
13
13
|
import { assertValidTrade, getAcrossAssetAddress } from './helpers.js';
|
|
@@ -172,5 +172,6 @@ export const getAcrossTradeContext = async ({ input, deps, depositor, recipient,
|
|
|
172
172
|
fallbackNetworkFeeCryptoBaseUnit: quote.fees.originGas.amount,
|
|
173
173
|
deps,
|
|
174
174
|
},
|
|
175
|
+
deadline: normalizeEpochToMs(quote.quoteExpiryTimestamp),
|
|
175
176
|
});
|
|
176
177
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { supportsETH } from '@shapeshiftoss/hdwallet-core';
|
|
2
2
|
import { Err, Ok } from '@sniptt/monads';
|
|
3
3
|
import { assertQuoteAddresses } from '../../../utils/index.js';
|
|
4
|
+
import { FALLBACK_QUOTE_DEADLINE_MS } from '../../../utils/helpers.js';
|
|
4
5
|
import { getArbitrumBridgeStepData } from '../utils/getArbitrumBridgeStepData.js';
|
|
5
6
|
import { getArbitrumBridgeTradeContext } from '../utils/getArbitrumBridgeTradeContext.js';
|
|
6
7
|
export const getTradeQuoteWithWallet = async (inputWithWallet, deps) => {
|
|
@@ -32,6 +33,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
32
33
|
const tradeQuote = {
|
|
33
34
|
...tradeCommon,
|
|
34
35
|
quoteOrRate: 'quote',
|
|
36
|
+
deadline: Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
35
37
|
receiveAddress,
|
|
36
38
|
steps: [
|
|
37
39
|
{
|
|
@@ -2,6 +2,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
2
2
|
import { validateAndParseAddress } from 'starknet';
|
|
3
3
|
import { TradeQuoteError } from '../../../types.js';
|
|
4
4
|
import { assertQuoteAddresses, makeSwapErrorRight } from '../../../utils/index.js';
|
|
5
|
+
import { FALLBACK_QUOTE_DEADLINE_MS } from '../../../utils/helpers.js';
|
|
5
6
|
import { getAvnuTradeContext } from '../utils/getAvnuTradeContext.js';
|
|
6
7
|
export const getTradeQuote = async (input, deps) => {
|
|
7
8
|
const { sellAsset, accountNumber } = input;
|
|
@@ -17,7 +18,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
17
18
|
const maybeContext = await getAvnuTradeContext({ input, takerAddress: normalizedSendAddress });
|
|
18
19
|
if (maybeContext.isErr())
|
|
19
20
|
return Err(maybeContext.unwrapErr());
|
|
20
|
-
const { tradeCommon, stepCommon, protocolFees, quoteId, sellTokenAddress } = maybeContext.unwrap();
|
|
21
|
+
const { tradeCommon, stepCommon, protocolFees, quoteId, sellTokenAddress, deadline } = maybeContext.unwrap();
|
|
21
22
|
const adapter = deps.assertGetStarknetChainAdapter(sellAsset.chainId);
|
|
22
23
|
const feeData = await adapter.getFeeData({
|
|
23
24
|
to: normalizedReceiveAddress,
|
|
@@ -32,6 +33,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
32
33
|
...tradeCommon,
|
|
33
34
|
receiveAddress: normalizedReceiveAddress,
|
|
34
35
|
quoteOrRate: 'quote',
|
|
36
|
+
deadline: deadline ?? Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
35
37
|
steps: [
|
|
36
38
|
{
|
|
37
39
|
...stepCommon,
|
|
@@ -6,6 +6,7 @@ type AvnuTradeContext = {
|
|
|
6
6
|
protocolFees: QuoteFeeData['protocolFees'];
|
|
7
7
|
quoteId: string;
|
|
8
8
|
sellTokenAddress: string;
|
|
9
|
+
deadline: number | undefined;
|
|
9
10
|
};
|
|
10
11
|
export declare const getAvnuTradeContext: ({ input, takerAddress, }: {
|
|
11
12
|
input: GetStarknetTradeQuoteInput | GetStarknetTradeRateInput;
|
|
@@ -7,7 +7,7 @@ import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constant
|
|
|
7
7
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
8
8
|
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils/index.js';
|
|
9
9
|
import { buildAffiliateFee } from '../../../utils/affiliateFee.js';
|
|
10
|
-
import { getTreasuryAddressFromChainId } from '../../../utils/helpers.js';
|
|
10
|
+
import { getTreasuryAddressFromChainId, normalizeEpochToMs } from '../../../utils/helpers.js';
|
|
11
11
|
import { assertValidTrade, getTokenAddress } from './helpers.js';
|
|
12
12
|
export const getAvnuTradeContext = async ({ input, takerAddress, }) => {
|
|
13
13
|
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, slippageTolerancePercentageDecimal, affiliateBps, } = input;
|
|
@@ -90,6 +90,7 @@ export const getAvnuTradeContext = async ({ input, takerAddress, }) => {
|
|
|
90
90
|
protocolFees,
|
|
91
91
|
quoteId: bestQuote.quoteId,
|
|
92
92
|
sellTokenAddress,
|
|
93
|
+
deadline: bestQuote.expiry ? normalizeEpochToMs(bestQuote.expiry) : undefined,
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
96
|
catch (error) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Err, Ok } from '@sniptt/monads';
|
|
2
2
|
import { TradeQuoteError } from '../../../types.js';
|
|
3
3
|
import { assertQuoteAddresses, makeSwapErrorRight } from '../../../utils/index.js';
|
|
4
|
+
import { normalizeEpochToMs } from '../../../utils/helpers.js';
|
|
4
5
|
import { getBebopSolanaTradeContext } from '../utils/getBebopSolanaTradeContext.js';
|
|
5
6
|
import { isBebopSolanaTxSafe } from '../utils/helpers.js';
|
|
6
7
|
export const getBebopSolanaTradeQuote = async (input, deps) => {
|
|
@@ -27,6 +28,8 @@ export const getBebopSolanaTradeQuote = async (input, deps) => {
|
|
|
27
28
|
const tradeQuote = {
|
|
28
29
|
...tradeCommon,
|
|
29
30
|
quoteOrRate: 'quote',
|
|
31
|
+
// The sealed multi-signer tx is blockhash-pinned, so the provider expiry governs
|
|
32
|
+
deadline: normalizeEpochToMs(response.expiry),
|
|
30
33
|
receiveAddress,
|
|
31
34
|
steps: [
|
|
32
35
|
{
|
|
@@ -17,7 +17,7 @@ export const getBebopTradeQuote = async (input, deps) => {
|
|
|
17
17
|
});
|
|
18
18
|
if (maybeContext.isErr())
|
|
19
19
|
return Err(maybeContext.unwrapErr());
|
|
20
|
-
const { tradeCommon, stepCommon, stepDataArgs } = maybeContext.unwrap();
|
|
20
|
+
const { tradeCommon, stepCommon, stepDataArgs, deadline } = maybeContext.unwrap();
|
|
21
21
|
const maybeStepData = await getBebopStepData({ ...stepDataArgs, type: 'quote', input });
|
|
22
22
|
if (maybeStepData.isErr())
|
|
23
23
|
return Err(maybeStepData.unwrapErr());
|
|
@@ -25,6 +25,7 @@ export const getBebopTradeQuote = async (input, deps) => {
|
|
|
25
25
|
const tradeQuote = {
|
|
26
26
|
...tradeCommon,
|
|
27
27
|
quoteOrRate: 'quote',
|
|
28
|
+
deadline,
|
|
28
29
|
receiveAddress,
|
|
29
30
|
steps: [
|
|
30
31
|
{
|
|
@@ -3,8 +3,8 @@ import type { Address, Hex } from 'viem';
|
|
|
3
3
|
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput } from '../../types.js';
|
|
4
4
|
export type BebopTradeQuoteInput = GetEvmTradeQuoteInput | GetSolanaTradeQuoteInput;
|
|
5
5
|
export type BebopTradeRateInput = GetEvmTradeRateInput | GetSolanaTradeRateInput;
|
|
6
|
-
export declare const bebopSupportedEvmChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet];
|
|
7
|
-
export declare const bebopSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.SolanaMainnet];
|
|
6
|
+
export declare const bebopSupportedEvmChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.RobinhoodMainnet];
|
|
7
|
+
export declare const bebopSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.RobinhoodMainnet, KnownChainIds.SolanaMainnet];
|
|
8
8
|
export type BebopSupportedChainId = (typeof bebopSupportedChainIds)[number];
|
|
9
9
|
export type BebopMetadata = {
|
|
10
10
|
name: 'bebop';
|
|
@@ -7,6 +7,7 @@ export const bebopSupportedEvmChainIds = [
|
|
|
7
7
|
KnownChainIds.AvalancheMainnet,
|
|
8
8
|
KnownChainIds.OptimismMainnet,
|
|
9
9
|
KnownChainIds.BnbSmartChainMainnet,
|
|
10
|
+
KnownChainIds.RobinhoodMainnet,
|
|
10
11
|
];
|
|
11
12
|
export const bebopSupportedChainIds = [
|
|
12
13
|
...bebopSupportedEvmChainIds,
|
|
@@ -20,6 +21,7 @@ export const chainIdToBebopChain = {
|
|
|
20
21
|
[KnownChainIds.AvalancheMainnet]: 'avalanche',
|
|
21
22
|
[KnownChainIds.OptimismMainnet]: 'optimism',
|
|
22
23
|
[KnownChainIds.BnbSmartChainMainnet]: 'bsc',
|
|
24
|
+
[KnownChainIds.RobinhoodMainnet]: 'robinhood',
|
|
23
25
|
[KnownChainIds.SolanaMainnet]: 'solana',
|
|
24
26
|
};
|
|
25
27
|
export const BEBOP_NATIVE_MARKER = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
@@ -6,6 +6,7 @@ type BebopTradeContext = {
|
|
|
6
6
|
tradeCommon: TradeCommon;
|
|
7
7
|
stepCommon: Omit<TradeStepCommon, 'feeData'>;
|
|
8
8
|
stepDataArgs: Omit<GetBebopStepDataArgs, 'type' | 'input'>;
|
|
9
|
+
deadline: number;
|
|
9
10
|
};
|
|
10
11
|
export declare const getBebopTradeContext: ({ input, deps, from, receiver, }: {
|
|
11
12
|
input: GetEvmTradeQuoteInput | GetEvmTradeRateInput;
|
|
@@ -5,7 +5,7 @@ import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constant
|
|
|
5
5
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
6
6
|
import { makeSwapErrorRight } from '../../../utils/index.js';
|
|
7
7
|
import { buildAffiliateFee } from '../../../utils/affiliateFee.js';
|
|
8
|
-
import { isNativeEvmAsset } from '../../../utils/helpers.js';
|
|
8
|
+
import { isNativeEvmAsset, normalizeEpochToMs } from '../../../utils/helpers.js';
|
|
9
9
|
import { fetchBebopQuote } from './fetchFromBebop.js';
|
|
10
10
|
import { assertValidTrade, calculateRate } from './helpers.js';
|
|
11
11
|
export const getBebopTradeContext = async ({ input, deps, from, receiver, }) => {
|
|
@@ -78,5 +78,6 @@ export const getBebopTradeContext = async ({ input, deps, from, receiver, }) =>
|
|
|
78
78
|
from,
|
|
79
79
|
deps,
|
|
80
80
|
},
|
|
81
|
+
deadline: normalizeEpochToMs(quote.expiry),
|
|
81
82
|
});
|
|
82
83
|
};
|
|
@@ -2,7 +2,7 @@ import type { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
|
2
2
|
import type { Asset } from '@shapeshiftoss/types';
|
|
3
3
|
export declare const assetIdToBebopToken: (assetId: AssetId) => string;
|
|
4
4
|
export declare const assetIdToBebopSolanaToken: (assetId: AssetId) => string;
|
|
5
|
-
export declare const isSupportedChainId: (chainId: ChainId) => chainId is import("@shapeshiftoss/types").KnownChainIds.EthereumMainnet | import("@shapeshiftoss/types").KnownChainIds.AvalancheMainnet | import("@shapeshiftoss/types").KnownChainIds.OptimismMainnet | import("@shapeshiftoss/types").KnownChainIds.BnbSmartChainMainnet | import("@shapeshiftoss/types").KnownChainIds.PolygonMainnet | import("@shapeshiftoss/types").KnownChainIds.ArbitrumMainnet | import("@shapeshiftoss/types").KnownChainIds.BaseMainnet | import("@shapeshiftoss/types").KnownChainIds.SolanaMainnet;
|
|
5
|
+
export declare const isSupportedChainId: (chainId: ChainId) => chainId is import("@shapeshiftoss/types").KnownChainIds.EthereumMainnet | import("@shapeshiftoss/types").KnownChainIds.AvalancheMainnet | import("@shapeshiftoss/types").KnownChainIds.OptimismMainnet | import("@shapeshiftoss/types").KnownChainIds.BnbSmartChainMainnet | import("@shapeshiftoss/types").KnownChainIds.PolygonMainnet | import("@shapeshiftoss/types").KnownChainIds.ArbitrumMainnet | import("@shapeshiftoss/types").KnownChainIds.BaseMainnet | import("@shapeshiftoss/types").KnownChainIds.SolanaMainnet | import("@shapeshiftoss/types").KnownChainIds.RobinhoodMainnet;
|
|
6
6
|
export declare const assertValidTrade: ({ buyAsset, sellAsset, }: {
|
|
7
7
|
buyAsset: Asset;
|
|
8
8
|
sellAsset: Asset;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
2
2
|
import { Err, Ok } from '@sniptt/monads';
|
|
3
3
|
import { assertQuoteAddresses } from '../../../utils/index.js';
|
|
4
|
+
import { FALLBACK_QUOTE_DEADLINE_MS } from '../../../utils/helpers.js';
|
|
4
5
|
import { getBobGatewayStepData } from '../utils/getBobGatewayStepData.js';
|
|
5
6
|
import { getBobGatewayTradeContext } from '../utils/getBobGatewayTradeContext.js';
|
|
6
7
|
export const getBobGatewayTradeQuote = async (input, deps) => {
|
|
@@ -33,6 +34,7 @@ export const getBobGatewayTradeQuote = async (input, deps) => {
|
|
|
33
34
|
const tradeQuote = {
|
|
34
35
|
...tradeCommon,
|
|
35
36
|
quoteOrRate: 'quote',
|
|
37
|
+
deadline: Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
36
38
|
receiveAddress,
|
|
37
39
|
steps: [
|
|
38
40
|
{
|
|
@@ -4,6 +4,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
4
4
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
5
5
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
6
6
|
import { assertQuoteAddresses, makeSwapErrorRight } from '../../../utils/index.js';
|
|
7
|
+
import { FALLBACK_QUOTE_DEADLINE_MS } from '../../../utils/helpers.js';
|
|
7
8
|
import { getButterSwapStepData } from '../utils/getButterSwapStepData.js';
|
|
8
9
|
import { getButterSwapTradeContext } from '../utils/getButterSwapTradeContext.js';
|
|
9
10
|
import { fetchTxData, isBuildTxSuccess } from '../xhr.js';
|
|
@@ -59,6 +60,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
59
60
|
const tradeQuote = {
|
|
60
61
|
...tradeCommon,
|
|
61
62
|
quoteOrRate: 'quote',
|
|
63
|
+
deadline: Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
62
64
|
receiveAddress,
|
|
63
65
|
steps: [
|
|
64
66
|
{
|
|
@@ -3,20 +3,22 @@ import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
|
3
3
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
4
4
|
import { BigAmount, bnOrZero } from '@shapeshiftoss/utils';
|
|
5
5
|
import { Err, Ok } from '@sniptt/monads';
|
|
6
|
+
import { arbitrum, avalanche, base, bsc, mainnet as ethereum, optimism, polygon, robinhood, tron, } from 'viem/chains';
|
|
6
7
|
import { TradeQuoteError } from '../../../types.js';
|
|
7
8
|
import { makeSwapErrorRight } from '../../../utils/index.js';
|
|
8
9
|
// https://docs.butternetwork.io/butter-swap-integration/butter-api-for-routing/get-supportedchainlist#butter-chain-id-explanation
|
|
9
10
|
const BUTTERSWAP_CHAIN_ID_TO_CHAIN_ID = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
[ethereum.id]: KnownChainIds.EthereumMainnet,
|
|
12
|
+
[polygon.id]: KnownChainIds.PolygonMainnet,
|
|
13
|
+
[bsc.id]: KnownChainIds.BnbSmartChainMainnet,
|
|
14
|
+
[arbitrum.id]: KnownChainIds.ArbitrumMainnet,
|
|
15
|
+
[optimism.id]: KnownChainIds.OptimismMainnet,
|
|
16
|
+
[base.id]: KnownChainIds.BaseMainnet,
|
|
17
|
+
[avalanche.id]: KnownChainIds.AvalancheMainnet,
|
|
18
|
+
[robinhood.id]: KnownChainIds.RobinhoodMainnet,
|
|
17
19
|
1360108768460801: KnownChainIds.SolanaMainnet,
|
|
18
20
|
1360095883558913: KnownChainIds.BitcoinMainnet,
|
|
19
|
-
|
|
21
|
+
[tron.id]: KnownChainIds.TronMainnet,
|
|
20
22
|
};
|
|
21
23
|
const CHAIN_ID_TO_BUTTERSWAP_CHAIN_ID = Object.entries(BUTTERSWAP_CHAIN_ID_TO_CHAIN_ID).reduce((acc, [butterSwapChainId, chainId]) => {
|
|
22
24
|
acc[chainId] = Number(butterSwapChainId);
|
|
@@ -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 { getCetusStepData } from './getCetusStepData.js';
|
|
4
5
|
import { getCetusTradeContext } from './getCetusTradeContext.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: Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
27
29
|
receiveAddress,
|
|
28
30
|
steps: [
|
|
29
31
|
{
|
|
@@ -5,6 +5,7 @@ import type { SwapSource } from '../../types.js';
|
|
|
5
5
|
import { ChainflipNetwork } from './types.js';
|
|
6
6
|
export declare const CHAINFLIP_REGULAR_QUOTE: "regular";
|
|
7
7
|
export declare const CHAINFLIP_DCA_QUOTE: "dca";
|
|
8
|
+
export declare const CHAINFLIP_CHANNEL_DEADLINE_MS: number;
|
|
8
9
|
export declare const ChainflipSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BitcoinMainnet, KnownChainIds.SolanaMainnet, KnownChainIds.TronMainnet];
|
|
9
10
|
export type ChainflipSupportedChainId = (typeof ChainflipSupportedChainIds)[number];
|
|
10
11
|
export declare const ChainflipSupportedAssetIdsByChainId: Partial<Record<KnownChainIds, AssetId[]>>;
|
|
@@ -4,6 +4,8 @@ import { SwapperName } from '../../types.js';
|
|
|
4
4
|
import { ChainflipNetwork } from './types.js';
|
|
5
5
|
export const CHAINFLIP_REGULAR_QUOTE = 'regular';
|
|
6
6
|
export const CHAINFLIP_DCA_QUOTE = 'dca';
|
|
7
|
+
// Deposit channels stay open ~24h - 6h keeps a 4x margin against depositing to an expired channel
|
|
8
|
+
export const CHAINFLIP_CHANNEL_DEADLINE_MS = 6 * 60 * 60 * 1000;
|
|
7
9
|
export const ChainflipSupportedChainIds = [
|
|
8
10
|
KnownChainIds.EthereumMainnet,
|
|
9
11
|
KnownChainIds.ArbitrumMainnet,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Err, Ok } from '@sniptt/monads';
|
|
2
2
|
import { TradeQuoteError } from '../../../types.js';
|
|
3
3
|
import { assertQuoteAddresses, makeSwapErrorRight } from '../../../utils/index.js';
|
|
4
|
+
import { CHAINFLIP_CHANNEL_DEADLINE_MS } from '../constants.js';
|
|
4
5
|
import { getChainflipStepData } from '../utils/getChainflipStepData.js';
|
|
5
6
|
import { getChainflipTradeContexts } from '../utils/getChainflipTradeContexts.js';
|
|
6
7
|
import { calculateChainflipMinPrice, getChainFlipSwap } from '../utils/helpers.js';
|
|
@@ -66,6 +67,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
66
67
|
tradeQuotes.push({
|
|
67
68
|
...tradeCommon,
|
|
68
69
|
quoteOrRate: 'quote',
|
|
70
|
+
deadline: Date.now() + CHAINFLIP_CHANNEL_DEADLINE_MS,
|
|
69
71
|
receiveAddress,
|
|
70
72
|
steps: [
|
|
71
73
|
{
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, bobChainId, bscChainId, cronosChainId, ethChainId, flowEvmChainId, gnosisChainId, hyperEvmChainId, lineaChainId, mantleChainId, megaethChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, seiChainId, sonicChainId, storyChainId, } from '@shapeshiftoss/caip';
|
|
1
|
+
import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, bobChainId, bscChainId, cronosChainId, ethChainId, flowEvmChainId, gnosisChainId, hyperEvmChainId, lineaChainId, mantleChainId, megaethChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, robinhoodChainId, seiChainId, sonicChainId, storyChainId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import invert from 'lodash/invert';
|
|
3
3
|
import { zeroAddress } from 'viem';
|
|
4
|
+
import { arbitrum, avalanche, base, bsc, linea, mainnet as ethereum, optimism, polygon, robinhood, } from 'viem/chains';
|
|
4
5
|
export const chainIdToDebridgeChainId = {
|
|
5
|
-
[ethChainId]:
|
|
6
|
-
[optimismChainId]:
|
|
7
|
-
[bscChainId]:
|
|
6
|
+
[ethChainId]: ethereum.id,
|
|
7
|
+
[optimismChainId]: optimism.id,
|
|
8
|
+
[bscChainId]: bsc.id,
|
|
8
9
|
[gnosisChainId]: 100000002,
|
|
9
|
-
[polygonChainId]:
|
|
10
|
+
[polygonChainId]: polygon.id,
|
|
10
11
|
[monadChainId]: 100000030,
|
|
11
12
|
[hyperEvmChainId]: 100000022,
|
|
12
13
|
[seiChainId]: 100000027,
|
|
13
|
-
[baseChainId]:
|
|
14
|
+
[baseChainId]: base.id,
|
|
14
15
|
[plasmaChainId]: 100000028,
|
|
15
|
-
[arbitrumChainId]:
|
|
16
|
-
[avalancheChainId]:
|
|
16
|
+
[arbitrumChainId]: arbitrum.id,
|
|
17
|
+
[avalancheChainId]: avalanche.id,
|
|
17
18
|
[mantleChainId]: 100000023,
|
|
18
19
|
[cronosChainId]: 100000019,
|
|
19
20
|
[berachainChainId]: 100000020,
|
|
20
|
-
[lineaChainId]:
|
|
21
|
+
[lineaChainId]: linea.id,
|
|
21
22
|
[bobChainId]: 100000021,
|
|
22
23
|
[sonicChainId]: 100000014,
|
|
23
24
|
[storyChainId]: 100000013,
|
|
24
25
|
[flowEvmChainId]: 100000009,
|
|
25
26
|
[megaethChainId]: 100000031,
|
|
27
|
+
[robinhoodChainId]: robinhood.id,
|
|
26
28
|
};
|
|
27
29
|
export const debridgeChainIdToChainId = invert(chainIdToDebridgeChainId);
|
|
28
30
|
export const DEBRIDGE_SUPPORTED_CHAIN_IDS = Object.keys(chainIdToDebridgeChainId);
|
|
@@ -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 { getDebridgeStepData } from '../utils/getDebridgeStepData.js';
|
|
4
5
|
import { getDebridgeTradeContext } from '../utils/getDebridgeTradeContext.js';
|
|
5
6
|
export const getTradeQuote = async (input, deps) => {
|
|
@@ -23,6 +24,7 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
23
24
|
const tradeQuote = {
|
|
24
25
|
...tradeCommon,
|
|
25
26
|
quoteOrRate: 'quote',
|
|
27
|
+
deadline: Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
26
28
|
receiveAddress,
|
|
27
29
|
steps: [
|
|
28
30
|
{
|
|
@@ -163,7 +163,9 @@ export const nearIntentsApi = {
|
|
|
163
163
|
const message = getNearIntentsStatusMessage(statusResponse.status);
|
|
164
164
|
// Extract buyTxHash from destination chain transactions
|
|
165
165
|
const buyTxHash = statusResponse.swapDetails?.destinationChainTxHashes?.[0]?.hash;
|
|
166
|
-
|
|
166
|
+
// amountOut is only meaningful destination-denominated on terminal success - in-flight and
|
|
167
|
+
// refund states may carry settlement-internal or refund values
|
|
168
|
+
const actualBuyAmountCryptoBaseUnit = statusResponse.status === 'SUCCESS' ? statusResponse.swapDetails?.amountOut : undefined;
|
|
167
169
|
return {
|
|
168
170
|
status: txStatus,
|
|
169
171
|
buyTxHash,
|
|
@@ -45,9 +45,16 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
45
45
|
if (maybeStepData.isErr())
|
|
46
46
|
return Err(maybeStepData.unwrapErr());
|
|
47
47
|
const { transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
48
|
+
const requestDeadlineMs = Date.parse(quoteRequest.deadline);
|
|
49
|
+
const responseDeadlineMs = Date.parse(quote.deadline ?? '');
|
|
48
50
|
const tradeQuote = {
|
|
49
51
|
...tradeCommon,
|
|
50
52
|
quoteOrRate: 'quote',
|
|
53
|
+
// Deposits mined after our requested refund deadline refund instead of executing as quoted;
|
|
54
|
+
// the response deadline (when the deposit address goes inactive, ~72h) only binds if tighter
|
|
55
|
+
deadline: Number.isFinite(responseDeadlineMs)
|
|
56
|
+
? Math.min(requestDeadlineMs, responseDeadlineMs)
|
|
57
|
+
: requestDeadlineMs,
|
|
51
58
|
receiveAddress,
|
|
52
59
|
steps: [
|
|
53
60
|
{
|
|
@@ -2,7 +2,7 @@ import { BigNumber, bn } from '@shapeshiftoss/utils';
|
|
|
2
2
|
import { Err, Ok } from '@sniptt/monads';
|
|
3
3
|
import { TradeQuoteError } from '../../../types.js';
|
|
4
4
|
import { assertQuoteAddresses, makeSwapErrorRight, makeTradeStepBuildFailedErr, } from '../../../utils/index.js';
|
|
5
|
-
import { getTreasuryAddressFromChainId } from '../../../utils/helpers.js';
|
|
5
|
+
import { FALLBACK_QUOTE_DEADLINE_MS, getTreasuryAddressFromChainId, normalizeEpochToMs, } from '../../../utils/helpers.js';
|
|
6
6
|
import { fetchPortalsTradeOrder, PortalsError } from '../utils/fetchPortalsTradeOrder.js';
|
|
7
7
|
import { getPortalsStepData } from '../utils/getPortalsStepData.js';
|
|
8
8
|
import { getPortalsTradeContext } from '../utils/getPortalsTradeContext.js';
|
|
@@ -125,9 +125,20 @@ export const getPortalsTradeQuote = async (input, deps) => {
|
|
|
125
125
|
if (maybeStepData.isErr())
|
|
126
126
|
return Err(maybeStepData.unwrapErr());
|
|
127
127
|
const { transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
128
|
+
// Nullable in practice (live validated orders return null) - numeric or ISO when supplied
|
|
129
|
+
const expiryMs = (() => {
|
|
130
|
+
if (!orderContext.expiry)
|
|
131
|
+
return undefined;
|
|
132
|
+
const numeric = Number(orderContext.expiry);
|
|
133
|
+
if (Number.isFinite(numeric))
|
|
134
|
+
return normalizeEpochToMs(numeric);
|
|
135
|
+
const parsed = Date.parse(orderContext.expiry);
|
|
136
|
+
return Number.isNaN(parsed) ? undefined : parsed;
|
|
137
|
+
})();
|
|
128
138
|
const tradeQuote = {
|
|
129
139
|
...tradeCommon,
|
|
130
140
|
quoteOrRate: 'quote',
|
|
141
|
+
deadline: expiryMs ?? Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
|
|
131
142
|
receiveAddress,
|
|
132
143
|
steps: [
|
|
133
144
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { abstractChainId, arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, blastChainId, bobChainId, bscChainId, btcChainId, celoChainId, cronosChainId, ethChainId, etherealChainId, flowEvmChainId, gnosisChainId, hemiChainId, hyperEvmChainId, inkChainId, katanaChainId, lineaChainId, mantleChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, plumeChainId, polygonChainId, scrollChainId, seiChainId, solanaChainId, soneiumChainId, sonicChainId, storyChainId, tronChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
1
|
+
import { abstractChainId, arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, blastChainId, bobChainId, bscChainId, btcChainId, celoChainId, cronosChainId, ethChainId, etherealChainId, flowEvmChainId, gnosisChainId, hemiChainId, hyperEvmChainId, inkChainId, katanaChainId, lineaChainId, mantleChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, plumeChainId, polygonChainId, robinhoodChainId, scrollChainId, seiChainId, solanaChainId, soneiumChainId, sonicChainId, storyChainId, tronChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import invert from 'lodash/invert';
|
|
3
3
|
import { zeroAddress } from 'viem';
|
|
4
|
-
import { arbitrum, avalanche, base, berachain, blast, bob, bsc, celo, cronos, flowMainnet, gnosis, hemi, hyperEvm, ink, katana, linea, mainnet as ethereum, mantle, mode, monad, optimism, plasma, plumeMainnet, polygon, scroll, sei, soneium, sonic, story, unichain, worldchain, zksync, } from 'viem/chains';
|
|
4
|
+
import { abstract, arbitrum, avalanche, base, berachain, blast, bob, bsc, celo, cronos, flowMainnet, gnosis, hemi, hyperEvm, ink, katana, linea, mainnet as ethereum, mantle, megaeth, mode, monad, optimism, plasma, plumeMainnet, polygon, robinhood, scroll, sei, soneium, sonic, story, tron, unichain, worldchain, zksync, } from 'viem/chains';
|
|
5
5
|
import { TradeQuoteError } from '../../types.js';
|
|
6
6
|
import { RelayErrorCode } from './utils/types.js';
|
|
7
7
|
// https://docs.relay.link/resources/supported-chains
|
|
@@ -16,12 +16,12 @@ export const chainIdToRelayChainId = {
|
|
|
16
16
|
[gnosisChainId]: gnosis.id,
|
|
17
17
|
[avalancheChainId]: avalanche.id,
|
|
18
18
|
[bscChainId]: bsc.id,
|
|
19
|
-
[tronChainId]:
|
|
19
|
+
[tronChainId]: tron.id,
|
|
20
20
|
[monadChainId]: monad.id,
|
|
21
21
|
[hyperEvmChainId]: hyperEvm.id,
|
|
22
22
|
[mantleChainId]: mantle.id,
|
|
23
23
|
[inkChainId]: ink.id,
|
|
24
|
-
[megaethChainId]:
|
|
24
|
+
[megaethChainId]: megaeth.id,
|
|
25
25
|
[plasmaChainId]: plasma.id,
|
|
26
26
|
[katanaChainId]: katana.id,
|
|
27
27
|
[etherealChainId]: 5064014,
|
|
@@ -43,7 +43,8 @@ export const chainIdToRelayChainId = {
|
|
|
43
43
|
[modeChainId]: mode.id,
|
|
44
44
|
[soneiumChainId]: soneium.id,
|
|
45
45
|
[seiChainId]: sei.id,
|
|
46
|
-
[abstractChainId]:
|
|
46
|
+
[abstractChainId]: abstract.id,
|
|
47
|
+
[robinhoodChainId]: robinhood.id,
|
|
47
48
|
};
|
|
48
49
|
export var RelayStatusMessage;
|
|
49
50
|
(function (RelayStatusMessage) {
|
|
@@ -10,7 +10,7 @@ import { getTradeQuote } from './getTradeQuote/getTradeQuote.js';
|
|
|
10
10
|
import { getTradeRate } from './getTradeRate/getTradeRate.js';
|
|
11
11
|
import { getLatestRelayStatusMessage } from './utils/getLatestRelayStatusMessage.js';
|
|
12
12
|
import { notifyTransactionIndexing } from './utils/notifyTransactionIndexing.js';
|
|
13
|
-
import { relayService } from './utils/relayService.js';
|
|
13
|
+
import { getRelayRequestConfig, relayService } from './utils/relayService.js';
|
|
14
14
|
// Keep track of the trades we already notified the relay indexer about
|
|
15
15
|
const txIndexingMap = new Map();
|
|
16
16
|
export const relayApi = {
|
|
@@ -61,7 +61,7 @@ export const relayApi = {
|
|
|
61
61
|
// relay.link tracks the swap by its origin chain transaction
|
|
62
62
|
const swapperTxId = txHash;
|
|
63
63
|
const swapperTxLink = `https://relay.link/transaction/${txHash}`;
|
|
64
|
-
const maybeStatusResponse = await relayService.get(`${config.VITE_RELAY_API_URL}/intents/status/
|
|
64
|
+
const maybeStatusResponse = await relayService.get(`${config.VITE_RELAY_API_URL}/intents/status/v3?requestId=${relayMetadata.relayId}`, getRelayRequestConfig(config));
|
|
65
65
|
if (maybeStatusResponse.isErr()) {
|
|
66
66
|
return {
|
|
67
67
|
buyTxHash: undefined,
|
|
@@ -76,9 +76,13 @@ export const relayApi = {
|
|
|
76
76
|
switch (statusResponse.status) {
|
|
77
77
|
case 'success':
|
|
78
78
|
return TxStatus.Confirmed;
|
|
79
|
+
case 'waiting':
|
|
80
|
+
case 'delayed':
|
|
79
81
|
case 'pending':
|
|
82
|
+
case 'depositing':
|
|
83
|
+
case 'submitted':
|
|
80
84
|
return TxStatus.Pending;
|
|
81
|
-
case '
|
|
85
|
+
case 'failure':
|
|
82
86
|
case 'refund':
|
|
83
87
|
return TxStatus.Failed;
|
|
84
88
|
default:
|