/** * 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 SETTLE_MISSION_DISCRIMINATOR = new Uint8Array([ 211, 246, 217, 40, 164, 155, 128, 35, ]); export function getSettleMissionDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SETTLE_MISSION_DISCRIMINATOR, ); } export type SettleMissionInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountStarbasePlayer extends string | AccountMeta = string, TAccountMissionProcess extends string | AccountMeta = string, TAccountRoster extends string | AccountMeta = string, TAccountRecentSlothashes extends string | AccountMeta = string, TAccountMissionVault extends string | AccountMeta = string, TAccountRewardPool extends string | AccountMeta = string, TAccountCharacter extends string | AccountMeta = string, TAccountRegionOrderAnchor extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountStarbasePlayer extends string ? WritableAccount : TAccountStarbasePlayer, TAccountMissionProcess extends string ? WritableAccount : TAccountMissionProcess, TAccountRoster extends string ? WritableAccount : TAccountRoster, TAccountRecentSlothashes extends string ? ReadonlyAccount : TAccountRecentSlothashes, TAccountMissionVault extends string ? WritableAccount : TAccountMissionVault, TAccountRewardPool extends string ? WritableAccount : TAccountRewardPool, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountRegionOrderAnchor extends string ? WritableAccount : TAccountRegionOrderAnchor, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type SettleMissionInstructionData = { discriminator: ReadonlyUint8Array; }; export type SettleMissionInstructionDataArgs = {}; export function getSettleMissionInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: SETTLE_MISSION_DISCRIMINATOR }), ); } export function getSettleMissionInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getSettleMissionInstructionDataCodec(): FixedSizeCodec< SettleMissionInstructionDataArgs, SettleMissionInstructionData > { return combineCodec( getSettleMissionInstructionDataEncoder(), getSettleMissionInstructionDataDecoder(), ); } export type SettleMissionInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountStarbasePlayer extends string = string, TAccountMissionProcess extends string = string, TAccountRoster extends string = string, TAccountRecentSlothashes extends string = string, TAccountMissionVault extends string = string, TAccountRewardPool extends string = string, TAccountCharacter extends string = string, TAccountRegionOrderAnchor extends string = string, TAccountSystemProgram extends string = string, > = { /** * The cranker (pays + reclaims the process rent). `recipient,funder` is REQUIRED for the * `CloseAccount` to be executable (convention #9). The ONLY signer; no `ProfileValidation`. */ funder: TransactionSigner; game: Address; /** The reserved-counter starbase-player, cross-checked by the process. `Mut` for the crew move. */ starbasePlayer: Address; /** * The process being settled — validated against its stored `starbase_player` (the owner * cross-check) and CLOSED on success (the no-leak guarantee). */ missionProcess: Address; /** The owner's pinned reward page — CONDITIONALLY REQUIRED when the WIN branch pours XP (fail-closed). */ roster?: Address; /** The future-hash entropy source. */ recentSlothashes: Address; /** The escrow vault, seeds re-derived from the process key (boundary-enforced). Swept + closed. */ missionVault: Address; /** The emissions-fed treasury — validated `== mission.reward_pool` in-handler. `Mut` for the draw + breaker. */ rewardPool: Address; /** * The owner's character (WIN ATLAS reward + stake-refund target). A `CharacterSeeds{profile,game}` * PDA the cranker can supply; validated in-handler against the process owner + the game-sub pin. */ character: Address; /** * The per-region sector anchor — seeds `(game, mission.region_id)` validated in-handler (region_id * comes from the process, not the caller). `Mut` for the impact fold. (CreateIfNeeded at first settle * is the alternative; v1 requires it pre-created by the admin ix.) */ regionOrderAnchor: Address; systemProgram?: Address; }; export function getSettleMissionInstruction< TAccountFunder extends string, TAccountGame extends string, TAccountStarbasePlayer extends string, TAccountMissionProcess extends string, TAccountRoster extends string, TAccountRecentSlothashes extends string, TAccountMissionVault extends string, TAccountRewardPool extends string, TAccountCharacter extends string, TAccountRegionOrderAnchor extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: SettleMissionInput< TAccountFunder, TAccountGame, TAccountStarbasePlayer, TAccountMissionProcess, TAccountRoster, TAccountRecentSlothashes, TAccountMissionVault, TAccountRewardPool, TAccountCharacter, TAccountRegionOrderAnchor, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): SettleMissionInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountStarbasePlayer, TAccountMissionProcess, TAccountRoster, TAccountRecentSlothashes, TAccountMissionVault, TAccountRewardPool, TAccountCharacter, TAccountRegionOrderAnchor, TAccountSystemProgram > { // 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 }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, missionProcess: { value: input.missionProcess ?? null, isWritable: true }, roster: { value: input.roster ?? null, isWritable: true }, recentSlothashes: { value: input.recentSlothashes ?? null, isWritable: false, }, missionVault: { value: input.missionVault ?? null, isWritable: true }, rewardPool: { value: input.rewardPool ?? null, isWritable: true }, character: { value: input.character ?? null, isWritable: true }, regionOrderAnchor: { value: input.regionOrderAnchor ?? null, isWritable: true, }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('game', accounts.game), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('missionProcess', accounts.missionProcess), getAccountMeta('roster', accounts.roster), getAccountMeta('recentSlothashes', accounts.recentSlothashes), getAccountMeta('missionVault', accounts.missionVault), getAccountMeta('rewardPool', accounts.rewardPool), getAccountMeta('character', accounts.character), getAccountMeta('regionOrderAnchor', accounts.regionOrderAnchor), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getSettleMissionInstructionDataEncoder().encode({}), programAddress, } as SettleMissionInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountStarbasePlayer, TAccountMissionProcess, TAccountRoster, TAccountRecentSlothashes, TAccountMissionVault, TAccountRewardPool, TAccountCharacter, TAccountRegionOrderAnchor, TAccountSystemProgram >); } export type ParsedSettleMissionInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** * The cranker (pays + reclaims the process rent). `recipient,funder` is REQUIRED for the * `CloseAccount` to be executable (convention #9). The ONLY signer; no `ProfileValidation`. */ funder: TAccountMetas[0]; game: TAccountMetas[1]; /** The reserved-counter starbase-player, cross-checked by the process. `Mut` for the crew move. */ starbasePlayer: TAccountMetas[2]; /** * The process being settled — validated against its stored `starbase_player` (the owner * cross-check) and CLOSED on success (the no-leak guarantee). */ missionProcess: TAccountMetas[3]; /** The owner's pinned reward page — CONDITIONALLY REQUIRED when the WIN branch pours XP (fail-closed). */ roster?: TAccountMetas[4] | undefined; /** The future-hash entropy source. */ recentSlothashes: TAccountMetas[5]; /** The escrow vault, seeds re-derived from the process key (boundary-enforced). Swept + closed. */ missionVault: TAccountMetas[6]; /** The emissions-fed treasury — validated `== mission.reward_pool` in-handler. `Mut` for the draw + breaker. */ rewardPool: TAccountMetas[7]; /** * The owner's character (WIN ATLAS reward + stake-refund target). A `CharacterSeeds{profile,game}` * PDA the cranker can supply; validated in-handler against the process owner + the game-sub pin. */ character: TAccountMetas[8]; /** * The per-region sector anchor — seeds `(game, mission.region_id)` validated in-handler (region_id * comes from the process, not the caller). `Mut` for the impact fold. (CreateIfNeeded at first settle * is the alternative; v1 requires it pre-created by the admin ix.) */ regionOrderAnchor: TAccountMetas[9]; systemProgram: TAccountMetas[10]; }; data: SettleMissionInstructionData; }; export function parseSettleMissionInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSettleMissionInstruction { if (instruction.accounts.length < 11) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 11, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SAGE_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), game: getNextAccount(), starbasePlayer: getNextAccount(), missionProcess: getNextAccount(), roster: getNextOptionalAccount(), recentSlothashes: getNextAccount(), missionVault: getNextAccount(), rewardPool: getNextAccount(), character: getNextAccount(), regionOrderAnchor: getNextAccount(), systemProgram: getNextAccount(), }, data: getSettleMissionInstructionDataDecoder().decode(instruction.data), }; }