/** * 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, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, type Account, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, } from '@solana/accounts'; import { getAddressDecoder, getAddressEncoder, type Address, } from '@solana/addresses'; import { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, getUtf8Decoder, getUtf8Encoder, transformEncoder, type Codec, type Decoder, type Encoder, type ReadonlyUint8Array, } from '@solana/codecs'; export const AGENT_ACCOUNT_DISCRIMINATOR = new Uint8Array([ 241, 119, 69, 140, 233, 9, 112, 50, ]); export function getAgentAccountDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( AGENT_ACCOUNT_DISCRIMINATOR ); } export type AgentAccount = { discriminator: ReadonlyUint8Array; pubkey: Address; capabilities: bigint; metadataUri: string; reputation: bigint; lastUpdated: bigint; bump: number; reserved: ReadonlyUint8Array; }; export type AgentAccountArgs = { pubkey: Address; capabilities: number | bigint; metadataUri: string; reputation: number | bigint; lastUpdated: number | bigint; bump: number; reserved: ReadonlyUint8Array; }; export function getAgentAccountEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['pubkey', getAddressEncoder()], ['capabilities', getU64Encoder()], ['metadataUri', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ['reputation', getU64Encoder()], ['lastUpdated', getI64Encoder()], ['bump', getU8Encoder()], ['reserved', fixEncoderSize(getBytesEncoder(), 7)], ]), (value) => ({ ...value, discriminator: AGENT_ACCOUNT_DISCRIMINATOR }) ); } export function getAgentAccountDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['pubkey', getAddressDecoder()], ['capabilities', getU64Decoder()], ['metadataUri', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ['reputation', getU64Decoder()], ['lastUpdated', getI64Decoder()], ['bump', getU8Decoder()], ['reserved', fixDecoderSize(getBytesDecoder(), 7)], ]); } export function getAgentAccountCodec(): Codec { return combineCodec(getAgentAccountEncoder(), getAgentAccountDecoder()); } export function decodeAgentAccount( encodedAccount: EncodedAccount ): Account; export function decodeAgentAccount( encodedAccount: MaybeEncodedAccount ): MaybeAccount; export function decodeAgentAccount( encodedAccount: EncodedAccount | MaybeEncodedAccount ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getAgentAccountDecoder() ); } export async function fetchAgentAccount( rpc: Parameters[0], address: Address, config?: FetchAccountConfig ): Promise> { const maybeAccount = await fetchMaybeAgentAccount(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeAgentAccount( rpc: Parameters[0], address: Address, config?: FetchAccountConfig ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeAgentAccount(maybeAccount); } export async function fetchAllAgentAccount( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig ): Promise[]> { const maybeAccounts = await fetchAllMaybeAgentAccount(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeAgentAccount( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeAgentAccount(maybeAccount)); }