/** * 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 REGISTER_CHARACTER_DISCRIMINATOR = new Uint8Array([ 191, 18, 66, 248, 63, 76, 124, 213, ]); export function getRegisterCharacterDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( REGISTER_CHARACTER_DISCRIMINATOR, ); } export type RegisterCharacterInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountProfile extends string | AccountMeta = string, TAccountFunder extends string | AccountMeta = string, TAccountCharacter extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TAccountXpBudget extends string | AccountMeta = string, TAccountXpBudgetConfig extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountProfile extends string ? ReadonlyAccount : TAccountProfile, TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountXpBudget extends string ? WritableAccount : TAccountXpBudget, TAccountXpBudgetConfig extends string ? ReadonlyAccount : TAccountXpBudgetConfig, ...TRemainingAccounts, ] >; export type RegisterCharacterInstructionData = { discriminator: ReadonlyUint8Array; }; export type RegisterCharacterInstructionDataArgs = {}; export function getRegisterCharacterInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: REGISTER_CHARACTER_DISCRIMINATOR }), ); } export function getRegisterCharacterInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getRegisterCharacterInstructionDataCodec(): FixedSizeCodec< RegisterCharacterInstructionDataArgs, RegisterCharacterInstructionData > { return combineCodec( getRegisterCharacterInstructionDataEncoder(), getRegisterCharacterInstructionDataDecoder(), ); } export type RegisterCharacterInput< TAccountProfile extends string = string, TAccountFunder extends string = string, TAccountCharacter extends string = string, TAccountGame extends string = string, TAccountSystemProgram extends string = string, TAccountXpBudget extends string = string, TAccountXpBudgetConfig extends string = string, > = { /** The player permissions [`Profile`] */ profile: Address; /** The funder for the new profile */ funder: TransactionSigner; /** The `Character` account */ character: Address; /** The game account */ game: Address; /** The Solana System program */ systemProgram?: Address; xpBudget?: Address; xpBudgetConfig?: Address; }; export function getRegisterCharacterInstruction< TAccountProfile extends string, TAccountFunder extends string, TAccountCharacter extends string, TAccountGame extends string, TAccountSystemProgram extends string, TAccountXpBudget extends string, TAccountXpBudgetConfig extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: RegisterCharacterInput< TAccountProfile, TAccountFunder, TAccountCharacter, TAccountGame, TAccountSystemProgram, TAccountXpBudget, TAccountXpBudgetConfig >, config?: { programAddress?: TProgramAddress }, ): RegisterCharacterInstruction< TProgramAddress, TAccountProfile, TAccountFunder, TAccountCharacter, TAccountGame, TAccountSystemProgram, TAccountXpBudget, TAccountXpBudgetConfig > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { profile: { value: input.profile ?? null, isWritable: false }, funder: { value: input.funder ?? null, isWritable: true }, character: { value: input.character ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, xpBudget: { value: input.xpBudget ?? null, isWritable: true }, xpBudgetConfig: { value: input.xpBudgetConfig ?? 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('profile', accounts.profile), getAccountMeta('funder', accounts.funder), getAccountMeta('character', accounts.character), getAccountMeta('game', accounts.game), getAccountMeta('systemProgram', accounts.systemProgram), getAccountMeta('xpBudget', accounts.xpBudget), getAccountMeta('xpBudgetConfig', accounts.xpBudgetConfig), ], data: getRegisterCharacterInstructionDataEncoder().encode({}), programAddress, } as RegisterCharacterInstruction< TProgramAddress, TAccountProfile, TAccountFunder, TAccountCharacter, TAccountGame, TAccountSystemProgram, TAccountXpBudget, TAccountXpBudgetConfig >); } export type ParsedRegisterCharacterInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The player permissions [`Profile`] */ profile: TAccountMetas[0]; /** The funder for the new profile */ funder: TAccountMetas[1]; /** The `Character` account */ character: TAccountMetas[2]; /** The game account */ game: TAccountMetas[3]; /** The Solana System program */ systemProgram: TAccountMetas[4]; xpBudget?: TAccountMetas[5] | undefined; xpBudgetConfig?: TAccountMetas[6] | undefined; }; data: RegisterCharacterInstructionData; }; export function parseRegisterCharacterInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedRegisterCharacterInstruction { 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; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SAGE_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { profile: getNextAccount(), funder: getNextAccount(), character: getNextAccount(), game: getNextAccount(), systemProgram: getNextAccount(), xpBudget: getNextOptionalAccount(), xpBudgetConfig: getNextOptionalAccount(), }, data: getRegisterCharacterInstructionDataDecoder().decode(instruction.data), }; }