/** * 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 { FactionTreasurySeeds, findFactionTreasuryPda } from '../pdas'; import { getCargoIdDecoder, getCargoIdEncoder, getMinorFactionIdDecoder, getMinorFactionIdEncoder, type CargoId, type CargoIdArgs, type MinorFactionId, type MinorFactionIdArgs, } from '../types'; export const FACTION_TREASURY_DISCRIMINATOR = new Uint8Array([ 65, 117, 44, 5, 129, 79, 91, 49, ]); export function getFactionTreasuryDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( FACTION_TREASURY_DISCRIMINATOR, ); } /** Per-faction value account (one per faction). 76 B sized header + `reserves` + `floors` Map tails. */ export type FactionTreasury = { discriminator: ReadonlyUint8Array; version: number; bump: number; gameId: Address; /** The owning faction (also the 2nd seed). One treasury per faction. */ factionId: MinorFactionId; /** ATLAS reserve: receives player buys (Ask), pays sell-backs (faucet). Same type as `LocalMarket.vault`. */ vault: bigint; /** * Per-epoch ATLAS-out circuit-breaker (verbatim `EncounterTreasury` idiom): caps total faucet ATLAS * emitted per epoch. Reset when `now >= epoch_start + epoch_len_secs`. */ epochStart: bigint; epochLenSecs: bigint; atlasOutThisEpoch: bigint; atlasOutCapPerEpoch: bigint; /** * Finite, pre-stocked cargo reserve (no minting). Asks draw down; Bids credit back. Byte-identical * codec to `EncounterTreasury.reserves`. */ reserves: Map; /** * Per-cargo strategic-reserve FLOOR (anti-drain): an Ask caps fill so `reserves[cargo] >= floors[cargo]`. * Lives on the treasury (NOT per-market) so it composes across a faction's N markets. Absent = 0. */ floors: Map; }; export type FactionTreasuryArgs = { version: number; bump: number; gameId: Address; /** The owning faction (also the 2nd seed). One treasury per faction. */ factionId: MinorFactionIdArgs; /** ATLAS reserve: receives player buys (Ask), pays sell-backs (faucet). Same type as `LocalMarket.vault`. */ vault: number | bigint; /** * Per-epoch ATLAS-out circuit-breaker (verbatim `EncounterTreasury` idiom): caps total faucet ATLAS * emitted per epoch. 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 (no minting). Asks draw down; Bids credit back. Byte-identical * codec to `EncounterTreasury.reserves`. */ reserves: Map; /** * Per-cargo strategic-reserve FLOOR (anti-drain): an Ask caps fill so `reserves[cargo] >= floors[cargo]`. * Lives on the treasury (NOT per-market) so it composes across a faction's N markets. Absent = 0. */ floors: Map; }; /** Gets the encoder for {@link FactionTreasuryArgs} account data. */ export function getFactionTreasuryEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['factionId', getMinorFactionIdEncoder()], ['vault', getU64Encoder()], ['epochStart', getI64Encoder()], ['epochLenSecs', getI64Encoder()], ['atlasOutThisEpoch', getU64Encoder()], ['atlasOutCapPerEpoch', getU64Encoder()], ['reserves', getMapEncoder(getCargoIdEncoder(), getU64Encoder())], ['floors', getMapEncoder(getCargoIdEncoder(), getU64Encoder())], ]), (value) => ({ ...value, discriminator: FACTION_TREASURY_DISCRIMINATOR }), ); } /** Gets the decoder for {@link FactionTreasury} account data. */ export function getFactionTreasuryDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['factionId', getMinorFactionIdDecoder()], ['vault', getU64Decoder()], ['epochStart', getI64Decoder()], ['epochLenSecs', getI64Decoder()], ['atlasOutThisEpoch', getU64Decoder()], ['atlasOutCapPerEpoch', getU64Decoder()], ['reserves', getMapDecoder(getCargoIdDecoder(), getU64Decoder())], ['floors', getMapDecoder(getCargoIdDecoder(), getU64Decoder())], ]); } /** Gets the codec for {@link FactionTreasury} account data. */ export function getFactionTreasuryCodec(): Codec< FactionTreasuryArgs, FactionTreasury > { return combineCodec(getFactionTreasuryEncoder(), getFactionTreasuryDecoder()); } export function decodeFactionTreasury( encodedAccount: EncodedAccount, ): Account; export function decodeFactionTreasury( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeFactionTreasury( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getFactionTreasuryDecoder(), ); } export async function fetchFactionTreasury( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeFactionTreasury(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionTreasury< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeFactionTreasury(maybeAccount); } export async function fetchAllFactionTreasury( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeFactionTreasury( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeFactionTreasury( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeFactionTreasury(maybeAccount), ); } export async function fetchFactionTreasuryFromSeeds( rpc: Parameters[0], seeds: FactionTreasurySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeFactionTreasuryFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionTreasuryFromSeeds( rpc: Parameters[0], seeds: FactionTreasurySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findFactionTreasuryPda(seeds, { programAddress }); return await fetchMaybeFactionTreasury(rpc, address, fetchConfig); }