UNPKG

@funkit/connect

Version:

Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.

183 lines (182 loc) 8.8 kB
/** * Lighter-specific withdrawal helpers, hooks, and display components. * * Extracted from WithdrawalContent.tsx to keep Lighter-specific logic isolated. */ import type { LighterAccountIndex } from '@funkit/api-base'; import React from 'react'; import type { Address } from 'viem'; import type { CustomWithdrawalConfig, LighterRouteType, WalletWithdrawalConfig } from '../../providers/FunkitCheckoutContext'; import type { LighterShare } from '../../utils/customer'; import type { SourceTokenOption } from './WithdrawAmountInput'; /** Stable method ids for the Fast / Secure options (used for tracking + switching). */ export declare const LIGHTER_FAST_METHOD_ID = "lighter-fast"; export declare const LIGHTER_SECURE_METHOD_ID = "lighter-secure"; /** * USDC exists twice on a Lighter account: as perps collateral * (`total_asset_value`, withdrawn via route 0) and as a spot asset balance * (asset entry 3, withdrawn via route 1). The Secure dropdown keys selection * by `symbol`, so the spot variant gets a pseudo-symbol to stay selectable * alongside the plain `USDC` (perps) entry. */ export declare const LIGHTER_USDC_SPOT_SYMBOL = "USDC (Spot)"; /** Lighter L2 route types (`RouteType` in the withdraw/transfer tx payload). */ export declare const LIGHTER_ROUTE_TYPE: { readonly PERPS: 0; readonly SPOT: 1; }; /** * Strips the ` (Spot)` / ` (Perps)` variant suffix off a Lighter source-token * selection, returning the real token symbol (e.g. `USDC (Spot)` → `USDC`). * Symbol-keyed lookups (icons, prices, asset indices, min amounts) operate on * the base symbol; only selection identity and route resolution keep the suffix. */ export declare function getLighterBaseSymbol(symbol: string): string; /** * Resolves the Lighter L2 route type for a Secure source-token selection. * Plain `USDC` withdraws perps collateral (route 0); everything else — * including the `USDC (Spot)` pseudo-symbol — is a spot asset (route 1). */ export declare function resolveLighterSecureRouteType(selectedSourceToken: string): LighterRouteType; /** * Mainnet ERC-20 address for a Lighter Secure source token symbol, or undefined * if the symbol isn't a known Secure asset. */ export declare function getLighterSecureMainnetAddress(symbol: string): Address | undefined; /** * Upper bound on a single Lighter Fast withdrawal, in USD. Amounts above this * block the CTA and surface the "submit a Secure withdrawal" footer. Fast is * USDC Perps only (price = 1), so this is also the token-unit cap. * {@link LIGHTER_FAST_MAX_WITHDRAWAL_LABEL} must stay in sync with this value. */ export declare const LIGHTER_FAST_MAX_WITHDRAWAL_USD = 3000000; /** * Footer shown beneath the CTA when a Lighter Fast amount exceeds the $3M cap. * Renders as the `description` of a FunNotification, which supplies the shared * notification typography; offers an inline link to switch to the Secure method. */ export declare function LighterFastMaxExceededMessage({ onSwitchToSecure, }: { onSwitchToSecure: () => void; }): React.JSX.Element; /** Free (withdrawable) balance for a single Lighter asset: balance - locked. */ export declare function freeBalance(balance: string, lockedBalance: string): string; /** * Lighter Fast charges an "unstaked" fee — a flat deduction taken off the * withdrawal amount before quoting — for users who aren't sufficiently staked * in Lighter's staking pool. Sufficiently-staked users pay nothing. * * "Sufficiently staked" = the user holds a share in the staking pool with a * principal above the threshold. The staking pool is identified by its index, * hardcoded here (previously read from `systemConfig.staking_pool_index`) since * it's currently the only public pool a withdrawing user holds a share in. * Non-stakers report `shares: []`. */ export declare const LIGHTER_STAKING_POOL_INDEX = 281474976624800; export declare const LIGHTER_UNSTAKED_FEE_TOKENS = 3; export declare const LIGHTER_STAKING_PRINCIPAL_THRESHOLD = 100; /** * Resolves the Lighter Fast unstaked fee (in source tokens, i.e. USDC) for a * user. Returns 0 when the user's staking-pool principal exceeds the threshold, * otherwise {@link LIGHTER_UNSTAKED_FEE_TOKENS}. A non-staker (`shares: []`, * or no staking-pool share) pays the fee. */ export declare function resolveLighterUnstakedFeeTokens(shares: LighterShare[]): number; /** * Deducts the Lighter Fast unstaked fee from a withdrawal input amount, clamped * at 0. Uses `dnum` fixed-point math so the subtraction stays exact (e.g. the * input is a decimal string straight from the amount field). */ export declare function deductLighterUnstakedFee(inputAmount: string, feeTokens: number): string; /** * Fetches all asset balances for a Lighter account. Returns: * * - `balances` — `Record<SYMBOL, freeBalance>` (uppercased symbol keys) * - `assets` — raw asset list from the API (for building source-token options) */ export declare function useLighterWithdrawalBalances({ accountIndex, }: { accountIndex: LighterAccountIndex | undefined; }): { balances: Record<string, string>; assets: import("../../utils/customer").LighterAsset[]; shares: LighterShare[]; isLoading: boolean; }; type FunkitWithdrawalConfig = WalletWithdrawalConfig | CustomWithdrawalConfig; /** * Resolves the Lighter `asset_id` for a selected source token symbol. Returns * `undefined` when the token isn't in the fetched assets list (e.g. timing * race before balances load, or an invalid selection) — callers should treat * that as "not ready to submit" rather than falling back to `0`, which would * silently target the wrong Lighter asset. */ export declare function resolveLighterAssetIndex(lighterAssets: { symbol: string; asset_id: number; }[], selectedSourceToken: string): number | undefined; /** * Builds the source-token options list for the Lighter compound input dropdown. * * - Fast path: only USDC (Perps). * - Secure path: USDC (Perps) (from total_asset_value) + USDC (Spot) when the * account carries a spot USDC asset + every non-USDC asset on the account. * * Unified Trading accounts (`isUnifiedTradingMode`) have a single USDC balance * — no spot/perps split — so the perps entry is labeled plain `USDC` and the * `USDC (Spot)` entry is hidden on both paths. */ export declare function buildLighterSourceTokenOptions(config: FunkitWithdrawalConfig, lighterAssets: { symbol: string; }[], isUnifiedTradingMode?: boolean): SourceTokenOption[]; /** * Detects Lighter Secure withdrawal (mainnet source chain), auto-fills the * recipient address with the connected wallet, and fetches the Lighter account * so per-asset balances are available to the withdrawal form. */ export declare function useLighterWithdrawal(config: FunkitWithdrawalConfig, setRecipientAddress: (addr: string) => void): { isLighterSecure: boolean; isLighterFast: boolean; isUnifiedTradingMode: boolean; connectedAddress: `0x${string}` | undefined; lighterBalances: Record<string, string>; lighterAssets: import("../../utils/customer").LighterAsset[]; lighterFastUnstakedFee: number; invalidateLighterAccount: () => void; }; /** * Resolves the source-token dropdown options for a Lighter customer. * Returns `undefined` for non-Lighter customers (no dropdown needed). */ export declare function useLighterSourceTokenOptions(config: FunkitWithdrawalConfig, apiKey: string, lighterAssets: { symbol: string; }[], isUnifiedTradingMode?: boolean): SourceTokenOption[] | undefined; /** * Lighter Secure: recipient address, locked to the connected wallet. A * read-only `FunInput` (not a `<div>`) keeps it focusable and announced by * screen readers; the hover tooltip explains the lock. */ export declare function LighterSecureAddressDisplay({ address }: { address: string; }): React.JSX.Element; /** * Lighter Secure: display-only receive token + chain. Both are locked — the * token always matches the source asset, and the destination chain is always * Ethereum mainnet. Each field surfaces a hover tooltip explaining the lock. */ export declare function LighterSecureReceiveDisplay({ sourceTokenSymbol: rawSourceTokenSymbol, }: { sourceTokenSymbol: string; }): React.JSX.Element; /** * Lighter Secure: receive amount value (1:1 — same token, no swap). */ export declare function LighterSecureReceiveAmountValue({ amount, tokenSymbol: rawTokenSymbol, }: { amount: string; tokenSymbol: string; }): React.JSX.Element; export declare function LighterSecureWithdrawalSuccess({ onClose, onNewWithdrawal, amount, tokenSymbol: rawTokenSymbol, txHash, }: { onClose: () => void; onNewWithdrawal: () => void; amount: string; tokenSymbol: string; txHash: string; }): React.JSX.Element; export {};