/** * 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, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, 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 { CareerXpBudgetSeeds, findCareerXpBudgetPda } from '../pdas'; import { getXpBudgetTrackDecoder, getXpBudgetTrackEncoder, type XpBudgetTrack, type XpBudgetTrackArgs, } from '../types'; export const CAREER_XP_BUDGET_DISCRIMINATOR = new Uint8Array([ 57, 155, 254, 11, 241, 94, 21, 28, ]); export function getCareerXpBudgetDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CAREER_XP_BUDGET_DISCRIMINATOR, ); } /** * The `CareerXpBudget` PDA body: six tracks, explicit version, scoped to * one Character. */ export type CareerXpBudget = { discriminator: ReadonlyUint8Array; /** Schema/migration lever (=1). */ version: number; /** This account's PDA bump. */ bump: number; /** Game scoping (AccountValidate compares). */ gameId: Address; /** Owning Character PDA. */ characterId: Address; /** * Ordered by `budget_track`: Pilot, DataRunner, Mining, Building, * Crafting, Combat. */ tracks: Array; /** * Permanent legacy→v1 reconciliation marker (#222). 0 = legacy, * >= 1 = reconciled; a second migration rejects. */ reconciledThresholdVersion: number; /** Additive growth budget — carve typed fields from the FRONT; NEVER append. */ reserved: Array; }; export type CareerXpBudgetArgs = { /** Schema/migration lever (=1). */ version: number; /** This account's PDA bump. */ bump: number; /** Game scoping (AccountValidate compares). */ gameId: Address; /** Owning Character PDA. */ characterId: Address; /** * Ordered by `budget_track`: Pilot, DataRunner, Mining, Building, * Crafting, Combat. */ tracks: Array; /** * Permanent legacy→v1 reconciliation marker (#222). 0 = legacy, * >= 1 = reconciled; a second migration rejects. */ reconciledThresholdVersion: number; /** Additive growth budget — carve typed fields from the FRONT; NEVER append. */ reserved: Array; }; /** Gets the encoder for {@link CareerXpBudgetArgs} account data. */ export function getCareerXpBudgetEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['characterId', getAddressEncoder()], ['tracks', getArrayEncoder(getXpBudgetTrackEncoder(), { size: 6 })], ['reconciledThresholdVersion', getU32Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 22 })], ]), (value) => ({ ...value, discriminator: CAREER_XP_BUDGET_DISCRIMINATOR }), ); } /** Gets the decoder for {@link CareerXpBudget} account data. */ export function getCareerXpBudgetDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['characterId', getAddressDecoder()], ['tracks', getArrayDecoder(getXpBudgetTrackDecoder(), { size: 6 })], ['reconciledThresholdVersion', getU32Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 22 })], ]); } /** Gets the codec for {@link CareerXpBudget} account data. */ export function getCareerXpBudgetCodec(): FixedSizeCodec< CareerXpBudgetArgs, CareerXpBudget > { return combineCodec(getCareerXpBudgetEncoder(), getCareerXpBudgetDecoder()); } export function decodeCareerXpBudget( encodedAccount: EncodedAccount, ): Account; export function decodeCareerXpBudget( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeCareerXpBudget( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getCareerXpBudgetDecoder(), ); } export async function fetchCareerXpBudget( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeCareerXpBudget(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCareerXpBudget< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeCareerXpBudget(maybeAccount); } export async function fetchAllCareerXpBudget( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeCareerXpBudget( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeCareerXpBudget( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeCareerXpBudget(maybeAccount), ); } export async function fetchCareerXpBudgetFromSeeds( rpc: Parameters[0], seeds: CareerXpBudgetSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeCareerXpBudgetFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCareerXpBudgetFromSeeds( rpc: Parameters[0], seeds: CareerXpBudgetSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findCareerXpBudgetPda(seeds, { programAddress }); return await fetchMaybeCareerXpBudget(rpc, address, fetchConfig); }