/** * 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' /** * Arguments used to create {@link MessageLib} * @category Accounts * @category generated */ export type MessageLibArgs = { eid: number endpoint: web3.PublicKey endpointProgram: web3.PublicKey bump: number admin: web3.PublicKey fee: beet.bignum lzTokenFee: beet.bignum wlCaller: web3.PublicKey } export const messageLibDiscriminator = [141, 191, 244, 48, 52, 174, 199, 209] /** * Holds the data for the {@link MessageLib} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ export class MessageLib implements MessageLibArgs { private constructor( readonly eid: number, readonly endpoint: web3.PublicKey, readonly endpointProgram: web3.PublicKey, readonly bump: number, readonly admin: web3.PublicKey, readonly fee: beet.bignum, readonly lzTokenFee: beet.bignum, readonly wlCaller: web3.PublicKey ) {} /** * Creates a {@link MessageLib} instance from the provided args. */ static fromArgs(args: MessageLibArgs) { return new MessageLib( args.eid, args.endpoint, args.endpointProgram, args.bump, args.admin, args.fee, args.lzTokenFee, args.wlCaller ) } /** * Deserializes the {@link MessageLib} 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 ): [MessageLib, number] { return MessageLib.deserialize(accountInfo.data, offset) } /** * Retrieves the account info from the provided address and deserializes * the {@link MessageLib} 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, commitmentOrConfig?: web3.Commitment | web3.GetAccountInfoConfig ): Promise { const accountInfo = await connection.getAccountInfo( address, commitmentOrConfig ) if (accountInfo == null) { throw new Error(`Unable to find MessageLib account at ${address}`) } return MessageLib.fromAccountInfo(accountInfo, 0)[0] } /** * Provides a {@link web3.Connection.getProgramAccounts} config builder, * to fetch accounts matching filters that can be specified via that builder. * * @param programId - the program that owns the accounts we are filtering */ static gpaBuilder( programId: web3.PublicKey = new web3.PublicKey( '6GsmxMTHAAiFKfemuM4zBjumTjNSX5CAiw4xSSXM2Toy' ) ) { return beetSolana.GpaBuilder.fromStruct(programId, messageLibBeet) } /** * Deserializes the {@link MessageLib} 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): [MessageLib, number] { return messageLibBeet.deserialize(buf, offset) } /** * Serializes the {@link MessageLib} 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 messageLibBeet.serialize({ accountDiscriminator: messageLibDiscriminator, ...this, }) } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link MessageLib} */ static get byteSize() { return messageLibBeet.byteSize } /** * Fetches the minimum balance needed to exempt an account holding * {@link MessageLib} 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( MessageLib.byteSize, commitment ) } /** * Determines if the provided {@link Buffer} has the correct byte size to * hold {@link MessageLib} data. */ static hasCorrectByteSize(buf: Buffer, offset = 0) { return buf.byteLength - offset === MessageLib.byteSize } /** * Returns a readable version of {@link MessageLib} properties * and can be used to convert to JSON and/or logging */ pretty() { return { eid: this.eid, endpoint: this.endpoint.toBase58(), endpointProgram: this.endpointProgram.toBase58(), bump: this.bump, admin: this.admin.toBase58(), fee: (() => { const x = <{ toNumber: () => number }>this.fee if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), lzTokenFee: (() => { const x = <{ toNumber: () => number }>this.lzTokenFee if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), wlCaller: this.wlCaller.toBase58(), } } } /** * @category Accounts * @category generated */ export const messageLibBeet = new beet.BeetStruct< MessageLib, MessageLibArgs & { accountDiscriminator: number[] /* size: 8 */ } >( [ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['eid', beet.u32], ['endpoint', beetSolana.publicKey], ['endpointProgram', beetSolana.publicKey], ['bump', beet.u8], ['admin', beetSolana.publicKey], ['fee', beet.u64], ['lzTokenFee', beet.u64], ['wlCaller', beetSolana.publicKey], ], MessageLib.fromArgs, 'MessageLib' )