/** * 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, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, 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 { CurrencyConfigCacheSeeds, findCurrencyConfigCachePda } from '../pdas'; import { getCurrencyBalanceCacheDecoder, getCurrencyBalanceCacheEncoder, type CurrencyBalanceCache, type CurrencyBalanceCacheArgs, } from '../types'; export const CURRENCY_CONFIG_CACHE_DISCRIMINATOR = new Uint8Array([ 231, 203, 142, 108, 210, 234, 7, 191, ]); export function getCurrencyConfigCacheDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CURRENCY_CONFIG_CACHE_DISCRIMINATOR, ); } export type CurrencyConfigCache = { discriminator: ReadonlyUint8Array; /** The data version of this `CurrencyConfigCache` account. */ version: number; /** The game_id that this `CurrencyConfigCache` belongs to */ gameId: Address; /** Bump of Account PDA */ bump: number; /** The ATLAS balance cache */ atlas: CurrencyBalanceCache; /** The POLIS balance cache */ polis: CurrencyBalanceCache; /** Holds ATLAS that should be withdrawn to the game's ATLAS token account */ atlasVault: bigint; /** Holds ATLAS that should be withdrawn to the DAO's ATLAS token account */ daoAtlasVault: bigint; }; export type CurrencyConfigCacheArgs = { /** The data version of this `CurrencyConfigCache` account. */ version: number; /** The game_id that this `CurrencyConfigCache` belongs to */ gameId: Address; /** Bump of Account PDA */ bump: number; /** The ATLAS balance cache */ atlas: CurrencyBalanceCacheArgs; /** The POLIS balance cache */ polis: CurrencyBalanceCacheArgs; /** Holds ATLAS that should be withdrawn to the game's ATLAS token account */ atlasVault: number | bigint; /** Holds ATLAS that should be withdrawn to the DAO's ATLAS token account */ daoAtlasVault: number | bigint; }; /** Gets the encoder for {@link CurrencyConfigCacheArgs} account data. */ export function getCurrencyConfigCacheEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['gameId', getAddressEncoder()], ['bump', getU8Encoder()], ['atlas', getCurrencyBalanceCacheEncoder()], ['polis', getCurrencyBalanceCacheEncoder()], ['atlasVault', getU64Encoder()], ['daoAtlasVault', getU64Encoder()], ]), (value) => ({ ...value, discriminator: CURRENCY_CONFIG_CACHE_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link CurrencyConfigCache} account data. */ export function getCurrencyConfigCacheDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['gameId', getAddressDecoder()], ['bump', getU8Decoder()], ['atlas', getCurrencyBalanceCacheDecoder()], ['polis', getCurrencyBalanceCacheDecoder()], ['atlasVault', getU64Decoder()], ['daoAtlasVault', getU64Decoder()], ]); } /** Gets the codec for {@link CurrencyConfigCache} account data. */ export function getCurrencyConfigCacheCodec(): FixedSizeCodec< CurrencyConfigCacheArgs, CurrencyConfigCache > { return combineCodec( getCurrencyConfigCacheEncoder(), getCurrencyConfigCacheDecoder(), ); } export function decodeCurrencyConfigCache( encodedAccount: EncodedAccount, ): Account; export function decodeCurrencyConfigCache( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeCurrencyConfigCache( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getCurrencyConfigCacheDecoder(), ); } export async function fetchCurrencyConfigCache< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeCurrencyConfigCache( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCurrencyConfigCache< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeCurrencyConfigCache(maybeAccount); } export async function fetchAllCurrencyConfigCache( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeCurrencyConfigCache( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeCurrencyConfigCache( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeCurrencyConfigCache(maybeAccount), ); } export async function fetchCurrencyConfigCacheFromSeeds( rpc: Parameters[0], seeds: CurrencyConfigCacheSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeCurrencyConfigCacheFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCurrencyConfigCacheFromSeeds( rpc: Parameters[0], seeds: CurrencyConfigCacheSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findCurrencyConfigCachePda(seeds, { programAddress }); return await fetchMaybeCurrencyConfigCache(rpc, address, fetchConfig); }