/** * @module plugin/magicblock/client * @description Typed HTTP client for the MagicBlock APIs. * * Wraps two API surfaces: * 1. ER Router — JSON-RPC 2.0 at `https://(devnet-)router.magicblock.app` * 2. Private Payments — REST at `https://payments.magicblock.app` * * Design goals: * - Zero external HTTP deps — use the global `fetch` (Node ≥ 18). * - Fully typed responses matching the OpenAPI specs. * - Stateless: each call is a standalone HTTP request. Auth tokens * are passed by the caller, not cached internally. * - Errors are thrown as `MagicBlockApiError` with status, body, and * endpoint for diagnostics. * * @category Plugin * @since v0.1.0 */ /** * Error thrown when a MagicBlock API call fails. * * @class MagicBlockApiError * @description Captures the HTTP status, response body, and endpoint * URL for diagnostic purposes. Extends the standard `Error` class. * @category Plugin * @since v0.1.0 */ export declare class MagicBlockApiError extends Error { /** HTTP status code (0 for network failures). */ readonly status: number; /** Raw response body text (may be empty). */ readonly body: string; /** The endpoint URL that was called. */ readonly endpoint: string; constructor(status: number, body: string, endpoint: string); } /** A single ER route from `getRoutes`. */ export interface ErRoute { readonly identity: string; readonly fqdn: string; readonly baseFee: number; readonly blockTimeMs: number; readonly countryCode: string; } /** Delegation record from `getDelegationStatus`. */ export interface DelegationRecord { readonly authority: string; readonly owner: string; readonly delegationSlot: number; readonly lamports: number; } /** Delegation status from `getDelegationStatus`. */ export interface DelegationStatus { readonly isDelegated: boolean; readonly fqdn?: string; readonly delegationRecord?: DelegationRecord; } /** Account info value from `getAccountInfo`. */ export interface AccountInfoValue { readonly data: readonly string[]; readonly executable: boolean; readonly lamports: number; readonly owner: string; readonly rentEpoch: string; readonly space: number; } /** Account info response from `getAccountInfo`. */ export interface AccountInfoResponse { readonly context: { readonly apiVersion: string; readonly slot: number; }; readonly value: AccountInfoValue; } /** Blockhash response from `getBlockhashForAccounts`. */ export interface BlockhashResponse { readonly blockhash: string; readonly lastValidBlockHeight: number; } /** Signature status for a single transaction. */ export interface SignatureStatus { readonly confirmationStatus?: "finalized" | "confirmed" | "processed"; readonly confirmations?: number | null; readonly err?: unknown | null; readonly slot?: number; } /** Unsigned transaction response from the Private Payment API. */ export interface UnsignedTransactionResponse { readonly kind: string; readonly version: "legacy" | "v0"; readonly transactionBase64: string; readonly sendTo: "base" | "ephemeral"; readonly recentBlockhash: string; readonly lastValidBlockHeight: number; readonly instructionCount: number; readonly requiredSigners: readonly string[]; readonly validator?: string; } /** Balance response from `balance` and `privateBalance`. */ export interface BalanceResponse { readonly address: string; readonly mint: string; readonly ata: string; readonly location: "base" | "ephemeral"; readonly balance: string; } /** Swap quote response from `swapQuote`. */ export interface SwapQuoteResponse { readonly inputMint: string; readonly inAmount: string; readonly outputMint: string; readonly outAmount: string; readonly otherAmountThreshold: string; readonly swapMode: "ExactIn" | "ExactOut"; readonly slippageBps: number; readonly priceImpactPct: string; readonly routePlan: readonly unknown[]; readonly contextSlot: number; readonly timeTaken: number; readonly [key: string]: unknown; } /** Swap transaction response from `swap`. */ export interface SwapTransactionResponse { readonly swapTransaction: string; readonly lastValidBlockHeight: number; readonly prioritizationFeeLamports?: number; readonly privateTransfer?: { readonly stashAta: string; readonly hydraCrankPda: string; readonly shuttleId: number; }; readonly [key: string]: unknown; } /** * Typed client for the MagicBlock ER Router + Private Payment APIs. * * @class MagicBlockClient * @description Stateless HTTP client. Each method is a single HTTP * request — no session state, no token caching. The caller manages * auth tokens obtained from `challenge` → `login`. * * Uses the global `fetch` (available in Node ≥ 18 and all modern browsers). * No external HTTP dependency. * * @category Plugin * @since v0.1.0 */ export declare class MagicBlockClient { /** * Call a JSON-RPC method on the MagicBlock Router. * * @private * @param endpoint - 'mainnet' or 'devnet' * @param method - JSON-RPC method name * @param params - JSON-RPC params array * @returns The `result` field from the JSON-RPC response * @throws {MagicBlockApiError} On non-200 status or JSON-RPC error */ private static rpcCall; /** * Make a GET request to the Private Payment API. * * @private * @param path - API path (e.g. `/v1/spl/balance`) * @param query - Query parameters (nullish values are skipped) * @param authToken - Optional bearer token for private endpoints * @returns Typed response body * @throws {MagicBlockApiError} On non-2xx status */ private static get; /** * Make a POST request to the Private Payment API. * * @private * @param path - API path (e.g. `/v1/spl/deposit`) * @param body - Request body object * @param authToken - Optional bearer token for private endpoints * @returns Typed response body * @throws {MagicBlockApiError} On non-2xx status */ private static post; /** Get available ER nodes from the Magic Router. */ static getRoutes(endpoint?: "mainnet" | "devnet"): Promise; /** Get the identity and FQDN of the current ER validator. */ static getIdentity(endpoint?: "mainnet" | "devnet"): Promise<{ readonly identity: string; readonly fqdn: string; }>; /** Check whether an account is delegated to an ER. */ static getDelegationStatus(account: string, endpoint?: "mainnet" | "devnet"): Promise; /** Fetch account info via the Magic Router. */ static getAccountInfo(account: string, encoding?: string, endpoint?: "mainnet" | "devnet"): Promise; /** Get a blockhash valid for a batch of accounts (max 100). */ static getBlockhashForAccounts(accounts: readonly string[], endpoint?: "mainnet" | "devnet"): Promise; /** Check the confirmation status of one or more transaction signatures. */ static getSignatureStatuses(signatures: readonly string[], endpoint?: "mainnet" | "devnet"): Promise<{ readonly context: { readonly apiVersion: string; readonly slot: number; }; readonly value: readonly SignatureStatus[]; }>; /** Check the health of the Private Payments API. */ static health(): Promise<{ readonly status: "ok"; }>; /** Generate a challenge string for the wallet to sign. */ static challenge(pubkey: string, cluster?: string | null, mock?: boolean): Promise<{ readonly challenge: string; }>; /** Exchange a signed challenge for a bearer token. */ static login(pubkey: string, challenge: string, signature: string, cluster?: string | null, mock?: boolean): Promise<{ readonly token: string; }>; /** Read the base-chain SPL token balance for an address. */ static balance(address: string, mint: string, cluster?: string | null): Promise; /** Read the ephemeral-rollup SPL token balance (requires auth). */ static privateBalance(address: string, mint: string, authToken: string, cluster?: string | null): Promise; /** Build an unsigned deposit transaction (Solana → ER). */ static deposit(owner: string, amount: number, options?: { readonly mint?: string | null; readonly cluster?: string | null; readonly validator?: string | null; readonly initIfMissing?: boolean; readonly initVaultIfMissing?: boolean; readonly initAtasIfMissing?: boolean; readonly idempotent?: boolean; }): Promise; /** Build an unsigned SPL transfer (public or private). */ static transfer(from: string, to: string, mint: string, amount: number, visibility: "public" | "private", fromBalance: "base" | "ephemeral", toBalance: "base" | "ephemeral", options?: { readonly cluster?: string | null; readonly validator?: string | null; readonly authToken?: string | null; readonly initIfMissing?: boolean; readonly initAtasIfMissing?: boolean; readonly initVaultIfMissing?: boolean; readonly memo?: string | null; readonly minDelayMs?: string | null; readonly maxDelayMs?: string | null; readonly clientRefId?: string | null; readonly split?: number; readonly gasless?: boolean; readonly legacy?: boolean; }): Promise; /** Build an unsigned withdraw transaction (ER → Solana). */ static withdraw(owner: string, mint: string, amount: number, options?: { readonly cluster?: string | null; readonly validator?: string | null; readonly initIfMissing?: boolean; readonly initAtasIfMissing?: boolean; readonly escrowIndex?: number | null; readonly idempotent?: boolean; }): Promise; /** Get a swap quote between two SPL mints. */ static swapQuote(inputMint: string, outputMint: string, amount: string, options?: { readonly slippageBps?: number | null; readonly swapMode?: "ExactIn" | "ExactOut"; readonly onlyDirectRoutes?: boolean; readonly restrictIntermediateTokens?: boolean; readonly platformFeeBps?: number | null; readonly maxAccounts?: number; }): Promise; /** Build an unsigned swap transaction from a quote. */ static swap(userPublicKey: string, quoteResponse: Record, options?: { readonly visibility?: "public" | "private"; readonly destination?: string | null; readonly minDelayMs?: string | null; readonly maxDelayMs?: string | null; readonly split?: number | null; readonly clientRefId?: string | null; readonly validator?: string | null; readonly wrapAndUnwrapSol?: boolean; readonly asLegacyTransaction?: boolean; }): Promise; /** Build an unsigned transaction to initialize a mint transfer queue. */ static initializeMint(owner: string, mint: string, options?: { readonly cluster?: string | null; readonly validator?: string | null; }): Promise; /** Check whether a mint's transfer queue is initialized. */ static isMintInitialized(mint: string, options?: { readonly cluster?: string | null; readonly validator?: string | null; }): Promise<{ readonly initialized: boolean; }>; /** * Strip nullish values from an options object for POST bodies. * Optionally exclude specific keys from the output (e.g. `authToken` * which is passed as a header, not in the body). * * @private */ private static stripNullish; /** * Strip nullish values from an options object for GET query params. * Converts all values to strings (URLSearchParams requirement). * * @private */ private static stripNullishQuery; } //# sourceMappingURL=client.d.ts.map