/** * 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, getMapDecoder, getMapEncoder, getOptionDecoder, getOptionEncoder, getSetDecoder, getSetEncoder, 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 Option, type OptionOrNullable, type ReadonlyUint8Array, } from '@solana/kit'; import { getI8F56Decoder, getI8F56Encoder, type I8F56, type I8F56Args, } from '../../fixed/codecs'; import { findStarSystemPda, StarSystemSeeds } from '../pdas'; import { getConnectionCostDecoder, getConnectionCostEncoder, getNameDecoder, getNameEncoder, getRegionIdDecoder, getRegionIdEncoder, getStarbaseDecoder, getStarbaseEncoder, getSystemIdDecoder, getSystemIdEncoder, type ConnectionCost, type ConnectionCostArgs, type Name, type NameArgs, type RegionId, type RegionIdArgs, type Starbase, type StarbaseArgs, type SystemId, type SystemIdArgs, } from '../types'; export const STAR_SYSTEM_DISCRIMINATOR = new Uint8Array([ 207, 32, 123, 9, 9, 251, 221, 169, ]); export function getStarSystemDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(STAR_SYSTEM_DISCRIMINATOR); } /** Star System Account */ export type StarSystem = { discriminator: ReadonlyUint8Array; /** The data version of this account. */ version: number; /** The game this star system belongs to */ gameId: Address; /** The unique system id */ systemId: SystemId; /** The name of this star system */ name: Name; /** The region this star system belongs to */ region: Option; /** The coordinates of this star system */ coordinates: Array; /** The sequence id for the `Starbase`. Incremented when starbase changes hands or is removed. */ seqId: bigint; /** * The connections to other star systems, forms warp lanes when both ends are owned by the same faction. * The value is the cost in atlas based on the starbase level. * Fee charged for the "warp lane" movement type which is meant to be charged in ATLAS. * Since ATLAS has 8 decimal places, units are in the smallest value of ATLAS possible. */ connections: Map; /** The celestial bodies in this star system */ celestialBodies: Set
; /** The starbase in this star system */ starbase: Option; }; export type StarSystemArgs = { /** The data version of this account. */ version: number; /** The game this star system belongs to */ gameId: Address; /** The unique system id */ systemId: SystemIdArgs; /** The name of this star system */ name: NameArgs; /** The region this star system belongs to */ region: OptionOrNullable; /** The coordinates of this star system */ coordinates: Array; /** The sequence id for the `Starbase`. Incremented when starbase changes hands or is removed. */ seqId: number | bigint; /** * The connections to other star systems, forms warp lanes when both ends are owned by the same faction. * The value is the cost in atlas based on the starbase level. * Fee charged for the "warp lane" movement type which is meant to be charged in ATLAS. * Since ATLAS has 8 decimal places, units are in the smallest value of ATLAS possible. */ connections: Map; /** The celestial bodies in this star system */ celestialBodies: Set
; /** The starbase in this star system */ starbase: OptionOrNullable; }; /** Gets the encoder for {@link StarSystemArgs} account data. */ export function getStarSystemEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['gameId', getAddressEncoder()], ['systemId', getSystemIdEncoder()], ['name', getNameEncoder()], [ 'region', getOptionEncoder(getRegionIdEncoder(), { noneValue: 'zeroes' }), ], ['coordinates', getArrayEncoder(getI8F56Encoder(), { size: 2 })], ['seqId', getU64Encoder()], [ 'connections', getMapEncoder(getSystemIdEncoder(), getConnectionCostEncoder()), ], ['celestialBodies', getSetEncoder(getAddressEncoder())], ['starbase', getOptionEncoder(getStarbaseEncoder())], ]), (value) => ({ ...value, discriminator: STAR_SYSTEM_DISCRIMINATOR }), ); } /** Gets the decoder for {@link StarSystem} account data. */ export function getStarSystemDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['gameId', getAddressDecoder()], ['systemId', getSystemIdDecoder()], ['name', getNameDecoder()], ['region', getOptionDecoder(getRegionIdDecoder(), { noneValue: 'zeroes' })], ['coordinates', getArrayDecoder(getI8F56Decoder(), { size: 2 })], ['seqId', getU64Decoder()], [ 'connections', getMapDecoder(getSystemIdDecoder(), getConnectionCostDecoder()), ], ['celestialBodies', getSetDecoder(getAddressDecoder())], ['starbase', getOptionDecoder(getStarbaseDecoder())], ]); } /** Gets the codec for {@link StarSystem} account data. */ export function getStarSystemCodec(): Codec { return combineCodec(getStarSystemEncoder(), getStarSystemDecoder()); } export function decodeStarSystem( encodedAccount: EncodedAccount, ): Account; export function decodeStarSystem( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeStarSystem( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getStarSystemDecoder(), ); } export async function fetchStarSystem( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeStarSystem(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeStarSystem( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeStarSystem(maybeAccount); } export async function fetchAllStarSystem( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeStarSystem(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeStarSystem( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeStarSystem(maybeAccount)); } export async function fetchStarSystemFromSeeds( rpc: Parameters[0], seeds: StarSystemSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeStarSystemFromSeeds(rpc, seeds, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeStarSystemFromSeeds( rpc: Parameters[0], seeds: StarSystemSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findStarSystemPda(seeds, { programAddress }); return await fetchMaybeStarSystem(rpc, address, fetchConfig); }