/** * 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, getI64Decoder, getI64Encoder, getMapDecoder, getMapEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array, } from '@solana/kit'; import { EncounterTreasurySeeds, findEncounterTreasuryPda } from '../pdas'; import { getCargoIdDecoder, getCargoIdEncoder, getMinorFactionIdDecoder, getMinorFactionIdEncoder, getRegionIdDecoder, getRegionIdEncoder, type CargoId, type CargoIdArgs, type MinorFactionId, type MinorFactionIdArgs, type RegionId, type RegionIdArgs, } from '../types'; export const ENCOUNTER_TREASURY_DISCRIMINATOR = new Uint8Array([ 81, 161, 197, 57, 227, 169, 146, 194, ]); export function getEncounterTreasuryDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( ENCOUNTER_TREASURY_DISCRIMINATOR, ); } /** * The finite, pre-funded reserve + per-epoch ATLAS-out circuit-breaker for one `(region, faction)` pool. * * All economic value lives here (decisions #1/#3): the ATLAS `vault` pays sell-backs and receives * player buys; `reserves` is the finite cargo stock (no minting — Asks draw down, Bids credit back). * Kept separate from [`EncounterPool`] (config) so the value account is written on trades while the * envelope stays a rarely-written config account. Modeled on `LocalMarket`'s vault + `CargoPod`'s map. */ export type EncounterTreasury = { discriminator: ReadonlyUint8Array; version: number; bump: number; gameId: Address; regionId: RegionId; minorFaction: MinorFactionId; /** ATLAS reserve: pays sell-backs (faucet leg), receives player buys. Same type as `LocalMarket.vault`. */ vault: bigint; /** * Circuit-breaker (decision #1), modeled on `CurrencyBalanceCache.circuit_breaker`: caps total ATLAS * emitted (faucet leg) per epoch, so concentrated/grinding draw cannot drain a restock in one block. * Reset when `now >= epoch_start + epoch_len_secs`. */ epochStart: bigint; epochLenSecs: bigint; atlasOutThisEpoch: bigint; atlasOutCapPerEpoch: bigint; /** * Finite, pre-stocked cargo reserve. Asks draw down from here; Bids (sell-back) credit back here. * No minting (decision #3). Same idiom as `CargoPod.amounts` / `CargoDefinitions.cargo_types`. */ reserves: Map; }; export type EncounterTreasuryArgs = { version: number; bump: number; gameId: Address; regionId: RegionIdArgs; minorFaction: MinorFactionIdArgs; /** ATLAS reserve: pays sell-backs (faucet leg), receives player buys. Same type as `LocalMarket.vault`. */ vault: number | bigint; /** * Circuit-breaker (decision #1), modeled on `CurrencyBalanceCache.circuit_breaker`: caps total ATLAS * emitted (faucet leg) per epoch, so concentrated/grinding draw cannot drain a restock in one block. * Reset when `now >= epoch_start + epoch_len_secs`. */ epochStart: number | bigint; epochLenSecs: number | bigint; atlasOutThisEpoch: number | bigint; atlasOutCapPerEpoch: number | bigint; /** * Finite, pre-stocked cargo reserve. Asks draw down from here; Bids (sell-back) credit back here. * No minting (decision #3). Same idiom as `CargoPod.amounts` / `CargoDefinitions.cargo_types`. */ reserves: Map; }; /** Gets the encoder for {@link EncounterTreasuryArgs} account data. */ export function getEncounterTreasuryEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['regionId', getRegionIdEncoder()], ['minorFaction', getMinorFactionIdEncoder()], ['vault', getU64Encoder()], ['epochStart', getI64Encoder()], ['epochLenSecs', getI64Encoder()], ['atlasOutThisEpoch', getU64Encoder()], ['atlasOutCapPerEpoch', getU64Encoder()], ['reserves', getMapEncoder(getCargoIdEncoder(), getU64Encoder())], ]), (value) => ({ ...value, discriminator: ENCOUNTER_TREASURY_DISCRIMINATOR }), ); } /** Gets the decoder for {@link EncounterTreasury} account data. */ export function getEncounterTreasuryDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['regionId', getRegionIdDecoder()], ['minorFaction', getMinorFactionIdDecoder()], ['vault', getU64Decoder()], ['epochStart', getI64Decoder()], ['epochLenSecs', getI64Decoder()], ['atlasOutThisEpoch', getU64Decoder()], ['atlasOutCapPerEpoch', getU64Decoder()], ['reserves', getMapDecoder(getCargoIdDecoder(), getU64Decoder())], ]); } /** Gets the codec for {@link EncounterTreasury} account data. */ export function getEncounterTreasuryCodec(): Codec< EncounterTreasuryArgs, EncounterTreasury > { return combineCodec( getEncounterTreasuryEncoder(), getEncounterTreasuryDecoder(), ); } export function decodeEncounterTreasury( encodedAccount: EncodedAccount, ): Account; export function decodeEncounterTreasury( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeEncounterTreasury( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getEncounterTreasuryDecoder(), ); } export async function fetchEncounterTreasury( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeEncounterTreasury(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeEncounterTreasury< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeEncounterTreasury(maybeAccount); } export async function fetchAllEncounterTreasury( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeEncounterTreasury( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeEncounterTreasury( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeEncounterTreasury(maybeAccount), ); } export async function fetchEncounterTreasuryFromSeeds( rpc: Parameters[0], seeds: EncounterTreasurySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeEncounterTreasuryFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeEncounterTreasuryFromSeeds( rpc: Parameters[0], seeds: EncounterTreasurySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findEncounterTreasuryPda(seeds, { programAddress }); return await fetchMaybeEncounterTreasury(rpc, address, fetchConfig); }