/** * 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 Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array, } from '@solana/kit'; import { EncounterCommitSeeds, findEncounterCommitPda } from '../pdas'; import { getMinorFactionIdDecoder, getMinorFactionIdEncoder, getRegionIdDecoder, getRegionIdEncoder, type MinorFactionId, type MinorFactionIdArgs, type RegionId, type RegionIdArgs, } from '../types'; export const ENCOUNTER_COMMIT_DISCRIMINATOR = new Uint8Array([ 241, 110, 50, 27, 147, 35, 0, 218, ]); export function getEncounterCommitDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( ENCOUNTER_COMMIT_DISCRIMINATOR, ); } /** * Per-character commit tracker for the two-phase encounter reveal (Option B — migration-safe; this * avoids touching the core `Fleet` account, which is a non-singleton `#[unsized_type]` with no spare * pad). Created once per character via `OpenEncounterTracking`; a scan that arms an encounter stamps * `commit_slot` + `region_id` + the triggering `fleet` here. The reveal reads it, draws the contents * from a *later* slot's hash, and clears it. One pending encounter per character at a time — a * subsequent scan overwrites the prior pending commit (reinforces the anti-multi-fleet design). */ export type EncounterCommit = { discriminator: ReadonlyUint8Array; version: number; bump: number; gameId: Address; /** The owning character (also the scoping seed). */ character: Address; /** The fleet that armed the current pending commit (`None` when empty). */ fleet: Address; /** The slot of the arming scan. The reveal must consume a slot hash strictly later than this. */ commitSlot: bigint; /** The region pinned at scan time (resolved from the fleet's location). */ regionId: RegionId; /** `STATUS_EMPTY` (0) or `STATUS_PENDING` (1). */ status: number; /** * The exact sector where the encounter armed (the scanning fleet's location). Copied onto the market * at reveal; trading requires a fleet idle AT this sector. */ location: Array; /** * The minor faction PINNED at scan time — the `(region, faction)` pool the player committed to BEFORE * the reveal's future hash existed. Reveal requires the supplied pool's `minor_faction` to equal this, * so the faction can't be steered after the entropy is knowable. `Default` (0) when the commit is empty. */ minorFaction: MinorFactionId; /** Tail-append room for additive growth. */ reserved: Array; }; export type EncounterCommitArgs = { version: number; bump: number; gameId: Address; /** The owning character (also the scoping seed). */ character: Address; /** The fleet that armed the current pending commit (`None` when empty). */ fleet: Address; /** The slot of the arming scan. The reveal must consume a slot hash strictly later than this. */ commitSlot: number | bigint; /** The region pinned at scan time (resolved from the fleet's location). */ regionId: RegionIdArgs; /** `STATUS_EMPTY` (0) or `STATUS_PENDING` (1). */ status: number; /** * The exact sector where the encounter armed (the scanning fleet's location). Copied onto the market * at reveal; trading requires a fleet idle AT this sector. */ location: Array; /** * The minor faction PINNED at scan time — the `(region, faction)` pool the player committed to BEFORE * the reveal's future hash existed. Reveal requires the supplied pool's `minor_faction` to equal this, * so the faction can't be steered after the entropy is knowable. `Default` (0) when the commit is empty. */ minorFaction: MinorFactionIdArgs; /** Tail-append room for additive growth. */ reserved: Array; }; /** Gets the encoder for {@link EncounterCommitArgs} account data. */ export function getEncounterCommitEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['character', getAddressEncoder()], ['fleet', getAddressEncoder()], ['commitSlot', getU64Encoder()], ['regionId', getRegionIdEncoder()], ['status', getU8Encoder()], ['location', getArrayEncoder(getI64Encoder(), { size: 2 })], ['minorFaction', getMinorFactionIdEncoder()], ['reserved', getArrayEncoder(getU8Encoder())], ]), (value) => ({ ...value, discriminator: ENCOUNTER_COMMIT_DISCRIMINATOR }), ); } /** Gets the decoder for {@link EncounterCommit} account data. */ export function getEncounterCommitDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['character', getAddressDecoder()], ['fleet', getAddressDecoder()], ['commitSlot', getU64Decoder()], ['regionId', getRegionIdDecoder()], ['status', getU8Decoder()], ['location', getArrayDecoder(getI64Decoder(), { size: 2 })], ['minorFaction', getMinorFactionIdDecoder()], ['reserved', getArrayDecoder(getU8Decoder())], ]); } /** Gets the codec for {@link EncounterCommit} account data. */ export function getEncounterCommitCodec(): Codec< EncounterCommitArgs, EncounterCommit > { return combineCodec(getEncounterCommitEncoder(), getEncounterCommitDecoder()); } export function decodeEncounterCommit( encodedAccount: EncodedAccount, ): Account; export function decodeEncounterCommit( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeEncounterCommit( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getEncounterCommitDecoder(), ); } export async function fetchEncounterCommit( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeEncounterCommit(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeEncounterCommit< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeEncounterCommit(maybeAccount); } export async function fetchAllEncounterCommit( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeEncounterCommit( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeEncounterCommit( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeEncounterCommit(maybeAccount), ); } export async function fetchEncounterCommitFromSeeds( rpc: Parameters[0], seeds: EncounterCommitSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeEncounterCommitFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeEncounterCommitFromSeeds( rpc: Parameters[0], seeds: EncounterCommitSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findEncounterCommitPda(seeds, { programAddress }); return await fetchMaybeEncounterCommit(rpc, address, fetchConfig); }