/** * 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, 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, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const CLEANUP_INVALID_MARKET_DISCRIMINATOR = new Uint8Array([ 236, 131, 187, 212, 115, 245, 125, 108, ]); export function getCleanupInvalidMarketDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CLEANUP_INVALID_MARKET_DISCRIMINATOR, ); } export type CleanupInvalidMarketInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountProfile extends string | AccountMeta = string, TAccountCharacter extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountSystem extends string | AccountMeta = string, TAccountLocalMarket extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountProfile extends string ? WritableAccount : TAccountProfile, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, TAccountLocalMarket extends string ? WritableAccount : TAccountLocalMarket, ...TRemainingAccounts, ] >; export type CleanupInvalidMarketInstructionData = { discriminator: ReadonlyUint8Array; keyIndex: number; }; export type CleanupInvalidMarketInstructionDataArgs = { keyIndex: number }; export function getCleanupInvalidMarketInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ]), (value) => ({ ...value, discriminator: CLEANUP_INVALID_MARKET_DISCRIMINATOR, }), ); } export function getCleanupInvalidMarketInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ]); } export function getCleanupInvalidMarketInstructionDataCodec(): FixedSizeCodec< CleanupInvalidMarketInstructionDataArgs, CleanupInvalidMarketInstructionData > { return combineCodec( getCleanupInvalidMarketInstructionDataEncoder(), getCleanupInvalidMarketInstructionDataDecoder(), ); } export type CleanupInvalidMarketAsyncInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountCharacter extends string = string, TAccountGame extends string = string, TAccountSystem extends string = string, TAccountLocalMarket extends string = string, > = { /** Any signer may perform this cleanup and fund Character rent growth. */ funder: TransactionSigner; /** The profile */ profile: Address; /** The Character account associated with the profile */ character?: Address; /** The game account */ game: Address; /** The starbase account */ system: Address; /** * The local market to clean up * We don't automatically clean up the rent here to allow for permissionless return */ localMarket: Address; keyIndex: CleanupInvalidMarketInstructionDataArgs['keyIndex']; }; export async function getCleanupInvalidMarketInstructionAsync< TAccountFunder extends string, TAccountProfile extends string, TAccountCharacter extends string, TAccountGame extends string, TAccountSystem extends string, TAccountLocalMarket extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CleanupInvalidMarketAsyncInput< TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountLocalMarket >, config?: { programAddress?: TProgramAddress }, ): Promise< CleanupInvalidMarketInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountLocalMarket > > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, profile: { value: input.profile ?? null, isWritable: true }, character: { value: input.character ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, system: { value: input.system ?? null, isWritable: false }, localMarket: { value: input.localMarket ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. 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( 'profile', accounts.profile.value, ), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount('game', accounts.game.value), ), ], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('profile', accounts.profile), getAccountMeta('character', accounts.character), getAccountMeta('game', accounts.game), getAccountMeta('system', accounts.system), getAccountMeta('localMarket', accounts.localMarket), ], data: getCleanupInvalidMarketInstructionDataEncoder().encode( args as CleanupInvalidMarketInstructionDataArgs, ), programAddress, } as CleanupInvalidMarketInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountLocalMarket >); } export type CleanupInvalidMarketInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountCharacter extends string = string, TAccountGame extends string = string, TAccountSystem extends string = string, TAccountLocalMarket extends string = string, > = { /** Any signer may perform this cleanup and fund Character rent growth. */ funder: TransactionSigner; /** The profile */ profile: Address; /** The Character account associated with the profile */ character: Address; /** The game account */ game: Address; /** The starbase account */ system: Address; /** * The local market to clean up * We don't automatically clean up the rent here to allow for permissionless return */ localMarket: Address; keyIndex: CleanupInvalidMarketInstructionDataArgs['keyIndex']; }; export function getCleanupInvalidMarketInstruction< TAccountFunder extends string, TAccountProfile extends string, TAccountCharacter extends string, TAccountGame extends string, TAccountSystem extends string, TAccountLocalMarket extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CleanupInvalidMarketInput< TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountLocalMarket >, config?: { programAddress?: TProgramAddress }, ): CleanupInvalidMarketInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountLocalMarket > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, profile: { value: input.profile ?? null, isWritable: true }, character: { value: input.character ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, system: { value: input.system ?? null, isWritable: false }, localMarket: { value: input.localMarket ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('profile', accounts.profile), getAccountMeta('character', accounts.character), getAccountMeta('game', accounts.game), getAccountMeta('system', accounts.system), getAccountMeta('localMarket', accounts.localMarket), ], data: getCleanupInvalidMarketInstructionDataEncoder().encode( args as CleanupInvalidMarketInstructionDataArgs, ), programAddress, } as CleanupInvalidMarketInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountLocalMarket >); } export type ParsedCleanupInvalidMarketInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Any signer may perform this cleanup and fund Character rent growth. */ funder: TAccountMetas[0]; /** The profile */ profile: TAccountMetas[1]; /** The Character account associated with the profile */ character: TAccountMetas[2]; /** The game account */ game: TAccountMetas[3]; /** The starbase account */ system: TAccountMetas[4]; /** * The local market to clean up * We don't automatically clean up the rent here to allow for permissionless return */ localMarket: TAccountMetas[5]; }; data: CleanupInvalidMarketInstructionData; }; export function parseCleanupInvalidMarketInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCleanupInvalidMarketInstruction { if (instruction.accounts.length < 6) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 6, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), profile: getNextAccount(), character: getNextAccount(), game: getNextAccount(), system: getNextAccount(), localMarket: getNextAccount(), }, data: getCleanupInvalidMarketInstructionDataDecoder().decode( instruction.data, ), }; }