import { Address, Instruction, KeyPairSigner, ReadonlyUint8Array, SignatureBytes, TransactionSigner } from "@solana/kit"; import { BuyArgs, CreateCampaignArgs, GrantRoleArgs, InitializeConfigArgs, RevokeRoleArgs, UpdateCampaignArgs, UpdateCampaignMetadataArgs, UpdateConfigArgs } from "../clients/generated/js/src"; /** * Main SDK class for interacting with the Moonshot Blindbox Smart Contract. * Provides methods for managing configs, campaigns, and executing buy operations. */ export declare class MoonshotBlindbox { private signer; private skipSimulation; private readonly estimateAndSetComputeUnitLimit; private readonly sendAndConfirmTransaction; private readonly rpc; private readonly rpcSubscriptions; private readonly signersCache; /** * Creates a new instance of the MoonshotBlindbox SDK. * * @param signer - The transaction signer (either TransactionSigner or KeyPairSigner) used to sign transactions * @param rpcUrl - The Solana RPC endpoint URL (e.g., "https://api.devnet.solana.com") * @param wssUrl - The Solana WebSocket endpoint URL (e.g., "wss://api.devnet.solana.com") * @param skipSimulation - Optional. If true, skips transaction simulation and uses fixed compute units. Defaults to false. * * @example * ```typescript * const signer = await generateKeyPairSigner(); * const moonshot = new MoonshotBlindbox( * signer, * "https://api.devnet.solana.com", * "wss://api.devnet.solana.com", * true * ); * ``` */ constructor(signer: TransactionSigner | KeyPairSigner, rpcUrl: string, wssUrl: string, skipSimulation?: boolean); /** * Creates an instruction to initialize a new config account. * The config is the top-level account that manages campaigns and access control. * * @param args - The initialization arguments * @param args.id - The unique identifier for this config (0-255) * @returns The initialize config instruction * * @example * ```typescript * const initConfigIx = await moonshot.getInitializeConfigInstruction({ * id: 1 * }); * await moonshot.signAndSendTransaction([initConfigIx]); * ``` */ getInitializeConfigInstruction(args: InitializeConfigArgs): Promise, string, string, string, string, string, "CEqRYLCkBsYoPBwSNsEiX12D3NGeTCWPtM95DAo6qt1U", []>>; /** * Creates an instruction to update an existing config account. * Can update the config status (Active/Inactive). * * @param args - The update arguments * @param args.configId - The ID of the config to update * @param args.status - Optional. The new status for the config * @returns The update config instruction * * @example * ```typescript * import { some, none } from "@solana/kit"; * import { Status } from "moonshot-blindbox-sdk"; * * const updateIx = await moonshot.getUpdateConfigInstruction({ * configId: 1, * status: some(Status.Inactive) * }); * await moonshot.signAndSendTransaction([updateIx]); * ``` */ getUpdateConfigInstruction(args: UpdateConfigArgs): Promise, string, string, string, "CEqRYLCkBsYoPBwSNsEiX12D3NGeTCWPtM95DAo6qt1U", []>>; /** * Creates an instruction to grant a role to an account. * Roles control access to various operations (Admin and Operator roles available). * * @param args - The grant role arguments * @param args.configId - The ID of the config * @param args.accountToGrant - The address of the account receiving the role * @param args.role - The role to grant (Role.Admin or Role.Operator) * @returns The grant role instruction * * @example * ```typescript * import { Role } from "moonshot-blindbox-sdk"; * * const grantIx = await moonshot.getGrantRoleInstruction({ * configId: 1, * accountToGrant: "AccountAddressHere", * role: Role.Admin * }); * await moonshot.signAndSendTransaction([grantIx]); * ``` */ getGrantRoleInstruction(args: GrantRoleArgs): Promise, string, string, string, string, string, string, "CEqRYLCkBsYoPBwSNsEiX12D3NGeTCWPtM95DAo6qt1U", []>>; /** * Creates an instruction to revoke a role from an account. * * @param args - The revoke role arguments * @param args.configId - The ID of the config * @param args.accountToRevoke - The address of the account losing the role * @param args.role - The role to revoke (Role.Admin or Role.Operator) * @returns The revoke role instruction * * @example * ```typescript * import { Role } from "moonshot-blindbox-sdk"; * * const revokeIx = await moonshot.getRevokeRoleInstruction({ * configId: 1, * accountToRevoke: "AccountAddressHere", * role: Role.Admin * }); * await moonshot.signAndSendTransaction([revokeIx]); * ``` */ getRevokeRoleInstruction(args: RevokeRoleArgs): Promise, string, string, string, string, string, "CEqRYLCkBsYoPBwSNsEiX12D3NGeTCWPtM95DAo6qt1U", []>>; /** * Creates an instruction to initialize a new campaign. * A campaign represents a blindbox sale with stages, pricing, and available items. * * @param args - The campaign creation arguments * @param args.configId - The ID of the parent config * @param args.campaignId - The unique identifier for this campaign (0-255) * @param args.stages - Array of stage configurations with startTime, endTime, and purchaseLimit * @param args.priceInLamports - The price per item in lamports * @param args.paymentDestination - The address that receives payment * @param args.itemsAvailable - Total number of items available in this campaign * @param args.campaignMetadata - Metadata for the campaign collection (name, symbol, uri) * @param args.itemMetadata - Metadata for individual NFT items (name, symbol, uri) * @returns A tuple of [instruction, mintAddress] where mintAddress is the generated mint for the campaign * * @example * ```typescript * const now = Math.floor(Date.now() / 1000); * const [createIx, mintAddress] = await moonshot.getCreateCampaignInstruction({ * configId: 1, * campaignId: 0, * stages: [ * { * startTime: BigInt(now), * endTime: BigInt(now + 3600), * purchaseLimit: BigInt(2) * } * ], * priceInLamports: BigInt(1000000000), * paymentDestination: "PaymentAddressHere", * itemsAvailable: BigInt(100), * campaignMetadata: { * name: "My Campaign", * symbol: "MC", * uri: "https://example.com/campaign.json" * }, * itemMetadata: { * name: "Campaign Item", * symbol: "CI", * uri: "https://example.com/item.json" * } * }); * await moonshot.signAndSendTransaction([createIx]); * ``` */ getCreateCampaignInstruction(args: CreateCampaignArgs): Promise<[Instruction, Address]>; /** * Creates an instruction to update an existing campaign. * Can update status, stages, price, payment destination, and items available. * * @param args - The update arguments * @param args.configId - The ID of the parent config * @param args.campaignId - The ID of the campaign to update * @param args.status - Optional. New status (Status.Active or Status.Inactive) * @param args.stages - Optional. New array of stage configurations * @param args.priceInLamports - Optional. New price per item in lamports * @param args.paymentDestination - Optional. New payment destination address * @param args.itemsAvailable - Optional. New total items available * @returns The update campaign instruction * * @example * ```typescript * import { some, none } from "@solana/kit"; * import { Status } from "moonshot-blindbox-sdk"; * * const updateIx = await moonshot.getUpdateCampaignInstruction({ * configId: 1, * campaignId: 0, * status: some(Status.Inactive), * stages: none(), * priceInLamports: some(BigInt(500000000)), * paymentDestination: none(), * itemsAvailable: none() * }); * await moonshot.signAndSendTransaction([updateIx]); * ``` */ getUpdateCampaignInstruction(args: UpdateCampaignArgs): Promise, string, string, string, string, string, "CEqRYLCkBsYoPBwSNsEiX12D3NGeTCWPtM95DAo6qt1U", []>>; /** * Creates an instruction to update campaign metadata. * Updates the metadata for the campaign's NFT collection. * * @param args - The update metadata arguments * @param args.configId - The ID of the parent config * @param args.campaignId - The ID of the campaign to update * @param args.mintAccount - The mint account address for the campaign * @param args.metadata - The new metadata (name, symbol, uri) * @returns The update campaign metadata instruction * * @example * ```typescript * const updateMetadataIx = await moonshot.getUpdateCampaignMetadataInstruction({ * configId: 1, * campaignId: 0, * mintAccount: "MintAddressHere", * metadata: { * name: "Updated Campaign Name", * symbol: "UCN", * uri: "https://example.com/updated.json" * } * }); * await moonshot.signAndSendTransaction([updateMetadataIx]); * ``` */ getUpdateCampaignMetadataInstruction(args: UpdateCampaignMetadataArgs): Promise, string, string, string, string, string, string, string, string, string, "CEqRYLCkBsYoPBwSNsEiX12D3NGeTCWPtM95DAo6qt1U", []>>; /** * Creates an instruction to buy items from a campaign. * Generates a new mint for the NFT that will be created upon purchase. * * @param args - The buy arguments * @param args.configId - The ID of the parent config * @param args.campaignId - The ID of the campaign to buy from * @param args.buyer - The address of the buyer (who will receive the NFT) * @returns A tuple of [instruction, mintAddress] where mintAddress is the generated mint for the NFT * * @throws {Error} If the campaign is not found * * @example * ```typescript * // Single signature (operator controls everything) * const [buyIx, mintAddress] = await moonshot.getBuyInstruction({ * configId: 1, * campaignId: 0, * buyer: "BuyerAddressHere", * }); * await moonshot.signAndSendTransaction([buyIx]); * ``` * * @example * ```typescript * // Multi-signature (buyer maintains control) * const [buyIx, mintAddress] = await operatorMoonshot.getBuyInstruction({ * configId: 1, * campaignId: 0, * buyer: buyerAddress, * }); * const encodedTx = await operatorMoonshot.partiallySignTransaction( * [buyIx], * buyerAddress * ); * await buyerMoonshot.signAndSendEncodedTransaction(encodedTx); * ``` */ getBuyInstruction(args: BuyArgs): Promise<[Instruction, Address]>; /** * Fetches a config account by its address. * * @param configAddress - The address of the config account * @returns The config data if it exists, null otherwise * * @example * ```typescript * import { getConfigAddress } from "moonshot-blindbox-sdk"; * * const configAddress = await getConfigAddress(1); * const config = await moonshot.fetchConfig(configAddress); * if (config) { * console.log("Config status:", config.status); * } * ``` */ fetchConfig(configAddress: Address): Promise; /** * Fetches a campaign account by its address. * * @param campaignAddress - The address of the campaign account * @returns The campaign data if it exists, null otherwise * * @example * ```typescript * import { getCampaignAddress, getConfigAddress } from "moonshot-blindbox-sdk"; * * const configAddress = await getConfigAddress(1); * const campaignAddress = await getCampaignAddress(0, configAddress); * const campaign = await moonshot.fetchCampaign(campaignAddress); * if (campaign) { * console.log("Items available:", campaign.itemsAvailable); * } * ``` */ fetchCampaign(campaignAddress: Address): Promise; /** * Fetches a capability account by its address. * Used to check if an account has a specific role. * * @param capabilityAddress - The address of the capability account * @returns The capability data if it exists, null otherwise * * @example * ```typescript * import { getCapabilityAddress, getConfigAddress, Role } from "moonshot-blindbox-sdk"; * * const configAddress = await getConfigAddress(1); * const capabilityAddress = await getCapabilityAddress(configAddress, accountAddress, Role.Admin); * const capability = await moonshot.fetchCapability(capabilityAddress); * console.log("Has Admin role:", capability !== null); * ``` */ fetchCapability(capabilityAddress: Address): Promise; /** * Fetches an NFT authority account by its address. * The NFT authority is a PDA that has authority over NFT minting operations for a specific config. * This account is used internally by the program to manage NFT creation during buy operations. * * @param nftAuthorityAddress - The address of the NFT authority account (PDA derived from config) * @returns The NFT authority data if it exists, null otherwise. Contains the config reference and bump seed. * * @example * ```typescript * import { getNftAuthorityAddress, getConfigAddress } from "moonshot-blindbox-sdk"; * * const configAddress = await getConfigAddress(1); * const nftAuthorityAddress = await getNftAuthorityAddress(configAddress); * const nftAuthority = await moonshot.fetchNftAuthority(nftAuthorityAddress); * if (nftAuthority) { * console.log("NFT Authority config:", nftAuthority.config); * } * ``` */ fetchNftAuthority(nftAuthorityAddress: Address): Promise; /** * Fetches a user account by its address. * User accounts track purchase history and limits for a specific buyer in a campaign. * * @param userAddress - The address of the user account * @returns The user data if it exists, null otherwise * * @example * ```typescript * import { getUserAddress, getCampaignAddress, getConfigAddress } from "moonshot-blindbox-sdk"; * * const configAddress = await getConfigAddress(1); * const campaignAddress = await getCampaignAddress(0, configAddress); * const userAddress = await getUserAddress(campaignAddress, buyerAddress); * const user = await moonshot.fetchUser(userAddress); * if (user) { * console.log("Items purchased:", user.itemsPurchased); * } * ``` */ fetchUser(userAddress: Address): Promise; /** * Gets the latest blockhash from the RPC endpoint. * This is used internally for setting transaction lifetime constraints. * The blockhash ensures transactions are only valid for a limited time window (~150 slots or ~60 seconds). * * @returns A promise that resolves to the latest blockhash information, including: * - blockhash: The recent blockhash string * - lastValidBlockHeight: The last block height this blockhash is valid for * * @remarks * This method is called automatically by `signAndSendTransaction` and `partiallySignTransaction`. * You typically don't need to call this directly unless implementing custom transaction flows. * * @example * ```typescript * const blockhash = await moonshot.getLatestBlockhash(); * console.log("Current blockhash:", blockhash.blockhash); * console.log("Valid until block:", blockhash.lastValidBlockHeight); * ``` */ getLatestBlockhash(): Promise>; /** * Signs and sends a transaction with the provided instructions. * This is the main method for executing transactions. It handles: * - Fetching the latest blockhash for transaction lifetime * - Setting the fee payer (the signer provided in constructor) * - Estimating and setting compute units (unless skipSimulation is true) * - Signing the transaction with the configured signer * - Sending the transaction to the network * - Waiting for confirmation with 'confirmed' commitment level * * @param ixs - Array of Solana instructions to include in the transaction. These will be executed in order. * @returns A promise that resolves to the transaction signature (base58 string) upon confirmation. * * @throws {Error} If the transaction fails to send or confirm * @throws {Error} If compute unit estimation fails (when skipSimulation is false) * * @remarks * - If `skipSimulation` is true (set in constructor), uses fixed 1,400,000 compute units * - If `skipSimulation` is false, estimates compute units by simulating the transaction * - Transactions are confirmed at 'confirmed' commitment level before returning * - The signer must have sufficient SOL to pay for transaction fees * * @example * ```typescript * // Single instruction * const initIx = await moonshot.getInitializeConfigInstruction({ id: 1 }); * const signature = await moonshot.signAndSendTransaction([initIx]); * console.log("Transaction signature:", signature); * ``` * * @example * ```typescript * // Multiple instructions in one transaction * const grantIx1 = await moonshot.getGrantRoleInstruction({ * configId: 1, * accountToGrant: address1, * role: Role.Admin * }); * const grantIx2 = await moonshot.getGrantRoleInstruction({ * configId: 1, * accountToGrant: address2, * role: Role.Operator * }); * const signature = await moonshot.signAndSendTransaction([grantIx1, grantIx2]); * console.log("Batch transaction signature:", signature); * ``` */ signAndSendTransaction(ixs: Instruction[]): Promise; /** * Partially signs a transaction with the operator's signature. * This method is used in multi-signature workflows where the buyer needs to maintain control * of the transaction. The operator (this SDK instance) signs the transaction, but the final * signature from the buyer is still required before the transaction can be sent to the network. * * **Workflow:** * 1. Operator creates transaction instructions (e.g., buy instruction) * 2. Operator partially signs with this method * 3. Operator sends encoded transaction to buyer (off-chain) * 4. Buyer completes signature and broadcasts with `signAndSendEncodedTransaction` * * @param ixs - Array of Solana instructions to include in the transaction. These will be executed in order. * @param feePayer - The address of the account that will pay transaction fees (typically the buyer's address). * This account must sign the transaction before it can be sent. * @returns A promise that resolves to the encoded partially-signed transaction as a ReadonlyUint8Array. * This can be serialized and sent to the buyer for completion. * * @remarks * - The transaction includes compute unit estimation/limits like `signAndSendTransaction` * - The transaction is valid for ~150 slots (~60 seconds) from creation * - The feePayer account must sign before the transaction can be broadcast * - The encoded transaction can be transferred via JSON-RPC, WebSocket, or any data channel * * @throws {Error} If compute unit estimation fails (when skipSimulation is false) * * @example * ```typescript * // Operator prepares and partially signs * const [buyIx, mintAddress] = await operatorMoonshot.getBuyInstruction({ * configId: 1, * campaignId: 0, * buyer: buyerAddress, * amount: BigInt(1) * }); * const encodedTx = await operatorMoonshot.partiallySignTransaction( * [buyIx], * buyerAddress * ); * * // Send encodedTx to buyer via your preferred method * // Buyer then completes with: * // await buyerMoonshot.signAndSendEncodedTransaction(encodedTx); * ``` * * @see {@link signAndSendEncodedTransaction} for the buyer's completion step */ partiallySignTransaction(ixs: Instruction[], feePayer: Address): Promise; /** * Signs and sends an encoded transaction. * This is the buyer's step in a multi-signature workflow. It takes a partially-signed transaction * from the operator, adds the buyer's signature, and broadcasts it to the Solana network. * * **Workflow (Buyer's perspective):** * 1. Receive encoded transaction from operator (via API, WebSocket, etc.) * 2. Call this method with the encoded transaction * 3. The buyer's signer (from constructor) signs the transaction * 4. Transaction is sent to the network and confirmed * * @param encodedTransaction - The encoded partially-signed transaction as ReadonlyUint8Array, * received from `partiallySignTransaction` call by the operator. * @returns A promise that resolves to the transaction signature (base58 string) upon confirmation. * For TransactionSendingSigner, returns the first signature from the array. * * @throws {Error} If the signer type is invalid (not TransactionSendingSigner or KeyPairSigner) * @throws {Error} If the transaction fails to decode * @throws {Error} If the transaction fails to send or confirm * * @remarks * - This method works with both KeyPairSigner and TransactionSendingSigner types * - The transaction must have been partially signed by the operator before calling this * - The buyer's account (signer) must be the fee payer specified in the original transaction * - The buyer's account must have sufficient SOL to pay for transaction fees * - Transaction is confirmed at 'confirmed' commitment level before returning * * @example * ```typescript * // Buyer receives encoded transaction from operator * const buyerSigner = await generateKeyPairSigner(); * const buyerMoonshot = new MoonshotBlindbox( * buyerSigner, * "https://api.devnet.solana.com", * "wss://api.devnet.solana.com", * true * ); * * // encodedTx received from operator * const signature = await buyerMoonshot.signAndSendEncodedTransaction(encodedTx); * console.log("Transaction completed:", signature); * ``` * * @example * ```typescript * // Complete multi-signature flow * // 1. Operator side: * const [buyIx, mintAddress] = await operatorMoonshot.getBuyInstruction({ * configId: 1, * campaignId: 0, * buyer: buyerAddress, * amount: BigInt(1) * }); * const encodedTx = await operatorMoonshot.partiallySignTransaction([buyIx], buyerAddress); * * // 2. Send encodedTx to buyer... * * // 3. Buyer side: * const signature = await buyerMoonshot.signAndSendEncodedTransaction(encodedTx); * console.log("Purchase complete! NFT mint:", mintAddress); * ``` * * @see {@link partiallySignTransaction} for the operator's preparation step */ signAndSendEncodedTransaction(encodedTransaction: ReadonlyUint8Array): Promise; } //# sourceMappingURL=MoonshotBlindbox.d.ts.map