/** * 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 { OrderType, orderTypeBeet } from '../types/OrderType' import { FixedSize, fixedSizeBeet } from '../types/FixedSize' import { QuoteAsset, quoteAssetBeet } from '../types/QuoteAsset' import { StoredRfqState, storedRfqStateBeet } from '../types/StoredRfqState' import { Leg, legBeet } from '../types/Leg' /** * Arguments used to create {@link Rfq} * @category Accounts * @category generated */ export type RfqArgs = { taker: web3.PublicKey orderType: OrderType fixedSize: FixedSize quoteAsset: QuoteAsset creationTimestamp: beet.bignum activeWindow: number settlingWindow: number expectedLegsSize: number expectedLegsHash: number[] /* size: 32 */ state: StoredRfqState nonResponseTakerCollateralLocked: beet.bignum totalTakerCollateralLocked: beet.bignum totalResponses: number clearedResponses: number confirmedResponses: number whitelist: web3.PublicKey reserved: number[] /* size: 224 */ printTradeProvider: beet.COption legs: Leg[] } export const rfqDiscriminator = [106, 19, 109, 78, 169, 13, 234, 58] /** * Holds the data for the {@link Rfq} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ export class Rfq implements RfqArgs { private constructor( readonly taker: web3.PublicKey, readonly orderType: OrderType, readonly fixedSize: FixedSize, readonly quoteAsset: QuoteAsset, readonly creationTimestamp: beet.bignum, readonly activeWindow: number, readonly settlingWindow: number, readonly expectedLegsSize: number, readonly expectedLegsHash: number[] /* size: 32 */, readonly state: StoredRfqState, readonly nonResponseTakerCollateralLocked: beet.bignum, readonly totalTakerCollateralLocked: beet.bignum, readonly totalResponses: number, readonly clearedResponses: number, readonly confirmedResponses: number, readonly whitelist: web3.PublicKey, readonly reserved: number[] /* size: 224 */, readonly printTradeProvider: beet.COption, readonly legs: Leg[] ) {} /** * Creates a {@link Rfq} instance from the provided args. */ static fromArgs(args: RfqArgs) { return new Rfq( args.taker, args.orderType, args.fixedSize, args.quoteAsset, args.creationTimestamp, args.activeWindow, args.settlingWindow, args.expectedLegsSize, args.expectedLegsHash, args.state, args.nonResponseTakerCollateralLocked, args.totalTakerCollateralLocked, args.totalResponses, args.clearedResponses, args.confirmedResponses, args.whitelist, args.reserved, args.printTradeProvider, args.legs ) } /** * Deserializes the {@link Rfq} 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 ): [Rfq, number] { return Rfq.deserialize(accountInfo.data, offset) } /** * Retrieves the account info from the provided address and deserializes * the {@link Rfq} 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 Rfq account at ${address}`) } return Rfq.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, rfqBeet) } /** * Deserializes the {@link Rfq} 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): [Rfq, number] { return rfqBeet.deserialize(buf, offset) } /** * Serializes the {@link Rfq} 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 rfqBeet.serialize({ accountDiscriminator: rfqDiscriminator, ...this, }) } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link Rfq} for the provided args. * * @param args need to be provided since the byte size for this account * depends on them */ static byteSize(args: RfqArgs) { const instance = Rfq.fromArgs(args) return rfqBeet.toFixedFromValue({ accountDiscriminator: rfqDiscriminator, ...instance, }).byteSize } /** * Fetches the minimum balance needed to exempt an account holding * {@link Rfq} 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: RfqArgs, connection: web3.Connection, commitment?: web3.Commitment ): Promise { return connection.getMinimumBalanceForRentExemption( Rfq.byteSize(args), commitment ) } /** * Returns a readable version of {@link Rfq} properties * and can be used to convert to JSON and/or logging */ pretty() { return { taker: this.taker.toBase58(), orderType: 'OrderType.' + OrderType[this.orderType], fixedSize: this.fixedSize.__kind, quoteAsset: this.quoteAsset, creationTimestamp: (() => { const x = <{ toNumber: () => number }>this.creationTimestamp if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), activeWindow: this.activeWindow, settlingWindow: this.settlingWindow, expectedLegsSize: this.expectedLegsSize, expectedLegsHash: this.expectedLegsHash, state: 'StoredRfqState.' + StoredRfqState[this.state], nonResponseTakerCollateralLocked: (() => { const x = <{ toNumber: () => number }>( this.nonResponseTakerCollateralLocked ) if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), totalTakerCollateralLocked: (() => { const x = <{ toNumber: () => number }>this.totalTakerCollateralLocked if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), totalResponses: this.totalResponses, clearedResponses: this.clearedResponses, confirmedResponses: this.confirmedResponses, whitelist: this.whitelist.toBase58(), reserved: this.reserved, printTradeProvider: this.printTradeProvider, legs: this.legs, } } } /** * @category Accounts * @category generated */ export const rfqBeet = new beet.FixableBeetStruct< Rfq, RfqArgs & { accountDiscriminator: number[] /* size: 8 */ } >( [ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['taker', beetSolana.publicKey], ['orderType', orderTypeBeet], ['fixedSize', fixedSizeBeet], ['quoteAsset', quoteAssetBeet], ['creationTimestamp', beet.i64], ['activeWindow', beet.u32], ['settlingWindow', beet.u32], ['expectedLegsSize', beet.u16], ['expectedLegsHash', beet.uniformFixedSizeArray(beet.u8, 32)], ['state', storedRfqStateBeet], ['nonResponseTakerCollateralLocked', beet.u64], ['totalTakerCollateralLocked', beet.u64], ['totalResponses', beet.u32], ['clearedResponses', beet.u32], ['confirmedResponses', beet.u32], ['whitelist', beetSolana.publicKey], ['reserved', beet.uniformFixedSizeArray(beet.u8, 224)], ['printTradeProvider', beet.coption(beetSolana.publicKey)], ['legs', beet.array(legBeet)], ], Rfq.fromArgs, 'Rfq' )