/** * 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, 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'; import { findRentSourceHeadPda, RentSourceHeadSeeds } from '../pdas'; export const RENT_SOURCE_HEAD_DISCRIMINATOR = new Uint8Array([ 23, 215, 250, 71, 104, 31, 59, 91, ]); export function getRentSourceHeadDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( RENT_SOURCE_HEAD_DISCRIMINATOR, ); } /** * The durable head of one price source. Its history is continuous for the life of the game: a source that * is removed and re-created keeps this head (generation is metadata only). */ export type RentSourceHead = { discriminator: ReadonlyUint8Array; version: number; bump: number; domain: Array; gameId: Address; kind: number; key: Address; /** Metadata only: bumped on a source close/recreate (never splits a bill). */ generation: bigint; /** `effective_from` of revision 0. */ firstEffectiveFrom: bigint; lastRecreatedAt: bigint; /** Revision of the latest record (revisions are contiguous from 0). */ currentRevision: bigint; /** `effective_from` of the latest record. */ lastEffectiveFrom: bigint; /** Optimistic-concurrency guard: bumped on every effective value mutation. */ writeVersion: bigint; /** 1 when a Preparing/Ready capture was recorded (first write wins). */ capturedPresent: number; capturedRevision: bigint; capturedValue: Array; /** 1 once the migration froze this source's pre-activation baseline. */ baselinePresent: number; baselineRevision: bigint; baselineValue: Array; /** 1 once the migration configured this source (usable for pricing when also baselined). */ configured: number; /** Additive growth budget — carve typed fields from the FRONT; NEVER append. */ reserved: Array; }; export type RentSourceHeadArgs = { version: number; bump: number; domain: Array; gameId: Address; kind: number; key: Address; /** Metadata only: bumped on a source close/recreate (never splits a bill). */ generation: number | bigint; /** `effective_from` of revision 0. */ firstEffectiveFrom: number | bigint; lastRecreatedAt: number | bigint; /** Revision of the latest record (revisions are contiguous from 0). */ currentRevision: number | bigint; /** `effective_from` of the latest record. */ lastEffectiveFrom: number | bigint; /** Optimistic-concurrency guard: bumped on every effective value mutation. */ writeVersion: number | bigint; /** 1 when a Preparing/Ready capture was recorded (first write wins). */ capturedPresent: number; capturedRevision: number | bigint; capturedValue: Array; /** 1 once the migration froze this source's pre-activation baseline. */ baselinePresent: number; baselineRevision: number | bigint; baselineValue: Array; /** 1 once the migration configured this source (usable for pricing when also baselined). */ configured: number; /** Additive growth budget — carve typed fields from the FRONT; NEVER append. */ reserved: Array; }; /** Gets the encoder for {@link RentSourceHeadArgs} account data. */ export function getRentSourceHeadEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['domain', getArrayEncoder(getU8Encoder(), { size: 8 })], ['gameId', getAddressEncoder()], ['kind', getU8Encoder()], ['key', getAddressEncoder()], ['generation', getU64Encoder()], ['firstEffectiveFrom', getI64Encoder()], ['lastRecreatedAt', getI64Encoder()], ['currentRevision', getU64Encoder()], ['lastEffectiveFrom', getI64Encoder()], ['writeVersion', getU64Encoder()], ['capturedPresent', getU8Encoder()], ['capturedRevision', getU64Encoder()], ['capturedValue', getArrayEncoder(getU8Encoder(), { size: 280 })], ['baselinePresent', getU8Encoder()], ['baselineRevision', getU64Encoder()], ['baselineValue', getArrayEncoder(getU8Encoder(), { size: 280 })], ['configured', getU8Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 64 })], ]), (value) => ({ ...value, discriminator: RENT_SOURCE_HEAD_DISCRIMINATOR }), ); } /** Gets the decoder for {@link RentSourceHead} account data. */ export function getRentSourceHeadDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['domain', getArrayDecoder(getU8Decoder(), { size: 8 })], ['gameId', getAddressDecoder()], ['kind', getU8Decoder()], ['key', getAddressDecoder()], ['generation', getU64Decoder()], ['firstEffectiveFrom', getI64Decoder()], ['lastRecreatedAt', getI64Decoder()], ['currentRevision', getU64Decoder()], ['lastEffectiveFrom', getI64Decoder()], ['writeVersion', getU64Decoder()], ['capturedPresent', getU8Decoder()], ['capturedRevision', getU64Decoder()], ['capturedValue', getArrayDecoder(getU8Decoder(), { size: 280 })], ['baselinePresent', getU8Decoder()], ['baselineRevision', getU64Decoder()], ['baselineValue', getArrayDecoder(getU8Decoder(), { size: 280 })], ['configured', getU8Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 64 })], ]); } /** Gets the codec for {@link RentSourceHead} account data. */ export function getRentSourceHeadCodec(): FixedSizeCodec< RentSourceHeadArgs, RentSourceHead > { return combineCodec(getRentSourceHeadEncoder(), getRentSourceHeadDecoder()); } export function decodeRentSourceHead( encodedAccount: EncodedAccount, ): Account; export function decodeRentSourceHead( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeRentSourceHead( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getRentSourceHeadDecoder(), ); } export async function fetchRentSourceHead( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeRentSourceHead(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeRentSourceHead< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeRentSourceHead(maybeAccount); } export async function fetchAllRentSourceHead( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeRentSourceHead( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeRentSourceHead( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeRentSourceHead(maybeAccount), ); } export async function fetchRentSourceHeadFromSeeds( rpc: Parameters[0], seeds: RentSourceHeadSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeRentSourceHeadFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeRentSourceHeadFromSeeds( rpc: Parameters[0], seeds: RentSourceHeadSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findRentSourceHeadPda(seeds, { programAddress }); return await fetchMaybeRentSourceHead(rpc, address, fetchConfig); }