/** * 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 { Key, keyBeet } from '../types/Key'; import { VaultState, vaultStateBeet } from '../types/VaultState'; /** * Arguments used to create {@link Vault} * @category Accounts * @category generated */ export type VaultArgs = { key: Key; tokenProgram: web3.PublicKey; fractionMint: web3.PublicKey; authority: web3.PublicKey; fractionTreasury: web3.PublicKey; redeemTreasury: web3.PublicKey; allowFurtherShareCreation: boolean; pricingLookupAddress: web3.PublicKey; tokenTypeCount: number; state: VaultState; lockedPricePerShare: beet.bignum; extraByte: number; }; /** * Holds the data for the {@link Vault} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ export class Vault implements VaultArgs { private constructor( readonly key: Key, readonly tokenProgram: web3.PublicKey, readonly fractionMint: web3.PublicKey, readonly authority: web3.PublicKey, readonly fractionTreasury: web3.PublicKey, readonly redeemTreasury: web3.PublicKey, readonly allowFurtherShareCreation: boolean, readonly pricingLookupAddress: web3.PublicKey, readonly tokenTypeCount: number, readonly state: VaultState, readonly lockedPricePerShare: beet.bignum, readonly extraByte: number, ) {} /** * Creates a {@link Vault} instance from the provided args. */ static fromArgs(args: VaultArgs) { return new Vault( args.key, args.tokenProgram, args.fractionMint, args.authority, args.fractionTreasury, args.redeemTreasury, args.allowFurtherShareCreation, args.pricingLookupAddress, args.tokenTypeCount, args.state, args.lockedPricePerShare, args.extraByte, ); } /** * Deserializes the {@link Vault} 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): [Vault, number] { return Vault.deserialize(accountInfo.data, offset); } /** * Retrieves the account info from the provided address and deserializes * the {@link Vault} 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 Vault account at ${address}`); } return Vault.fromAccountInfo(accountInfo, 0)[0]; } /** * Deserializes the {@link Vault} 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): [Vault, number] { return vaultBeet.deserialize(buf, offset); } /** * Serializes the {@link Vault} 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 vaultBeet.serialize(this); } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link Vault} */ static get byteSize() { return vaultBeet.byteSize; } /** * Fetches the minimum balance needed to exempt an account holding * {@link Vault} data from rent * * @param connection used to retrieve the rent exemption information */ static async getMinimumBalanceForRentExemption( connection: web3.Connection, commitment?: web3.Commitment, ): Promise { return connection.getMinimumBalanceForRentExemption(Vault.byteSize, commitment); } /** * Determines if the provided {@link Buffer} has the correct byte size to * hold {@link Vault} data. */ static hasCorrectByteSize(buf: Buffer, offset = 0) { return buf.byteLength - offset === Vault.byteSize; } /** * Returns a readable version of {@link Vault} properties * and can be used to convert to JSON and/or logging */ pretty() { return { key: 'Key.' + Key[this.key], tokenProgram: this.tokenProgram.toBase58(), fractionMint: this.fractionMint.toBase58(), authority: this.authority.toBase58(), fractionTreasury: this.fractionTreasury.toBase58(), redeemTreasury: this.redeemTreasury.toBase58(), allowFurtherShareCreation: this.allowFurtherShareCreation, pricingLookupAddress: this.pricingLookupAddress.toBase58(), tokenTypeCount: this.tokenTypeCount, state: 'VaultState.' + VaultState[this.state], lockedPricePerShare: this.lockedPricePerShare, extraByte: this.extraByte, }; } } /** * @category Accounts * @category generated */ export const vaultBeet = new beet.BeetStruct( [ ['key', keyBeet], ['tokenProgram', beetSolana.publicKey], ['fractionMint', beetSolana.publicKey], ['authority', beetSolana.publicKey], ['fractionTreasury', beetSolana.publicKey], ['redeemTreasury', beetSolana.publicKey], ['allowFurtherShareCreation', beet.bool], ['pricingLookupAddress', beetSolana.publicKey], ['tokenTypeCount', beet.u8], ['state', vaultStateBeet], ['lockedPricePerShare', beet.u64], ['extraByte', beet.u8], ], Vault.fromArgs, 'Vault', );