UNPKG

@wuwei-labs/srsly

Version:
213 lines 6.78 kB
/** * @purpose Simple SDK configuration management * * Provides global configuration with per-call overrides. * Supports both @solana/kit (default) and @solana/web3.js modes. */ import type { Commitment } from '@solana/kit'; import { type ProgramSet as AddressesProgramSet, type NetworkAddresses } from './addresses'; import type { TransactionSigner } from '@solana/kit'; /** * PublicKey constructor type for web3.js compatibility */ export interface PublicKeyConstructor<TPublicKey = any> { new (address: string): TPublicKey; } /** * Program address set type * Re-exported from addresses module for convenience */ export type ProgramSet = AddressesProgramSet; /** * Affiliate configuration for automatic discount handling * * When configured, the SDK can automatically create discount authorizations * for rental operations (acceptRental, claimRental) when discountBps is specified. */ export interface AffiliateConfig { /** Affiliate member PDA address */ address: string; /** Signer for discount creation (discount_authority or main authority) */ signer: TransactionSigner; /** Slot buffer for expiry (default: 1000 slots, ~6-7 minutes) */ expirySlotBuffer?: bigint; } /** * SDK configuration options */ export interface SdkConfig { /** * Program address set (determines which SAGE, ATLAS, ProfileFaction addresses to use) */ programs: ProgramSet; /** * RPC URL - defaults based on programs if not specified * @default 'https://api.mainnet-beta.solana.com' for mainnet * @default 'https://api.devnet.solana.com' for atlasnet * @default 'http://localhost:8899' for localnet */ rpcUrl?: string; /** * Custom SRSLY program ID (overrides default) */ programId?: string; /** * Transaction commitment level */ commitment?: Commitment; /** * PublicKey constructor for web3.js mode (optional) * If provided, instructions will be returned in web3.js format * @example import { PublicKey } from '@solana/web3.js'; */ PublicKey?: PublicKeyConstructor; /** * Affiliate configuration for automatic discount handling * * When configured, the SDK can automatically create discount authorizations * for rental operations when discountBps is specified. * * @example * ```typescript * setSdkConfig({ * programs: 'mainnet', * affiliate: { * address: 'AFFILIATE_MEMBER_PDA', * signer: affiliateWallet, * } * }); * * // Then use discountBps in rental operations * await acceptRental({ * borrower: wallet, * contract: contractAddress, * duration: { days: 7 }, * discountBps: 500, // SDK auto-creates discount auth * }); * ``` */ affiliate?: AffiliateConfig; } /** * Set global SDK configuration * * This configuration will be used as the default for all SDK operations. * Individual function calls can override these settings. * * @param config - Configuration options to set globally * * @example * ```typescript * // Use atlasnet programs with default devnet RPC * setSdkConfig({ programs: 'atlasnet' }); * * // Use mainnet programs with web3.js * import { PublicKey } from '@solana/web3.js'; * setSdkConfig({ * programs: 'mainnet', * PublicKey * }); * * // Use mainnet programs with custom RPC (e.g., Helius, QuickNode) * setSdkConfig({ * programs: 'mainnet', * rpcUrl: 'https://my-custom-mainnet-rpc.com' * }); * * // Use atlasnet programs with custom devnet RPC * setSdkConfig({ * programs: 'atlasnet', * rpcUrl: 'https://my-custom-devnet-rpc.com' * }); * ``` */ export declare function setSdkConfig(config: Partial<SdkConfig>): void; /** * Get the current global SDK configuration * * @returns A copy of the current global configuration */ export declare function getSdkConfig(): SdkConfig; /** * Clear global SDK configuration (resets to defaults) */ export declare function clearSdkConfig(): void; /** * Merge global config with optional overrides * * @param overrides - Optional configuration overrides * @returns Merged configuration */ export declare function mergeConfig(overrides?: Partial<SdkConfig>): SdkConfig; /** * Get the effective RPC URL for a configuration * * @param config - Optional SDK configuration. If not provided, uses global config * @returns RPC URL to use */ export declare function getRpcUrl(config?: Partial<SdkConfig>): string; /** * Get the effective program ID for a configuration * * @param config - SDK configuration * @returns Program ID to use */ export declare function getProgramId(config: SdkConfig): string; /** * Get the effective commitment level for a configuration * * @param config - SDK configuration * @returns Commitment level to use */ export declare function getCommitment(config: SdkConfig): Commitment; /** * Get the affiliate configuration from global config with optional overrides * * @param config - Optional SDK configuration overrides * @returns Affiliate configuration if set, undefined otherwise */ export declare function getAffiliateConfig(config?: Partial<SdkConfig>): AffiliateConfig | undefined; /** * Get program-specific addresses with optional overrides * * Returns addresses for the configured program set. The SRSLY program ID * can be overridden via config.programId. * * @param config - Optional SDK configuration overrides * @returns Program addresses with any config overrides applied * * @example * ```typescript * // Get atlasnet addresses (from global config) * setSdkConfig({ programs: 'atlasnet' }); * const addresses = getAddresses(); * console.log(addresses.atlasMint); // Atlasnet ATLAS mint * * // Override programs for specific call * const mainnetAddrs = getAddresses({ programs: 'mainnet' }); * * // Custom SRSLY program * const customAddrs = getAddresses({ programId: 'MyCustomProgram...' }); * console.log(customAddrs.srsly); // 'MyCustomProgram...' * ``` */ export declare function getAddresses(config?: Partial<SdkConfig>): NetworkAddresses & { srsly: string; }; /** * Auto-detect the correct program set by querying the chain's genesis hash * * Returns the raw genesis hash string, which can be passed directly to * `setSdkConfig({ programs: genesisHash })` or `getProgramAddresses(genesisHash)`. * * @param rpcUrl - RPC endpoint URL to query * @returns Genesis hash string identifying the chain * * @example * ```typescript * const genesisHash = await detectProgramSet('https://api.mainnet-beta.solana.com'); * setSdkConfig({ programs: genesisHash }); * ``` */ export declare function detectProgramSet(rpcUrl: string): Promise<string>; //# sourceMappingURL=config.d.ts.map