UNPKG

@boxfish-studio/candymachine-client-sdk

Version:
542 lines (525 loc) 19.9 kB
import * as anchor from '@project-serum/anchor'; import { Program, BN, web3 } from '@project-serum/anchor'; import { PublicKey, Connection, TransactionInstruction, Commitment, Transaction, TransactionSignature, SignatureStatus, Keypair, Blockhash } from '@solana/web3.js'; /** * * Update a given candy machine with the new settings passed and cache. * At the end of the update, the updated cache can be downloaded. * @newSettings The new settings to update the candy machine with. * @candyMachinePubkey The public key of the candy machine to update. * @publicKey The public key of the authority of the candy machine * @treasuryWallet The public key of the treasury wallet * @anchorProgram The program that is used to update the candy machine. * @cache The cache to update the candy machine with. * @newAuthority (Optional) The new authority of the candy machine. */ declare function updateV2({ newSettings, candyMachinePubkey, publicKey, treasuryWallet, anchorProgram, cache, newAuthority, }: { newSettings: any; candyMachinePubkey: string | string[]; publicKey: PublicKey; treasuryWallet: PublicKey; anchorProgram: Program; cache: string; newAuthority: string; }): Promise<void>; type Account = string | string[] | undefined; /** * The Manifest object for a given asset. * This object holds the contents of the asset's JSON file. * Represented here in its minimal form. */ type Manifest = { image: string; animation_url: string; name: string; symbol: string; seller_fee_basis_points: number; properties: { files: Array<{ type: string; uri: string; }>; creators: Array<{ address: string; share: number; }>; }; }; type UnwrapPromise<T> = T extends Promise<infer Return> ? Return : T; type NumberToString<T extends number | string> = T extends infer T ? (T extends number ? string : T) : never; /** * Upload the NFTs and their metadata to the Arweave network. * @param walletKeyPair - keypair of the wallet to use for the mint transaction * @param anchorProgram - anchor program to use for the mint transaction * @param env - environment to use for the mint transaction (mainnet-beta, devnet, testnet) * @param image - image to upload * @param manifestBuffer - buffer of the manifest to upload * @param manifest - manifest to upload * @param index - index of the image to upload * @returns - The links for the manifest and the image in Arweave. */ declare function arweaveUpload(walletKeyPair: any, anchorProgram: anchor.Program, env: string, image: File, manifestBuffer: Buffer, manifest: Manifest, index: number): Promise<string[]>; declare enum StorageType { ArweaveBundle = "arweave-bundle", ArweaveSol = "arweave-sol", Arweave = "arweave", Ipfs = "ipfs", Aws = "aws", NftStorage = "nft-storage", Pinata = "pinata" } declare const SUPPORTED_IMAGE_TYPES: string[]; declare const SUPPORTED_ANIMATION_TYPES: string[]; declare const DEFAULT_GATEKEEPER: { gatekeeperNetwork: string; expireOnUse: boolean; }; declare const JSON_EXTENSION = "application/json"; declare const DEFAULT_TIMEOUT = 30000; declare const NOTIFICATION_TIMEOUT_NEVER = -1; declare const NOTIFICATION_TIMEOUT_DEFAULT = 5000; declare const CANDY_MACHINE = "candy_machine"; declare const AUCTION_HOUSE = "auction_house"; declare const TOKEN_ENTANGLER = "token_entangler"; declare const ESCROW = "escrow"; declare const A = "A"; declare const B = "B"; declare const FEE_PAYER = "fee_payer"; declare const TREASURY = "treasury"; declare const MAX_NAME_LENGTH = 32; declare const MAX_URI_LENGTH = 200; declare const MAX_SYMBOL_LENGTH = 10; declare const MAX_CREATOR_LEN: number; declare const MAX_CREATOR_LIMIT = 5; declare const ARWEAVE_PAYMENT_WALLET: PublicKey; declare const CANDY_MACHINE_PROGRAM_ID: PublicKey; declare const CANDY_MACHINE_PROGRAM_V2_ID: PublicKey; declare const TOKEN_METADATA_PROGRAM_ID: PublicKey; declare const SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID: PublicKey; declare const TOKEN_PROGRAM_ID: PublicKey; declare const FAIR_LAUNCH_PROGRAM_ID: PublicKey; declare const AUCTION_HOUSE_PROGRAM_ID: PublicKey; declare const TOKEN_ENTANGLEMENT_PROGRAM_ID: PublicKey; declare const WRAPPED_SOL_MINT: PublicKey; declare const ARWEAVE_UPLOAD_ENDPOINT = "https://us-central1-metaplex-studios.cloudfunctions.net/uploadFile"; declare const CONFIG_ARRAY_START: number; declare const CONFIG_ARRAY_START_V2: number; declare const CONFIG_LINE_SIZE_V2: number; declare const CONFIG_LINE_SIZE: number; declare const CACHE_PATH = "./.cache"; interface IWhitelistMintSettings { mode: any; mint: PublicKey; presale: boolean; discountPrice: null | BN; } interface IHiddenSettings { name: string; uri: string; hash: Uint8Array; } interface IWhitelistMintMode { neverBurn: undefined | boolean; burnEveryTime: undefined | boolean; } interface IFetchedCandyMachineConfig { creators: { address: PublicKey; share: 100; verified: true; }[]; endSettings: null; gatekeeper: null; goLiveDate: BN; hiddenSettings: null; isMutable: true; itemsAvailable: BN; maxSupply: BN; price: BN; retainAuthority: boolean; sellerFeeBasisPoints: number; symbol: string; uuid: string; whitelistMintSettings: null; solTreasuryAccount: PublicKey; itemsRedeemed: BN; } interface ICandyMachineConfig { price: number; number: number; gatekeeper: typeof DEFAULT_GATEKEEPER | null; solTreasuryAccount: string; splTokenAccount: null; splToken: null; goLiveDate: string; endSettings: any; whitelistMintSettings: IWhitelistMintSettings | null; hiddenSettings: IHiddenSettings | null; storage: StorageType; ipfsInfuraProjectId: null; ipfsInfuraSecret: null; nftStorageKey: null; awsS3Bucket: null; noRetainAuthority: boolean; noMutable: boolean; pinataJwt: null; pinataGateway: null; batchSize: null; uuid: null; arweaveJwk: null; } interface ICandyMachineData { itemsAvailable: BN; uuid: null | string; symbol: string; sellerFeeBasisPoints: number; isMutable: boolean; maxSupply: BN; price: BN; retainAuthority: boolean; gatekeeper: null | { expireOnUse: boolean; gatekeeperNetwork: PublicKey; }; goLiveDate: null | BN; endSettings: null | [number, BN]; whitelistMintSettings: null | { mode: IWhitelistMintMode; mint: PublicKey; presale: boolean; discountPrice: null | BN; }; hiddenSettings: null | { name: string; uri: string; hash: Uint8Array; }; creators: { address: PublicKey; verified: boolean; share: number; }[]; } type SetupState = { mint: web3.Keypair; userTokenAccount: web3.PublicKey; transaction: string; }; interface CandyMachineAccount { id: web3.PublicKey; program: Program; state: CandyMachineState; } interface CandyMachineState { authority: web3.PublicKey; itemsAvailable: number; itemsRedeemed: number; itemsRemaining: number; treasury: web3.PublicKey; tokenMint: null | web3.PublicKey; isSoldOut: boolean; isActive: boolean; isPresale: boolean; isWhitelistOnly: boolean; goLiveDate: BN; price: BN; gatekeeper: null | { expireOnUse: boolean; gatekeeperNetwork: web3.PublicKey; }; endSettings: null | { number: BN; endSettingType: any; }; whitelistMintSettings: IWhitelistMintSettings; hiddenSettings: IHiddenSettings; retainAuthority: boolean; } interface CollectionData { mint: web3.PublicKey; candyMachine: web3.PublicKey; } /** * Load the candy program v2.. * @param provider The anchor provider. * @param customRpcUrl (Optional) The custom rpc url of the candy machine. * @returns The IDL. * */ declare function loadCandyProgramV2(provider: anchor.Provider, customRpcUrl?: string): Promise<anchor.Program<anchor.Idl>>; /** * Get the candy machine settings. * @param walletKeyPair The wallet key pair. * @param configForm The config form. * @param anchorProgram The anchor program. * @returns The settings of the candy machine. */ declare function getCandyMachineV2Config(walletKeyPair: PublicKey, configForm: ICandyMachineConfig, anchorProgram: anchor.Program<anchor.Idl>): Promise<{ storage: StorageType; nftStorageKey: string | null; ipfsInfuraProjectId: string | null; number: number; ipfsInfuraSecret: string | null; pinataJwt: string | null; pinataGateway: string | null; awsS3Bucket: string | null; retainAuthority: boolean; mutable: boolean; batchSize: number | null; price: anchor.BN; treasuryWallet: PublicKey; splToken: PublicKey | null; gatekeeper: null | { expireOnUse: boolean; gatekeeperNetwork: PublicKey; }; endSettings: null | [number, anchor.BN]; whitelistMintSettings: null | { mode: any; mint: PublicKey; presale: boolean; discountPrice: null | anchor.BN; }; hiddenSettings: null | { name: string; uri: string; hash: Uint8Array; }; goLiveDate: anchor.BN | null; uuid: string | null; arweaveJwk: string | null; }>; /** * @typedef {Object} VerifiedAssets * @property {File[]} supportedFiles how the person is called * @property {number} elemCount how many years the person lived */ /** * * @param files : list of files to analuze (json+image) * @param storage : Storage to use * @param number :number of assets * @returns {VerifiedAssets} returns an array of verified assets and the number of assets */ declare function verifyAssets(files: File[], storage: StorageType, number: number): { supportedFiles: File[]; elemCount: number; }; /** * Parse a date. * @param date The date to parse. * @returns The parsed date. */ declare function parseDate(date: string): number; declare function sleep(milliseconds: number): Promise<void>; declare function uuidFromConfigPubkey(configAccount: PublicKey): string; /** * Create a candy machine v2. * @param anchorProgram The anchor program to use. * @param payerWallet The payer wallet to use. * @param treasuryWallet The treasury wallet to use. * @param candyData The candy machine data to use. * @returns The config account. */ declare const createCandyMachineV2: (anchorProgram: anchor.Program, payerWallet: any, treasuryWallet: PublicKey, candyData: ICandyMachineData) => Promise<{ candyMachine: anchor.web3.PublicKey; uuid: string; txId: string; }>; /** * Create a candy machine v2 account. * @param anchorProgram The anchor program to use. * @param candyData The candy machine data to use. * @param payerWallet The payer wallet to use. * @param candyAccount The candy machine account to use. * @returns The instruction to create the candy machine account. */ declare function createCandyMachineV2Account(anchorProgram: anchor.Program, candyData: ICandyMachineData, payerWallet: PublicKey, candyAccount: PublicKey): Promise<anchor.web3.TransactionInstruction>; declare const getUnixTs: () => number; declare const getFileName: (fileName: string) => string; declare const getFileExtension: (fileName: string) => string; interface IBlockhashAndFeeCalculator { blockhash: Blockhash; lastValidBlockHeight: number; } /** * Attempt to send a transaction to the network. * @param connection The connection to the cluster. * @param wallet The wallet to use for signing. * @param instructions The instructions to sign. * @param commitment The commitment to use for the transaction. * @param block The blockhash to use for the transaction. * @param beforeSend The function to call before sending the transaction. * @returns The transaction signature. */ declare const sendTransactionWithRetryWithKeypair: (connection: Connection, wallet: any, instructions: TransactionInstruction[], commitment?: Commitment, block?: IBlockhashAndFeeCalculator, beforeSend?: () => void) => Promise<{ txid: string; slot: number; }>; /** * Attempt to send a signed transaction to the network. * @param signedTransaction The signed transaction to send. * @param connection The connection to the cluster. * @returns The transaction id and slot. */ declare function sendSignedTransaction({ signedTransaction, connection, timeout, }: { signedTransaction: Transaction; connection: Connection; sendingMessage?: string; sentMessage?: string; successMessage?: string; timeout?: number; }): Promise<{ txid: string; slot: number; }>; /** * Wait for a transaction to be confirmed. * @param txid The transaction id to await confirmation for. * @param timeout The timeout in milliseconds. * @param connection The connection to the cluster. * @param commitment The commitment to use for the transaction. * @param queryStatus Whether to query the status of the transaction. * @returns The transaction signature. */ declare function awaitTransactionSignatureConfirmation(txid: TransactionSignature, timeout: number, connection: Connection, commitment?: Commitment, queryStatus?: boolean): Promise<SignatureStatus | null | void>; declare enum SequenceType { Sequential = 0, Parallel = 1, StopOnFailure = 2 } /** * Execute a sequence of transactions. * @returns The transaction signature. */ declare const sendTransactions: (connection: Connection, wallet: any, instructionSet: TransactionInstruction[][], signersSet: Keypair[][], sequenceType?: SequenceType, commitment?: Commitment, successCallback?: (txid: string, ind: number) => void, failCallback?: (reason: string, ind: number) => boolean, block?: IBlockhashAndFeeCalculator, beforeTransactions?: Transaction[], afterTransactions?: Transaction[]) => Promise<{ number: number; txs: { txid: string; slot: number; }[]; }>; type Env = 'mainnet-beta' | 'devnet'; /** * * Upload a new candy machine with the settings passed and cache. * At the end of the upload, the cache can be downloaded. */ declare function uploadV2({ files, cacheName, env, totalNFTs, storage, retainAuthority, mutable, batchSize, price, treasuryWallet, gatekeeper, goLiveDate, endSettings, whitelistMintSettings, hiddenSettings, walletKeyPair, anchorProgram, rateLimit, }: { files: File[]; cacheName: string; env: Env; totalNFTs: number; storage: string; retainAuthority: boolean; mutable: boolean; batchSize: number | null; price: BN; treasuryWallet: PublicKey; gatekeeper: null | { expireOnUse: boolean; gatekeeperNetwork: web3.PublicKey; }; goLiveDate: null | BN; endSettings: null | [number, BN]; whitelistMintSettings: null | { mode: any; mint: PublicKey; presale: boolean; discountPrice: null | BN; }; hiddenSettings: null | { name: string; uri: string; hash: Uint8Array; }; walletKeyPair: any; anchorProgram: Program; rateLimit: number | null; }): Promise<boolean | string>; /** * Returns a Manifest from a path and an assetKey * Replaces image.ext => index.ext * Replaces animation_url.ext => index.ext */ declare function getAssetManifest(assetIndex: string, manifest: Manifest): Manifest; interface ICache { authority?: string; program: { uuid: string; candyMachine: string; }; items: Record<NumberToString<number | string>, { link: string; imageLink: string; name: string; onChain: boolean; verifyRun?: boolean; }>; startDate: BN | null; env: string; cacheName: string; } /** * Save the cache to the cache path. * @param cacheName The name of the cache to save. * @param env The environment used 'mainnet-beta' | 'devnet' | 'testnet' * @param cacheContent The content of the cache to save. */ declare function saveCache(cacheName: string, env: string, cacheContent: ICache): void; /** * Get the associated token account from a mint and the owner. * * @param mint The mint to get the associated token account of. * @param buyer The owner of the associated token account. * @returns The associated token account */ declare const getAtaForMint: (mint: web3.PublicKey, buyer: web3.PublicKey) => Promise<[web3.PublicKey, number]>; /** * Get the mint metadata. * * @param mint The mint to get the metadata of. * @returns The mint metadata. * */ declare const getMetadata: (mint: web3.PublicKey) => Promise<web3.PublicKey>; /** * Get the mint edition. * @param mint The mint to get the edition of. * @returns The mint edition. * **/ declare const getMasterEdition: (mint: web3.PublicKey) => Promise<web3.PublicKey>; /** * Get the creator of a candy machine. * @param candyMachine The candy machine to get the mint of. * @returns The creator of the Candy Machine. */ declare const getCandyMachineCreator: (candyMachine: web3.PublicKey) => Promise<[web3.PublicKey, number]>; /** * Get the collection PDA from a Candy Machine Account. * @param candyMachineAddress The address of the candy machine. * @returns The collection PDA from a candy Machine */ declare const getCollectionPDA: (candyMachineAddress: web3.PublicKey) => Promise<[web3.PublicKey, number]>; /** * Create the associated token account for a mint. * @param candyMachine The candy machine to get the mint of. * @param payer The payer to pay for the transaction. * @returns The associated token account for a mint. */ declare const createAccountsForMint: (candyMachine: CandyMachineAccount | undefined, payer: web3.PublicKey) => Promise<SetupState | undefined>; type MintResult = { mintTxId: string; metadataKey: web3.PublicKey; }; /** * Attempt to mint one nft. * @param candyMachine The candy machine to mint to. * @param payer The payer to pay for the transaction. * @param beforeTransactions The transactions to run before minting. * @param afterTransactions The transactions to run after minting. * @param setupState The setup state to use. * @returns The mint result. */ declare const mintOneNft: (candyMachine: CandyMachineAccount | undefined, payer: web3.PublicKey, beforeTransactions?: Transaction[], afterTransactions?: Transaction[], setupState?: SetupState) => Promise<MintResult | null>; export { A, ARWEAVE_PAYMENT_WALLET, ARWEAVE_UPLOAD_ENDPOINT, AUCTION_HOUSE, AUCTION_HOUSE_PROGRAM_ID, Account, B, CACHE_PATH, CANDY_MACHINE, CANDY_MACHINE_PROGRAM_ID, CANDY_MACHINE_PROGRAM_V2_ID, CONFIG_ARRAY_START, CONFIG_ARRAY_START_V2, CONFIG_LINE_SIZE, CONFIG_LINE_SIZE_V2, CandyMachineAccount, CollectionData, DEFAULT_GATEKEEPER, DEFAULT_TIMEOUT, ESCROW, FAIR_LAUNCH_PROGRAM_ID, FEE_PAYER, ICache, ICandyMachineConfig, ICandyMachineData, IFetchedCandyMachineConfig, JSON_EXTENSION, MAX_CREATOR_LEN, MAX_CREATOR_LIMIT, MAX_NAME_LENGTH, MAX_SYMBOL_LENGTH, MAX_URI_LENGTH, Manifest, NOTIFICATION_TIMEOUT_DEFAULT, NOTIFICATION_TIMEOUT_NEVER, NumberToString, SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID, SUPPORTED_ANIMATION_TYPES, SUPPORTED_IMAGE_TYPES, SequenceType, SetupState, StorageType, TOKEN_ENTANGLEMENT_PROGRAM_ID, TOKEN_ENTANGLER, TOKEN_METADATA_PROGRAM_ID, TOKEN_PROGRAM_ID, TREASURY, UnwrapPromise, WRAPPED_SOL_MINT, arweaveUpload, awaitTransactionSignatureConfirmation, createAccountsForMint, createCandyMachineV2, createCandyMachineV2Account, getAssetManifest, getAtaForMint, getCandyMachineCreator, getCandyMachineV2Config, getCollectionPDA, getFileExtension, getFileName, getMasterEdition, getMetadata, getUnixTs, loadCandyProgramV2, mintOneNft, parseDate, saveCache, sendSignedTransaction, sendTransactionWithRetryWithKeypair, sendTransactions, sleep, updateV2, uploadV2, uuidFromConfigPubkey, verifyAssets };