/** * 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, 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 { findFleetCrewBindingPda, FleetCrewBindingSeeds } from '../pdas'; import { getRosterSummaryDecoder, getRosterSummaryEncoder, type RosterSummary, type RosterSummaryArgs, } from '../types'; export const FLEET_CREW_BINDING_DISCRIMINATOR = new Uint8Array([ 203, 64, 149, 37, 111, 204, 184, 181, ]); export function getFleetCrewBindingDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( FLEET_CREW_BINDING_DISCRIMINATOR, ); } /** * Each fleet's per-fleet crew aggregate. **Presence = at least one crew onboarded.** The * gameplay folds read `summary` (the sum of ONLY this fleet's onboarded crew), maintained by * `LoadFleetCrewRoster`/`UnloadFleetCrewRoster`. * * Body = 1 (version) + 1 (bump) + 6 (reserved) + 32 (fleet) + 32 (owner) + 315 (summary) * + 8 (last_action_epoch) = **395 B**, align 1. (The summary grew 274 → 314 with the * per-skill-XP accumulator block, → 315 with the `max_rarity` cache byte; `last_action_epoch` * is the binding-tail Cold Start marker. The header fields before the summary — * version/bump/_reserved/fleet/owner, 72 B — are unchanged, so the summary still begins at * account-offset `8 (disc) + 72 = 80`, exactly as before.) */ export type FleetCrewBinding = { discriminator: ReadonlyUint8Array; /** Data version of this account. */ version: number; /** PDA bump (managed by the framework on create). */ bump: number; /** Reserved (zero today) — forward-compat slack (no alignment under `packed`). */ reserved: Array; /** The fleet this cache belongs to (integrity check vs. the PDA seed). */ fleet: Address; /** * The owner profile — the **owner-lock**, captured when the first crew onboards; a gameplay * resolve re-checks this == the fleet's `owner_profile`. */ ownerProfile: Address; /** * The per-fleet crew aggregate — the sum of ONLY the crew onboarded to this fleet. Identical * O(1) cache shape as the whole-roster `RosterSummary`, so the existing folds read it * unchanged in spirit (they just point at this per-fleet summary instead of the roster's). */ summary: RosterSummary; /** * The fleet's last-acted withdraw-epoch (PerkCtx activation §2.4 — the * `FirstActionPerEpoch` marker for Cold Start #7). The warp instruction computes * `epoch = now / withdraw_epoch_duration`, evaluates * `first_action_this_epoch = (epoch != last_action_epoch)`, and stamps the new epoch after * the warp resolves (riding the existing `Mut` binding the XP-pour already holds). * Crew-owned state: a flag-off path has no binding, so this is never read nor written there. * Zero-default ⇒ the first action of epoch 0 reads "first" once — harmless, and only * observable when a Cold Start entry is present. Tail-appended after `summary`. */ lastActionEpoch: bigint; }; export type FleetCrewBindingArgs = { /** Data version of this account. */ version: number; /** PDA bump (managed by the framework on create). */ bump: number; /** Reserved (zero today) — forward-compat slack (no alignment under `packed`). */ reserved: Array; /** The fleet this cache belongs to (integrity check vs. the PDA seed). */ fleet: Address; /** * The owner profile — the **owner-lock**, captured when the first crew onboards; a gameplay * resolve re-checks this == the fleet's `owner_profile`. */ ownerProfile: Address; /** * The per-fleet crew aggregate — the sum of ONLY the crew onboarded to this fleet. Identical * O(1) cache shape as the whole-roster `RosterSummary`, so the existing folds read it * unchanged in spirit (they just point at this per-fleet summary instead of the roster's). */ summary: RosterSummaryArgs; /** * The fleet's last-acted withdraw-epoch (PerkCtx activation §2.4 — the * `FirstActionPerEpoch` marker for Cold Start #7). The warp instruction computes * `epoch = now / withdraw_epoch_duration`, evaluates * `first_action_this_epoch = (epoch != last_action_epoch)`, and stamps the new epoch after * the warp resolves (riding the existing `Mut` binding the XP-pour already holds). * Crew-owned state: a flag-off path has no binding, so this is never read nor written there. * Zero-default ⇒ the first action of epoch 0 reads "first" once — harmless, and only * observable when a Cold Start entry is present. Tail-appended after `summary`. */ lastActionEpoch: number | bigint; }; /** Gets the encoder for {@link FleetCrewBindingArgs} account data. */ export function getFleetCrewBindingEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 6 })], ['fleet', getAddressEncoder()], ['ownerProfile', getAddressEncoder()], ['summary', getRosterSummaryEncoder()], ['lastActionEpoch', getU64Encoder()], ]), (value) => ({ ...value, discriminator: FLEET_CREW_BINDING_DISCRIMINATOR }), ); } /** Gets the decoder for {@link FleetCrewBinding} account data. */ export function getFleetCrewBindingDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 6 })], ['fleet', getAddressDecoder()], ['ownerProfile', getAddressDecoder()], ['summary', getRosterSummaryDecoder()], ['lastActionEpoch', getU64Decoder()], ]); } /** Gets the codec for {@link FleetCrewBinding} account data. */ export function getFleetCrewBindingCodec(): FixedSizeCodec< FleetCrewBindingArgs, FleetCrewBinding > { return combineCodec( getFleetCrewBindingEncoder(), getFleetCrewBindingDecoder(), ); } export function decodeFleetCrewBinding( encodedAccount: EncodedAccount, ): Account; export function decodeFleetCrewBinding( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeFleetCrewBinding( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getFleetCrewBindingDecoder(), ); } export async function fetchFleetCrewBinding( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeFleetCrewBinding(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFleetCrewBinding< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeFleetCrewBinding(maybeAccount); } export async function fetchAllFleetCrewBinding( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeFleetCrewBinding( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeFleetCrewBinding( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeFleetCrewBinding(maybeAccount), ); } export async function fetchFleetCrewBindingFromSeeds( rpc: Parameters[0], seeds: FleetCrewBindingSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeFleetCrewBindingFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFleetCrewBindingFromSeeds( rpc: Parameters[0], seeds: FleetCrewBindingSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findFleetCrewBindingPda(seeds, { programAddress }); return await fetchMaybeFleetCrewBinding(rpc, address, fetchConfig); }