/** * Lighter.xyz withdrawal. * * Lighter supports two withdrawal types — the SDK exposes them as a * multi-method config so the user is shown a selection screen first: * * 1. **Fast** — routed through Fun + Relay. Perps collateral only (USDC; * USDG on Robinhood). Multiple destination chains/tokens supported. * Completes in seconds. * 2. **Secure** — Lighter's native bridge to its L1 (Ethereum; Robinhood * Chain for Lighter on Robinhood). Destination chain is locked to the L1 * and the destination token matches the source. * * Both callbacks conform to CustomWithdrawalConfig.withdrawCallback; the * caller provides the actual on-chain implementation. */ import { type LighterChainId } from '@funkit/chains'; import { type Address } from 'viem'; import { type LighterSigner } from '@funkit/connect-core/clients/lighter'; import type { CustomWithdrawalConfig, LighterRouteType, MultiMethodWithdrawalConfig, SourceTokenOption, WithdrawalSourceTokenBalanceParams } from '../providers/FunkitCheckoutContext/types'; export { LIGHTER_ROUTE_TYPE } from '@funkit/connect-core/clients/lighter'; export type { LighterRouteType } from '../providers/FunkitCheckoutContext/types'; export type { LighterSigner, LighterTransaction, LighterTransferParams, WithdrawalIntent, } from '@funkit/connect-core/clients/lighter'; export { LIGHTER_WITHDRAW_ABI, buildLighterL1WithdrawTransaction, isLighterWithdrawalRateLimitError, } from '@funkit/connect-core/clients/lighter'; /** Lighter base units, defaulting to mainnet for existing connect integrators. */ export declare function lighterWithdrawBaseUnits(assetIndex: number, amountTokenUnits: string, chainId?: LighterChainId): bigint; export interface LighterWithdrawalConfig { /** * The connected user's L1 address. The hook resolves the Lighter account * index from this internally — get it from `useFunkitUserInfo` (or your * own wallet hook) in the caller and pass it through. */ l1Address: Address; /** Instance both the signer and Secure callback sign on; defaults to mainnet. */ chainId?: LighterChainId; /** Title shown on the selection screen. Defaults to "Withdraw". */ modalTitle?: string; disableConnectedWallet?: boolean; fastIconSrc?: string; secureIconSrc?: string; /** Pre-built Lighter signer. */ signerClient: LighterSigner; sendLighterSecureWithdrawal: LighterSecureWithdrawalExec; /** * Withdrawable balance for the selected source token, applied to both methods. * Lighter's own accounting — it must account for what the SDK cannot see * (margin requirements, locked collateral), so the integrator owns it. */ withdrawalSourceTokenBalance?: (params: WithdrawalSourceTokenBalanceParams) => string | number; /** * Returns the minimum Secure withdrawal amount in token units for the given symbol. * Spot USDC is passed as `USDC (Spot)` (perps collateral is plain `USDC`); * return `undefined` to fall back to the per-base-symbol defaults. * * ```ts * getSecureMinWithdrawalAmount: (symbol) => ({ USDC: 1, ETH: 0.001 }[symbol] ?? 0) * ``` */ getSecureMinWithdrawalAmount?: (symbol: string) => number | undefined; /** * Awaited hook fired after the user taps "Withdraw" but before either method * (Fast or Secure) fetches a nonce, prompts the wallet, or submits the L2 tx. * * Lighter strategies and withdrawals share the same L2 signing account, so a * strategy that's still placing/cancelling orders will bump the nonce out * from under the withdrawal and the signed tx is rejected. Cancel in-flight * strategies here (awaited) so the withdrawal signs against a stable nonce. * * Throw to abort the withdrawal — the message is shown to the user verbatim * and no nonce is consumed. Applies to both Fast and Secure. */ onBeforeSign?: () => Promise | void; } export interface LighterSecureWithdrawalCallbackParams { /** Withdrawal amount in token units (e.g. "1.5" for 1.5 ETH). */ amountTokenUnits: string; /** The Lighter asset index (e.g. 1 for ETH, 3 for USDC). */ assetIndex: number; /** * Lighter L2 route type ({@link LIGHTER_ROUTE_TYPE}: 0 = perps / USDC * collateral, 1 = spot). Pass it through to `client.withdraw({ routeType })` * — USDC shares asset index 3 across both routes, so the route type is what * selects Perps vs Spot. */ routeType: LighterRouteType; /** * Lighter instance to withdraw from. Sign on this instance: the same asset * index and account index mean different things on mainnet and RH. */ chainId: LighterChainId; } type LighterSecureWithdrawalExec = (params: LighterSecureWithdrawalCallbackParams) => Promise; export interface LighterSecureWithdrawalConfig { accountIndex: string; /** Lighter instance the callback signs on. Defaults to mainnet Lighter. */ chainId?: LighterChainId; modalTitle?: string; disableConnectedWallet?: boolean; iconSrc?: string; /** Selectable source tokens, built from the account's live asset list. */ sourceTokens?: SourceTokenOption[]; withdrawalSourceTokenBalance?: (params: WithdrawalSourceTokenBalanceParams) => string | number; /** * Submit the Secure withdrawal on Lighter's L2. Funds bridge directly to the * instance's L1. No relay/swap — the token withdrawn is the token received. */ sendLighterSecureWithdrawal: LighterSecureWithdrawalExec; /** * Returns the minimum withdrawal amount in token units for the given symbol. * * ```ts * getMinWithdrawalAmount: (symbol) => ({ USDC: 1, ETH: 0.001 }[symbol] ?? 0) * ``` */ getMinWithdrawalAmount?: (symbol: string) => number; /** * Awaited hook fired before the Secure withdrawal fetches a nonce, prompts * the wallet, or submits the L2 tx. See {@link LighterWithdrawalConfig['onBeforeSign']}. */ onBeforeSign?: () => Promise | void; } /** Single-method config for Secure withdrawal to the instance's L1. */ export declare function createLighterSecureWithdrawalConfig(config: LighterSecureWithdrawalConfig): CustomWithdrawalConfig; /** * Builds the source-token options list for the Lighter compound input dropdown. * * - Fast path: only the instance's perps collateral. * - Secure path: perps collateral + supported spot assets on the account. * * Unified Trading accounts have a single collateral balance: label it with * the base symbol and suppress the separate collateral spot entry. */ export declare function buildLighterSourceTokenOptions({ isSecure, lighterAssets, isUnifiedTradingMode, chainId, }: { /** Secure lists every spot asset alongside perps; Fast is perps-only. */ isSecure: boolean; lighterAssets: { symbol: string; }[]; isUnifiedTradingMode?: boolean; /** Lighter instance the options are for. Defaults to mainnet Lighter. */ chainId?: LighterChainId; }): SourceTokenOption[]; /** * The single React entry point for Lighter withdrawals. Returns a * `MultiMethodWithdrawalConfig` ready to hand to the withdrawal modal, or * `null` while the inputs aren't ready yet. * * The hook owns every Lighter-specific concern that requires React context: * - the user's Lighter account index (resolved from `config.l1Address`) * - the live Secure-withdrawal delay (`/api/v1/withdrawalDelay`) * - the active locale (so the disclaimer renders correctly) * * Pass `null` while prerequisites (wallet, signer, etc.) aren't ready — the * hook always invokes its inner hooks (Rules of Hooks) and returns `null` * until you supply a real config and the account resolves: * * ```tsx * const { address: l1Address } = useFunkitUserInfo() * const lighter = useLighterWithdrawalConfig( * l1Address && walletClient * ? { l1Address, signerClient, sendLighterSecureWithdrawal, ... } * : null, * ) * if (!lighter) return { ready: false, disabledReason: '...' } * ``` */ export declare function useLighterWithdrawalConfig(config: LighterWithdrawalConfig | null): MultiMethodWithdrawalConfig | null;