From 33b546bde579e81696bca8334187666ce3468060 Mon Sep 17 00:00:00 2001 From: pedromcunha Date: Tue, 26 Nov 2024 11:50:48 -0500 Subject: [PATCH] Bug fixes for deposit addresses --- packages/sdk/src/routes/index.ts | 3 +- packages/sdk/src/types/Execute.ts | 1 + packages/sdk/src/types/api.ts | 174 +++++++++--------- .../common/TokenSelector/TokenSelector.tsx | 9 +- .../DepositAddressModalRenderer.tsx | 9 +- .../components/widgets/SwapWidget/index.tsx | 30 ++- .../components/widgets/SwapWidgetRenderer.tsx | 6 + packages/ui/src/utils/quote.ts | 7 +- 8 files changed, 138 insertions(+), 101 deletions(-) diff --git a/packages/sdk/src/routes/index.ts b/packages/sdk/src/routes/index.ts index dbc2eb91..a516aad2 100644 --- a/packages/sdk/src/routes/index.ts +++ b/packages/sdk/src/routes/index.ts @@ -1,5 +1,6 @@ export const routes = [ "/chains", + "/chains/health", "/config", "/config/v2", "/execute/bridge", @@ -11,13 +12,13 @@ export const routes = [ "/execute/permits", "/quote", "/price", - "/execute/user-op/{chainId}", "/lives", "/intents/status", "/intents/status/v2", "/intents/quote", "/intents/quote/v2", "/requests/{requestId}/signature", + "/requests/{requestId}/signature/v2", "/requests", "/requests/v2", "/transactions/index", diff --git a/packages/sdk/src/types/Execute.ts b/packages/sdk/src/types/Execute.ts index 5adef436..7e92e831 100644 --- a/packages/sdk/src/types/Execute.ts +++ b/packages/sdk/src/types/Execute.ts @@ -42,6 +42,7 @@ export type Execute = { kind: 'transaction' | 'signature' id: string requestId?: string + depositAddress?: string items?: { status: 'complete' | 'incomplete' progressState?: TransactionStepState | SignatureStepState diff --git a/packages/sdk/src/types/api.ts b/packages/sdk/src/types/api.ts index c8aab21f..b478df91 100644 --- a/packages/sdk/src/types/api.ts +++ b/packages/sdk/src/types/api.ts @@ -96,6 +96,35 @@ export interface paths { }; }; }; + "/chains/health": { + get: { + parameters: { + query?: { + chainId?: string; + }; + }; + responses: { + /** @description Default Response */ + 200: { + content: { + "application/json": { + /** @description A boolean indicating if the chain is healthy (true) or not (false) */ + healthy?: boolean; + }; + }; + }; + /** @description Default Response */ + 400: { + content: { + "application/json": { + message?: string; + code?: string; + }; + }; + }; + }; + }; + }; "/config": { get: { parameters: { @@ -144,7 +173,7 @@ export interface paths { /** @description User address, when supplied returns user balance and max bridge amount */ user?: string; /** @description Restricts the user balance and capacity to a particular currency when supplied with a currency id. Defaults to the native currency of the destination chain. */ - currency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth"; + currency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape"; }; }; responses: { @@ -197,7 +226,7 @@ export interface paths { originChainId: number; destinationChainId: number; /** @enum {string} */ - currency: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth"; + currency: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape"; /** @description Amount to bridge as the base amount (can be switched to exact input using the dedicated flag), denoted in wei */ amount: string; /** @description App fees to be charged for execution */ @@ -307,10 +336,10 @@ export interface paths { * @description The currency for all relayer fees (gas and service) * @enum {string} */ - relayerCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth"; + relayerCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape"; app?: string; /** @enum {string} */ - appCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth"; + appCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape"; }; breakdown?: { /** @description Amount that will be bridged in the estimated time */ @@ -372,7 +401,7 @@ export interface paths { originChainId: number; destinationChainId: number; /** @enum {string} */ - currency: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth"; + currency: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape"; /** @description Amount to bridge as the base amount (can be switched to exact input using the dedicated flag), denoted in wei */ amount: string; /** @description App fees to be charged for execution */ @@ -817,10 +846,10 @@ export interface paths { * @description The currency for all relayer fees (gas and service) * @enum {string} */ - relayerCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth"; + relayerCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape"; app?: string; /** @enum {string} */ - appCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth"; + appCurrency?: "anime" | "btc" | "cgt" | "degen" | "eth" | "omi" | "pop" | "sipher" | "tg7" | "tia" | "topia" | "usdc" | "xai" | "weth" | "apeeth" | "ape"; }; /** * @example { @@ -2241,6 +2270,11 @@ 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; }; }; }; @@ -2290,6 +2324,8 @@ export interface paths { kind?: string; /** @description A unique identifier for this step, tying all related transactions together */ requestId?: string; + /** @description The deposit address for the bridge request */ + depositAddress?: string; /** @description While uncommon it is possible for steps to contain multiple items of the same kind (transaction/signature) grouped together that can be executed simultaneously. */ items?: { /** @description Can either be complete or incomplete, this can be locally controlled once the step item is completed (depending on the kind) and the check object (if returned) has been verified. Once all step items are complete, the bridge is complete */ @@ -2624,6 +2660,7 @@ export interface paths { content: { "application/json": { message?: string; + errorCode?: string; }; }; }; @@ -2632,6 +2669,7 @@ export interface paths { content: { "application/json": { message?: string; + errorCode?: string; }; }; }; @@ -2640,6 +2678,7 @@ export interface paths { content: { "application/json": { message?: string; + errorCode?: string; }; }; }; @@ -3023,6 +3062,7 @@ export interface paths { content: { "application/json": { message?: string; + errorCode?: string; }; }; }; @@ -3031,6 +3071,7 @@ export interface paths { content: { "application/json": { message?: string; + errorCode?: string; }; }; }; @@ -3039,83 +3080,7 @@ export interface paths { content: { "application/json": { message?: string; - }; - }; - }; - }; - }; - }; - "/execute/user-op/{chainId}": { - post: { - parameters: { - path: { - chainId: string; - }; - }; - requestBody: { - content: { - "application/json": { - id: number; - jsonrpc: string; - method: string; - params: [{ - sender: string; - nonce: string; - factory?: string | null; - factoryData?: string | null; - callData: string; - callGasLimit: string; - verificationGasLimit: string; - preVerificationGas: string; - maxFeePerGas: string; - maxPriorityFeePerGas: string; - paymaster?: string | null; - paymasterVerificationGasLimit?: string | null; - paymasterPostOpGasLimit?: string | null; - paymasterData?: string | null; - signature: string; - }, string]; - }; - }; - }; - responses: { - /** @description Default Response */ - 200: { - content: { - "application/json": { - jsonrpc?: string; - id?: number; - result?: string; - }; - }; - }; - /** @description Default Response */ - 400: { - content: { - "application/json": { - jsonrpc?: string; - id?: number; - error?: unknown; - }; - }; - }; - /** @description Default Response */ - 401: { - content: { - "application/json": { - jsonrpc?: string; - id?: number; - error?: unknown; - }; - }; - }; - /** @description Default Response */ - 500: { - content: { - "application/json": { - jsonrpc?: string; - id?: number; - error?: unknown; + errorCode?: string; }; }; }; @@ -3397,6 +3362,42 @@ export interface paths { }; }; }; + "/requests/{requestId}/signature/v2": { + get: { + parameters: { + path: { + requestId: string; + }; + }; + responses: { + /** @description Default Response */ + 200: { + content: { + "application/json": { + requestData?: { + originChainId?: number; + originUser?: string; + originCurrency?: string; + destinationChainId?: number; + destinationUser?: string; + destinationCurrency?: string; + }; + signature?: string; + }; + }; + }; + /** @description Default Response */ + 400: { + content: { + "application/json": { + message?: string; + code?: string; + }; + }; + }; + }; + }; + }; "/requests": { get: { parameters: { @@ -4055,6 +4056,7 @@ export interface paths { OMI?: number; TOPIA?: number; ANIME?: number; + APE?: number; }; }; }; @@ -4086,6 +4088,8 @@ export interface paths { includeAllChains?: boolean; /** @description Uses 3rd party API's to search for a token, in case relay does not have it indexed */ useExternalSearch?: boolean; + /** @description Returns only currencies supported with deposit address bridging */ + depositAddressOnly?: boolean; }; }; }; @@ -4101,7 +4105,7 @@ export interface paths { name?: string; decimals?: number; /** @enum {string} */ - vmType?: "bvm" | "evm" | "svm"; + vmType?: "bvm" | "evm" | "svm" | "tvm"; metadata?: { logoURI?: string; verified?: boolean; diff --git a/packages/ui/src/components/common/TokenSelector/TokenSelector.tsx b/packages/ui/src/components/common/TokenSelector/TokenSelector.tsx index 8eb987ee..16bc2673 100644 --- a/packages/ui/src/components/common/TokenSelector/TokenSelector.tsx +++ b/packages/ui/src/components/common/TokenSelector/TokenSelector.tsx @@ -47,6 +47,7 @@ export type TokenSelectorProps = { address?: Address | string isValidAddress?: boolean multiWalletSupportEnabled?: boolean + depositAddressOnly?: boolean setToken: (token: Token) => void onAnalyticEvent?: (eventName: string, data?: any) => void } @@ -77,6 +78,7 @@ const TokenSelector: FC = ({ address, isValidAddress, multiWalletSupportEnabled = false, + depositAddressOnly, setToken, onAnalyticEvent }) => { @@ -162,6 +164,7 @@ const TokenSelector: FC = ({ : undefined, defaultList: useDefaultTokenList, limit: 20, + depositAddressOnly, ...(tokenListQuery ? { tokens: tokenListQuery } : {}) } ) @@ -180,7 +183,8 @@ const TokenSelector: FC = ({ defaultList: false, limit: 20, ...(tokenListQuery ? { tokens: tokenListQuery } : {}), - useExternalSearch: true + useExternalSearch: true, + depositAddressOnly }, { enabled: !!debouncedTokenSearchValue @@ -234,7 +238,8 @@ const TokenSelector: FC = ({ suggestedTokenQuery ? { tokens: suggestedTokenQuery, - limit: 20 + limit: 20, + depositAddressOnly } : undefined, { diff --git a/packages/ui/src/components/common/TransactionModal/DepositAddressModalRenderer.tsx b/packages/ui/src/components/common/TransactionModal/DepositAddressModalRenderer.tsx index 2e98d940..7f11466a 100644 --- a/packages/ui/src/components/common/TransactionModal/DepositAddressModalRenderer.tsx +++ b/packages/ui/src/components/common/TransactionModal/DepositAddressModalRenderer.tsx @@ -226,7 +226,8 @@ export const DepositAddressModalRenderer: FC = ({ useEffect(() => { if ( executionStatus?.status === 'failure' || - executionStatus?.status === 'refund' + executionStatus?.status === 'refund' || + quoteError ) { const swapError = new Error( executionStatus?.details ?? @@ -237,7 +238,7 @@ export const DepositAddressModalRenderer: FC = ({ } setProgressStep(TransactionProgressStep.Error) onAnalyticEvent?.(EventNames.DEPOSIT_ADDRESS_SWAP_ERROR, { - error_message: executionStatus.details, + error_message: executionStatus?.details ?? quoteError, wallet_connector: connector?.name, quote_id: requestId, amount_in: parseFloat(`${debouncedInputAmountValue}`), @@ -246,7 +247,7 @@ export const DepositAddressModalRenderer: FC = ({ amount_out: parseFloat(`${debouncedOutputAmountValue}`), currency_out: toToken?.symbol, chain_id_out: toToken?.chainId, - txHashes: executionStatus.txHashes ?? [] + txHashes: executionStatus?.txHashes ?? [] }) setSwapError(swapError) invalidateBalanceQueries() @@ -259,7 +260,7 @@ export const DepositAddressModalRenderer: FC = ({ } else if (executionStatus?.status === 'pending') { setProgressStep(TransactionProgressStep.Validating) } - }, [executionStatus?.status]) + }, [executionStatus?.status, quoteError]) const allTxHashes = useMemo(() => { const isRefund = executionStatus?.status === 'refund' diff --git a/packages/ui/src/components/widgets/SwapWidget/index.tsx b/packages/ui/src/components/widgets/SwapWidget/index.tsx index 1edabad9..647d4428 100644 --- a/packages/ui/src/components/widgets/SwapWidget/index.tsx +++ b/packages/ui/src/components/widgets/SwapWidget/index.tsx @@ -22,7 +22,7 @@ import TokenSelectorContainer from '../TokenSelectorContainer.js' import FeeBreakdown from '../FeeBreakdown.js' import { mainnet } from 'viem/chains' import { PriceImpactTooltip } from '../PriceImpactTooltip.js' -import { faPenToSquare } from '@fortawesome/free-solid-svg-icons' +import { faClipboard, faPenToSquare } from '@fortawesome/free-solid-svg-icons' import { SwapWidgetTokenTrigger } from '../../common/TokenSelector/triggers/SwapWidgetTokenTrigger.js' import { ChainTrigger } from '../../common/TokenSelector/triggers/ChainTrigger.js' import type { AdaptedWallet } from '@reservoir0x/relay-sdk' @@ -193,6 +193,7 @@ const SwapWidget: FC = ({ toChainWalletVMSupported, isValidRefundAddress, refundAddress, + isRecipientLinked, setRefundAddress, setUseExternalLiquidity, setSwapError, @@ -420,6 +421,7 @@ const SwapWidget: FC = ({ isValidAddress={isValidFromAddress} token={fromToken} onAnalyticEvent={onAnalyticEvent} + depositAddressOnly={!fromChainWalletVMSupported} setToken={(token) => { onAnalyticEvent?.(EventNames.SWAP_TOKEN_SELECT, { direction: 'input', @@ -690,7 +692,11 @@ const SwapWidget: FC = ({ {!multiWalletSupportEnabled || !toChainWalletVMSupported ? (