diff --git a/.changeset/curly-bears-swim.md b/.changeset/curly-bears-swim.md new file mode 100644 index 000000000..cae5e326e --- /dev/null +++ b/.changeset/curly-bears-swim.md @@ -0,0 +1,5 @@ +--- +"@reservoir0x/relay-kit-hooks": patch +--- + +feat: optimize usePrice hook to skip invalid canonical routes diff --git a/.changeset/sixty-olives-shave.md b/.changeset/sixty-olives-shave.md new file mode 100644 index 000000000..23a25c18a --- /dev/null +++ b/.changeset/sixty-olives-shave.md @@ -0,0 +1,5 @@ +--- +"@reservoir0x/relay-kit-ui": patch +--- + +Optimize usePrice hook by moving baseChainId validation to SwapWidgetRenderer and removing checkExternalLiquiditySupport prop. This improves performance by skipping invalid canonical routes based on baseChainId relationships. diff --git a/packages/sdk/src/types/RelayChain.ts b/packages/sdk/src/types/RelayChain.ts index 55b9655fa..c7d4438a5 100644 --- a/packages/sdk/src/types/RelayChain.ts +++ b/packages/sdk/src/types/RelayChain.ts @@ -36,4 +36,5 @@ export type RelayChain = { brandColor?: string | null vmType?: ChainVM viemChain?: Chain + baseChainId?: number | null } diff --git a/packages/sdk/src/types/api.ts b/packages/sdk/src/types/api.ts index b478df91b..573256e39 100644 --- a/packages/sdk/src/types/api.ts +++ b/packages/sdk/src/types/api.ts @@ -89,6 +89,8 @@ export interface paths { explorerQueryParams?: { [key: string]: unknown; } | null; + /** @description The chain id which the chain rolls up to. This is always set as Ethereum for L1 chains */ + baseChainId?: number | null; })[]; }; }; @@ -325,7 +327,7 @@ export interface paths { * @description Origin chain gas currency * @enum {string} */ - gasCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape" | "avax" | "bnb" | "dai" | "matic" | "sol"; + gasCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape" | "avax" | "bnb" | "dai" | "matic" | "sol" | "sei" | "mnt" | "trx"; /** @description Combination of the relayerGas and relayerService to give you the full relayer fee in wei */ relayer?: string; /** @description Destination chain gas fee in wei */ @@ -835,7 +837,7 @@ export interface paths { * @description Origin chain gas currency * @enum {string} */ - gasCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape" | "avax" | "bnb" | "dai" | "matic" | "sol"; + gasCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape" | "avax" | "bnb" | "dai" | "matic" | "sol" | "sei" | "mnt" | "trx"; /** @description Combination of the relayerGas and relayerService to give you the full relayer fee in wei */ relayer?: string; /** @description Destination chain gas fee in wei */ @@ -2256,6 +2258,11 @@ export interface paths { * @default true */ useReceiver?: boolean; + /** + * @description Specify the method for routing the deposit to the solver + * @enum {string} + */ + depositMethod?: "receiver" | "depositor-v1"; /** @description Enable this to use canonical+ bridging, trading speed for more liquidity */ useExternalLiquidity?: boolean; /** @description Enable this to use permit (eip3009) when bridging, only works on supported currency such as usdc */ @@ -2270,11 +2277,8 @@ export interface paths { /** @description App fees to be charged for execution in basis points, e.g. 100 = 1% */ fee?: string; }[]; - /** - * @description Enable this to use the Relay protocol for insuring the request - use with caution, this is an experimental flag - * @default true - */ - useCommitment?: boolean; + /** @description If the request involves specifying transactions to be executed during the deposit transaction, an explicit gas limit must be set when requesting the quote */ + gasLimitForDepositSpecifiedTxs?: number; }; }; }; @@ -3634,6 +3638,8 @@ export interface paths { id?: string; startTimestamp?: number; endTimestamp?: number; + startBlock?: number; + endBlock?: number; /** @description Get all requests for a single chain in either direction. Setting originChainId and/or destinationChainId will override this parameter. */ chainId?: string; sortBy?: "createdAt" | "updatedAt"; @@ -3730,6 +3736,7 @@ export interface paths { data?: unknown; stateChanges?: unknown; hash?: string; + block?: number; /** @description The type of transaction, always set to onchain */ type?: string; chainId?: number; @@ -3893,6 +3900,7 @@ export interface paths { data?: unknown; stateChanges?: unknown; hash?: string; + block?: number; /** @description The type of transaction, always set to onchain */ type?: string; chainId?: number; diff --git a/packages/ui/src/components/widgets/SwapWidget/index.tsx b/packages/ui/src/components/widgets/SwapWidget/index.tsx index 738fe2a10..1cdc55a12 100644 --- a/packages/ui/src/components/widgets/SwapWidget/index.tsx +++ b/packages/ui/src/components/widgets/SwapWidget/index.tsx @@ -139,7 +139,6 @@ const SwapWidget: FC = ({ multiWalletSupportEnabled={multiWalletSupportEnabled} onSwapError={onSwapError} onAnalyticEvent={onAnalyticEvent} - checkExternalLiquiditySupport={true} supportedWalletVMs={supportedWalletVMs} > {({ diff --git a/packages/ui/src/components/widgets/SwapWidgetRenderer.tsx b/packages/ui/src/components/widgets/SwapWidgetRenderer.tsx index 2b2072ef8..2b58a4065 100644 --- a/packages/ui/src/components/widgets/SwapWidgetRenderer.tsx +++ b/packages/ui/src/components/widgets/SwapWidgetRenderer.tsx @@ -15,7 +15,7 @@ import { useAccount } from 'wagmi' import { useCapabilities } from 'wagmi/experimental' import type { BridgeFee, Token } from '../../types/index.js' import { useQueryClient } from '@tanstack/react-query' -import type { ChainVM, Execute } from '@reservoir0x/relay-sdk' +import type { ChainVM, Execute, RelayChain } from '@reservoir0x/relay-sdk' import { calculatePriceTimeEstimate, calculateRelayerFeeProportionUsd, @@ -48,7 +48,6 @@ type SwapWidgetRendererProps = { defaultToAddress?: Address defaultAmount?: string defaultTradeType?: TradeType - checkExternalLiquiditySupport?: boolean context: 'Swap' | 'Deposit' | 'Withdraw' wallet?: AdaptedWallet linkedWallets?: LinkedWallet[] @@ -142,7 +141,6 @@ const SwapWidgetRenderer: FC = ({ defaultAmount, defaultTradeType, context, - checkExternalLiquiditySupport, wallet, multiWalletSupportEnabled = false, linkedWallets, @@ -389,9 +387,12 @@ const SwapWidgetRenderer: FC = ({ undefined, { enabled: - checkExternalLiquiditySupport && fromToken !== undefined && - toToken !== undefined + toToken !== undefined && + fromChain && + toChain && + (fromChain.id === toChain.baseChainId || + toChain.id === fromChain.baseChainId) } ) const supportsExternalLiquidity =