import { LifecycleStatusUpdate } from '../internal/types'; import { Dispatch, ReactNode, SetStateAction } from 'react'; import { Address, Hex, TransactionReceipt, WalletCapabilities } from 'viem'; import { Config, UseBalanceReturnType, UseReadContractReturnType } from 'wagmi'; import { SendTransactionMutateAsync, SwitchChainMutateAsync } from 'wagmi/query'; import { BuildSwapTransaction, RawTransactionData } from '../api/types'; import { Token } from '../token/types'; import { Call } from '../transaction/types'; import { ToastProps } from '../internal/components/Toast'; import { SlippageSettingsType } from './constants'; export type SendSwapTransactionParams = { config: Config; isSponsored?: boolean; paymaster?: string; sendCallsAsync: any; sendTransactionAsync: SendTransactionMutateAsync; transactions: SwapTransaction[]; updateLifecycleStatus: (state: LifecycleStatusUpdate) => void; walletCapabilities: WalletCapabilities; }; export type SendSingleTransactionsParams = { config: Config; sendTransactionAsync: SendTransactionMutateAsync; transactions: SwapTransaction[]; updateLifecycleStatus: (state: LifecycleStatusUpdate) => void; }; /** * Note: exported as public Type */ export type Fee = { /** The amount of the fee */ amount: string; /** The base asset for the fee */ baseAsset: Token; /** The percentage of the fee */ percentage: string; }; export type FromTo = { from: SwapUnit; to: SwapUnit; }; export type GetSwapMessageParams = { address?: Address; lifecycleStatus: LifecycleStatus; to: SwapUnit; from: SwapUnit; }; /** * Note: exported as public Type */ export type QuoteWarning = { /** The description of the warning */ description?: string; /** The message of the warning */ message?: string; /** The type of the warning */ type?: string; }; type LifecycleStatusDataShared = { isMissingRequiredField: boolean; maxSlippage: number; }; /** * List of swap lifecycle statuses. * The order of the statuses loosely follows the swap lifecycle. * * Note: exported as public Type */ export type LifecycleStatus = { statusName: 'init'; statusData: LifecycleStatusDataShared; } | { statusName: 'error'; statusData: SwapError & LifecycleStatusDataShared; } | { statusName: 'amountChange'; statusData: { amountFrom?: string; amountETH?: string; amountUSDC?: string; amountTo: string; tokenFrom?: Token; tokenFromETH?: Token; tokenFromUSDC?: Token; tokenTo?: Token; } & LifecycleStatusDataShared; } | { statusName: 'slippageChange'; statusData: LifecycleStatusDataShared; } | { statusName: 'transactionPending'; statusData: LifecycleStatusDataShared; } | { statusName: 'transactionApproved'; statusData: { callsId?: Hex; transactionHash?: Hex; transactionType: SwapTransactionType; } & LifecycleStatusDataShared; } | { statusName: 'success'; statusData: { transactionReceipt: TransactionReceipt; } & LifecycleStatusDataShared; }; export type ProcessSwapTransactionParams = { chainId?: number; config: Config; isSponsored?: boolean; paymaster?: string; sendCallsAsync: any; sendTransactionAsync: SendTransactionMutateAsync; swapTransaction: BuildSwapTransaction; switchChainAsync: SwitchChainMutateAsync; updateLifecycleStatus: (state: LifecycleStatusUpdate) => void; useAggregator: boolean; walletCapabilities: WalletCapabilities; }; /** * Note: exported as public Type */ export type SwapAmountInputProps = { /** Optional className override for top div element */ className?: string; /** The debounce delay in milliseconds */ delayMs?: number; /** Descriptive label for the input field */ label: string; /** Swappable tokens */ swappableTokens?: Token[]; /** Selected token */ token?: Token; /** Identifies if component is for toToken or fromToken */ type: 'to' | 'from'; render?: (props: { token: SwapUnit; setAmountToMax: () => void; onSetToken: (token: Token) => void; hasInsufficientBalance: boolean; }) => ReactNode; }; export type SwapAPIResponse = { approveTx?: RawTransactionData; chainId: string; fee: Fee; quote: SwapQuoteParams; tx: RawTransactionData; }; /** * Note: exported as public Type */ export type SwapButtonProps = { /** Optional className override for top div element */ className?: string; /** Disables swap button */ disabled?: boolean; /** Label for the swap button */ label?: ReactNode; render?: (props: { onSubmit: () => void; isLoading: boolean; lifecycleStatus: LifecycleStatus; isDisabled: boolean; isSwapInvalid: boolean; }) => ReactNode; }; export type SwapConfig = { maxSlippage: number; }; export type SwapContextType = { address?: Address; config: SwapConfig; from: SwapUnit; lifecycleStatus: LifecycleStatus; handleAmountChange: (t: 'from' | 'to', amount: string, st?: Token, dt?: Token) => void; handleSubmit: () => void; handleToggle: () => void; updateLifecycleStatus: (state: LifecycleStatusUpdate) => void; to: SwapUnit; isToastVisible: boolean; setIsToastVisible: (visible: boolean) => void; transactionHash: string; setTransactionHash: (hash: string) => void; }; /** * Note: exported as public Type */ export type SwapError = { /** The error code representing the type of swap error */ code: string; /** The error message providing details about the swap error */ error: string; /** The error message providing details about the swap error */ message: string; }; export type SwapLoadingState = { isSwapLoading: boolean; }; /** * Note: exported as public Type */ export type SwapMessageProps = { /** Optional className override for top div element */ className?: string; render?: (props: { message: string | null; }) => ReactNode; }; /** * Note: exported as public Type */ export type SwapQuoteParams = { /** The reference amount for the quote */ amountReference: string; /** The source token for the swap */ from: Token; /** The amount of the source token */ fromAmount: string; /** The USD value of the source token */ fromAmountUSD: string; /** Whether the price impact is high */ hasHighPriceImpact: boolean; /** The price impact of the swap */ priceImpact: string; /** The slippage of the swap */ slippage: string; /** The destination token for the swap */ to: Token; /** The amount of the destination token */ toAmount: string; /** The USD value of the destination token */ toAmountUSD: string; /** The warning associated with the quote */ warning?: QuoteWarning; }; export type SwapParams = { amount: string; fromAddress: Address; from: Token; to: Token; }; export type SwapProviderProps = { children: React.ReactNode; config?: { maxSlippage: number; }; experimental: { useAggregator: boolean; }; isSponsored?: boolean; onError?: (error: SwapError) => void; onStatus?: (lifecycleStatus: LifecycleStatus) => void; onSuccess?: (transactionReceipt: TransactionReceipt) => void; }; /** * Note: exported as public Type */ export type SwapProps = { /** Optional className override for top div element */ className?: string; /** Configuration options */ config?: SwapConfig; /** Experimental features */ experimental?: { /** Whether to use a DEX aggregator. (default: false) */ useAggregator: boolean; }; /** An optional setting to sponsor swaps with a Paymaster. (default: false) */ isSponsored?: boolean; /** An optional callback function that handles errors within the provider */ onError?: (error: SwapError) => void; /** An optional callback function that exposes the component lifecycle state */ onStatus?: (lifecycleStatus: LifecycleStatus) => void; /** An optional callback function that exposes the transaction receipt */ onSuccess?: (transactionReceipt: TransactionReceipt) => void; } & ({ /** When children is provided, swappableTokens, toToken, and fromToken are not required */ children: ReactNode; /** To token */ to?: never; /** From token */ from?: never; /** Disables swap button */ disabled?: never; /** Title for the Swap component. (default: "Swap") */ title?: never; /** Header left content for the Swap component (eg. back button) */ headerLeftContent?: never; } | { /** When children is undefined, swappableTokens, toToken, and fromToken are required */ children?: never; /** To token */ to?: Token[]; /** From token */ from?: Token[]; /** Disables swap button */ disabled?: boolean; /** Title for the Swap component. (default: "Swap") */ title?: ReactNode; /** Header left content for the Swap component (eg. back button) */ headerLeftContent?: ReactNode; }); /** * Note: exported as public Type */ export type SwapDefaultProps = { /** Swappable tokens */ to: Token[]; /** Swappable tokens */ from: Token[]; /** Disables swap button */ disabled?: boolean; } & Omit; /** * Note: exported as public Type */ export type SwapSettingsProps = { children?: ReactNode; /** Optional className override for top div element */ className?: string; /** Optional icon override */ icon?: ReactNode; /** Optional text override */ text?: string; }; /** * Note: exported as public Type */ export type SwapSettingsSlippageDescriptionProps = { children: ReactNode; /** Optional className override for top div element */ className?: string; }; /** * Note: exported as public Type */ export type SwapSettingsSlippageInputProps = { /** Optional className override for top div element */ className?: string; render?: (props: { slippageSetting: SlippageSettingsType; setSlippageSetting: (slippageSetting: SlippageSettingsType) => void; setSlippageValue: (number: number) => void; }) => ReactNode; }; export type SwapSettingsSlippageLayoutProps = { children: ReactNode; /** Optional className override for top div element */ className?: string; }; /** * Note: exported as public Type */ export type SwapSettingsSlippageTitleProps = { children: ReactNode; /** Optional className override for top div element */ className?: string; }; /** * Note: exported as public Type */ export type SwapToggleButtonProps = { /** Optional className override for top div element */ className?: string; render?: (props: { onToggle: () => void; }) => ReactNode; }; /** * Note: exported as public Type * Consists of atomic batch transactions, ERC-20 approvals, Permit2 approvals, and Swaps */ export type SwapTransactionType = 'Batched' | 'ERC20' | 'Permit2' | 'Swap'; export type SwapUnit = { amount: string; amountUSD: string; balance?: string; balanceResponse?: UseBalanceReturnType | UseReadContractReturnType; error?: SwapError; loading: boolean; setAmount: Dispatch>; setAmountUSD: Dispatch>; setLoading: Dispatch>; setToken?: Dispatch>; token: Token | undefined; }; /** * Note: exported as public Type */ export type TransactionParams = { /** The chain ID */ chainId: number; /** The data for the transaction */ data: Hex; /** The gas limit */ gas: bigint; /** The maximum fee per gas */ maxFeePerGas?: bigint | undefined; /** The maximum priority fee per gas */ maxPriorityFeePerGas?: bigint | undefined; /** The nonce for the transaction */ nonce?: number; /** The recipient address */ to: Address; /** The value of the transaction */ value: bigint; }; export type SwapToastProps = Pick & { render?: (props: { isToastVisible: boolean; transactionHash: string; resetToastState: () => void; chainExplorer: string; }) => ReactNode; }; export type SwapTransaction = { transaction: Call; transactionType: SwapTransactionType; }; export type UseAwaitCallsParams = { accountConfig: Config; lifecycleStatus: LifecycleStatus; /** A function to set the lifecycle status of the component */ updateLifecycleStatus: (state: LifecycleStatusUpdate) => void; }; export {}; //# sourceMappingURL=types.d.ts.map