/** * 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 { BaseAssetIndex, baseAssetIndexBeet } from '../types/BaseAssetIndex' import { RiskCategory, riskCategoryBeet } from '../types/RiskCategory' import { OracleSource, oracleSourceBeet } from '../types/OracleSource' /** * Arguments used to create {@link BaseAssetInfo} * @category Accounts * @category generated */ export type BaseAssetInfoArgs = { bump: number index: BaseAssetIndex enabled: boolean riskCategory: RiskCategory oracleSource: OracleSource switchboardOracle: web3.PublicKey pythOracle: web3.PublicKey inPlacePrice: number nonStrict: boolean reserved: number[] /* size: 159 */ ticker: string } export const baseAssetInfoDiscriminator = [3, 254, 100, 55, 115, 255, 7, 23] /** * Holds the data for the {@link BaseAssetInfo} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ export class BaseAssetInfo implements BaseAssetInfoArgs { private constructor( readonly bump: number, readonly index: BaseAssetIndex, readonly enabled: boolean, readonly riskCategory: RiskCategory, readonly oracleSource: OracleSource, readonly switchboardOracle: web3.PublicKey, readonly pythOracle: web3.PublicKey, readonly inPlacePrice: number, readonly nonStrict: boolean, readonly reserved: number[] /* size: 159 */, readonly ticker: string ) {} /** * Creates a {@link BaseAssetInfo} instance from the provided args. */ static fromArgs(args: BaseAssetInfoArgs) { return new BaseAssetInfo( args.bump, args.index, args.enabled, args.riskCategory, args.oracleSource, args.switchboardOracle, args.pythOracle, args.inPlacePrice, args.nonStrict, args.reserved, args.ticker ) } /** * Deserializes the {@link BaseAssetInfo} 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 ): [BaseAssetInfo, number] { return BaseAssetInfo.deserialize(accountInfo.data, offset) } /** * Retrieves the account info from the provided address and deserializes * the {@link BaseAssetInfo} 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 BaseAssetInfo account at ${address}`) } return BaseAssetInfo.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, baseAssetInfoBeet) } /** * Deserializes the {@link BaseAssetInfo} 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): [BaseAssetInfo, number] { return baseAssetInfoBeet.deserialize(buf, offset) } /** * Serializes the {@link BaseAssetInfo} 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 baseAssetInfoBeet.serialize({ accountDiscriminator: baseAssetInfoDiscriminator, ...this, }) } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link BaseAssetInfo} for the provided args. * * @param args need to be provided since the byte size for this account * depends on them */ static byteSize(args: BaseAssetInfoArgs) { const instance = BaseAssetInfo.fromArgs(args) return baseAssetInfoBeet.toFixedFromValue({ accountDiscriminator: baseAssetInfoDiscriminator, ...instance, }).byteSize } /** * Fetches the minimum balance needed to exempt an account holding * {@link BaseAssetInfo} 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: BaseAssetInfoArgs, connection: web3.Connection, commitment?: web3.Commitment ): Promise { return connection.getMinimumBalanceForRentExemption( BaseAssetInfo.byteSize(args), commitment ) } /** * Returns a readable version of {@link BaseAssetInfo} properties * and can be used to convert to JSON and/or logging */ pretty() { return { bump: this.bump, index: this.index, enabled: this.enabled, riskCategory: 'RiskCategory.' + RiskCategory[this.riskCategory], oracleSource: 'OracleSource.' + OracleSource[this.oracleSource], switchboardOracle: this.switchboardOracle.toBase58(), pythOracle: this.pythOracle.toBase58(), inPlacePrice: this.inPlacePrice, nonStrict: this.nonStrict, reserved: this.reserved, ticker: this.ticker, } } } /** * @category Accounts * @category generated */ export const baseAssetInfoBeet = new beet.FixableBeetStruct< BaseAssetInfo, BaseAssetInfoArgs & { accountDiscriminator: number[] /* size: 8 */ } >( [ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['bump', beet.u8], ['index', baseAssetIndexBeet], ['enabled', beet.bool], ['riskCategory', riskCategoryBeet], ['oracleSource', oracleSourceBeet], ['switchboardOracle', beetSolana.publicKey], ['pythOracle', beetSolana.publicKey], ['inPlacePrice', beet.f64], ['nonStrict', beet.bool], ['reserved', beet.uniformFixedSizeArray(beet.u8, 159)], ['ticker', beet.utf8String], ], BaseAssetInfo.fromArgs, 'BaseAssetInfo' )