/** * 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, getU32Decoder, getU32Encoder, 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 { FactionEconomicsConfigSeeds, findFactionEconomicsConfigPda, } from '../pdas'; export const FACTION_ECONOMICS_CONFIG_DISCRIMINATOR = new Uint8Array([ 234, 110, 66, 176, 3, 48, 136, 227, ]); export function getFactionEconomicsConfigDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( FACTION_ECONOMICS_CONFIG_DISCRIMINATOR, ); } /** Per-game NPC-economy tuning dials. Sized, packed, `Align1`, 72 bytes. */ export type FactionEconomicsConfig = { discriminator: ReadonlyUint8Array; /** Schema/migration lever. */ version: number; /** PDA bump. */ bump: number; /** Game scoping (also the sole seed). */ gameId: Address; /** * ATLAS debited from the minting faction's treasury per `MintNpcFleet`. `0` = free (test only — set * `> 0` at activation so the treasury is load-bearing and "defunded ⇒ quiet" actually holds). */ npcMintCostAtlas: bigint; /** ATLAS debited per NPC fleet respawn (the churn brake; keep `> 0` at activation). */ npcRespawnCostAtlas: bigint; /** * ATLAS debited from the captor faction's treasury per dynamic starbase capture (skin-in-the-game; a * defunded faction cannot pay ⇒ self-quieting). `0` = no capture cost. */ captureCostAtlas: number; /** * Per-faction anti-blitz capture cooldown (secs): `attack_starbase` STEP H refuses a new dynamic capture * until `FactionAccount.last_capture_at + this`. Lives here (8 B) — it does NOT fit the tracker reserve. */ factionCaptureCooldownSecs: bigint; /** Additive growth budget (carve from the front; never append). */ reserved: Array; }; export type FactionEconomicsConfigArgs = { /** Schema/migration lever. */ version: number; /** PDA bump. */ bump: number; /** Game scoping (also the sole seed). */ gameId: Address; /** * ATLAS debited from the minting faction's treasury per `MintNpcFleet`. `0` = free (test only — set * `> 0` at activation so the treasury is load-bearing and "defunded ⇒ quiet" actually holds). */ npcMintCostAtlas: number | bigint; /** ATLAS debited per NPC fleet respawn (the churn brake; keep `> 0` at activation). */ npcRespawnCostAtlas: number | bigint; /** * ATLAS debited from the captor faction's treasury per dynamic starbase capture (skin-in-the-game; a * defunded faction cannot pay ⇒ self-quieting). `0` = no capture cost. */ captureCostAtlas: number; /** * Per-faction anti-blitz capture cooldown (secs): `attack_starbase` STEP H refuses a new dynamic capture * until `FactionAccount.last_capture_at + this`. Lives here (8 B) — it does NOT fit the tracker reserve. */ factionCaptureCooldownSecs: number | bigint; /** Additive growth budget (carve from the front; never append). */ reserved: Array; }; /** Gets the encoder for {@link FactionEconomicsConfigArgs} account data. */ export function getFactionEconomicsConfigEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['npcMintCostAtlas', getU64Encoder()], ['npcRespawnCostAtlas', getU64Encoder()], ['captureCostAtlas', getU32Encoder()], ['factionCaptureCooldownSecs', getI64Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 10 })], ]), (value) => ({ ...value, discriminator: FACTION_ECONOMICS_CONFIG_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link FactionEconomicsConfig} account data. */ export function getFactionEconomicsConfigDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['npcMintCostAtlas', getU64Decoder()], ['npcRespawnCostAtlas', getU64Decoder()], ['captureCostAtlas', getU32Decoder()], ['factionCaptureCooldownSecs', getI64Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 10 })], ]); } /** Gets the codec for {@link FactionEconomicsConfig} account data. */ export function getFactionEconomicsConfigCodec(): FixedSizeCodec< FactionEconomicsConfigArgs, FactionEconomicsConfig > { return combineCodec( getFactionEconomicsConfigEncoder(), getFactionEconomicsConfigDecoder(), ); } export function decodeFactionEconomicsConfig( encodedAccount: EncodedAccount, ): Account; export function decodeFactionEconomicsConfig( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeFactionEconomicsConfig( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getFactionEconomicsConfigDecoder(), ); } export async function fetchFactionEconomicsConfig< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeFactionEconomicsConfig( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionEconomicsConfig< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeFactionEconomicsConfig(maybeAccount); } export async function fetchAllFactionEconomicsConfig( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeFactionEconomicsConfig( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeFactionEconomicsConfig( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeFactionEconomicsConfig(maybeAccount), ); } export async function fetchFactionEconomicsConfigFromSeeds( rpc: Parameters[0], seeds: FactionEconomicsConfigSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeFactionEconomicsConfigFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionEconomicsConfigFromSeeds( rpc: Parameters[0], seeds: FactionEconomicsConfigSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findFactionEconomicsConfigPda(seeds, { programAddress, }); return await fetchMaybeFactionEconomicsConfig(rpc, address, fetchConfig); }