/** * 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, getU32Decoder, getU32Encoder, 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 { AtlasRewardRegistrySeeds, findAtlasRewardRegistryPda } from '../pdas'; export const ATLAS_REWARD_REGISTRY_DISCRIMINATOR = new Uint8Array([ 202, 183, 49, 108, 35, 241, 28, 31, ]); export function getAtlasRewardRegistryDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( ATLAS_REWARD_REGISTRY_DISCRIMINATOR, ); } /** Per-game epoch clock and pointer to immutable reward-config versions. */ export type AtlasRewardRegistry = { discriminator: ReadonlyUint8Array; version: number; bump: number; gameId: Address; currentEpoch: bigint; currentEpochStartedAt: bigint; currentEpochEndsAt: bigint; initialEpochOffsetSecs: bigint; activeConfigVersion: number; pendingConfigVersion: number; pendingEffectiveEpoch: bigint; latestConfigVersion: number; reserved: Array; }; export type AtlasRewardRegistryArgs = { version: number; bump: number; gameId: Address; currentEpoch: number | bigint; currentEpochStartedAt: number | bigint; currentEpochEndsAt: number | bigint; initialEpochOffsetSecs: number | bigint; activeConfigVersion: number; pendingConfigVersion: number; pendingEffectiveEpoch: number | bigint; latestConfigVersion: number; reserved: Array; }; /** Gets the encoder for {@link AtlasRewardRegistryArgs} account data. */ export function getAtlasRewardRegistryEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['currentEpoch', getU64Encoder()], ['currentEpochStartedAt', getI64Encoder()], ['currentEpochEndsAt', getI64Encoder()], ['initialEpochOffsetSecs', getI64Encoder()], ['activeConfigVersion', getU32Encoder()], ['pendingConfigVersion', getU32Encoder()], ['pendingEffectiveEpoch', getU64Encoder()], ['latestConfigVersion', getU32Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 32 })], ]), (value) => ({ ...value, discriminator: ATLAS_REWARD_REGISTRY_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link AtlasRewardRegistry} account data. */ export function getAtlasRewardRegistryDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['currentEpoch', getU64Decoder()], ['currentEpochStartedAt', getI64Decoder()], ['currentEpochEndsAt', getI64Decoder()], ['initialEpochOffsetSecs', getI64Decoder()], ['activeConfigVersion', getU32Decoder()], ['pendingConfigVersion', getU32Decoder()], ['pendingEffectiveEpoch', getU64Decoder()], ['latestConfigVersion', getU32Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 32 })], ]); } /** Gets the codec for {@link AtlasRewardRegistry} account data. */ export function getAtlasRewardRegistryCodec(): FixedSizeCodec< AtlasRewardRegistryArgs, AtlasRewardRegistry > { return combineCodec( getAtlasRewardRegistryEncoder(), getAtlasRewardRegistryDecoder(), ); } export function decodeAtlasRewardRegistry( encodedAccount: EncodedAccount, ): Account; export function decodeAtlasRewardRegistry( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeAtlasRewardRegistry( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getAtlasRewardRegistryDecoder(), ); } export async function fetchAtlasRewardRegistry< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeAtlasRewardRegistry( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeAtlasRewardRegistry< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeAtlasRewardRegistry(maybeAccount); } export async function fetchAllAtlasRewardRegistry( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeAtlasRewardRegistry( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeAtlasRewardRegistry( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeAtlasRewardRegistry(maybeAccount), ); } export async function fetchAtlasRewardRegistryFromSeeds( rpc: Parameters[0], seeds: AtlasRewardRegistrySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeAtlasRewardRegistryFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeAtlasRewardRegistryFromSeeds( rpc: Parameters[0], seeds: AtlasRewardRegistrySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findAtlasRewardRegistryPda(seeds, { programAddress }); return await fetchMaybeAtlasRewardRegistry(rpc, address, fetchConfig); }