/** * 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, 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 { CareerXpTargetDefinitionsV1Seeds, findCareerXpTargetDefinitionsV1Pda, } from '../pdas'; export const CAREER_XP_TARGET_DEFINITIONS_V1_DISCRIMINATOR = new Uint8Array([ 32, 26, 247, 132, 54, 117, 108, 248, ]); export function getCareerXpTargetDefinitionsV1DiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CAREER_XP_TARGET_DEFINITIONS_V1_DISCRIMINATOR, ); } /** * Staged v1 threshold payload. Seeded * `[b"career_xp_target_definitions", game_id, 1u32_le]` per the #222 * contract — note the lower-case seed literal from the spec. * * The header fields are exactly the digest preimage header: `version:u32_le`, * `row_count:u32_le`, `renown_divisor:u32_le`, `feeder_mask:u16_le`. */ export type CareerXpTargetDefinitionsV1 = { discriminator: ReadonlyUint8Array; /** Target version (1). */ version: number; /** Row count; must be `V1_THRESHOLD_ROWS`. */ rowCount: number; /** Renown divisor the migration credits through. */ renownDivisor: number; /** Feeder-category mask (u16, `0x00fc` for the six careers). */ feederMask: number; /** * Number of rows written so far by `AppendCareerXpTargetRows` (staging * bookkeeping only; not part of the digest preimage). */ rowsWritten: number; pad: number; /** * All 80 packed `XpLevelThresholdInfo` rows in current Programs packed * field order. */ rows: Array>; }; export type CareerXpTargetDefinitionsV1Args = { /** Target version (1). */ version: number; /** Row count; must be `V1_THRESHOLD_ROWS`. */ rowCount: number; /** Renown divisor the migration credits through. */ renownDivisor: number; /** Feeder-category mask (u16, `0x00fc` for the six careers). */ feederMask: number; /** * Number of rows written so far by `AppendCareerXpTargetRows` (staging * bookkeeping only; not part of the digest preimage). */ rowsWritten: number; pad: number; /** * All 80 packed `XpLevelThresholdInfo` rows in current Programs packed * field order. */ rows: Array>; }; /** Gets the encoder for {@link CareerXpTargetDefinitionsV1Args} account data. */ export function getCareerXpTargetDefinitionsV1Encoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU32Encoder()], ['rowCount', getU32Encoder()], ['renownDivisor', getU32Encoder()], ['feederMask', getU16Encoder()], ['rowsWritten', getU8Encoder()], ['pad', getU8Encoder()], [ 'rows', getArrayEncoder(getArrayEncoder(getU8Encoder(), { size: 64 }), { size: 80, }), ], ]), (value) => ({ ...value, discriminator: CAREER_XP_TARGET_DEFINITIONS_V1_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link CareerXpTargetDefinitionsV1} account data. */ export function getCareerXpTargetDefinitionsV1Decoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU32Decoder()], ['rowCount', getU32Decoder()], ['renownDivisor', getU32Decoder()], ['feederMask', getU16Decoder()], ['rowsWritten', getU8Decoder()], ['pad', getU8Decoder()], [ 'rows', getArrayDecoder(getArrayDecoder(getU8Decoder(), { size: 64 }), { size: 80, }), ], ]); } /** Gets the codec for {@link CareerXpTargetDefinitionsV1} account data. */ export function getCareerXpTargetDefinitionsV1Codec(): FixedSizeCodec< CareerXpTargetDefinitionsV1Args, CareerXpTargetDefinitionsV1 > { return combineCodec( getCareerXpTargetDefinitionsV1Encoder(), getCareerXpTargetDefinitionsV1Decoder(), ); } export function decodeCareerXpTargetDefinitionsV1< TAddress extends string = string, >( encodedAccount: EncodedAccount, ): Account; export function decodeCareerXpTargetDefinitionsV1< TAddress extends string = string, >( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeCareerXpTargetDefinitionsV1< TAddress extends string = string, >( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getCareerXpTargetDefinitionsV1Decoder(), ); } export async function fetchCareerXpTargetDefinitionsV1< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeCareerXpTargetDefinitionsV1( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCareerXpTargetDefinitionsV1< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeCareerXpTargetDefinitionsV1(maybeAccount); } export async function fetchAllCareerXpTargetDefinitionsV1( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeCareerXpTargetDefinitionsV1( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeCareerXpTargetDefinitionsV1( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeCareerXpTargetDefinitionsV1(maybeAccount), ); } export async function fetchCareerXpTargetDefinitionsV1FromSeeds( rpc: Parameters[0], seeds: CareerXpTargetDefinitionsV1Seeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeCareerXpTargetDefinitionsV1FromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCareerXpTargetDefinitionsV1FromSeeds( rpc: Parameters[0], seeds: CareerXpTargetDefinitionsV1Seeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findCareerXpTargetDefinitionsV1Pda(seeds, { programAddress, }); return await fetchMaybeCareerXpTargetDefinitionsV1(rpc, address, fetchConfig); }