/** * 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, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, 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 { EphemeralMarketSeeds, findEphemeralMarketPda } from '../pdas'; import { getLiveOfferDecoder, getLiveOfferEncoder, getMinorFactionIdDecoder, getMinorFactionIdEncoder, getRegionIdDecoder, getRegionIdEncoder, type LiveOffer, type LiveOfferArgs, type MinorFactionId, type MinorFactionIdArgs, type RegionId, type RegionIdArgs, } from '../types'; export const EPHEMERAL_MARKET_DISCRIMINATOR = new Uint8Array([ 187, 168, 40, 83, 90, 37, 217, 193, ]); export function getEphemeralMarketDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( EPHEMERAL_MARKET_DISCRIMINATOR, ); } /** * The revealed, player-scoped, time-boxed NPC market (Phase 3). Created (player-funded) at reveal when * the rare candidacy hits; holds the concrete `LiveOffer`s + an `expires_at`. Trades settle DIRECTLY * against the `EncounterTreasury`, so this account itself holds NO funds (close is trivial — nothing to * sweep). One open market per character at a time (seeds = game + owner character); the prior one must * be reaped before a new reveal. */ export type EphemeralMarket = { discriminator: ReadonlyUint8Array; version: number; bump: number; gameId: Address; /** The only character that may trade here — the access binding (seed component). */ ownerCharacter: Address; regionId: RegionId; minorFaction: MinorFactionId; pool: Address; treasury: Address; /** Rent payer (the owner), refunded on close. */ funder: Address; /** * ATLAS-burn on the faucet (sell-back) leg, basis points — copied from the pool at reveal so the * trade is self-contained (doesn't need the pool account). */ atlasBurnBps: number; /** Market lifetime, unix seconds: set to `now + pool.market_ttl_secs` at reveal; fail-closed at trade. */ expiresAt: bigint; /** * The exact sector the encounter spawned at (copied from the commit at reveal). Trading requires the * owner's fleet to be idle AT this sector; the map UI + nemesis read it to place the merchant marker. */ location: Array; /** The concrete offers drawn from the pool envelope at reveal; trading decrements `remaining_qty`. */ offers: Array; }; export type EphemeralMarketArgs = { version: number; bump: number; gameId: Address; /** The only character that may trade here — the access binding (seed component). */ ownerCharacter: Address; regionId: RegionIdArgs; minorFaction: MinorFactionIdArgs; pool: Address; treasury: Address; /** Rent payer (the owner), refunded on close. */ funder: Address; /** * ATLAS-burn on the faucet (sell-back) leg, basis points — copied from the pool at reveal so the * trade is self-contained (doesn't need the pool account). */ atlasBurnBps: number; /** Market lifetime, unix seconds: set to `now + pool.market_ttl_secs` at reveal; fail-closed at trade. */ expiresAt: number | bigint; /** * The exact sector the encounter spawned at (copied from the commit at reveal). Trading requires the * owner's fleet to be idle AT this sector; the map UI + nemesis read it to place the merchant marker. */ location: Array; /** The concrete offers drawn from the pool envelope at reveal; trading decrements `remaining_qty`. */ offers: Array; }; /** Gets the encoder for {@link EphemeralMarketArgs} account data. */ export function getEphemeralMarketEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['ownerCharacter', getAddressEncoder()], ['regionId', getRegionIdEncoder()], ['minorFaction', getMinorFactionIdEncoder()], ['pool', getAddressEncoder()], ['treasury', getAddressEncoder()], ['funder', getAddressEncoder()], ['atlasBurnBps', getU16Encoder()], ['expiresAt', getI64Encoder()], ['location', getArrayEncoder(getI64Encoder(), { size: 2 })], ['offers', getArrayEncoder(getLiveOfferEncoder())], ]), (value) => ({ ...value, discriminator: EPHEMERAL_MARKET_DISCRIMINATOR }), ); } /** Gets the decoder for {@link EphemeralMarket} account data. */ export function getEphemeralMarketDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['ownerCharacter', getAddressDecoder()], ['regionId', getRegionIdDecoder()], ['minorFaction', getMinorFactionIdDecoder()], ['pool', getAddressDecoder()], ['treasury', getAddressDecoder()], ['funder', getAddressDecoder()], ['atlasBurnBps', getU16Decoder()], ['expiresAt', getI64Decoder()], ['location', getArrayDecoder(getI64Decoder(), { size: 2 })], ['offers', getArrayDecoder(getLiveOfferDecoder())], ]); } /** Gets the codec for {@link EphemeralMarket} account data. */ export function getEphemeralMarketCodec(): Codec< EphemeralMarketArgs, EphemeralMarket > { return combineCodec(getEphemeralMarketEncoder(), getEphemeralMarketDecoder()); } export function decodeEphemeralMarket( encodedAccount: EncodedAccount, ): Account; export function decodeEphemeralMarket( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeEphemeralMarket( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getEphemeralMarketDecoder(), ); } export async function fetchEphemeralMarket( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeEphemeralMarket(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeEphemeralMarket< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeEphemeralMarket(maybeAccount); } export async function fetchAllEphemeralMarket( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeEphemeralMarket( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeEphemeralMarket( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeEphemeralMarket(maybeAccount), ); } export async function fetchEphemeralMarketFromSeeds( rpc: Parameters[0], seeds: EphemeralMarketSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeEphemeralMarketFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeEphemeralMarketFromSeeds( rpc: Parameters[0], seeds: EphemeralMarketSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findEphemeralMarketPda(seeds, { programAddress }); return await fetchMaybeEphemeralMarket(rpc, address, fetchConfig); }