/** * 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, getU16Decoder, getU16Encoder, 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 SYNC_CHARACTER_DISCRIMINATOR = new Uint8Array([ 28, 220, 61, 38, 62, 66, 212, 67, ]); export function getSyncCharacterDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SYNC_CHARACTER_DISCRIMINATOR, ); } export type SyncCharacterInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountCharacter extends string | AccountMeta = string, TAccountCharacterSync extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountCharacterSync extends string ? WritableAccount : TAccountCharacterSync, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type SyncCharacterInstructionData = { discriminator: ReadonlyUint8Array; /** Maximum unlocked research-node levels to replay in this transaction. */ maxSteps: number; }; export type SyncCharacterInstructionDataArgs = { /** Maximum unlocked research-node levels to replay in this transaction. */ maxSteps: number; }; export function getSyncCharacterInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['maxSteps', getU16Encoder()], ]), (value) => ({ ...value, discriminator: SYNC_CHARACTER_DISCRIMINATOR }), ); } export function getSyncCharacterInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['maxSteps', getU16Decoder()], ]); } export function getSyncCharacterInstructionDataCodec(): FixedSizeCodec< SyncCharacterInstructionDataArgs, SyncCharacterInstructionData > { return combineCodec( getSyncCharacterInstructionDataEncoder(), getSyncCharacterInstructionDataDecoder(), ); } export type SyncCharacterInput< TAccountFunder extends string = string, TAccountCharacter extends string = string, TAccountCharacterSync extends string = string, TAccountGame extends string = string, TAccountSystemProgram extends string = string, > = { /** * Permissionless cranker. Pays missing Character or staging-account rent; * existing rent surplus is never refunded to the cranker. */ funder: TransactionSigner; /** * Character to advance. Raw validation intentionally avoids the eager, * unbounded sync performed by `ValidatedCharacter`. */ character: Address; /** * PDA accumulator for the bounded rebuild. Created on the first call, * reused by intermediate calls, and closed into the Character on commit. */ characterSync: Address; /** Game whose research and XP definitions are authoritative. */ game: Address; /** Solana System program used when the staging PDA must be created. */ systemProgram?: Address; maxSteps: SyncCharacterInstructionDataArgs['maxSteps']; }; export function getSyncCharacterInstruction< TAccountFunder extends string, TAccountCharacter extends string, TAccountCharacterSync extends string, TAccountGame extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: SyncCharacterInput< TAccountFunder, TAccountCharacter, TAccountCharacterSync, TAccountGame, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): SyncCharacterInstruction< TProgramAddress, TAccountFunder, TAccountCharacter, TAccountCharacterSync, TAccountGame, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, character: { value: input.character ?? null, isWritable: true }, characterSync: { value: input.characterSync ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // 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('character', accounts.character), getAccountMeta('characterSync', accounts.characterSync), getAccountMeta('game', accounts.game), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getSyncCharacterInstructionDataEncoder().encode( args as SyncCharacterInstructionDataArgs, ), programAddress, } as SyncCharacterInstruction< TProgramAddress, TAccountFunder, TAccountCharacter, TAccountCharacterSync, TAccountGame, TAccountSystemProgram >); } export type ParsedSyncCharacterInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** * Permissionless cranker. Pays missing Character or staging-account rent; * existing rent surplus is never refunded to the cranker. */ funder: TAccountMetas[0]; /** * Character to advance. Raw validation intentionally avoids the eager, * unbounded sync performed by `ValidatedCharacter`. */ character: TAccountMetas[1]; /** * PDA accumulator for the bounded rebuild. Created on the first call, * reused by intermediate calls, and closed into the Character on commit. */ characterSync: TAccountMetas[2]; /** Game whose research and XP definitions are authoritative. */ game: TAccountMetas[3]; /** Solana System program used when the staging PDA must be created. */ systemProgram: TAccountMetas[4]; }; data: SyncCharacterInstructionData; }; export function parseSyncCharacterInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSyncCharacterInstruction { if (instruction.accounts.length < 5) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 5, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), character: getNextAccount(), characterSync: getNextAccount(), game: getNextAccount(), systemProgram: getNextAccount(), }, data: getSyncCharacterInstructionDataDecoder().decode(instruction.data), }; }