Skip to content

Commit

Permalink
Merge pull request #402 from reservoirprotocol/devin/1734380438-optim…
Browse files Browse the repository at this point in the history
…ize-price-hook

feat: optimize usePrice hook to skip invalid canonical routes
  • Loading branch information
pedromcunha authored Dec 16, 2024
2 parents d2a095f + ef5aba1 commit 2652757
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-bears-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reservoir0x/relay-kit-hooks": patch
---

feat: optimize usePrice hook to skip invalid canonical routes
5 changes: 5 additions & 0 deletions .changeset/sixty-olives-shave.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions packages/sdk/src/types/RelayChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export type RelayChain = {
brandColor?: string | null
vmType?: ChainVM
viemChain?: Chain
baseChainId?: number | null
}
22 changes: 15 additions & 7 deletions packages/sdk/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})[];
};
};
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand All @@ -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;
};
};
};
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/components/widgets/SwapWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ const SwapWidget: FC<SwapWidgetProps> = ({
multiWalletSupportEnabled={multiWalletSupportEnabled}
onSwapError={onSwapError}
onAnalyticEvent={onAnalyticEvent}
checkExternalLiquiditySupport={true}
supportedWalletVMs={supportedWalletVMs}
>
{({
Expand Down
11 changes: 6 additions & 5 deletions packages/ui/src/components/widgets/SwapWidgetRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,7 +48,6 @@ type SwapWidgetRendererProps = {
defaultToAddress?: Address
defaultAmount?: string
defaultTradeType?: TradeType
checkExternalLiquiditySupport?: boolean
context: 'Swap' | 'Deposit' | 'Withdraw'
wallet?: AdaptedWallet
linkedWallets?: LinkedWallet[]
Expand Down Expand Up @@ -142,7 +141,6 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
defaultAmount,
defaultTradeType,
context,
checkExternalLiquiditySupport,
wallet,
multiWalletSupportEnabled = false,
linkedWallets,
Expand Down Expand Up @@ -389,9 +387,12 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
undefined,
{
enabled:
checkExternalLiquiditySupport &&
fromToken !== undefined &&
toToken !== undefined
toToken !== undefined &&
fromChain &&
toChain &&
(fromChain.id === toChain.baseChainId ||
toChain.id === fromChain.baseChainId)
}
)
const supportsExternalLiquidity =
Expand Down

0 comments on commit 2652757

Please sign in to comment.