/** * 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, getMapDecoder, getMapEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, 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 { getFactionDecoder, getFactionEncoder, type Faction, type FactionArgs, } from '@staratlas/dev-profile-faction'; import { getI8F56Decoder, getI8F56Encoder, type I8F56, type I8F56Args, } from '../../fixed/codecs'; import { findFleetPda, FleetSeeds } from '../pdas'; import { getActiveStimulantDecoder, getActiveStimulantEncoder, getCargoPodDecoder, getCargoPodEncoder, getCombatStatFieldDecoder, getCombatStatFieldEncoder, getFleetStanceDecoder, getFleetStanceEncoder, getFleetStateDecoder, getFleetStateEncoder, getMinorFactionIdDecoder, getMinorFactionIdEncoder, getNameDecoder, getNameEncoder, getShipCountsDecoder, getShipCountsEncoder, getShipIdDecoder, getShipIdEncoder, getShipStatsDecoder, getShipStatsEncoder, getSingleCargoDecoder, getSingleCargoEncoder, type ActiveStimulant, type ActiveStimulantArgs, type CargoPod, type CargoPodArgs, type CombatStatField, type CombatStatFieldArgs, type FleetStance, type FleetStanceArgs, type FleetState, type FleetStateArgs, type MinorFactionId, type MinorFactionIdArgs, type Name, type NameArgs, type ShipCounts, type ShipCountsArgs, type ShipId, type ShipIdArgs, type ShipStats, type ShipStatsArgs, type SingleCargo, type SingleCargoArgs, } from '../types'; export const FLEET_DISCRIMINATOR = new Uint8Array([ 109, 207, 251, 48, 106, 2, 136, 163, ]); export function getFleetDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(FLEET_DISCRIMINATOR); } /** A `SAGE` fleet. */ export type Fleet = { discriminator: ReadonlyUint8Array; /** The data version of this account. */ version: number; /** The fleet's bump. */ bump: number; /** The game id this belongs to. */ gameId: Address; /** The owner's profile. */ ownerProfile: Address; /** * The fleet's sub-authority. * If `Some` will have the exclusive ability to interact with this fleet. */ subProfile: Address; /** The authority for revoking a sun-authority. */ subProfileInvalidator: Address; /** The faction of the profile. */ faction: Faction; /** * Structural NPC classification. `0` is a player fleet; a nonzero id is the authored NPC faction. * Reward branching reads this field instead of trusting an omittable ownership sidecar. */ npcFactionId: MinorFactionId; /** The label or name of the fleet. */ fleetLabel: Name; /** The number of ships in the fleet. */ shipCounts: ShipCounts; /** The time at which the warp cooldown expires */ warpCooldownExpiresAt: bigint; /** The time at which the scan cooldown expires */ scanCooldownExpiresAt: bigint; /** The fleet's stats. */ stats: ShipStats; /** The Cargo pod representing the fleet's fuel tank */ fuelTank: SingleCargo; /** The Cargo pod representing the fleet's ammo bank */ ammoBank: SingleCargo; /** The fleet's crew count */ crewCount: number; /** The fleet's rented crew */ rentedCrew: number; /** The fleet's state */ shipDefinitionsSeqId: number; /** Current fleet ability power */ ap: number; /** Current fleet shield points */ sp: number; /** Current fleet health points */ hp: number; /** Current fleet pending health points */ pendingHp: number; /** The fleet's stance */ stance: FleetStance; /** The time at which reloading completes */ apReloadExpiresAt: bigint; /** The time at which SP can resume regenerating */ shieldBreakDelayExpiresAt: bigint; /** The last time the combat was updated */ lastCombatUpdate: bigint; location: Array; /** The last time the fleet's state was updated */ lastUpdateAt: bigint; /** The fleet's ships */ fleetShips: Map; /** Cargo waiting to respawn for this fleet */ respawningCargo: CargoPod; /** The fleet's equipped ship components */ components: CargoPod; /** The Cargo pod representing the fleet's cargo hold */ cargoHold: CargoPod; /** Active combat stimulants applied to the fleet, keyed by affected combat stat. */ activeStimulants: Map; /** The fleet's state */ state: FleetState; }; export type FleetArgs = { /** The data version of this account. */ version: number; /** The fleet's bump. */ bump: number; /** The game id this belongs to. */ gameId: Address; /** The owner's profile. */ ownerProfile: Address; /** * The fleet's sub-authority. * If `Some` will have the exclusive ability to interact with this fleet. */ subProfile: Address; /** The authority for revoking a sun-authority. */ subProfileInvalidator: Address; /** The faction of the profile. */ faction: FactionArgs; /** * Structural NPC classification. `0` is a player fleet; a nonzero id is the authored NPC faction. * Reward branching reads this field instead of trusting an omittable ownership sidecar. */ npcFactionId: MinorFactionIdArgs; /** The label or name of the fleet. */ fleetLabel: NameArgs; /** The number of ships in the fleet. */ shipCounts: ShipCountsArgs; /** The time at which the warp cooldown expires */ warpCooldownExpiresAt: number | bigint; /** The time at which the scan cooldown expires */ scanCooldownExpiresAt: number | bigint; /** The fleet's stats. */ stats: ShipStatsArgs; /** The Cargo pod representing the fleet's fuel tank */ fuelTank: SingleCargoArgs; /** The Cargo pod representing the fleet's ammo bank */ ammoBank: SingleCargoArgs; /** The fleet's crew count */ crewCount: number; /** The fleet's rented crew */ rentedCrew: number; /** The fleet's state */ shipDefinitionsSeqId: number; /** Current fleet ability power */ ap: number; /** Current fleet shield points */ sp: number; /** Current fleet health points */ hp: number; /** Current fleet pending health points */ pendingHp: number; /** The fleet's stance */ stance: FleetStanceArgs; /** The time at which reloading completes */ apReloadExpiresAt: number | bigint; /** The time at which SP can resume regenerating */ shieldBreakDelayExpiresAt: number | bigint; /** The last time the combat was updated */ lastCombatUpdate: number | bigint; location: Array; /** The last time the fleet's state was updated */ lastUpdateAt: number | bigint; /** The fleet's ships */ fleetShips: Map; /** Cargo waiting to respawn for this fleet */ respawningCargo: CargoPodArgs; /** The fleet's equipped ship components */ components: CargoPodArgs; /** The Cargo pod representing the fleet's cargo hold */ cargoHold: CargoPodArgs; /** Active combat stimulants applied to the fleet, keyed by affected combat stat. */ activeStimulants: Map; /** The fleet's state */ state: FleetStateArgs; }; /** Gets the encoder for {@link FleetArgs} account data. */ export function getFleetEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['ownerProfile', getAddressEncoder()], ['subProfile', getAddressEncoder()], ['subProfileInvalidator', getAddressEncoder()], ['faction', getFactionEncoder()], ['npcFactionId', getMinorFactionIdEncoder()], ['fleetLabel', getNameEncoder()], ['shipCounts', getShipCountsEncoder()], ['warpCooldownExpiresAt', getI64Encoder()], ['scanCooldownExpiresAt', getI64Encoder()], ['stats', getShipStatsEncoder()], ['fuelTank', getSingleCargoEncoder()], ['ammoBank', getSingleCargoEncoder()], ['crewCount', getU16Encoder()], ['rentedCrew', getU16Encoder()], ['shipDefinitionsSeqId', getU32Encoder()], ['ap', getU32Encoder()], ['sp', getU32Encoder()], ['hp', getU32Encoder()], ['pendingHp', getU32Encoder()], ['stance', getFleetStanceEncoder()], ['apReloadExpiresAt', getI64Encoder()], ['shieldBreakDelayExpiresAt', getI64Encoder()], ['lastCombatUpdate', getI64Encoder()], ['location', getArrayEncoder(getI8F56Encoder(), { size: 2 })], ['lastUpdateAt', getI64Encoder()], ['fleetShips', getMapEncoder(getShipIdEncoder(), getU64Encoder())], ['respawningCargo', getCargoPodEncoder()], ['components', getCargoPodEncoder()], ['cargoHold', getCargoPodEncoder()], [ 'activeStimulants', getMapEncoder(getCombatStatFieldEncoder(), getActiveStimulantEncoder()), ], ['state', getFleetStateEncoder()], ]), (value) => ({ ...value, discriminator: FLEET_DISCRIMINATOR }), ); } /** Gets the decoder for {@link Fleet} account data. */ export function getFleetDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['ownerProfile', getAddressDecoder()], ['subProfile', getAddressDecoder()], ['subProfileInvalidator', getAddressDecoder()], ['faction', getFactionDecoder()], ['npcFactionId', getMinorFactionIdDecoder()], ['fleetLabel', getNameDecoder()], ['shipCounts', getShipCountsDecoder()], ['warpCooldownExpiresAt', getI64Decoder()], ['scanCooldownExpiresAt', getI64Decoder()], ['stats', getShipStatsDecoder()], ['fuelTank', getSingleCargoDecoder()], ['ammoBank', getSingleCargoDecoder()], ['crewCount', getU16Decoder()], ['rentedCrew', getU16Decoder()], ['shipDefinitionsSeqId', getU32Decoder()], ['ap', getU32Decoder()], ['sp', getU32Decoder()], ['hp', getU32Decoder()], ['pendingHp', getU32Decoder()], ['stance', getFleetStanceDecoder()], ['apReloadExpiresAt', getI64Decoder()], ['shieldBreakDelayExpiresAt', getI64Decoder()], ['lastCombatUpdate', getI64Decoder()], ['location', getArrayDecoder(getI8F56Decoder(), { size: 2 })], ['lastUpdateAt', getI64Decoder()], ['fleetShips', getMapDecoder(getShipIdDecoder(), getU64Decoder())], ['respawningCargo', getCargoPodDecoder()], ['components', getCargoPodDecoder()], ['cargoHold', getCargoPodDecoder()], [ 'activeStimulants', getMapDecoder(getCombatStatFieldDecoder(), getActiveStimulantDecoder()), ], ['state', getFleetStateDecoder()], ]); } /** Gets the codec for {@link Fleet} account data. */ export function getFleetCodec(): Codec { return combineCodec(getFleetEncoder(), getFleetDecoder()); } export function decodeFleet( encodedAccount: EncodedAccount, ): Account; export function decodeFleet( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeFleet( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getFleetDecoder(), ); } export async function fetchFleet( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeFleet(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFleet( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeFleet(maybeAccount); } export async function fetchAllFleet( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeFleet(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeFleet( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeFleet(maybeAccount)); } export async function fetchFleetFromSeeds( rpc: Parameters[0], seeds: FleetSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeFleetFromSeeds(rpc, seeds, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFleetFromSeeds( rpc: Parameters[0], seeds: FleetSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findFleetPda(seeds, { programAddress }); return await fetchMaybeFleet(rpc, address, fetchConfig); }