/** * 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 { findLoyaltyContributionPda, LoyaltyContributionSeeds } from '../pdas'; import { getMinorFactionIdDecoder, getMinorFactionIdEncoder, type MinorFactionId, type MinorFactionIdArgs, } from '../types'; export const LOYALTY_CONTRIBUTION_DISCRIMINATOR = new Uint8Array([ 128, 198, 30, 135, 58, 67, 148, 162, ]); export function getLoyaltyContributionDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( LOYALTY_CONTRIBUTION_DISCRIMINATOR, ); } /** One profile's LP in one faction epoch. LP never rolls forward. */ export type LoyaltyContribution = { discriminator: ReadonlyUint8Array; version: number; bump: number; settled: number; pad0: number; gameId: Address; profile: Address; factionId: MinorFactionId; pad1: Array; epochIndex: bigint; lp: bigint; atlasEntitlement: bigint; settledAt: bigint; reserved: Array; }; export type LoyaltyContributionArgs = { version: number; bump: number; settled: number; pad0: number; gameId: Address; profile: Address; factionId: MinorFactionIdArgs; pad1: Array; epochIndex: number | bigint; lp: number | bigint; atlasEntitlement: number | bigint; settledAt: number | bigint; reserved: Array; }; /** Gets the encoder for {@link LoyaltyContributionArgs} account data. */ export function getLoyaltyContributionEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['settled', getU8Encoder()], ['pad0', getU8Encoder()], ['gameId', getAddressEncoder()], ['profile', getAddressEncoder()], ['factionId', getMinorFactionIdEncoder()], ['pad1', getArrayEncoder(getU8Encoder(), { size: 6 })], ['epochIndex', getU64Encoder()], ['lp', getU128Encoder()], ['atlasEntitlement', getU64Encoder()], ['settledAt', getI64Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 24 })], ]), (value) => ({ ...value, discriminator: LOYALTY_CONTRIBUTION_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link LoyaltyContribution} account data. */ export function getLoyaltyContributionDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['settled', getU8Decoder()], ['pad0', getU8Decoder()], ['gameId', getAddressDecoder()], ['profile', getAddressDecoder()], ['factionId', getMinorFactionIdDecoder()], ['pad1', getArrayDecoder(getU8Decoder(), { size: 6 })], ['epochIndex', getU64Decoder()], ['lp', getU128Decoder()], ['atlasEntitlement', getU64Decoder()], ['settledAt', getI64Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 24 })], ]); } /** Gets the codec for {@link LoyaltyContribution} account data. */ export function getLoyaltyContributionCodec(): FixedSizeCodec< LoyaltyContributionArgs, LoyaltyContribution > { return combineCodec( getLoyaltyContributionEncoder(), getLoyaltyContributionDecoder(), ); } export function decodeLoyaltyContribution( encodedAccount: EncodedAccount, ): Account; export function decodeLoyaltyContribution( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeLoyaltyContribution( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getLoyaltyContributionDecoder(), ); } export async function fetchLoyaltyContribution< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeLoyaltyContribution( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeLoyaltyContribution< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeLoyaltyContribution(maybeAccount); } export async function fetchAllLoyaltyContribution( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeLoyaltyContribution( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeLoyaltyContribution( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeLoyaltyContribution(maybeAccount), ); } export async function fetchLoyaltyContributionFromSeeds( rpc: Parameters[0], seeds: LoyaltyContributionSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeLoyaltyContributionFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeLoyaltyContributionFromSeeds( rpc: Parameters[0], seeds: LoyaltyContributionSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findLoyaltyContributionPda(seeds, { programAddress }); return await fetchMaybeLoyaltyContribution(rpc, address, fetchConfig); }