/** * 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, getU128Decoder, getU128Encoder, 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 { findLoyaltyEpochPda, LoyaltyEpochSeeds } from '../pdas'; import { getLoyaltyEpochStatusDecoder, getLoyaltyEpochStatusEncoder, getMinorFactionIdDecoder, getMinorFactionIdEncoder, type LoyaltyEpochStatus, type LoyaltyEpochStatusArgs, type MinorFactionId, type MinorFactionIdArgs, } from '../types'; export const LOYALTY_EPOCH_DISCRIMINATOR = new Uint8Array([ 17, 80, 238, 11, 237, 5, 171, 115, ]); export function getLoyaltyEpochDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( LOYALTY_EPOCH_DISCRIMINATOR, ); } /** One faction's daily LP total, ATLAS entitlement, and legacy prepaid reserve. */ export type LoyaltyEpoch = { discriminator: ReadonlyUint8Array; version: number; bump: number; status: LoyaltyEpochStatus; kingSystems: number; gameId: Address; factionId: MinorFactionId; pad0: Array; configVersion: number; epochIndex: bigint; startsAt: bigint; endsAt: bigint; settlementDeadline: bigint; totalLp: bigint; poolAtlas: bigint; unsettledAtlas: bigint; settledAtlas: bigint; reserved: Array; }; export type LoyaltyEpochArgs = { version: number; bump: number; status: LoyaltyEpochStatusArgs; kingSystems: number; gameId: Address; factionId: MinorFactionIdArgs; pad0: Array; configVersion: number; epochIndex: number | bigint; startsAt: number | bigint; endsAt: number | bigint; settlementDeadline: number | bigint; totalLp: number | bigint; poolAtlas: number | bigint; unsettledAtlas: number | bigint; settledAtlas: number | bigint; reserved: Array; }; /** Gets the encoder for {@link LoyaltyEpochArgs} account data. */ export function getLoyaltyEpochEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['status', getLoyaltyEpochStatusEncoder()], ['kingSystems', getU8Encoder()], ['gameId', getAddressEncoder()], ['factionId', getMinorFactionIdEncoder()], ['pad0', getArrayEncoder(getU8Encoder(), { size: 2 })], ['configVersion', getU32Encoder()], ['epochIndex', getU64Encoder()], ['startsAt', getI64Encoder()], ['endsAt', getI64Encoder()], ['settlementDeadline', getI64Encoder()], ['totalLp', getU128Encoder()], ['poolAtlas', getU64Encoder()], ['unsettledAtlas', getU64Encoder()], ['settledAtlas', getU64Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 32 })], ]), (value) => ({ ...value, discriminator: LOYALTY_EPOCH_DISCRIMINATOR }), ); } /** Gets the decoder for {@link LoyaltyEpoch} account data. */ export function getLoyaltyEpochDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['status', getLoyaltyEpochStatusDecoder()], ['kingSystems', getU8Decoder()], ['gameId', getAddressDecoder()], ['factionId', getMinorFactionIdDecoder()], ['pad0', getArrayDecoder(getU8Decoder(), { size: 2 })], ['configVersion', getU32Decoder()], ['epochIndex', getU64Decoder()], ['startsAt', getI64Decoder()], ['endsAt', getI64Decoder()], ['settlementDeadline', getI64Decoder()], ['totalLp', getU128Decoder()], ['poolAtlas', getU64Decoder()], ['unsettledAtlas', getU64Decoder()], ['settledAtlas', getU64Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 32 })], ]); } /** Gets the codec for {@link LoyaltyEpoch} account data. */ export function getLoyaltyEpochCodec(): FixedSizeCodec< LoyaltyEpochArgs, LoyaltyEpoch > { return combineCodec(getLoyaltyEpochEncoder(), getLoyaltyEpochDecoder()); } export function decodeLoyaltyEpoch( encodedAccount: EncodedAccount, ): Account; export function decodeLoyaltyEpoch( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeLoyaltyEpoch( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getLoyaltyEpochDecoder(), ); } export async function fetchLoyaltyEpoch( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeLoyaltyEpoch(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeLoyaltyEpoch( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeLoyaltyEpoch(maybeAccount); } export async function fetchAllLoyaltyEpoch( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeLoyaltyEpoch(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeLoyaltyEpoch( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeLoyaltyEpoch(maybeAccount)); } export async function fetchLoyaltyEpochFromSeeds( rpc: Parameters[0], seeds: LoyaltyEpochSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeLoyaltyEpochFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeLoyaltyEpochFromSeeds( rpc: Parameters[0], seeds: LoyaltyEpochSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findLoyaltyEpochPda(seeds, { programAddress }); return await fetchMaybeLoyaltyEpoch(rpc, address, fetchConfig); }