UNPKG

@funkit/connect

Version:

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

455 lines (454 loc) 15.5 kB
import type { LighterAccountIndex } from '@funkit/api-base'; import type { DynamicTargetAssetCandidate } from '@funkit/connect-core'; import type { Address } from 'viem'; /** * Lighter `account_trading_mode` discriminator: `0` = simple (separate spot * and perps USDC balances), `1` = Unified Trading account (one USDC balance * no spot/perps split). Unified accounts hide the spot USDC option and label * perps USDC as plain `USDC` in both deposit and withdrawal flows. */ export declare const LIGHTER_TRADING_MODE: { readonly SIMPLE: 0; readonly UNIFIED: 1; }; /** * Strips the ` (Perps)` variant suffix off a Lighter ticker (e.g. * `USDC (Perps)` `USDC`). Non-perps tickers pass through unchanged. */ export declare function stripLighterPerpsSuffix(symbol: string): string; export declare function stripLighterPerpsSuffix(symbol: string | undefined): string | undefined; /** * Rewrites the deposit target-asset candidates for a Unified Trading account: * drops the spot-USDC candidates and relabels `USDC (Perps)` as `USDC`. The * underlying routing is unchanged unified deposits still ride the perps * routes (`LIGHTER_USDC_PERPS*`), only the presentation differs. */ export declare function adaptLighterTargetAssetsForUnifiedAccount(candidates: DynamicTargetAssetCandidate[]): DynamicTargetAssetCandidate[]; export type LighterSubAccount = { code: number; account_type: number; index: number; l1_address: Address; cancel_all_time: number; total_order_count: number; total_isolated_order_count: number; pending_order_count: number; available_balance: string; status: number; collateral: string; transaction_time: number; account_trading_mode: number; }; export type LighterAccountsByL1AddressResponse = { code: number; l1_address: Address; sub_accounts: LighterSubAccount[]; }; export declare function getLighterAccountsByL1Address(address: Address): Promise<LighterAccountsByL1AddressResponse>; export type LighterAsset = { symbol: string; asset_id: number; balance: string; locked_balance: string; }; /** * A user's stake in a Lighter public pool. The staking pool is identified by * matching `public_pool_index` against the known staking pool index; * `principal_amount` is the staked USDC principal (decimal string). */ export type LighterShare = { public_pool_index: number; shares_amount: number; entry_usdc: string; principal_amount: string; entry_timestamp: number; }; export type LighterAccount = { code: number; account_type: number; index: number; l1_address: Address; cancel_all_time: number; total_order_count: number; total_isolated_order_count: number; pending_order_count: number; available_balance: string; status: number; collateral: string; transaction_time: number; account_trading_mode: number; account_index: number; name: string; description: string; can_invite: boolean; referral_points_percentage: string; can_rfq: boolean; created_at: number; positions: unknown[]; assets: LighterAsset[]; total_asset_value: string; cross_asset_value: string; shares: LighterShare[]; pending_unlocks: unknown[]; }; export type LighterAccountResponse = { code: number; total: number; accounts: LighterAccount[]; }; export type LighterAccountLookup = { by: 'index'; value: LighterAccountIndex; } | { by: 'l1_address'; value: Address; }; export declare function getLighterAccount(lookup: LighterAccountLookup, activeOnly?: boolean): Promise<LighterAccountResponse>; export declare function useLighterAccount(lookup: LighterAccountLookup | null, options?: { activeOnly?: boolean; }): { account: LighterAccount | undefined; data: LighterAccountResponse; error: Error; isError: true; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: true; isSuccess: false; isPlaceholderData: false; status: "error"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountResponse>; } | { account: LighterAccount | undefined; data: LighterAccountResponse; error: null; isError: false; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isSuccess: true; isPlaceholderData: false; status: "success"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountResponse>; } | { account: LighterAccount | undefined; data: undefined; error: Error; isError: true; isPending: false; isLoading: false; isLoadingError: true; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "error"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountResponse>; } | { account: LighterAccount | undefined; data: undefined; error: null; isError: false; isPending: true; isLoading: true; isLoadingError: false; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "pending"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountResponse>; } | { account: LighterAccount | undefined; data: undefined; error: null; isError: false; isPending: true; isLoadingError: false; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "pending"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isLoading: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountResponse>; } | { account: LighterAccount | undefined; data: LighterAccountResponse; isError: false; error: null; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isSuccess: true; isPlaceholderData: true; status: "success"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountResponse>; }; export declare function useLighterAccounts({ address, }: { address: Address | '' | undefined; }): { mainAccountIndex: string | undefined; isUnifiedTradingMode: boolean; subAccounts: LighterSubAccount[] | undefined; data: LighterAccountsByL1AddressResponse; error: Error; isError: true; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: true; isSuccess: false; isPlaceholderData: false; status: "error"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountsByL1AddressResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountsByL1AddressResponse>; } | { mainAccountIndex: string | undefined; isUnifiedTradingMode: boolean; subAccounts: LighterSubAccount[] | undefined; data: LighterAccountsByL1AddressResponse; error: null; isError: false; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isSuccess: true; isPlaceholderData: false; status: "success"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountsByL1AddressResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountsByL1AddressResponse>; } | { mainAccountIndex: string | undefined; isUnifiedTradingMode: boolean; subAccounts: LighterSubAccount[] | undefined; data: undefined; error: Error; isError: true; isPending: false; isLoading: false; isLoadingError: true; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "error"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountsByL1AddressResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountsByL1AddressResponse>; } | { mainAccountIndex: string | undefined; isUnifiedTradingMode: boolean; subAccounts: LighterSubAccount[] | undefined; data: undefined; error: null; isError: false; isPending: true; isLoading: true; isLoadingError: false; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "pending"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountsByL1AddressResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountsByL1AddressResponse>; } | { mainAccountIndex: string | undefined; isUnifiedTradingMode: boolean; subAccounts: LighterSubAccount[] | undefined; data: undefined; error: null; isError: false; isPending: true; isLoadingError: false; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "pending"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isLoading: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountsByL1AddressResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountsByL1AddressResponse>; } | { mainAccountIndex: string | undefined; isUnifiedTradingMode: boolean; subAccounts: LighterSubAccount[] | undefined; data: LighterAccountsByL1AddressResponse; isError: false; error: null; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isSuccess: true; isPlaceholderData: true; status: "success"; dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<LighterAccountsByL1AddressResponse, Error>>; fetchStatus: import("@tanstack/react-query").FetchStatus; promise: Promise<LighterAccountsByL1AddressResponse>; }; /** * Returns a callback that invalidates the cached Lighter account queries so the * balance refetches eagerly (e.g. right after a withdrawal). No-op for * non-Lighter customers. */ export declare function useInvalidateLighterAccount(): () => void;