/** * @fileoverview Legacy SDK for Moonshot Blindbox Smart Contract * * This module provides a TypeScript SDK for interacting with the Moonshot Blindbox * smart contract on Solana. It offers methods for: * - Managing campaigns (create, update, fetch) * - Role-based access control (grant, revoke, check roles) * - Transaction building and confirmation * * The SDK uses Anchor framework and supports Version 0 transactions for * optimal performance on Solana. * * @module MoonshotBlindboxLegacy * @author Moonshot Team */ import * as anchor from "@coral-xyz/anchor"; import BN from "bn.js"; import { Role, Status } from "../clients/generated/js/src"; /** * Represents a campaign stage with time-based restrictions * Stages allow for phased launches with different limits per stage */ export type TStage = { /** Unix timestamp when this stage starts */ startTime: BN; /** Unix timestamp when this stage ends */ endTime: BN; /** Maximum items a single user can purchase in this stage */ maxItemsPerUser: BN; /** Total items available for purchase in this stage */ itemsAvailable: BN; /** Number of items already purchased in this stage */ itemsPurchased: BN; }; /** * NFT metadata information for campaigns and items */ export type TMetadata = { /** Display name of the NFT */ name: string; /** Token symbol for the NFT collection */ symbol: string; /** URI pointing to the metadata JSON file */ uri: string; }; /** * Arguments for creating a new campaign */ export type TCreateCampaignArgs = { /** The configuration ID this campaign belongs to */ configId: number; /** Unique identifier for the campaign */ campaignId: number; /** Array of stages defining the campaign's timeline and limits */ stages: Array; /** Price per item in lamports (1 SOL = 1,000,000,000 lamports) */ priceInLamports: BN; /** Wallet address where payment funds will be sent */ paymentDestination: anchor.web3.PublicKey; /** Total number of items available across all stages */ itemsAvailable: BN; /** Maximum items a single user can purchase across all stages */ maxItemsPerUser: BN; /** Metadata for the campaign itself */ campaignMetadata: TMetadata; /** Metadata template for items in this campaign */ itemMetadata: TMetadata; }; /** * Arguments for updating an existing campaign * All fields except IDs are optional - only provided fields will be updated */ export type TUpdateCampaignArgs = { /** The configuration ID this campaign belongs to */ configId: number; /** Unique identifier for the campaign to update */ campaignId: number; /** Optional: New stages configuration */ stages?: Array; /** Optional: New campaign status (Active/Inactive) */ status?: Status; /** Optional: New price per item in lamports */ priceInLamports?: BN; /** Optional: New payment destination wallet */ paymentDestination?: anchor.web3.PublicKey; /** Optional: New total items available */ itemsAvailable?: BN; /** Optional: New max items per user */ maxItemsPerUser?: BN; }; /** * Arguments for granting a role to an account */ export type TGrantRoleArgs = { /** The configuration ID */ configId: number; /** The account public key to grant the role to */ accountToGrant: anchor.web3.PublicKey; /** The role to grant (Admin or Operator) */ role: Role; }; /** * Arguments for revoking a role from an account */ export type TRevokeRoleArgs = { /** The configuration ID */ configId: number; /** The account public key to revoke the role from */ accountToRevoke: anchor.web3.PublicKey; /** The role to revoke (Admin or Operator) */ role: Role; }; /** * Status mappings for campaign status conversion * Maps enum values to their on-chain representation */ export declare const statuses: { 0: { active: {}; }; 1: { inactive: {}; }; }; /** * Role mappings for role conversion * Maps enum values to their on-chain representation */ export declare const roles: { 0: { admin: {}; }; 1: { operator: {}; }; }; /** * Legacy SDK class for interacting with the Moonshot Blindbox smart contract * Provides methods for managing campaigns, roles, and transactions * * @class MoonshotBlindboxLegacy * @example * const sdk = new MoonshotBlindboxLegacy("https://api.devnet.solana.com"); * const config = await sdk.fetchConfig(0); */ export declare class MoonshotBlindboxLegacy { private readonly program; private readonly connection; /** * Creates an instance of MoonshotBlindboxLegacy * * @param {string} rpcUrl - The Solana RPC endpoint URL * @param {anchor.web3.PublicKey} [programId] - The program ID (defaults to deployed program address) */ constructor(rpcUrl: string, programId?: anchor.web3.PublicKey); /** * Fetches the configuration account data from the blockchain * * @param {number} configId - The unique identifier for the configuration * @returns {Promise} The configuration account data, or null if not found * @example * const config = await sdk.fetchConfig(0); * if (config) { * console.log("Owner:", config.owner); * } */ fetchConfig(configId: number): Promise; /** * Fetches a specific campaign account data from the blockchain * * @param {number} configId - The configuration ID the campaign belongs to * @param {number} campaignId - The unique identifier for the campaign * @returns {Promise} The campaign account data, or null if not found * @example * const campaign = await sdk.fetchCampaign(0, 1); * if (campaign) { * console.log("Items available:", campaign.itemsAvailable.toString()); * } */ fetchCampaign(configId: number, campaignId: number): Promise; /** * Fetches the capability (role permission) account for a specific account and role * * @param {number} configId - The configuration ID * @param {anchor.web3.PublicKey} account - The account public key to check capabilities for * @param {Role} role - The role to check (Admin or Operator) * @returns {Promise} The capability account data, or null if not found * @example * const capability = await sdk.fetchCapability(0, adminPubkey, Role.Admin); * if (capability) { * console.log("Account has admin role"); * } */ fetchCapability(configId: number, account: anchor.web3.PublicKey, role: Role): Promise; /** * Creates a versioned transaction for creating a new campaign * * This method generates a new mint account for the campaign's NFT collection, * validates the admin's capability, and prepares the transaction. * * @param {anchor.web3.PublicKey} admin - The admin's public key (must have admin role) * @param {TCreateCampaignArgs} args - The campaign creation parameters including stages, pricing, and metadata * @returns {Promise<[anchor.web3.VersionedTransaction, anchor.web3.PublicKey]>} A tuple of [transaction, mintAccountPublicKey] * @throws {Error} If config or admin capability is not found * @example * const [tx, mintPubkey] = await sdk.getCreateCampaignTransaction(adminPubkey, { * configId: 0, * campaignId: 1, * stages: [...], * priceInLamports: new BN(1000000), * // ... other args * }); */ getCreateCampaignTransaction(admin: anchor.web3.PublicKey, args: TCreateCampaignArgs): Promise<[anchor.web3.VersionedTransaction, anchor.web3.PublicKey]>; /** * Creates a versioned transaction for updating an existing campaign * * This method allows partial updates - only provided fields will be updated. * Validates the admin's capability before creating the transaction. * * @param {anchor.web3.PublicKey} admin - The admin's public key (must have admin role) * @param {TUpdateCampaignArgs} args - The campaign update parameters (all fields optional except IDs) * @returns {Promise} The prepared transaction * @throws {Error} If config or admin capability is not found * @example * const tx = await sdk.getUpdateCampaignTransaction(adminPubkey, { * configId: 0, * campaignId: 1, * status: Status.Inactive, * priceInLamports: new BN(2000000), * }); */ getUpdateCampaignTransaction(admin: anchor.web3.PublicKey, args: TUpdateCampaignArgs): Promise; /** * Creates a versioned transaction for granting a role to an account * * This creates a capability account that gives the specified account permission * to perform actions associated with the granted role (Admin or Operator). * * @param {anchor.web3.PublicKey} owner - The config owner's public key * @param {TGrantRoleArgs} args - The role grant parameters including account and role * @returns {Promise} The prepared transaction * @throws {Error} If config is not found * @example * const tx = await sdk.getGrantRoleTransaction(ownerPubkey, { * configId: 0, * accountToGrant: newAdminPubkey, * role: Role.Admin, * }); */ getGrantRoleTransaction(owner: anchor.web3.PublicKey, args: TGrantRoleArgs): Promise; /** * Creates a versioned transaction for revoking a role from an account * * This closes the capability account, removing the account's permission * to perform actions associated with the revoked role. * * @param {anchor.web3.PublicKey} owner - The config owner's public key * @param {TRevokeRoleArgs} args - The role revoke parameters including account and role * @returns {Promise} The prepared transaction * @throws {Error} If config is not found * @example * const tx = await sdk.getRevokeRoleTransaction(ownerPubkey, { * configId: 0, * accountToRevoke: oldAdminPubkey, * role: Role.Admin, * }); */ getRevokeRoleTransaction(owner: anchor.web3.PublicKey, args: TRevokeRoleArgs): Promise; /** * Checks if an account has a specific role * * This is a convenience method that fetches the capability and returns * a boolean indicating whether the account has the specified role. * * @param {number} configId - The configuration ID * @param {anchor.web3.PublicKey} account - The account to check * @param {Role} role - The role to check for * @returns {Promise} True if the account has the role, false otherwise * @example * const isAdmin = await sdk.hasRole(0, userPubkey, Role.Admin); * if (isAdmin) { * console.log("User has admin privileges"); * } */ hasRole(configId: number, account: anchor.web3.PublicKey, role: Role): Promise; /** * Creates a Version 0 transaction from instructions * * This is a helper method that compiles transaction instructions into a * versioned transaction with the latest blockhash. Optionally signs the * transaction with provided keypairs (e.g., for mint accounts). * * @param {anchor.web3.TransactionInstruction[]} ixs - Array of transaction instructions * @param {anchor.web3.PublicKey} payer - The transaction fee payer's public key * @param {anchor.web3.Keypair[]} [signers=[]] - Optional array of keypairs to sign the transaction * @returns {Promise} The compiled and optionally signed transaction * @example * const tx = await sdk.createAndSendV0Tx( * [instruction1, instruction2], * payerPubkey, * [mintKeypair] * ); */ createAndSendV0Tx(ixs: anchor.web3.TransactionInstruction[], payer: anchor.web3.PublicKey, signers?: anchor.web3.Keypair[]): Promise; /** * Confirms a transaction by polling for its status * * Continuously polls the transaction status until it reaches the desired * confirmation level or times out. Returns immediately if finalized. * * @param {anchor.web3.Connection} connection - The Solana connection to use * @param {anchor.web3.TransactionSignature} signature - The transaction signature to confirm * @param {anchor.web3.TransactionConfirmationStatus} [desiredConfirmationStatus="confirmed"] - The desired confirmation level (processed/confirmed/finalized) * @param {number} [timeout=30000] - Maximum time to wait in milliseconds * @param {number} [pollInterval=1000] - How often to check status in milliseconds * @param {boolean} [searchTransactionHistory=false] - Whether to search historical transactions * @returns {Promise} The transaction status once confirmed * @throws {Error} If transaction fails, status cannot be fetched, or confirmation times out * @example * const status = await sdk.confirmTransaction( * connection, * signature, * "finalized", * 60000 * ); */ confirmTransaction(connection: anchor.web3.Connection, signature: anchor.web3.TransactionSignature, desiredConfirmationStatus?: anchor.web3.TransactionConfirmationStatus, timeout?: number, pollInterval?: number, searchTransactionHistory?: boolean): Promise; /** * Sends a transaction to the network and waits for confirmation * * This is a convenience method that combines sending and confirming a transaction. * It will retry sending up to 5 times and wait for confirmation before returning. * * @param {anchor.web3.VersionedTransaction} transaction - The versioned transaction to send * @returns {Promise} Resolves when transaction is confirmed * @throws {Error} If transaction fails or cannot be confirmed * @example * const [tx] = await sdk.getCreateCampaignTransaction(admin, args); * // Sign the transaction with your wallet first * await sdk.sendAndConfirmTransaction(tx); * console.log("Campaign created successfully!"); */ sendAndConfirmTransaction(transaction: anchor.web3.VersionedTransaction): Promise; } //# sourceMappingURL=MoonshotBlindboxLegacy.d.ts.map