UNPKG

@metaplex-foundation/mpl-candy-machine-core

Version:

MPL Candy Machine Core JavaScript API. This MPL package is for the current generation of the Candy Machine Core (a.k.a. Candy Machine V3).

115 lines 5.09 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.candyMachineBeet = exports.CandyMachine = exports.candyMachineDiscriminator = void 0; const web3 = __importStar(require("@solana/web3.js")); const beet = __importStar(require("@metaplex-foundation/beet")); const beetSolana = __importStar(require("@metaplex-foundation/beet-solana")); const AccountVersion_1 = require("../types/AccountVersion"); const CandyMachineData_1 = require("../types/CandyMachineData"); exports.candyMachineDiscriminator = [51, 173, 177, 113, 25, 241, 109, 189]; class CandyMachine { constructor(version, tokenStandard, features, authority, mintAuthority, collectionMint, itemsRedeemed, data) { this.version = version; this.tokenStandard = tokenStandard; this.features = features; this.authority = authority; this.mintAuthority = mintAuthority; this.collectionMint = collectionMint; this.itemsRedeemed = itemsRedeemed; this.data = data; } static fromArgs(args) { return new CandyMachine(args.version, args.tokenStandard, args.features, args.authority, args.mintAuthority, args.collectionMint, args.itemsRedeemed, args.data); } static fromAccountInfo(accountInfo, offset = 0) { return CandyMachine.deserialize(accountInfo.data, offset); } static async fromAccountAddress(connection, address, commitmentOrConfig) { const accountInfo = await connection.getAccountInfo(address, commitmentOrConfig); if (accountInfo == null) { throw new Error(`Unable to find CandyMachine account at ${address}`); } return CandyMachine.fromAccountInfo(accountInfo, 0)[0]; } static gpaBuilder(programId = new web3.PublicKey('CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR')) { return beetSolana.GpaBuilder.fromStruct(programId, exports.candyMachineBeet); } static deserialize(buf, offset = 0) { return exports.candyMachineBeet.deserialize(buf, offset); } serialize() { return exports.candyMachineBeet.serialize({ accountDiscriminator: exports.candyMachineDiscriminator, ...this, }); } static byteSize(args) { const instance = CandyMachine.fromArgs(args); return exports.candyMachineBeet.toFixedFromValue({ accountDiscriminator: exports.candyMachineDiscriminator, ...instance, }).byteSize; } static async getMinimumBalanceForRentExemption(args, connection, commitment) { return connection.getMinimumBalanceForRentExemption(CandyMachine.byteSize(args), commitment); } pretty() { return { version: 'AccountVersion.' + AccountVersion_1.AccountVersion[this.version], tokenStandard: this.tokenStandard, features: this.features, authority: this.authority.toBase58(), mintAuthority: this.mintAuthority.toBase58(), collectionMint: this.collectionMint.toBase58(), itemsRedeemed: (() => { const x = this.itemsRedeemed; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), data: this.data, }; } } exports.CandyMachine = CandyMachine; exports.candyMachineBeet = new beet.FixableBeetStruct([ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['version', AccountVersion_1.accountVersionBeet], ['tokenStandard', beet.u8], ['features', beet.uniformFixedSizeArray(beet.u8, 6)], ['authority', beetSolana.publicKey], ['mintAuthority', beetSolana.publicKey], ['collectionMint', beetSolana.publicKey], ['itemsRedeemed', beet.u64], ['data', CandyMachineData_1.candyMachineDataBeet], ], CandyMachine.fromArgs, 'CandyMachine'); //# sourceMappingURL=CandyMachine.js.map