/** * @module core/connection * @description RPC connection factory for SAP v2 SDK. * * Provides a high-level, synapse-client-sdk–compatible entry point * for creating {@link SapClient} instances from an RPC URL and wallet. * * @category Core * @since v0.1.0 * * @example * ```ts * import { SapConnection } from "@synapse-sap/sdk"; * * // Quick start — RPC URL + Keypair * const sap = SapConnection.fromKeypair("https://api.devnet.solana.com", keypair); * const agent = await sap.client.agent.fetch(); * * // Or build step-by-step * const conn = new SapConnection({ * rpcUrl: "https://us-1-mainnet.oobeprotocol.ai/rpc?api_key=xxx", * cluster: "mainnet-beta", * commitment: "confirmed", * }); * const client = conn.createClient(wallet); * ``` */ import { Connection, type Commitment, Keypair, type PublicKey, type Transaction, type VersionedTransaction } from "@solana/web3.js"; import { SapClient } from "./client"; /** * @interface SapWallet * @description Minimal wallet/signer interface compatible with * Anchor's `AnchorProvider`. Avoids importing `Wallet` from * `@coral-xyz/anchor` which is absent in ESM builds. * @category Core * @since v0.4.1 */ export interface SapWallet { readonly publicKey: PublicKey; signTransaction(tx: T): Promise; signAllTransactions(txs: T[]): Promise; } /** * @name KeypairWallet * @description Simple wallet wrapper around a `Keypair`. * Drop-in replacement for Anchor's `NodeWallet` / `Wallet` class. * @category Core * @since v0.4.1 */ export declare class KeypairWallet implements SapWallet { readonly payer: Keypair; readonly publicKey: PublicKey; constructor(payer: Keypair); signTransaction(tx: T): Promise; signAllTransactions(txs: T[]): Promise; } /** * @name SapCluster * @description Supported Solana cluster names used to select the RPC endpoint * and corresponding SAP program ID. * @category Core * @since v0.1.0 */ export type SapCluster = "mainnet-beta" | "devnet" | "localnet"; /** * @interface SapConnectionConfig * @description Configuration object used to initialise a {@link SapConnection}. * @category Core * @since v0.1.0 * @see {@link SapConnection} */ export interface SapConnectionConfig { /** * @property {string} rpcUrl * @description Solana JSON-RPC endpoint URL (e.g. `https://api.devnet.solana.com`). */ rpcUrl: string; /** * @property {string} [wsUrl] * @description WebSocket endpoint URL. When omitted the SDK derives it * automatically from {@link rpcUrl} by swapping the protocol scheme. */ wsUrl?: string; /** * @property {Commitment} [commitment] * @description Commitment level for queries and transaction confirmations. * Defaults to `"confirmed"` when not provided. */ commitment?: Commitment; /** * @property {SapCluster} [cluster] * @description Cluster hint (`mainnet-beta` | `devnet` | `localnet`). * When omitted the SDK infers it from {@link rpcUrl} via * {@link SapConnection.detectCluster}. */ cluster?: SapCluster; } /** * @name SapConnection * @description Lightweight RPC connection wrapper that creates * properly-configured {@link SapClient} instances. * * Compatible with the `synapse-client-sdk` connection model: * start from an RPC URL, attach a wallet, get a typed client. * * @category Core * @since v0.1.0 * @see {@link SapClient} * @see {@link SapConnectionConfig} * * @example * ```ts * // Factory shortcut for devnet * const conn = SapConnection.devnet(); * const client = conn.createClient(wallet); * * // One-liner with Keypair * const { client } = SapConnection.fromKeypair( * "https://api.devnet.solana.com", * keypair, * ); * ``` */ export declare class SapConnection { /** * @readonly * @description Raw Solana {@link Connection}. Exposed for advanced * use-cases that need direct RPC access. */ readonly connection: Connection; /** * @readonly * @description The resolved Solana cluster for this connection, * either explicitly provided or auto-detected from the RPC URL. */ readonly cluster: SapCluster; /** * @readonly * @description Commitment level used for all queries and * transaction confirmations on this connection. */ readonly commitment: Commitment; /** * @readonly * @description The SAP on-chain program {@link PublicKey} resolved * for the current {@link cluster}. * @see {@link SapConnection.programIdForCluster} */ readonly programId: PublicKey; constructor(config: SapConnectionConfig); /** * Create a {@link SapConnection} for **devnet** with sensible defaults. * * @static * @param {Commitment} [commitment="confirmed"] — Commitment level. * @returns {SapConnection} A connection targeting Solana devnet. * @since v0.1.0 * * @example * ```ts * const conn = SapConnection.devnet(); * ``` */ static devnet(commitment?: Commitment): SapConnection; /** * Create a {@link SapConnection} for **mainnet-beta** with sensible defaults. * * @static * @param {string} [rpcUrl="https://api.mainnet-beta.solana.com"] — Custom RPC URL. * @param {Commitment} [commitment="confirmed"] — Commitment level. * @returns {SapConnection} A connection targeting Solana mainnet-beta. * @since v0.1.0 * * @example * ```ts * const conn = SapConnection.mainnet("https://my-rpc.example.com"); * ``` */ static mainnet(rpcUrl?: string, commitment?: Commitment): SapConnection; /** * Create a {@link SapConnection} for **localnet** (`localhost:8899`). * * @static * @param {Commitment} [commitment="confirmed"] — Commitment level. * @returns {SapConnection} A connection targeting a local validator. * @since v0.1.0 * * @example * ```ts * const conn = SapConnection.localnet(); * ``` */ static localnet(commitment?: Commitment): SapConnection; /** * One-liner: create a {@link SapConnection} + {@link SapClient} from * an RPC URL and a `Keypair`. Perfect for scripts and CLI tools. * * @static * @param {string} rpcUrl — Solana JSON-RPC endpoint. * @param {Keypair} keypair — Signer keypair. * @param {object} [opts] — Optional overrides. * @param {Commitment} [opts.commitment] — Commitment level. * @param {SapCluster} [opts.cluster] — Explicit cluster hint. * @returns {SapConnection & { readonly client: SapClient }} Connection with an attached client. * @since v0.1.0 * * @example * ```ts * const { client, connection } = SapConnection.fromKeypair( * "https://api.devnet.solana.com", * Keypair.generate(), * ); * ``` */ static fromKeypair(rpcUrl: string, keypair: Keypair, opts?: { commitment?: Commitment; cluster?: SapCluster; }): SapConnection & { readonly client: SapClient; }; /** * Create a {@link SapClient} from a {@link SapWallet} (signer). * * @param {SapWallet} wallet — A wallet/signer implementing {@link SapWallet}. * @returns {SapClient} A fully-configured SAP client. * @since v0.1.0 * * @example * ```ts * const client = conn.createClient(new KeypairWallet(keypair)); * ``` */ createClient(wallet: SapWallet): SapClient; /** * Create a {@link SapClient} from a raw {@link Keypair}. * * @param {Keypair} keypair — The signer keypair. * @returns {SapClient} A fully-configured SAP client. * @since v0.1.0 * * @example * ```ts * const client = conn.fromKeypair(Keypair.generate()); * ``` */ fromKeypair(keypair: Keypair): SapClient; /** * Request an airdrop (devnet / localnet only). * * @param {PublicKey} to — Recipient public key. * @param {number} solAmount — Amount of SOL to airdrop. * @returns {Promise} The confirmed transaction signature. * @throws {Error} If the airdrop request or confirmation fails (e.g. on mainnet). * @since v0.1.0 * * @example * ```ts * const sig = await conn.airdrop(wallet.publicKey, 2); * ``` */ airdrop(to: PublicKey, solAmount: number): Promise; /** * Get the SOL balance of an address in **lamports**. * * @param {PublicKey} address — The account to query. * @returns {Promise} Balance in lamports. * @since v0.1.0 */ getBalance(address: PublicKey): Promise; /** * Get the SOL balance of an address in **SOL** (human-readable). * * @param {PublicKey} address — The account to query. * @returns {Promise} Balance in SOL. * @since v0.1.0 * * @example * ```ts * const sol = await conn.getBalanceSol(wallet.publicKey); * console.log(`Balance: ${sol} SOL`); * ``` */ getBalanceSol(address: PublicKey): Promise; /** * Infer the {@link SapCluster} from an RPC URL by inspecting * well-known substrings (`devnet`, `localhost`, `:8899`). * * @static * @param {string} rpcUrl — The RPC endpoint to inspect. * @returns {SapCluster} The detected cluster, defaulting to `"mainnet-beta"`. * @since v0.1.0 */ static detectCluster(rpcUrl: string): SapCluster; /** * Map a {@link SapCluster} to the canonical SAP on-chain program ID. * * @static * @param {SapCluster} cluster — Target cluster. * @returns {PublicKey} The program {@link PublicKey} for the given cluster. * @since v0.1.0 * @see {@link SAP_PROGRAM_ID} */ static programIdForCluster(cluster: SapCluster): PublicKey; } //# sourceMappingURL=connection.d.ts.map