/** * 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, 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 { findLoyaltyAtlasBankPda, LoyaltyAtlasBankSeeds } from '../pdas'; import { getMinorFactionIdDecoder, getMinorFactionIdEncoder, type MinorFactionId, type MinorFactionIdArgs, } from '../types'; export const LOYALTY_ATLAS_BANK_DISCRIMINATOR = new Uint8Array([ 239, 214, 43, 108, 204, 57, 3, 115, ]); export function getLoyaltyAtlasBankDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( LOYALTY_ATLAS_BANK_DISCRIMINATOR, ); } /** * Persistent accumulated ATLAS entitlement for one `(profile, faction)`. * * Expiry is inactivity-based: a new credit extends the whole accumulated balance. Configuring expiry to * `0` makes the bank non-expiring. This is bounded state (one account per profile/faction), supports * week/month batching, and avoids an unbounded list of daily claim tranches. */ export type LoyaltyAtlasBank = { discriminator: ReadonlyUint8Array; version: number; bump: number; gameId: Address; profile: Address; factionId: MinorFactionId; pad0: Array; claimableAtlas: bigint; lifetimeLp: bigint; lifetimeAtlas: bigint; lastCreditedAt: bigint; expiresAt: bigint; reserved: Array; }; export type LoyaltyAtlasBankArgs = { version: number; bump: number; gameId: Address; profile: Address; factionId: MinorFactionIdArgs; pad0: Array; claimableAtlas: number | bigint; lifetimeLp: number | bigint; lifetimeAtlas: number | bigint; lastCreditedAt: number | bigint; expiresAt: number | bigint; reserved: Array; }; /** Gets the encoder for {@link LoyaltyAtlasBankArgs} account data. */ export function getLoyaltyAtlasBankEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['profile', getAddressEncoder()], ['factionId', getMinorFactionIdEncoder()], ['pad0', getArrayEncoder(getU8Encoder(), { size: 6 })], ['claimableAtlas', getU64Encoder()], ['lifetimeLp', getU128Encoder()], ['lifetimeAtlas', getU128Encoder()], ['lastCreditedAt', getI64Encoder()], ['expiresAt', getI64Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 32 })], ]), (value) => ({ ...value, discriminator: LOYALTY_ATLAS_BANK_DISCRIMINATOR }), ); } /** Gets the decoder for {@link LoyaltyAtlasBank} account data. */ export function getLoyaltyAtlasBankDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['profile', getAddressDecoder()], ['factionId', getMinorFactionIdDecoder()], ['pad0', getArrayDecoder(getU8Decoder(), { size: 6 })], ['claimableAtlas', getU64Decoder()], ['lifetimeLp', getU128Decoder()], ['lifetimeAtlas', getU128Decoder()], ['lastCreditedAt', getI64Decoder()], ['expiresAt', getI64Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 32 })], ]); } /** Gets the codec for {@link LoyaltyAtlasBank} account data. */ export function getLoyaltyAtlasBankCodec(): FixedSizeCodec< LoyaltyAtlasBankArgs, LoyaltyAtlasBank > { return combineCodec( getLoyaltyAtlasBankEncoder(), getLoyaltyAtlasBankDecoder(), ); } export function decodeLoyaltyAtlasBank( encodedAccount: EncodedAccount, ): Account; export function decodeLoyaltyAtlasBank( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeLoyaltyAtlasBank( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getLoyaltyAtlasBankDecoder(), ); } export async function fetchLoyaltyAtlasBank( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeLoyaltyAtlasBank(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeLoyaltyAtlasBank< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeLoyaltyAtlasBank(maybeAccount); } export async function fetchAllLoyaltyAtlasBank( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeLoyaltyAtlasBank( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeLoyaltyAtlasBank( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeLoyaltyAtlasBank(maybeAccount), ); } export async function fetchLoyaltyAtlasBankFromSeeds( rpc: Parameters[0], seeds: LoyaltyAtlasBankSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeLoyaltyAtlasBankFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeLoyaltyAtlasBankFromSeeds( rpc: Parameters[0], seeds: LoyaltyAtlasBankSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findLoyaltyAtlasBankPda(seeds, { programAddress }); return await fetchMaybeLoyaltyAtlasBank(rpc, address, fetchConfig); }