/** * 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, getI16Decoder, getI16Encoder, getI64Decoder, getI64Encoder, 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 { FactionMarketSeeds, findFactionMarketPda } from '../pdas'; import { getLiveOfferDecoder, getLiveOfferEncoder, getMinorFactionIdDecoder, getMinorFactionIdEncoder, getScanPatternStatusDecoder, getScanPatternStatusEncoder, type LiveOffer, type LiveOfferArgs, type MinorFactionId, type MinorFactionIdArgs, type ScanPatternStatus, type ScanPatternStatusArgs, } from '../types'; export const FACTION_MARKET_DISCRIMINATOR = new Uint8Array([ 161, 70, 46, 105, 57, 57, 238, 2, ]); export function getFactionMarketDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( FACTION_MARKET_DISCRIMINATOR, ); } /** A persistent faction market at one starbase. 120 B sized header + `offers: List` tail. */ export type FactionMarket = { discriminator: ReadonlyUint8Array; version: number; bump: number; gameId: Address; /** Owning faction; the `FactionTreasury` PDA is derived from this (2nd treasury seed). */ factionId: MinorFactionId; /** Anchored star system (2nd market seed). `KeyFor` does not exist → key on the system. */ system: Address; /** * Pins a starbase incarnation within the system (3rd seed). Source is `StarSystem.seq_id` * (read `system.data()?.seq_id`); this is the market's own copy. */ starbaseSeqId: bigint; /** Draft/Active lifecycle (REUSED `ScanPatternStatus`; `CheckedBitPattern`, not `Pod`). */ status: ScanPatternStatus; /** Access band to BUY (Ask leg): converted via `band_of(.0 as i32)`. `<= -1000` = open. */ minStandingBuy: number; /** Access band to SELL (faucet leg). `<= -1000` = open (so a Hostile player can still sell their way back). */ minStandingSell: number; /** * Per-depletion-tier Ask price multiplier (bps). Index from reserve depletion (`depletion_tier`, * quartile bands); standing does NOT affect pricing (access-gating-only decision). `[u16;4]` (each * element align-1). */ priceTierBps: Array; /** Per-offer restock target, committed at create; opportunistic restock tops `remaining_qty` toward it. */ authoredTargetQty: bigint; /** In-trade restock time-gate (seconds); a restock runs at most once per period. */ restockPeriodSecs: number; /** Last successful restock (unix seconds). */ lastRestockAt: bigint; /** ATLAS-burn on the faucet (sell-back) leg, basis points. */ atlasBurnBps: number; /** Graduated per-market accrual rate (overrides `FactionConfig.standing_bps`); `0` disables earning here. */ standingBps: number; /** `0` = sell-only (faucet disabled). */ faucetEnabled: number; /** Reserved (carve-from for additive growth, e.g. more price tiers). */ pad: Array; /** Concrete Ask/Bid offers; `remaining_qty` topped toward `authored_target_qty` by the in-trade restock. */ offers: Array; }; export type FactionMarketArgs = { version: number; bump: number; gameId: Address; /** Owning faction; the `FactionTreasury` PDA is derived from this (2nd treasury seed). */ factionId: MinorFactionIdArgs; /** Anchored star system (2nd market seed). `KeyFor` does not exist → key on the system. */ system: Address; /** * Pins a starbase incarnation within the system (3rd seed). Source is `StarSystem.seq_id` * (read `system.data()?.seq_id`); this is the market's own copy. */ starbaseSeqId: number | bigint; /** Draft/Active lifecycle (REUSED `ScanPatternStatus`; `CheckedBitPattern`, not `Pod`). */ status: ScanPatternStatusArgs; /** Access band to BUY (Ask leg): converted via `band_of(.0 as i32)`. `<= -1000` = open. */ minStandingBuy: number; /** Access band to SELL (faucet leg). `<= -1000` = open (so a Hostile player can still sell their way back). */ minStandingSell: number; /** * Per-depletion-tier Ask price multiplier (bps). Index from reserve depletion (`depletion_tier`, * quartile bands); standing does NOT affect pricing (access-gating-only decision). `[u16;4]` (each * element align-1). */ priceTierBps: Array; /** Per-offer restock target, committed at create; opportunistic restock tops `remaining_qty` toward it. */ authoredTargetQty: number | bigint; /** In-trade restock time-gate (seconds); a restock runs at most once per period. */ restockPeriodSecs: number; /** Last successful restock (unix seconds). */ lastRestockAt: number | bigint; /** ATLAS-burn on the faucet (sell-back) leg, basis points. */ atlasBurnBps: number; /** Graduated per-market accrual rate (overrides `FactionConfig.standing_bps`); `0` disables earning here. */ standingBps: number; /** `0` = sell-only (faucet disabled). */ faucetEnabled: number; /** Reserved (carve-from for additive growth, e.g. more price tiers). */ pad: Array; /** Concrete Ask/Bid offers; `remaining_qty` topped toward `authored_target_qty` by the in-trade restock. */ offers: Array; }; /** Gets the encoder for {@link FactionMarketArgs} account data. */ export function getFactionMarketEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['factionId', getMinorFactionIdEncoder()], ['system', getAddressEncoder()], ['starbaseSeqId', getU64Encoder()], ['status', getScanPatternStatusEncoder()], ['minStandingBuy', getI16Encoder()], ['minStandingSell', getI16Encoder()], ['priceTierBps', getArrayEncoder(getU16Encoder(), { size: 4 })], ['authoredTargetQty', getU64Encoder()], ['restockPeriodSecs', getU32Encoder()], ['lastRestockAt', getI64Encoder()], ['atlasBurnBps', getU16Encoder()], ['standingBps', getU32Encoder()], ['faucetEnabled', getU8Encoder()], ['pad', getArrayEncoder(getU8Encoder(), { size: 4 })], ['offers', getArrayEncoder(getLiveOfferEncoder())], ]), (value) => ({ ...value, discriminator: FACTION_MARKET_DISCRIMINATOR }), ); } /** Gets the decoder for {@link FactionMarket} account data. */ export function getFactionMarketDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['factionId', getMinorFactionIdDecoder()], ['system', getAddressDecoder()], ['starbaseSeqId', getU64Decoder()], ['status', getScanPatternStatusDecoder()], ['minStandingBuy', getI16Decoder()], ['minStandingSell', getI16Decoder()], ['priceTierBps', getArrayDecoder(getU16Decoder(), { size: 4 })], ['authoredTargetQty', getU64Decoder()], ['restockPeriodSecs', getU32Decoder()], ['lastRestockAt', getI64Decoder()], ['atlasBurnBps', getU16Decoder()], ['standingBps', getU32Decoder()], ['faucetEnabled', getU8Decoder()], ['pad', getArrayDecoder(getU8Decoder(), { size: 4 })], ['offers', getArrayDecoder(getLiveOfferDecoder())], ]); } /** Gets the codec for {@link FactionMarket} account data. */ export function getFactionMarketCodec(): Codec< FactionMarketArgs, FactionMarket > { return combineCodec(getFactionMarketEncoder(), getFactionMarketDecoder()); } export function decodeFactionMarket( encodedAccount: EncodedAccount, ): Account; export function decodeFactionMarket( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeFactionMarket( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getFactionMarketDecoder(), ); } export async function fetchFactionMarket( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeFactionMarket(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionMarket( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeFactionMarket(maybeAccount); } export async function fetchAllFactionMarket( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeFactionMarket( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeFactionMarket( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeFactionMarket(maybeAccount)); } export async function fetchFactionMarketFromSeeds( rpc: Parameters[0], seeds: FactionMarketSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeFactionMarketFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionMarketFromSeeds( rpc: Parameters[0], seeds: FactionMarketSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findFactionMarketPda(seeds, { programAddress }); return await fetchMaybeFactionMarket(rpc, address, fetchConfig); }