/** * 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array, } from '@solana/kit'; import { FactionConfigSeeds, findFactionConfigPda } from '../pdas'; export const FACTION_CONFIG_DISCRIMINATOR = new Uint8Array([ 52, 12, 254, 166, 143, 53, 124, 55, ]); export function getFactionConfigDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( FACTION_CONFIG_DISCRIMINATOR, ); } /** Per-game reputation dials. Sized, packed, 48 bytes. */ export type FactionConfig = { discriminator: ReadonlyUint8Array; /** Schema/migration lever. */ version: number; /** PDA bump. */ bump: number; /** Passive decay toward 0 per day. */ decayPerDay: number; /** Per-(profile,faction) daily burst ceiling on `|delta|`. */ dailyCap: number; /** Ask-leg value→standing bps (Accrual A); `0` disables sell-order accrual. */ standingBps: number; /** `lifetime_earned` DR half-life. */ drHalfLife: bigint; /** `lifetime_earned` divisor before the DR curve. */ drScale: bigint; /** Per-faction per-epoch aggregate standing-emission cap. */ standingEpochCap: number; /** Epoch length (secs) for the per-faction breaker. */ standingEpochLenSecs: bigint; /** Gate (d) economic-dock minimum band index. */ dockMinBand: number; /** P5 territory payoff: ATLAS yield per hold-tick to the controlling faction's treasury (0 = disabled). */ territoryYieldPerTick: number; /** P5 territory payoff: yield accrual cadence (secs); a claim credits the whole ticks elapsed. */ territoryYieldTickSecs: number; /** Reserved (carve from the front). */ pad: Array; }; export type FactionConfigArgs = { /** Schema/migration lever. */ version: number; /** PDA bump. */ bump: number; /** Passive decay toward 0 per day. */ decayPerDay: number; /** Per-(profile,faction) daily burst ceiling on `|delta|`. */ dailyCap: number; /** Ask-leg value→standing bps (Accrual A); `0` disables sell-order accrual. */ standingBps: number; /** `lifetime_earned` DR half-life. */ drHalfLife: number | bigint; /** `lifetime_earned` divisor before the DR curve. */ drScale: number | bigint; /** Per-faction per-epoch aggregate standing-emission cap. */ standingEpochCap: number; /** Epoch length (secs) for the per-faction breaker. */ standingEpochLenSecs: number | bigint; /** Gate (d) economic-dock minimum band index. */ dockMinBand: number; /** P5 territory payoff: ATLAS yield per hold-tick to the controlling faction's treasury (0 = disabled). */ territoryYieldPerTick: number; /** P5 territory payoff: yield accrual cadence (secs); a claim credits the whole ticks elapsed. */ territoryYieldTickSecs: number; /** Reserved (carve from the front). */ pad: Array; }; /** Gets the encoder for {@link FactionConfigArgs} account data. */ export function getFactionConfigEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['decayPerDay', getU16Encoder()], ['dailyCap', getU32Encoder()], ['standingBps', getU32Encoder()], ['drHalfLife', getU64Encoder()], ['drScale', getU64Encoder()], ['standingEpochCap', getU32Encoder()], ['standingEpochLenSecs', getI64Encoder()], ['dockMinBand', getU8Encoder()], ['territoryYieldPerTick', getU16Encoder()], ['territoryYieldTickSecs', getU32Encoder()], ['pad', getArrayEncoder(getU8Encoder(), { size: 1 })], ]), (value) => ({ ...value, discriminator: FACTION_CONFIG_DISCRIMINATOR }), ); } /** Gets the decoder for {@link FactionConfig} account data. */ export function getFactionConfigDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['decayPerDay', getU16Decoder()], ['dailyCap', getU32Decoder()], ['standingBps', getU32Decoder()], ['drHalfLife', getU64Decoder()], ['drScale', getU64Decoder()], ['standingEpochCap', getU32Decoder()], ['standingEpochLenSecs', getI64Decoder()], ['dockMinBand', getU8Decoder()], ['territoryYieldPerTick', getU16Decoder()], ['territoryYieldTickSecs', getU32Decoder()], ['pad', getArrayDecoder(getU8Decoder(), { size: 1 })], ]); } /** Gets the codec for {@link FactionConfig} account data. */ export function getFactionConfigCodec(): FixedSizeCodec< FactionConfigArgs, FactionConfig > { return combineCodec(getFactionConfigEncoder(), getFactionConfigDecoder()); } export function decodeFactionConfig( encodedAccount: EncodedAccount, ): Account; export function decodeFactionConfig( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeFactionConfig( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getFactionConfigDecoder(), ); } export async function fetchFactionConfig( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeFactionConfig(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionConfig( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeFactionConfig(maybeAccount); } export async function fetchAllFactionConfig( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeFactionConfig( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeFactionConfig( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeFactionConfig(maybeAccount)); } export async function fetchFactionConfigFromSeeds( rpc: Parameters[0], seeds: FactionConfigSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeFactionConfigFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionConfigFromSeeds( rpc: Parameters[0], seeds: FactionConfigSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findFactionConfigPda(seeds, { programAddress }); return await fetchMaybeFactionConfig(rpc, address, fetchConfig); }