/** * 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 '@convergence-rfq/beet' import * as beetSolana from '@convergence-rfq/beet-solana' import { FeeParameters, feeParametersBeet } from '../types/FeeParameters' import { PrintTradeProvider, printTradeProviderBeet, } from '../types/PrintTradeProvider' import { Instrument, instrumentBeet } from '../types/Instrument' /** * Arguments used to create {@link ProtocolState} * @category Accounts * @category generated */ export type ProtocolStateArgs = { authority: web3.PublicKey bump: number active: boolean settleFees: FeeParameters defaultFees: FeeParameters riskEngine: web3.PublicKey collateralMint: web3.PublicKey printTradeProviders: PrintTradeProvider[] instruments: Instrument[] assetAddFee: beet.bignum reserved: number[] /* size: 1016 */ } export const protocolStateDiscriminator = [33, 51, 173, 134, 35, 140, 195, 248] /** * Holds the data for the {@link ProtocolState} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ export class ProtocolState implements ProtocolStateArgs { private constructor( readonly authority: web3.PublicKey, readonly bump: number, readonly active: boolean, readonly settleFees: FeeParameters, readonly defaultFees: FeeParameters, readonly riskEngine: web3.PublicKey, readonly collateralMint: web3.PublicKey, readonly printTradeProviders: PrintTradeProvider[], readonly instruments: Instrument[], readonly assetAddFee: beet.bignum, readonly reserved: number[] /* size: 1016 */ ) {} /** * Creates a {@link ProtocolState} instance from the provided args. */ static fromArgs(args: ProtocolStateArgs) { return new ProtocolState( args.authority, args.bump, args.active, args.settleFees, args.defaultFees, args.riskEngine, args.collateralMint, args.printTradeProviders, args.instruments, args.assetAddFee, args.reserved ) } /** * Deserializes the {@link ProtocolState} 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 ): [ProtocolState, number] { return ProtocolState.deserialize(accountInfo.data, offset) } /** * Retrieves the account info from the provided address and deserializes * the {@link ProtocolState} 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 ProtocolState account at ${address}`) } return ProtocolState.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( 'FqAhTZg86EKEzeWMLtutVDRXJuLWrey7oDHr3Au6RFdo' ) ) { return beetSolana.GpaBuilder.fromStruct(programId, protocolStateBeet) } /** * Deserializes the {@link ProtocolState} 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): [ProtocolState, number] { return protocolStateBeet.deserialize(buf, offset) } /** * Serializes the {@link ProtocolState} 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 protocolStateBeet.serialize({ accountDiscriminator: protocolStateDiscriminator, ...this, }) } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link ProtocolState} for the provided args. * * @param args need to be provided since the byte size for this account * depends on them */ static byteSize(args: ProtocolStateArgs) { const instance = ProtocolState.fromArgs(args) return protocolStateBeet.toFixedFromValue({ accountDiscriminator: protocolStateDiscriminator, ...instance, }).byteSize } /** * Fetches the minimum balance needed to exempt an account holding * {@link ProtocolState} 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: ProtocolStateArgs, connection: web3.Connection, commitment?: web3.Commitment ): Promise { return connection.getMinimumBalanceForRentExemption( ProtocolState.byteSize(args), commitment ) } /** * Returns a readable version of {@link ProtocolState} properties * and can be used to convert to JSON and/or logging */ pretty() { return { authority: this.authority.toBase58(), bump: this.bump, active: this.active, settleFees: this.settleFees, defaultFees: this.defaultFees, riskEngine: this.riskEngine.toBase58(), collateralMint: this.collateralMint.toBase58(), printTradeProviders: this.printTradeProviders, instruments: this.instruments, assetAddFee: (() => { const x = <{ toNumber: () => number }>this.assetAddFee if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), reserved: this.reserved, } } } /** * @category Accounts * @category generated */ export const protocolStateBeet = new beet.FixableBeetStruct< ProtocolState, ProtocolStateArgs & { accountDiscriminator: number[] /* size: 8 */ } >( [ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['authority', beetSolana.publicKey], ['bump', beet.u8], ['active', beet.bool], ['settleFees', feeParametersBeet], ['defaultFees', feeParametersBeet], ['riskEngine', beetSolana.publicKey], ['collateralMint', beetSolana.publicKey], ['printTradeProviders', beet.array(printTradeProviderBeet)], ['instruments', beet.array(instrumentBeet)], ['assetAddFee', beet.u64], ['reserved', beet.uniformFixedSizeArray(beet.u8, 1016)], ], ProtocolState.fromArgs, 'ProtocolState' )