/** * 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, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getMapDecoder, getMapEncoder, getStructDecoder, getStructEncoder, 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 { findStarbasePlayerPda, StarbasePlayerSeeds } from '../pdas'; import { getCargoPodDecoder, getCargoPodEncoder, getClaimStakeDefinitionIdDecoder, getClaimStakeDefinitionIdEncoder, getCraftingHabDefinitionIdDecoder, getCraftingHabDefinitionIdEncoder, getRespawnQueueDecoder, getRespawnQueueEncoder, getShipIdDecoder, getShipIdEncoder, type CargoPod, type CargoPodArgs, type ClaimStakeDefinitionId, type ClaimStakeDefinitionIdArgs, type CraftingHabDefinitionId, type CraftingHabDefinitionIdArgs, type RespawnQueue, type RespawnQueueArgs, type ShipId, type ShipIdArgs, } from '../types'; export const STARBASE_PLAYER_DISCRIMINATOR = new Uint8Array([ 192, 234, 144, 86, 72, 19, 5, 99, ]); export function getStarbasePlayerDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( STARBASE_PLAYER_DISCRIMINATOR, ); } /** The `SAGE` player info within a `Starbase` */ export type StarbasePlayer = { discriminator: ReadonlyUint8Array; /** The data version of this account */ version: number; /** The `Profile` key */ playerProfile: Address; /** The `Faction` of the player. */ faction: Faction; /** The `System` key */ system: Address; /** The `Character` key */ character: Address; /** The total crew members from the player's fleets at the `Starbase` */ totalCrew: number; /** The number of crew members that is engaged/busy and not available */ busyCrew: number; /** Crew currently respawning from this starbase */ respawningCrew: RespawnQueue; /** The seq_id of `Starbase` */ seqId: bigint; /** The time at which cargo respawn completes */ cargoRespawnEndsAt: bigint; /** Bump of Account PDA */ bump: number; /** Ships currently respawning from this starbase */ respawningShips: Map; /** Claim stakes currently respawning from this starbase */ respawningClaimStakes: Map; /** Crafting habs currently respawning from this starbase */ respawningCraftingHabs: Map; /** Cargo waiting to respawn for this starbase player */ respawningCargo: CargoPod; /** Ships in escrow */ shipsInEscrow: Map; /** The cargo pod for the player at this starbase */ cargoPod: CargoPod; }; export type StarbasePlayerArgs = { /** The data version of this account */ version: number; /** The `Profile` key */ playerProfile: Address; /** The `Faction` of the player. */ faction: FactionArgs; /** The `System` key */ system: Address; /** The `Character` key */ character: Address; /** The total crew members from the player's fleets at the `Starbase` */ totalCrew: number; /** The number of crew members that is engaged/busy and not available */ busyCrew: number; /** Crew currently respawning from this starbase */ respawningCrew: RespawnQueueArgs; /** The seq_id of `Starbase` */ seqId: number | bigint; /** The time at which cargo respawn completes */ cargoRespawnEndsAt: number | bigint; /** Bump of Account PDA */ bump: number; /** Ships currently respawning from this starbase */ respawningShips: Map; /** Claim stakes currently respawning from this starbase */ respawningClaimStakes: Map; /** Crafting habs currently respawning from this starbase */ respawningCraftingHabs: Map; /** Cargo waiting to respawn for this starbase player */ respawningCargo: CargoPodArgs; /** Ships in escrow */ shipsInEscrow: Map; /** The cargo pod for the player at this starbase */ cargoPod: CargoPodArgs; }; /** Gets the encoder for {@link StarbasePlayerArgs} account data. */ export function getStarbasePlayerEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['playerProfile', getAddressEncoder()], ['faction', getFactionEncoder()], ['system', getAddressEncoder()], ['character', getAddressEncoder()], ['totalCrew', getU32Encoder()], ['busyCrew', getU32Encoder()], ['respawningCrew', getRespawnQueueEncoder()], ['seqId', getU64Encoder()], ['cargoRespawnEndsAt', getI64Encoder()], ['bump', getU8Encoder()], [ 'respawningShips', getMapEncoder(getShipIdEncoder(), getRespawnQueueEncoder()), ], [ 'respawningClaimStakes', getMapEncoder( getClaimStakeDefinitionIdEncoder(), getRespawnQueueEncoder(), ), ], [ 'respawningCraftingHabs', getMapEncoder( getCraftingHabDefinitionIdEncoder(), getRespawnQueueEncoder(), ), ], ['respawningCargo', getCargoPodEncoder()], ['shipsInEscrow', getMapEncoder(getShipIdEncoder(), getU64Encoder())], ['cargoPod', getCargoPodEncoder()], ]), (value) => ({ ...value, discriminator: STARBASE_PLAYER_DISCRIMINATOR }), ); } /** Gets the decoder for {@link StarbasePlayer} account data. */ export function getStarbasePlayerDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['playerProfile', getAddressDecoder()], ['faction', getFactionDecoder()], ['system', getAddressDecoder()], ['character', getAddressDecoder()], ['totalCrew', getU32Decoder()], ['busyCrew', getU32Decoder()], ['respawningCrew', getRespawnQueueDecoder()], ['seqId', getU64Decoder()], ['cargoRespawnEndsAt', getI64Decoder()], ['bump', getU8Decoder()], [ 'respawningShips', getMapDecoder(getShipIdDecoder(), getRespawnQueueDecoder()), ], [ 'respawningClaimStakes', getMapDecoder( getClaimStakeDefinitionIdDecoder(), getRespawnQueueDecoder(), ), ], [ 'respawningCraftingHabs', getMapDecoder( getCraftingHabDefinitionIdDecoder(), getRespawnQueueDecoder(), ), ], ['respawningCargo', getCargoPodDecoder()], ['shipsInEscrow', getMapDecoder(getShipIdDecoder(), getU64Decoder())], ['cargoPod', getCargoPodDecoder()], ]); } /** Gets the codec for {@link StarbasePlayer} account data. */ export function getStarbasePlayerCodec(): Codec< StarbasePlayerArgs, StarbasePlayer > { return combineCodec(getStarbasePlayerEncoder(), getStarbasePlayerDecoder()); } export function decodeStarbasePlayer( encodedAccount: EncodedAccount, ): Account; export function decodeStarbasePlayer( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeStarbasePlayer( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getStarbasePlayerDecoder(), ); } export async function fetchStarbasePlayer( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeStarbasePlayer(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeStarbasePlayer< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeStarbasePlayer(maybeAccount); } export async function fetchAllStarbasePlayer( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeStarbasePlayer( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeStarbasePlayer( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeStarbasePlayer(maybeAccount), ); } export async function fetchStarbasePlayerFromSeeds( rpc: Parameters[0], seeds: StarbasePlayerSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeStarbasePlayerFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeStarbasePlayerFromSeeds( rpc: Parameters[0], seeds: StarbasePlayerSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findStarbasePlayerPda(seeds, { programAddress }); return await fetchMaybeStarbasePlayer(rpc, address, fetchConfig); }