/** * 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, 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 { FactionOwnershipSeeds, findFactionOwnershipPda } from '../pdas'; import { getMinorFactionIdDecoder, getMinorFactionIdEncoder, type MinorFactionId, type MinorFactionIdArgs, } from '../types'; export const FACTION_OWNERSHIP_DISCRIMINATOR = new Uint8Array([ 80, 199, 51, 81, 135, 100, 99, 227, ]); export function getFactionOwnershipDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( FACTION_OWNERSHIP_DISCRIMINATOR, ); } /** * Dynamic-ownership sidecar for ONE asset. Sized `Pod` (the `CurrencyConfigCache` idiom), `#[repr(C,packed)]`, * `Align1`. `directive_block` is RESERVED for P5 (zero-written, read nowhere in P4). */ export type FactionOwnership = { discriminator: ReadonlyUint8Array; /** Schema/migration lever (=0). */ version: number; /** This account's PDA bump. */ bump: number; /** Game scoping (AccountValidate compares). */ gameId: Address; /** STARBASE=0 / FLEET=1 / REGION=2 (== the 2nd seed byte; MUST stay a seed forever — collision boundary). */ assetKind: number; /** Canonical 32-byte identity (== the 3rd seed). */ assetKey: Array; /** Dynamic controller; 0 = fall back to the legacy enum owner. */ controllingFaction: MinorFactionId; /** * The controller BEFORE the most recent capture (0 = none) — grants the displaced owner a * contested-window re-capture bypass (anti capture-and-camp). */ previousController: MinorFactionId; /** Unix ts of the last (re)capture / pre-seed. */ capturedAt: bigint; /** No re-flip until `now >= this` (0 = immediately capturable). */ contestedUntil: bigint; /** * Generation witness (== `StarSystem.seq_id` at capture) — NOT a seed (seq_id mutates on capture/removal). * Checked + re-stamped at the boundary. 0 for Fleet/Region. */ capturedSeqId: bigint; /** RESERVED for P5 (asset_kind=Fleet directive payload). Written ALL-ZERO in P4; read NOWHERE. */ directiveBlock: Array; /** * P5 territory payoff: per-asset yield idempotency cursor (STARBASE sidecars only; whole-tick advance). * 0 = never claimed. NEVER overlaps `directive_block` (the FLEET-sidecar reuse of those bytes). */ lastYieldTickTs: bigint; /** * Additive growth budget — carve typed (Pod, 0-valid) fields from the FRONT; NEVER append. `asset_kind` * MUST remain a seed component forever. */ reserved: Array; }; export type FactionOwnershipArgs = { /** Schema/migration lever (=0). */ version: number; /** This account's PDA bump. */ bump: number; /** Game scoping (AccountValidate compares). */ gameId: Address; /** STARBASE=0 / FLEET=1 / REGION=2 (== the 2nd seed byte; MUST stay a seed forever — collision boundary). */ assetKind: number; /** Canonical 32-byte identity (== the 3rd seed). */ assetKey: Array; /** Dynamic controller; 0 = fall back to the legacy enum owner. */ controllingFaction: MinorFactionIdArgs; /** * The controller BEFORE the most recent capture (0 = none) — grants the displaced owner a * contested-window re-capture bypass (anti capture-and-camp). */ previousController: MinorFactionIdArgs; /** Unix ts of the last (re)capture / pre-seed. */ capturedAt: number | bigint; /** No re-flip until `now >= this` (0 = immediately capturable). */ contestedUntil: number | bigint; /** * Generation witness (== `StarSystem.seq_id` at capture) — NOT a seed (seq_id mutates on capture/removal). * Checked + re-stamped at the boundary. 0 for Fleet/Region. */ capturedSeqId: number | bigint; /** RESERVED for P5 (asset_kind=Fleet directive payload). Written ALL-ZERO in P4; read NOWHERE. */ directiveBlock: Array; /** * P5 territory payoff: per-asset yield idempotency cursor (STARBASE sidecars only; whole-tick advance). * 0 = never claimed. NEVER overlaps `directive_block` (the FLEET-sidecar reuse of those bytes). */ lastYieldTickTs: number | bigint; /** * Additive growth budget — carve typed (Pod, 0-valid) fields from the FRONT; NEVER append. `asset_kind` * MUST remain a seed component forever. */ reserved: Array; }; /** Gets the encoder for {@link FactionOwnershipArgs} account data. */ export function getFactionOwnershipEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['assetKind', getU8Encoder()], ['assetKey', getArrayEncoder(getU8Encoder(), { size: 32 })], ['controllingFaction', getMinorFactionIdEncoder()], ['previousController', getMinorFactionIdEncoder()], ['capturedAt', getI64Encoder()], ['contestedUntil', getI64Encoder()], ['capturedSeqId', getU64Encoder()], ['directiveBlock', getArrayEncoder(getU8Encoder(), { size: 28 })], ['lastYieldTickTs', getI64Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 6 })], ]), (value) => ({ ...value, discriminator: FACTION_OWNERSHIP_DISCRIMINATOR }), ); } /** Gets the decoder for {@link FactionOwnership} account data. */ export function getFactionOwnershipDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['assetKind', getU8Decoder()], ['assetKey', getArrayDecoder(getU8Decoder(), { size: 32 })], ['controllingFaction', getMinorFactionIdDecoder()], ['previousController', getMinorFactionIdDecoder()], ['capturedAt', getI64Decoder()], ['contestedUntil', getI64Decoder()], ['capturedSeqId', getU64Decoder()], ['directiveBlock', getArrayDecoder(getU8Decoder(), { size: 28 })], ['lastYieldTickTs', getI64Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 6 })], ]); } /** Gets the codec for {@link FactionOwnership} account data. */ export function getFactionOwnershipCodec(): FixedSizeCodec< FactionOwnershipArgs, FactionOwnership > { return combineCodec( getFactionOwnershipEncoder(), getFactionOwnershipDecoder(), ); } export function decodeFactionOwnership( encodedAccount: EncodedAccount, ): Account; export function decodeFactionOwnership( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeFactionOwnership( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getFactionOwnershipDecoder(), ); } export async function fetchFactionOwnership( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeFactionOwnership(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionOwnership< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeFactionOwnership(maybeAccount); } export async function fetchAllFactionOwnership( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeFactionOwnership( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeFactionOwnership( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeFactionOwnership(maybeAccount), ); } export async function fetchFactionOwnershipFromSeeds( rpc: Parameters[0], seeds: FactionOwnershipSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeFactionOwnershipFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionOwnershipFromSeeds( rpc: Parameters[0], seeds: FactionOwnershipSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findFactionOwnershipPda(seeds, { programAddress }); return await fetchMaybeFactionOwnership(rpc, address, fetchConfig); }