/** * 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, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU64Decoder, getU64Encoder, 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 ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from '@solana/kit'; import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; import { getXpCategoryDecoder, getXpCategoryEncoder, type XpCategory, type XpCategoryArgs, } from '../types'; export const GRANT_XP_DISCRIMINATOR = new Uint8Array([ 223, 147, 25, 252, 91, 237, 124, 213, ]); export function getGrantXpDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(GRANT_XP_DISCRIMINATOR); } export type GrantXpInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountProfileValidationSigner extends string | AccountMeta = string, TAccountProfileValidationProfile extends string | AccountMeta = string, TAccountProfileValidationCertificate extends string | AccountMeta = string, TAccountProfileValidationProgram extends string | AccountMeta = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u', TAccountCharacter extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountXpBudget extends string | AccountMeta = string, TAccountXpBudgetConfig extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountProfileValidationSigner extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountProfileValidationSigner, TAccountProfileValidationProfile extends string ? WritableAccount : TAccountProfileValidationProfile, TAccountProfileValidationCertificate extends string ? ReadonlyAccount : TAccountProfileValidationCertificate, TAccountProfileValidationProgram extends string ? ReadonlyAccount : TAccountProfileValidationProgram, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountXpBudget extends string ? WritableAccount : TAccountXpBudget, TAccountXpBudgetConfig extends string ? ReadonlyAccount : TAccountXpBudgetConfig, ...TRemainingAccounts, ] >; export type GrantXpInstructionData = { discriminator: ReadonlyUint8Array; keyIndex: number; /** * The XP category to grant into. Granting any non-`CouncilRank` career category also * increments `CouncilRank` (see `collect_xp`). */ category: XpCategory; /** The amount of XP to grant. */ amount: bigint; }; export type GrantXpInstructionDataArgs = { keyIndex: number; /** * The XP category to grant into. Granting any non-`CouncilRank` career category also * increments `CouncilRank` (see `collect_xp`). */ category: XpCategoryArgs; /** The amount of XP to grant. */ amount: number | bigint; }; export function getGrantXpInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ['category', getXpCategoryEncoder()], ['amount', getU64Encoder()], ]), (value) => ({ ...value, discriminator: GRANT_XP_DISCRIMINATOR }), ); } export function getGrantXpInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ['category', getXpCategoryDecoder()], ['amount', getU64Decoder()], ]); } export function getGrantXpInstructionDataCodec(): FixedSizeCodec< GrantXpInstructionDataArgs, GrantXpInstructionData > { return combineCodec( getGrantXpInstructionDataEncoder(), getGrantXpInstructionDataDecoder(), ); } export type GrantXpAsyncInput< TAccountProfileValidationSigner extends string = string, TAccountProfileValidationProfile extends string = string, TAccountProfileValidationCertificate extends string = string, TAccountProfileValidationProgram extends string = string, TAccountCharacter extends string = string, TAccountGame extends string = string, TAccountXpBudget extends string = string, TAccountXpBudgetConfig extends string = string, > = { profileValidationSigner: TransactionSigner; profileValidationProfile: Address; profileValidationCertificate?: Address; profileValidationProgram?: Address; /** The character (owned by the signer's profile) to grant XP to. */ character?: Address; /** The game account (provides the XP thresholds used to recompute levels). */ game: Address; xpBudget?: Address; xpBudgetConfig?: Address; keyIndex: GrantXpInstructionDataArgs['keyIndex']; category: GrantXpInstructionDataArgs['category']; amount: GrantXpInstructionDataArgs['amount']; }; export async function getGrantXpInstructionAsync< TAccountProfileValidationSigner extends string, TAccountProfileValidationProfile extends string, TAccountProfileValidationCertificate extends string, TAccountProfileValidationProgram extends string, TAccountCharacter extends string, TAccountGame extends string, TAccountXpBudget extends string, TAccountXpBudgetConfig extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: GrantXpAsyncInput< TAccountProfileValidationSigner, TAccountProfileValidationProfile, TAccountProfileValidationCertificate, TAccountProfileValidationProgram, TAccountCharacter, TAccountGame, TAccountXpBudget, TAccountXpBudgetConfig >, config?: { programAddress?: TProgramAddress }, ): Promise< GrantXpInstruction< TProgramAddress, TAccountProfileValidationSigner, TAccountProfileValidationProfile, TAccountProfileValidationCertificate, TAccountProfileValidationProgram, TAccountCharacter, TAccountGame, TAccountXpBudget, TAccountXpBudgetConfig > > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { profileValidationSigner: { value: input.profileValidationSigner ?? null, isWritable: false, }, profileValidationProfile: { value: input.profileValidationProfile ?? null, isWritable: true, }, profileValidationCertificate: { value: input.profileValidationCertificate ?? null, isWritable: false, }, profileValidationProgram: { value: input.profileValidationProgram ?? null, isWritable: false, }, character: { value: input.character ?? null, isWritable: true }, game: { value: input.game ?? 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 >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.profileValidationProgram.value) { accounts.profileValidationProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } if (!accounts.character.value) { accounts.character.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([67, 104, 97, 114, 97, 99, 116, 101, 114]), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( 'profileValidationProfile', accounts.profileValidationProfile.value, ), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount('game', accounts.game.value), ), ], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta( 'profileValidationSigner', accounts.profileValidationSigner, ), getAccountMeta( 'profileValidationProfile', accounts.profileValidationProfile, ), getAccountMeta( 'profileValidationCertificate', accounts.profileValidationCertificate, ), getAccountMeta( 'profileValidationProgram', accounts.profileValidationProgram, ), getAccountMeta('character', accounts.character), getAccountMeta('game', accounts.game), getAccountMeta('xpBudget', accounts.xpBudget), getAccountMeta('xpBudgetConfig', accounts.xpBudgetConfig), ], data: getGrantXpInstructionDataEncoder().encode( args as GrantXpInstructionDataArgs, ), programAddress, } as GrantXpInstruction< TProgramAddress, TAccountProfileValidationSigner, TAccountProfileValidationProfile, TAccountProfileValidationCertificate, TAccountProfileValidationProgram, TAccountCharacter, TAccountGame, TAccountXpBudget, TAccountXpBudgetConfig >); } export type GrantXpInput< TAccountProfileValidationSigner extends string = string, TAccountProfileValidationProfile extends string = string, TAccountProfileValidationCertificate extends string = string, TAccountProfileValidationProgram extends string = string, TAccountCharacter extends string = string, TAccountGame extends string = string, TAccountXpBudget extends string = string, TAccountXpBudgetConfig extends string = string, > = { profileValidationSigner: TransactionSigner; profileValidationProfile: Address; profileValidationCertificate?: Address; profileValidationProgram?: Address; /** The character (owned by the signer's profile) to grant XP to. */ character: Address; /** The game account (provides the XP thresholds used to recompute levels). */ game: Address; xpBudget?: Address; xpBudgetConfig?: Address; keyIndex: GrantXpInstructionDataArgs['keyIndex']; category: GrantXpInstructionDataArgs['category']; amount: GrantXpInstructionDataArgs['amount']; }; export function getGrantXpInstruction< TAccountProfileValidationSigner extends string, TAccountProfileValidationProfile extends string, TAccountProfileValidationCertificate extends string, TAccountProfileValidationProgram extends string, TAccountCharacter extends string, TAccountGame extends string, TAccountXpBudget extends string, TAccountXpBudgetConfig extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: GrantXpInput< TAccountProfileValidationSigner, TAccountProfileValidationProfile, TAccountProfileValidationCertificate, TAccountProfileValidationProgram, TAccountCharacter, TAccountGame, TAccountXpBudget, TAccountXpBudgetConfig >, config?: { programAddress?: TProgramAddress }, ): GrantXpInstruction< TProgramAddress, TAccountProfileValidationSigner, TAccountProfileValidationProfile, TAccountProfileValidationCertificate, TAccountProfileValidationProgram, TAccountCharacter, TAccountGame, TAccountXpBudget, TAccountXpBudgetConfig > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { profileValidationSigner: { value: input.profileValidationSigner ?? null, isWritable: false, }, profileValidationProfile: { value: input.profileValidationProfile ?? null, isWritable: true, }, profileValidationCertificate: { value: input.profileValidationCertificate ?? null, isWritable: false, }, profileValidationProgram: { value: input.profileValidationProgram ?? null, isWritable: false, }, character: { value: input.character ?? null, isWritable: true }, game: { value: input.game ?? 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 >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.profileValidationProgram.value) { accounts.profileValidationProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta( 'profileValidationSigner', accounts.profileValidationSigner, ), getAccountMeta( 'profileValidationProfile', accounts.profileValidationProfile, ), getAccountMeta( 'profileValidationCertificate', accounts.profileValidationCertificate, ), getAccountMeta( 'profileValidationProgram', accounts.profileValidationProgram, ), getAccountMeta('character', accounts.character), getAccountMeta('game', accounts.game), getAccountMeta('xpBudget', accounts.xpBudget), getAccountMeta('xpBudgetConfig', accounts.xpBudgetConfig), ], data: getGrantXpInstructionDataEncoder().encode( args as GrantXpInstructionDataArgs, ), programAddress, } as GrantXpInstruction< TProgramAddress, TAccountProfileValidationSigner, TAccountProfileValidationProfile, TAccountProfileValidationCertificate, TAccountProfileValidationProgram, TAccountCharacter, TAccountGame, TAccountXpBudget, TAccountXpBudgetConfig >); } export type ParsedGrantXpInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { profileValidationSigner: TAccountMetas[0]; profileValidationProfile: TAccountMetas[1]; profileValidationCertificate?: TAccountMetas[2] | undefined; profileValidationProgram: TAccountMetas[3]; /** The character (owned by the signer's profile) to grant XP to. */ character: TAccountMetas[4]; /** The game account (provides the XP thresholds used to recompute levels). */ game: TAccountMetas[5]; xpBudget?: TAccountMetas[6] | undefined; xpBudgetConfig?: TAccountMetas[7] | undefined; }; data: GrantXpInstructionData; }; export function parseGrantXpInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedGrantXpInstruction { 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; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SAGE_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { profileValidationSigner: getNextAccount(), profileValidationProfile: getNextAccount(), profileValidationCertificate: getNextOptionalAccount(), profileValidationProgram: getNextAccount(), character: getNextAccount(), game: getNextAccount(), xpBudget: getNextOptionalAccount(), xpBudgetConfig: getNextOptionalAccount(), }, data: getGrantXpInstructionDataDecoder().decode(instruction.data), }; }