import { V1Transaction, type V1TransactionContext } from "../../program/transaction"; import { PublicKey, type TransactionInstruction } from "@solana/web3.js"; import type { ClientContext } from "../../context"; import type { Position as ProgramPosition, RedeemWinningsParams, WithdrawConditionalFromPositionParams, WithdrawFromPositionParams, InitPositionTokensParams, DepositToGlobalParams, GlobalToMarketDepositParams, WithdrawFromGlobalParams, ClosePositionTokenAccountsParams } from "../../program/types"; import type { Market } from "../market"; import type { DepositTokenBalancesSnapshot } from "./index"; import { type SolActionCosts, type SolBalanceAvailability, type WalletDepositBalancesState } from "./state"; import type { MarketPositionsResponse, PositionsResponse } from "./wire"; import { DepositBuilder, MergeBuilder, WithdrawBuilder, RedeemWinningsBuilder, WithdrawFromPositionBuilder, InitPositionTokensBuilder, DepositToGlobalBuilder, WithdrawFromGlobalBuilder, GlobalToMarketDepositBuilder } from "./builders"; /** * Identifies the SOL-aware operation represented by an action plan. * * `wrap` and `unwrapAll` identify explicit native-keypair conversion plans. * Ordinary plan kinds do not call those planners or include canonical-account * closure. */ export type SolActionKind = "split" | "merge" | "redeem" | "nativeWithdraw" | "wrap" | "unwrapAll"; /** Expected changes to the separately authoritative SOL balances. */ export interface SolBalanceDelta { /** System-account change in lamports, including unsponsored costs. */ nativeLamports: bigint; /** Persistent canonical WSOL ATA change in lamports. */ canonicalWsolLamports: bigint; } /** Unsigned prepared transaction plus the exact preflight facts authorizing it. */ export interface SolActionPlan { /** Operation whose balance semantics produced this plan. */ kind: SolActionKind; /** Fee-prepared message that submission must preserve exactly. */ transaction: V1Transaction; /** Live fee/rent observations and explicit sponsorship capability. */ costs: SolActionCosts; /** Balance totals after action-specific native reserve. */ availability: SolBalanceAvailability; /** Balance projection that does not replace authoritative state. */ expectedDelta: SolBalanceDelta; } /** * Derive the cross-SDK temporary-account seed for native withdrawal. * * SHA-256 receives the ASCII domain `lightcone:wsol-withdraw:v1`, one zero byte, * raw 32-byte blockhash, wallet, and recipient keys, the amount as unsigned * eight-byte big-endian lamports, then the one-byte attempt. The first 16 digest * bytes become 32 lowercase hexadecimal ASCII characters for Solana's seed limit. */ export declare function nativeWithdrawSeed(recentBlockhash: string, wallet: PublicKey, recipient: PublicKey, amountLamports: bigint, attempt: number): string; /** * Plans position operations and explicit canonical WSOL conversions. * * Explicit conversion state flows as follows: complete matching wallet state and * native keypair -> live account and cost reads -> signer, account, reserve, and * amount guards -> fee-prepared plan -> unchanged prepared submission -> complete * snapshot covering the confirmed slot. An uncertain submission returns control * to the caller, which refreshes authoritative state before planning again. */ export declare class Positions { private readonly client; constructor(client: ClientContext); pda(owner: PublicKey, market: PublicKey): PublicKey; get(userPubkey: string): Promise; getForMarket(userPubkey: string, marketPubkey: string): Promise; /** * Get all conditional-token positions for the authenticated user across * every market. The wallet is resolved server-side from the auth cookie, * so no parameter is required. Same response shape as `get()`. * * `GET /api/users/positions` */ positions(): Promise; /** * Same as {@link positions}, but uses the supplied `cookieHeader` for this * call instead of the SDK's process-wide cookie store. * * Intended for server-side cookie forwarding (SSR / server functions) * where the per-request browser cookie can't propagate to the shared * client. In a browser context this is equivalent to {@link positions} * because the runtime is already attaching the cookie via * `credentials: "include"`. */ positionsWithCookies(cookieHeader: string): Promise; /** * Get the authenticated user's positions in a specific market. The wallet * is resolved server-side from the auth cookie. * * `GET /api/users/markets/{market_pubkey}/positions` */ positionsForMarket(marketPubkey: string): Promise; /** * Same as {@link positionsForMarket}, but uses the supplied `cookieHeader` * for this call instead of the SDK's process-wide cookie store. For * server-side cookie forwarding (SSR / server functions). */ positionsForMarketWithCookies(marketPubkey: string, cookieHeader: string): Promise; /** * Fetch a complete authenticated SPL and native-SOL balance snapshot. * * `minContextSlot` lower-bounds the complete balance snapshot. Native SOL is * required canonical nine-decimal text and remains outside the SPL map. The * generic HTTP layer trusts that shape at runtime; WebSocket frames are decoded * strictly, while malformed REST exact values fail later when state scales them. */ depositTokenBalances(minContextSlot?: number): Promise; /** * Same as {@link depositTokenBalances}, but uses the supplied `cookieHeader` * for this call instead of the SDK's process-wide cookie store. * * Intended for server-side cookie forwarding (SSR / server functions) * where the per-request browser cookie can't propagate to the shared * client. The complete response has the same separate, exact native-SOL * contract as {@link depositTokenBalances}. In a browser this is equivalent to * {@link depositTokenBalances} because the runtime is already attaching * the cookie via `credentials: "include"`. */ depositTokenBalancesWithCookies(minContextSlot: number | undefined, cookieHeader: string): Promise; /** * Return a fee-prepared plan for an exact canonical WSOL wrap. * * The authenticated Trading Wallet must have a local native keypair and complete * balance state. Live canonical account data must match that state. An existing * account must have account lamports equal to its token amount plus native * reserve. Otherwise a later `SyncNative` instruction would recalculate the WSOL * token amount from account lamports and wrap donated excess beyond * `amountLamports`. The returned transaction contains strict Tokenkeg ATA * creation only when the account is absent. It then contains the exact transfer * and `SyncNative`. Availability uses the ordinary reserve floor. * * Callers rebuild immediately before prepared submission. They retain the * returned balance projection until a complete snapshot covers the confirmed * slot. An uncertain outcome requires authoritative refresh before another plan. */ planWrapSol(amountLamports: bigint, state: WalletDepositBalancesState): Promise; /** * Return a fee-prepared plan for closing the complete canonical WSOL account. * * The Trading Wallet must have a local native keypair. Canonical WSOL in the * complete balance state must be positive and equal the live token amount. The * returned transaction contains one `CloseAccount` instruction whose authority, * destination, and fee payer are that wallet. If submitted successfully, the * instruction transfers the complete account balance, including rent and donated * lamports. The returned costs contain only the fresh fee. Availability requires * native SOL to fund that fee without relying on the later account transfer. * * Callers rebuild immediately before prepared submission. They retain the * returned balance projection until a complete snapshot covers the confirmed * slot. Signing, submission, or confirmation uncertainty requires authoritative * refresh and does not authorize automatic resubmission. */ planUnwrapWsolAll(state: WalletDepositBalancesState): Promise; /** * Plan one atomic split that consumes canonical WSOL before wrapping a shortfall. * Amounts and live costs are lamports; unavailable account, fee, or rent reads * fail closed, and sponsored planning is rejected until a sponsor owns costs. */ planSolSplit(market: Market, amountLamports: bigint, state: WalletDepositBalancesState, sponsored: boolean): Promise; /** * Plan a merge that leaves returned WSOL in the persistent canonical ATA. * The prepared transaction does not mutate cached state; refresh authority * after confirmed submission. */ planSolMerge(market: Market, amountLamports: bigint, state: WalletDepositBalancesState, sponsored: boolean): Promise; /** * Plan a redemption that leaves returned WSOL in the persistent canonical ATA. * `amountLamports` is exact collateral scale; `outcomeIndex` is validated * against the supplied authoritative `numOutcomes`. */ planSolRedeem(market: PublicKey, amountLamports: bigint, outcomeIndex: number, numOutcomes: number, state: WalletDepositBalancesState, sponsored: boolean): Promise; /** * Plan exact native SOL delivery without closing the canonical WSOL ATA. * * Native funds are preferred. A shortfall uses a bounded seeded Tokenkeg * account whose rent returns on close; all account, rent, and fee reads fail * closed. At most eight blockhash-scoped candidates bound RPC latency while * making accidental exhaustion negligible. The returned transaction already * carries its prepared message. */ planNativeSolWithdrawal(recipient: PublicKey, amountLamports: bigint, state: WalletDepositBalancesState, sponsored: boolean): Promise; /** * Resolve an unexpired wallet from matching initialized balance state. * This requires the configured signing strategy to control the authenticated * wallet. It does not prove balance freshness. */ private planningWallet; /** * Return the authenticated Trading Wallet after native-keypair validation. * * Complete wallet state and identity are validated by `planningWallet`. This * additional guard rejects wallet-adapter and Privy strategies before conversion * RPC reads. Ordinary planners do not call this method. */ private conversionPlanningWallet; /** * Return an unsigned wrap transaction with exact instruction ordering. * * When planning observed no canonical ATA, the first instruction is strict ATA * creation. A concurrently created ATA therefore makes execution fail instead of * using account state that was absent from the plan. The transfer and `SyncNative` * instructions follow. The explicit context supplies the blockhash and resource limits. */ private buildWrapSolTransaction; /** * Return an unsigned transaction containing one canonical `CloseAccount`. * * The Trading Wallet is the fee payer, close authority, and destination. A later * successful submission transfers the complete account balance to that wallet. */ private buildUnwrapWsolAllTransaction; /** * Build idempotent creation of the persistent Tokenkeg WSOL ATA. * Tokenkeg is Solana's legacy SPL Token Program; canonical native-mint ATA * derivation is pinned to it rather than Token-2022 across the protocol. */ private createCanonicalWsolAccount; /** Read canonical-account existence and upfront rent for merge/redeem plans. */ private receivePlanContext; /** Finish merge/redeem planning with live fee authority and balance deltas. */ private finishReceivePlan; /** * Build the sole WSOL-to-native path without closing canonical authority. * The temporary Tokenkeg account is initialized, funded, and closed back to * the wallet before the exact recipient transfer in the same transaction. */ private buildTemporaryNativeWithdrawal; redeemWinningsIx(params: RedeemWinningsParams, outcomeIndex: number): TransactionInstruction; withdrawConditionalFromPositionIx(params: WithdrawConditionalFromPositionParams): TransactionInstruction; withdrawFromPositionIx(params: WithdrawFromPositionParams): TransactionInstruction; initPositionTokensIx(params: InitPositionTokensParams, numOutcomes: number): TransactionInstruction; depositToGlobalIx(params: DepositToGlobalParams): TransactionInstruction; globalToMarketDepositIx(params: GlobalToMarketDepositParams, numOutcomes: number): TransactionInstruction; withdrawFromGlobalIx(params: WithdrawFromGlobalParams): TransactionInstruction; closePositionTokenAccountsIx(params: ClosePositionTokenAccountsParams, numOutcomes: number): TransactionInstruction; redeemWinningsTx(params: RedeemWinningsParams, outcomeIndex: number, context: V1TransactionContext): V1Transaction; withdrawConditionalFromPositionTx(params: WithdrawConditionalFromPositionParams, context: V1TransactionContext): V1Transaction; withdrawFromPositionTx(params: WithdrawFromPositionParams, context: V1TransactionContext): V1Transaction; initPositionTokensTx(params: InitPositionTokensParams, numOutcomes: number, context: V1TransactionContext): V1Transaction; depositToGlobalTx(params: DepositToGlobalParams, context: V1TransactionContext): V1Transaction; globalToMarketDepositTx(params: GlobalToMarketDepositParams, numOutcomes: number, context: V1TransactionContext): V1Transaction; withdrawFromGlobalTx(params: WithdrawFromGlobalParams, context: V1TransactionContext): V1Transaction; closePositionTokenAccountsTx(params: ClosePositionTokenAccountsParams, numOutcomes: number, context: V1TransactionContext): V1Transaction; deposit(): DepositBuilder; merge(): MergeBuilder; withdraw(): WithdrawBuilder; redeemWinnings(): RedeemWinningsBuilder; withdrawFromPosition(): WithdrawFromPositionBuilder; withdrawConditionalFromPosition(): WithdrawFromPositionBuilder; initPositionTokens(): InitPositionTokensBuilder; depositToGlobal(): DepositToGlobalBuilder; withdrawFromGlobal(): WithdrawFromGlobalBuilder; globalToMarketDeposit(): GlobalToMarketDepositBuilder; getOnchain(owner: PublicKey, market: PublicKey): Promise; } //# sourceMappingURL=client.d.ts.map