/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array, } from "@solana/kit"; export const PROTOCOL_DISCRIMINATOR = new Uint8Array([ 45, 39, 101, 43, 115, 72, 131, 40, ]); export function getProtocolDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(PROTOCOL_DISCRIMINATOR); } export type Protocol = { discriminator: ReadonlyUint8Array; /** The admin of the protocol. */ admin: Address; /** The operational state of the protocol. */ operationalState: number; /** Padding after the operational-state flags. */ padding1: ReadonlyUint8Array; /** The bump for the protocol. */ bump: number; /** 1 byte of padding to align future 8-byte fields on 8-byte boundaries. */ padding0: ReadonlyUint8Array; /** The pending admin for admin transfer. */ pendingAdmin: Address; /** The treasury that receives protocol fees. */ treasury: Address; }; export type ProtocolArgs = { /** The admin of the protocol. */ admin: Address; /** The operational state of the protocol. */ operationalState: number; /** Padding after the operational-state flags. */ padding1: ReadonlyUint8Array; /** The bump for the protocol. */ bump: number; /** 1 byte of padding to align future 8-byte fields on 8-byte boundaries. */ padding0: ReadonlyUint8Array; /** The pending admin for admin transfer. */ pendingAdmin: Address; /** The treasury that receives protocol fees. */ treasury: Address; }; /** Gets the encoder for {@link ProtocolArgs} account data. */ export function getProtocolEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["admin", getAddressEncoder()], ["operationalState", getU16Encoder()], ["padding1", fixEncoderSize(getBytesEncoder(), 2)], ["bump", getU8Encoder()], ["padding0", fixEncoderSize(getBytesEncoder(), 1)], ["pendingAdmin", getAddressEncoder()], ["treasury", getAddressEncoder()], ]), (value) => ({ ...value, discriminator: PROTOCOL_DISCRIMINATOR }), ); } /** Gets the decoder for {@link Protocol} account data. */ export function getProtocolDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["admin", getAddressDecoder()], ["operationalState", getU16Decoder()], ["padding1", fixDecoderSize(getBytesDecoder(), 2)], ["bump", getU8Decoder()], ["padding0", fixDecoderSize(getBytesDecoder(), 1)], ["pendingAdmin", getAddressDecoder()], ["treasury", getAddressDecoder()], ]); } /** Gets the codec for {@link Protocol} account data. */ export function getProtocolCodec(): FixedSizeCodec { return combineCodec(getProtocolEncoder(), getProtocolDecoder()); } export function decodeProtocol( encodedAccount: EncodedAccount, ): Account; export function decodeProtocol( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeProtocol( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getProtocolDecoder(), ); } export async function fetchProtocol( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeProtocol(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeProtocol( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeProtocol(maybeAccount); } export async function fetchAllProtocol( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeProtocol(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeProtocol( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeProtocol(maybeAccount)); } export function getProtocolSize(): number { return 110; }