/** * 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, 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 RECONCILE_LEGACY_CHARACTER_DISCRIMINATOR = new Uint8Array([ 197, 117, 98, 203, 40, 255, 127, 70, ]); export function getReconcileLegacyCharacterDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( RECONCILE_LEGACY_CHARACTER_DISCRIMINATOR, ); } export type ReconcileLegacyCharacterInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountCharacter extends string | AccountMeta = string, TAccountXpBudget extends string | AccountMeta = string, TAccountXpBudgetConfig extends string | AccountMeta = string, TAccountMigrationConfig extends string | AccountMeta = string, TAccountTargetDefinitions 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, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountXpBudget extends string ? WritableAccount : TAccountXpBudget, TAccountXpBudgetConfig extends string ? ReadonlyAccount : TAccountXpBudgetConfig, TAccountMigrationConfig extends string ? WritableAccount : TAccountMigrationConfig, TAccountTargetDefinitions extends string ? ReadonlyAccount : TAccountTargetDefinitions, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type ReconcileLegacyCharacterInstructionData = { discriminator: ReadonlyUint8Array; /** Position of this Character in the sorted manifest. */ leafIndex: bigint; /** Merkle siblings, leaf level first (`verify_manifest_membership`). */ proof: Array>; }; export type ReconcileLegacyCharacterInstructionDataArgs = { /** Position of this Character in the sorted manifest. */ leafIndex: number | bigint; /** Merkle siblings, leaf level first (`verify_manifest_membership`). */ proof: Array>; }; export function getReconcileLegacyCharacterInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['leafIndex', getU64Encoder()], ['proof', getArrayEncoder(getArrayEncoder(getU8Encoder(), { size: 32 }))], ]), (value) => ({ ...value, discriminator: RECONCILE_LEGACY_CHARACTER_DISCRIMINATOR, }), ); } export function getReconcileLegacyCharacterInstructionDataDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['leafIndex', getU64Decoder()], ['proof', getArrayDecoder(getArrayDecoder(getU8Decoder(), { size: 32 }))], ]); } export function getReconcileLegacyCharacterInstructionDataCodec(): Codec< ReconcileLegacyCharacterInstructionDataArgs, ReconcileLegacyCharacterInstructionData > { return combineCodec( getReconcileLegacyCharacterInstructionDataEncoder(), getReconcileLegacyCharacterInstructionDataDecoder(), ); } export type ReconcileLegacyCharacterInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountCharacter extends string = string, TAccountXpBudget extends string = string, TAccountXpBudgetConfig extends string = string, TAccountMigrationConfig extends string = string, TAccountTargetDefinitions extends string = string, TAccountSystemProgram extends string = string, > = { /** Permissionless cranker: pays the budget PDA rent (deterministic state writes). */ funder: TransactionSigner; game: Address; /** * The character being migrated. Raw validation on purpose: the eager * `ValidatedCharacter` sync must not run ahead of the snapshot. */ character: Address; /** * The Character's budget PDA, created here. An existing PDA means the * Character was already reconciled: the duplicate is rejected. */ xpBudget: Address; /** The game's configured budgets: the fresh PDA is seeded full at these ceilings. */ xpBudgetConfig: Address; migrationConfig: Address; targetDefinitions: Address; systemProgram?: Address; leafIndex: ReconcileLegacyCharacterInstructionDataArgs['leafIndex']; proof: ReconcileLegacyCharacterInstructionDataArgs['proof']; }; export function getReconcileLegacyCharacterInstruction< TAccountFunder extends string, TAccountGame extends string, TAccountCharacter extends string, TAccountXpBudget extends string, TAccountXpBudgetConfig extends string, TAccountMigrationConfig extends string, TAccountTargetDefinitions extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ReconcileLegacyCharacterInput< TAccountFunder, TAccountGame, TAccountCharacter, TAccountXpBudget, TAccountXpBudgetConfig, TAccountMigrationConfig, TAccountTargetDefinitions, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): ReconcileLegacyCharacterInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCharacter, TAccountXpBudget, TAccountXpBudgetConfig, TAccountMigrationConfig, TAccountTargetDefinitions, 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 }, character: { value: input.character ?? null, isWritable: true }, xpBudget: { value: input.xpBudget ?? null, isWritable: true }, xpBudgetConfig: { value: input.xpBudgetConfig ?? null, isWritable: false }, migrationConfig: { value: input.migrationConfig ?? null, isWritable: true }, targetDefinitions: { value: input.targetDefinitions ?? 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('game', accounts.game), getAccountMeta('character', accounts.character), getAccountMeta('xpBudget', accounts.xpBudget), getAccountMeta('xpBudgetConfig', accounts.xpBudgetConfig), getAccountMeta('migrationConfig', accounts.migrationConfig), getAccountMeta('targetDefinitions', accounts.targetDefinitions), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getReconcileLegacyCharacterInstructionDataEncoder().encode( args as ReconcileLegacyCharacterInstructionDataArgs, ), programAddress, } as ReconcileLegacyCharacterInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCharacter, TAccountXpBudget, TAccountXpBudgetConfig, TAccountMigrationConfig, TAccountTargetDefinitions, TAccountSystemProgram >); } export type ParsedReconcileLegacyCharacterInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Permissionless cranker: pays the budget PDA rent (deterministic state writes). */ funder: TAccountMetas[0]; game: TAccountMetas[1]; /** * The character being migrated. Raw validation on purpose: the eager * `ValidatedCharacter` sync must not run ahead of the snapshot. */ character: TAccountMetas[2]; /** * The Character's budget PDA, created here. An existing PDA means the * Character was already reconciled: the duplicate is rejected. */ xpBudget: TAccountMetas[3]; /** The game's configured budgets: the fresh PDA is seeded full at these ceilings. */ xpBudgetConfig: TAccountMetas[4]; migrationConfig: TAccountMetas[5]; targetDefinitions: TAccountMetas[6]; systemProgram: TAccountMetas[7]; }; data: ReconcileLegacyCharacterInstructionData; }; export function parseReconcileLegacyCharacterInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedReconcileLegacyCharacterInstruction { if (instruction.accounts.length < 8) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8, }, ); } 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(), character: getNextAccount(), xpBudget: getNextAccount(), xpBudgetConfig: getNextAccount(), migrationConfig: getNextAccount(), targetDefinitions: getNextAccount(), systemProgram: getNextAccount(), }, data: getReconcileLegacyCharacterInstructionDataDecoder().decode( instruction.data, ), }; }