UNPKG

@shogun-sdk/one-shot

Version:

Shogun Network unified SDK — core logic, React hooks, and wallet adapters.

134 lines (125 loc) 4.1 kB
import React from 'react'; import { O as OneShotSDKConfig, e as OneShotSDK, d as QuoteParams, Q as QuoteResponse, P as PlaceOrderResult, f as Stage, T as TokenInfo, c as BalanceRequestParams, B as BalanceResponse } from './index-CxfzE4Zk.js'; export { C as ChainId, a as SupportedChain, S as SupportedChains, b as TokenBalance, i as isEvmChain } from './index-CxfzE4Zk.js'; import { WalletClient } from 'viem'; import { A as AdaptedWallet } from './wallet-DfvPIcuW.js'; import '@solana/web3.js'; /** * @fileoverview React provider for OneShot SDK */ declare const OneShotProvider: React.FC<React.PropsWithChildren<{ config: OneShotSDKConfig; }>>; /** * Access the OneShot SDK instance inside React hooks/components. */ declare const useOneShot: () => OneShotSDK; /** * Augment globalThis to safely hold a shared params reference. */ declare global { var __QUOTE_PARAMS_REF__: { current: QuoteParams | null; } | undefined; } /** * SWR-powered, centralized quote fetching hook. * * ## Features * - Shared global cache across all components (SWR) * - Strongly typed params and responses * - Abort-safe concurrent refetch * - Auto refresh every 10 seconds * - Centralized params sync using `globalThis` */ declare function useQuote(initialParams?: QuoteParams | null): { data: QuoteResponse | null | undefined; loading: boolean; error: string | null; refetch: () => Promise<void>; setParams: (next: QuoteParams | null) => void; readonly activeParams: QuoteParams | null; }; /** * ⚡ useExecuteTransaction — React Hook * Executes a cross-chain swap and tracks its status. */ declare function useExecuteTransaction(): { execute: ({ quote, wallet, options }: { quote: QuoteResponse; wallet: AdaptedWallet | WalletClient; options?: { maxAttempts?: number; retryDelayMs?: number; }; }) => Promise<PlaceOrderResult>; isLoading: boolean; stage: Stage | null; message: string | null; error: string | null; result: PlaceOrderResult | null; }; /** * useTokenList — React hook for searching and paginating tokens. * * Features: * - Supports optional networkId (chain-specific or global search) * - Caches results per query/page to reduce API calls * - Handles pagination, loading, and error state */ declare function useTokenList(): { tokens: TokenInfo[]; loading: boolean; error: string | null; hasMore: boolean; page: number; lastQuery: { q?: string; networkId?: number; }; loadTokens: (params: { q?: string; networkId?: number; reset?: boolean; }) => Promise<void>; resetTokens: () => void; }; /** * Augment globalThis to safely hold a shared params reference. */ declare global { var __BALANCES_PARAMS_REF__: { current: BalanceRequestParams | null; } | undefined; } /** * SWR-powered, centralized balance fetching hook. * * ## Features * - Shared global cache across all components (SWR) * - Strongly typed params and responses * - Abort-safe concurrent refetch * - Centralized params sync using `globalThis` * - Keeps previous data during refetch (no reset) * - Auto-refetch when initialParams change (svm_address or evm_address) */ declare function useBalances(initialParams?: BalanceRequestParams | null): { data: BalanceResponse | null | undefined; loading: boolean; error: Error | null; refetch: () => Promise<void>; setParams: (next: BalanceRequestParams | null) => void; readonly activeParams: BalanceRequestParams | null; }; /** * React hook to fetch metadata and price for one or multiple tokens. * * @example * const { data, loading, error } = useTokensData(["0xA0b8...", "0xC02..."]); */ declare function useTokensData(addresses: string[]): { data: TokenInfo[]; loading: boolean; error: Error | null; }; export { BalanceRequestParams, BalanceResponse, OneShotProvider, QuoteParams, QuoteResponse, useBalances, useExecuteTransaction, useOneShot, useQuote, useTokenList, useTokensData };