/** * This code was GENERATED using the solita package. * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. * * See: https://github.com/metaplex-foundation/solita */ import * as web3 from '@solana/web3.js'; import * as beet from '@metaplex-foundation/beet'; import * as beetSolana from '@metaplex-foundation/beet-solana'; import { MarketState, marketStateBeet } from '../types/MarketState'; import { GatingConfig, gatingConfigBeet } from '../types/GatingConfig'; /** * Arguments used to create {@link Market} * @category Accounts * @category generated */ export type MarketArgs = { store: web3.PublicKey; sellingResource: web3.PublicKey; treasuryMint: web3.PublicKey; treasuryHolder: web3.PublicKey; treasuryOwner: web3.PublicKey; owner: web3.PublicKey; name: string; description: string; mutable: boolean; price: beet.bignum; piecesInOneWallet: beet.COption; startDate: beet.bignum; endDate: beet.COption; state: MarketState; fundsCollected: beet.bignum; gatekeeper: beet.COption; }; const marketDiscriminator = [219, 190, 213, 55, 0, 227, 198, 154]; /** * Holds the data for the {@link Market} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ export class Market implements MarketArgs { private constructor( readonly store: web3.PublicKey, readonly sellingResource: web3.PublicKey, readonly treasuryMint: web3.PublicKey, readonly treasuryHolder: web3.PublicKey, readonly treasuryOwner: web3.PublicKey, readonly owner: web3.PublicKey, readonly name: string, readonly description: string, readonly mutable: boolean, readonly price: beet.bignum, readonly piecesInOneWallet: beet.COption, readonly startDate: beet.bignum, readonly endDate: beet.COption, readonly state: MarketState, readonly fundsCollected: beet.bignum, readonly gatekeeper: beet.COption, ) {} /** * Creates a {@link Market} instance from the provided args. */ static fromArgs(args: MarketArgs) { return new Market( args.store, args.sellingResource, args.treasuryMint, args.treasuryHolder, args.treasuryOwner, args.owner, args.name, args.description, args.mutable, args.price, args.piecesInOneWallet, args.startDate, args.endDate, args.state, args.fundsCollected, args.gatekeeper, ); } /** * Deserializes the {@link Market} from the data of the provided {@link web3.AccountInfo}. * @returns a tuple of the account data and the offset up to which the buffer was read to obtain it. */ static fromAccountInfo(accountInfo: web3.AccountInfo, offset = 0): [Market, number] { return Market.deserialize(accountInfo.data, offset); } /** * Retrieves the account info from the provided address and deserializes * the {@link Market} from its data. * * @throws Error if no account info is found at the address or if deserialization fails */ static async fromAccountAddress( connection: web3.Connection, address: web3.PublicKey, ): Promise { const accountInfo = await connection.getAccountInfo(address); if (accountInfo == null) { throw new Error(`Unable to find Market account at ${address}`); } return Market.fromAccountInfo(accountInfo, 0)[0]; } /** * Deserializes the {@link Market} from the provided data Buffer. * @returns a tuple of the account data and the offset up to which the buffer was read to obtain it. */ static deserialize(buf: Buffer, offset = 0): [Market, number] { return marketBeet.deserialize(buf, offset); } /** * Serializes the {@link Market} into a Buffer. * @returns a tuple of the created Buffer and the offset up to which the buffer was written to store it. */ serialize(): [Buffer, number] { return marketBeet.serialize({ accountDiscriminator: marketDiscriminator, ...this, }); } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link Market} for the provided args. * * @param args need to be provided since the byte size for this account * depends on them */ static byteSize(args: MarketArgs) { const instance = Market.fromArgs(args); return marketBeet.toFixedFromValue({ accountDiscriminator: marketDiscriminator, ...instance, }).byteSize; } /** * Fetches the minimum balance needed to exempt an account holding * {@link Market} data from rent * * @param args need to be provided since the byte size for this account * depends on them * @param connection used to retrieve the rent exemption information */ static async getMinimumBalanceForRentExemption( args: MarketArgs, connection: web3.Connection, commitment?: web3.Commitment, ): Promise { return connection.getMinimumBalanceForRentExemption(Market.byteSize(args), commitment); } /** * Returns a readable version of {@link Market} properties * and can be used to convert to JSON and/or logging */ pretty() { return { store: this.store.toBase58(), sellingResource: this.sellingResource.toBase58(), treasuryMint: this.treasuryMint.toBase58(), treasuryHolder: this.treasuryHolder.toBase58(), treasuryOwner: this.treasuryOwner.toBase58(), owner: this.owner.toBase58(), name: this.name, description: this.description, mutable: this.mutable, price: this.price, piecesInOneWallet: this.piecesInOneWallet, startDate: this.startDate, endDate: this.endDate, state: 'MarketState.' + MarketState[this.state], fundsCollected: this.fundsCollected, gatekeeper: this.gatekeeper, }; } } /** * @category Accounts * @category generated */ export const marketBeet = new beet.FixableBeetStruct< Market, MarketArgs & { accountDiscriminator: number[] /* size: 8 */; } >( [ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['store', beetSolana.publicKey], ['sellingResource', beetSolana.publicKey], ['treasuryMint', beetSolana.publicKey], ['treasuryHolder', beetSolana.publicKey], ['treasuryOwner', beetSolana.publicKey], ['owner', beetSolana.publicKey], ['name', beet.utf8String], ['description', beet.utf8String], ['mutable', beet.bool], ['price', beet.u64], ['piecesInOneWallet', beet.coption(beet.u64)], ['startDate', beet.u64], ['endDate', beet.coption(beet.u64)], ['state', marketStateBeet], ['fundsCollected', beet.u64], ['gatekeeper', beet.coption(gatingConfigBeet)], ], Market.fromArgs, 'Market', );