/** * 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 { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const CLAIM_TERRITORY_YIELD_DISCRIMINATOR = new Uint8Array([ 87, 18, 111, 142, 110, 143, 71, 46, ]); export function getClaimTerritoryYieldDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CLAIM_TERRITORY_YIELD_DISCRIMINATOR, ); } export type ClaimTerritoryYieldInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountSystem extends string | AccountMeta = string, TAccountFactionOwnership extends string | AccountMeta = string, TAccountFactionConfig extends string | AccountMeta = string, TAccountFactionTreasury extends string | AccountMeta = string, TAccountCurrencyCache extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, TAccountFactionOwnership extends string ? WritableAccount : TAccountFactionOwnership, TAccountFactionConfig extends string ? ReadonlyAccount : TAccountFactionConfig, TAccountFactionTreasury extends string ? WritableAccount : TAccountFactionTreasury, TAccountCurrencyCache extends string ? WritableAccount : TAccountCurrencyCache, ...TRemainingAccounts, ] >; export type ClaimTerritoryYieldInstructionData = { discriminator: ReadonlyUint8Array; }; export type ClaimTerritoryYieldInstructionDataArgs = {}; export function getClaimTerritoryYieldInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLAIM_TERRITORY_YIELD_DISCRIMINATOR, }), ); } export function getClaimTerritoryYieldInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getClaimTerritoryYieldInstructionDataCodec(): FixedSizeCodec< ClaimTerritoryYieldInstructionDataArgs, ClaimTerritoryYieldInstructionData > { return combineCodec( getClaimTerritoryYieldInstructionDataEncoder(), getClaimTerritoryYieldInstructionDataDecoder(), ); } export type ClaimTerritoryYieldInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountSystem extends string = string, TAccountFactionOwnership extends string = string, TAccountFactionConfig extends string = string, TAccountFactionTreasury extends string = string, TAccountCurrencyCache extends string = string, > = { /** Permissionless cranker — pays tx fees only; the yield credits the controlling faction's treasury. */ funder: TransactionSigner; game: Address; /** The starbase's system — supplies the legacy owner (resolution fallback) + the generation witness. */ system: Address; /** The STARBASE dynamic-ownership sidecar (Mut — the yield cursor is stamped). PDA-bound to the system. */ factionOwnership: Address; /** Per-game reputation/yield dials (PDA-checked; supplies the yield rate + cadence). */ factionConfig: Address; /** * The CONTROLLING faction's treasury (Mut — vault credited). The PDA is re-derived from the resolved * controller in `process()` and compared (the controller is a data-dependent seed). */ factionTreasury: Address; /** The game's central ATLAS source vault (the finite, admin-funded yield ceiling). Mut — debited. */ currencyCache: Address; }; export function getClaimTerritoryYieldInstruction< TAccountFunder extends string, TAccountGame extends string, TAccountSystem extends string, TAccountFactionOwnership extends string, TAccountFactionConfig extends string, TAccountFactionTreasury extends string, TAccountCurrencyCache extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ClaimTerritoryYieldInput< TAccountFunder, TAccountGame, TAccountSystem, TAccountFactionOwnership, TAccountFactionConfig, TAccountFactionTreasury, TAccountCurrencyCache >, config?: { programAddress?: TProgramAddress }, ): ClaimTerritoryYieldInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountSystem, TAccountFactionOwnership, TAccountFactionConfig, TAccountFactionTreasury, TAccountCurrencyCache > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, system: { value: input.system ?? null, isWritable: false }, factionOwnership: { value: input.factionOwnership ?? null, isWritable: true, }, factionConfig: { value: input.factionConfig ?? null, isWritable: false }, factionTreasury: { value: input.factionTreasury ?? null, isWritable: true }, currencyCache: { value: input.currencyCache ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('game', accounts.game), getAccountMeta('system', accounts.system), getAccountMeta('factionOwnership', accounts.factionOwnership), getAccountMeta('factionConfig', accounts.factionConfig), getAccountMeta('factionTreasury', accounts.factionTreasury), getAccountMeta('currencyCache', accounts.currencyCache), ], data: getClaimTerritoryYieldInstructionDataEncoder().encode({}), programAddress, } as ClaimTerritoryYieldInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountSystem, TAccountFactionOwnership, TAccountFactionConfig, TAccountFactionTreasury, TAccountCurrencyCache >); } export type ParsedClaimTerritoryYieldInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Permissionless cranker — pays tx fees only; the yield credits the controlling faction's treasury. */ funder: TAccountMetas[0]; game: TAccountMetas[1]; /** The starbase's system — supplies the legacy owner (resolution fallback) + the generation witness. */ system: TAccountMetas[2]; /** The STARBASE dynamic-ownership sidecar (Mut — the yield cursor is stamped). PDA-bound to the system. */ factionOwnership: TAccountMetas[3]; /** Per-game reputation/yield dials (PDA-checked; supplies the yield rate + cadence). */ factionConfig: TAccountMetas[4]; /** * The CONTROLLING faction's treasury (Mut — vault credited). The PDA is re-derived from the resolved * controller in `process()` and compared (the controller is a data-dependent seed). */ factionTreasury: TAccountMetas[5]; /** The game's central ATLAS source vault (the finite, admin-funded yield ceiling). Mut — debited. */ currencyCache: TAccountMetas[6]; }; data: ClaimTerritoryYieldInstructionData; }; export function parseClaimTerritoryYieldInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedClaimTerritoryYieldInstruction { if (instruction.accounts.length < 7) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 7, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), game: getNextAccount(), system: getNextAccount(), factionOwnership: getNextAccount(), factionConfig: getNextAccount(), factionTreasury: getNextAccount(), currencyCache: getNextAccount(), }, data: getClaimTerritoryYieldInstructionDataDecoder().decode( instruction.data, ), }; }