/** * 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 { StoredResponseState, storedResponseStateBeet, } from '../types/StoredResponseState' import { Confirmation, confirmationBeet } from '../types/Confirmation' import { DefaultingParty, defaultingPartyBeet } from '../types/DefaultingParty' import { AuthoritySide, authoritySideBeet } from '../types/AuthoritySide' import { Quote, quoteBeet } from '../types/Quote' /** * Arguments used to create {@link Response} * @category Accounts * @category generated */ export type ResponseArgs = { maker: web3.PublicKey rfq: web3.PublicKey creationTimestamp: beet.bignum expirationTimestamp: beet.bignum makerCollateralLocked: beet.bignum takerCollateralLocked: beet.bignum state: StoredResponseState takerPreparedCounter: number makerPreparedCounter: number settledEscrowLegs: number reserved: number[] /* size: 256 */ confirmed: beet.COption defaultingParty: beet.COption printTradeInitializedBy: beet.COption escrowLegPreparationsInitializedBy: AuthoritySide[] bid: beet.COption ask: beet.COption additionalData: Uint8Array } export const responseDiscriminator = [198, 155, 246, 149, 75, 240, 81, 122] /** * Holds the data for the {@link Response} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ export class Response implements ResponseArgs { private constructor( readonly maker: web3.PublicKey, readonly rfq: web3.PublicKey, readonly creationTimestamp: beet.bignum, readonly expirationTimestamp: beet.bignum, readonly makerCollateralLocked: beet.bignum, readonly takerCollateralLocked: beet.bignum, readonly state: StoredResponseState, readonly takerPreparedCounter: number, readonly makerPreparedCounter: number, readonly settledEscrowLegs: number, readonly reserved: number[] /* size: 256 */, readonly confirmed: beet.COption, readonly defaultingParty: beet.COption, readonly printTradeInitializedBy: beet.COption, readonly escrowLegPreparationsInitializedBy: AuthoritySide[], readonly bid: beet.COption, readonly ask: beet.COption, readonly additionalData: Uint8Array ) {} /** * Creates a {@link Response} instance from the provided args. */ static fromArgs(args: ResponseArgs) { return new Response( args.maker, args.rfq, args.creationTimestamp, args.expirationTimestamp, args.makerCollateralLocked, args.takerCollateralLocked, args.state, args.takerPreparedCounter, args.makerPreparedCounter, args.settledEscrowLegs, args.reserved, args.confirmed, args.defaultingParty, args.printTradeInitializedBy, args.escrowLegPreparationsInitializedBy, args.bid, args.ask, args.additionalData ) } /** * Deserializes the {@link Response} 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 ): [Response, number] { return Response.deserialize(accountInfo.data, offset) } /** * Retrieves the account info from the provided address and deserializes * the {@link Response} 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 Response account at ${address}`) } return Response.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, responseBeet) } /** * Deserializes the {@link Response} 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): [Response, number] { return responseBeet.deserialize(buf, offset) } /** * Serializes the {@link Response} 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 responseBeet.serialize({ accountDiscriminator: responseDiscriminator, ...this, }) } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link Response} for the provided args. * * @param args need to be provided since the byte size for this account * depends on them */ static byteSize(args: ResponseArgs) { const instance = Response.fromArgs(args) return responseBeet.toFixedFromValue({ accountDiscriminator: responseDiscriminator, ...instance, }).byteSize } /** * Fetches the minimum balance needed to exempt an account holding * {@link Response} 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: ResponseArgs, connection: web3.Connection, commitment?: web3.Commitment ): Promise { return connection.getMinimumBalanceForRentExemption( Response.byteSize(args), commitment ) } /** * Returns a readable version of {@link Response} properties * and can be used to convert to JSON and/or logging */ pretty() { return { maker: this.maker.toBase58(), rfq: this.rfq.toBase58(), creationTimestamp: (() => { const x = <{ toNumber: () => number }>this.creationTimestamp if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), expirationTimestamp: (() => { const x = <{ toNumber: () => number }>this.expirationTimestamp if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), makerCollateralLocked: (() => { const x = <{ toNumber: () => number }>this.makerCollateralLocked if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), takerCollateralLocked: (() => { const x = <{ toNumber: () => number }>this.takerCollateralLocked if (typeof x.toNumber === 'function') { try { return x.toNumber() } catch (_) { return x } } return x })(), state: 'StoredResponseState.' + StoredResponseState[this.state], takerPreparedCounter: this.takerPreparedCounter, makerPreparedCounter: this.makerPreparedCounter, settledEscrowLegs: this.settledEscrowLegs, reserved: this.reserved, confirmed: this.confirmed, defaultingParty: this.defaultingParty, printTradeInitializedBy: this.printTradeInitializedBy, escrowLegPreparationsInitializedBy: this.escrowLegPreparationsInitializedBy, bid: this.bid, ask: this.ask, additionalData: this.additionalData, } } } /** * @category Accounts * @category generated */ export const responseBeet = new beet.FixableBeetStruct< Response, ResponseArgs & { accountDiscriminator: number[] /* size: 8 */ } >( [ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['maker', beetSolana.publicKey], ['rfq', beetSolana.publicKey], ['creationTimestamp', beet.i64], ['expirationTimestamp', beet.i64], ['makerCollateralLocked', beet.u64], ['takerCollateralLocked', beet.u64], ['state', storedResponseStateBeet], ['takerPreparedCounter', beet.u8], ['makerPreparedCounter', beet.u8], ['settledEscrowLegs', beet.u8], ['reserved', beet.uniformFixedSizeArray(beet.u8, 256)], ['confirmed', beet.coption(confirmationBeet)], ['defaultingParty', beet.coption(defaultingPartyBeet)], ['printTradeInitializedBy', beet.coption(authoritySideBeet)], ['escrowLegPreparationsInitializedBy', beet.array(authoritySideBeet)], ['bid', beet.coption(quoteBeet)], ['ask', beet.coption(quoteBeet)], ['additionalData', beet.bytes], ], Response.fromArgs, 'Response' )