/** * 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'; export const CLAIM_DEMOCRACY_PTR_LEGACY_REWARDS_DISCRIMINATOR = new Uint8Array([ 212, 201, 149, 45, 150, 243, 201, 129, ]); export function getClaimDemocracyPtrLegacyRewardsDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CLAIM_DEMOCRACY_PTR_LEGACY_REWARDS_DISCRIMINATOR, ); } export type ClaimDemocracyPtrLegacyRewardsInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountCurrentSigner extends string | AccountMeta = string, TAccountCurrentProfile extends string | AccountMeta = string, TAccountCurrentCertificate extends string | AccountMeta = string, TAccountCurrentProgram extends string | AccountMeta = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u', TAccountGame extends string | AccountMeta = string, TAccountIdentity extends string | AccountMeta = string, TAccountProgress extends string | AccountMeta = string, TAccountReceipt extends string | AccountMeta = string, TAccountCharacter extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountCurrentSigner extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountCurrentSigner, TAccountCurrentProfile extends string ? WritableAccount : TAccountCurrentProfile, TAccountCurrentCertificate extends string ? ReadonlyAccount : TAccountCurrentCertificate, TAccountCurrentProgram extends string ? ReadonlyAccount : TAccountCurrentProgram, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountIdentity extends string ? ReadonlyAccount : TAccountIdentity, TAccountProgress extends string ? ReadonlyAccount : TAccountProgress, TAccountReceipt extends string ? WritableAccount : TAccountReceipt, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, ...TRemainingAccounts, ] >; export type ClaimDemocracyPtrLegacyRewardsInstructionData = { discriminator: ReadonlyUint8Array; keyIndex: number; expectedAuthorizationRevision: bigint; }; export type ClaimDemocracyPtrLegacyRewardsInstructionDataArgs = { keyIndex: number; expectedAuthorizationRevision: number | bigint; }; export function getClaimDemocracyPtrLegacyRewardsInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ['expectedAuthorizationRevision', getU64Encoder()], ]), (value) => ({ ...value, discriminator: CLAIM_DEMOCRACY_PTR_LEGACY_REWARDS_DISCRIMINATOR, }), ); } export function getClaimDemocracyPtrLegacyRewardsInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ['expectedAuthorizationRevision', getU64Decoder()], ]); } export function getClaimDemocracyPtrLegacyRewardsInstructionDataCodec(): FixedSizeCodec< ClaimDemocracyPtrLegacyRewardsInstructionDataArgs, ClaimDemocracyPtrLegacyRewardsInstructionData > { return combineCodec( getClaimDemocracyPtrLegacyRewardsInstructionDataEncoder(), getClaimDemocracyPtrLegacyRewardsInstructionDataDecoder(), ); } export type ClaimDemocracyPtrLegacyRewardsAsyncInput< TAccountCurrentSigner extends string = string, TAccountCurrentProfile extends string = string, TAccountCurrentCertificate extends string = string, TAccountCurrentProgram extends string = string, TAccountGame extends string = string, TAccountIdentity extends string = string, TAccountProgress extends string = string, TAccountReceipt extends string = string, TAccountCharacter extends string = string, > = { currentSigner: TransactionSigner; currentProfile: Address; currentCertificate?: Address; currentProgram?: Address; game: Address; identity: Address; progress: Address; receipt: Address; character?: Address; keyIndex: ClaimDemocracyPtrLegacyRewardsInstructionDataArgs['keyIndex']; expectedAuthorizationRevision: ClaimDemocracyPtrLegacyRewardsInstructionDataArgs['expectedAuthorizationRevision']; }; export async function getClaimDemocracyPtrLegacyRewardsInstructionAsync< TAccountCurrentSigner extends string, TAccountCurrentProfile extends string, TAccountCurrentCertificate extends string, TAccountCurrentProgram extends string, TAccountGame extends string, TAccountIdentity extends string, TAccountProgress extends string, TAccountReceipt extends string, TAccountCharacter extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ClaimDemocracyPtrLegacyRewardsAsyncInput< TAccountCurrentSigner, TAccountCurrentProfile, TAccountCurrentCertificate, TAccountCurrentProgram, TAccountGame, TAccountIdentity, TAccountProgress, TAccountReceipt, TAccountCharacter >, config?: { programAddress?: TProgramAddress }, ): Promise< ClaimDemocracyPtrLegacyRewardsInstruction< TProgramAddress, TAccountCurrentSigner, TAccountCurrentProfile, TAccountCurrentCertificate, TAccountCurrentProgram, TAccountGame, TAccountIdentity, TAccountProgress, TAccountReceipt, TAccountCharacter > > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { currentSigner: { value: input.currentSigner ?? null, isWritable: false }, currentProfile: { value: input.currentProfile ?? null, isWritable: true }, currentCertificate: { value: input.currentCertificate ?? null, isWritable: false, }, currentProgram: { value: input.currentProgram ?? null, isWritable: false }, game: { value: input.game ?? null, isWritable: false }, identity: { value: input.identity ?? null, isWritable: false }, progress: { value: input.progress ?? null, isWritable: false }, receipt: { value: input.receipt ?? null, isWritable: true }, character: { value: input.character ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.currentProgram.value) { accounts.currentProgram.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( 'currentProfile', accounts.currentProfile.value, ), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount('game', accounts.game.value), ), ], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('currentSigner', accounts.currentSigner), getAccountMeta('currentProfile', accounts.currentProfile), getAccountMeta('currentCertificate', accounts.currentCertificate), getAccountMeta('currentProgram', accounts.currentProgram), getAccountMeta('game', accounts.game), getAccountMeta('identity', accounts.identity), getAccountMeta('progress', accounts.progress), getAccountMeta('receipt', accounts.receipt), getAccountMeta('character', accounts.character), ], data: getClaimDemocracyPtrLegacyRewardsInstructionDataEncoder().encode( args as ClaimDemocracyPtrLegacyRewardsInstructionDataArgs, ), programAddress, } as ClaimDemocracyPtrLegacyRewardsInstruction< TProgramAddress, TAccountCurrentSigner, TAccountCurrentProfile, TAccountCurrentCertificate, TAccountCurrentProgram, TAccountGame, TAccountIdentity, TAccountProgress, TAccountReceipt, TAccountCharacter >); } export type ClaimDemocracyPtrLegacyRewardsInput< TAccountCurrentSigner extends string = string, TAccountCurrentProfile extends string = string, TAccountCurrentCertificate extends string = string, TAccountCurrentProgram extends string = string, TAccountGame extends string = string, TAccountIdentity extends string = string, TAccountProgress extends string = string, TAccountReceipt extends string = string, TAccountCharacter extends string = string, > = { currentSigner: TransactionSigner; currentProfile: Address; currentCertificate?: Address; currentProgram?: Address; game: Address; identity: Address; progress: Address; receipt: Address; character: Address; keyIndex: ClaimDemocracyPtrLegacyRewardsInstructionDataArgs['keyIndex']; expectedAuthorizationRevision: ClaimDemocracyPtrLegacyRewardsInstructionDataArgs['expectedAuthorizationRevision']; }; export function getClaimDemocracyPtrLegacyRewardsInstruction< TAccountCurrentSigner extends string, TAccountCurrentProfile extends string, TAccountCurrentCertificate extends string, TAccountCurrentProgram extends string, TAccountGame extends string, TAccountIdentity extends string, TAccountProgress extends string, TAccountReceipt extends string, TAccountCharacter extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ClaimDemocracyPtrLegacyRewardsInput< TAccountCurrentSigner, TAccountCurrentProfile, TAccountCurrentCertificate, TAccountCurrentProgram, TAccountGame, TAccountIdentity, TAccountProgress, TAccountReceipt, TAccountCharacter >, config?: { programAddress?: TProgramAddress }, ): ClaimDemocracyPtrLegacyRewardsInstruction< TProgramAddress, TAccountCurrentSigner, TAccountCurrentProfile, TAccountCurrentCertificate, TAccountCurrentProgram, TAccountGame, TAccountIdentity, TAccountProgress, TAccountReceipt, TAccountCharacter > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { currentSigner: { value: input.currentSigner ?? null, isWritable: false }, currentProfile: { value: input.currentProfile ?? null, isWritable: true }, currentCertificate: { value: input.currentCertificate ?? null, isWritable: false, }, currentProgram: { value: input.currentProgram ?? null, isWritable: false }, game: { value: input.game ?? null, isWritable: false }, identity: { value: input.identity ?? null, isWritable: false }, progress: { value: input.progress ?? null, isWritable: false }, receipt: { value: input.receipt ?? null, isWritable: true }, character: { value: input.character ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.currentProgram.value) { accounts.currentProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('currentSigner', accounts.currentSigner), getAccountMeta('currentProfile', accounts.currentProfile), getAccountMeta('currentCertificate', accounts.currentCertificate), getAccountMeta('currentProgram', accounts.currentProgram), getAccountMeta('game', accounts.game), getAccountMeta('identity', accounts.identity), getAccountMeta('progress', accounts.progress), getAccountMeta('receipt', accounts.receipt), getAccountMeta('character', accounts.character), ], data: getClaimDemocracyPtrLegacyRewardsInstructionDataEncoder().encode( args as ClaimDemocracyPtrLegacyRewardsInstructionDataArgs, ), programAddress, } as ClaimDemocracyPtrLegacyRewardsInstruction< TProgramAddress, TAccountCurrentSigner, TAccountCurrentProfile, TAccountCurrentCertificate, TAccountCurrentProgram, TAccountGame, TAccountIdentity, TAccountProgress, TAccountReceipt, TAccountCharacter >); } export type ParsedClaimDemocracyPtrLegacyRewardsInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { currentSigner: TAccountMetas[0]; currentProfile: TAccountMetas[1]; currentCertificate?: TAccountMetas[2] | undefined; currentProgram: TAccountMetas[3]; game: TAccountMetas[4]; identity: TAccountMetas[5]; progress: TAccountMetas[6]; receipt: TAccountMetas[7]; character: TAccountMetas[8]; }; data: ClaimDemocracyPtrLegacyRewardsInstructionData; }; export function parseClaimDemocracyPtrLegacyRewardsInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedClaimDemocracyPtrLegacyRewardsInstruction { if (instruction.accounts.length < 9) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 9, }, ); } 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: { currentSigner: getNextAccount(), currentProfile: getNextAccount(), currentCertificate: getNextOptionalAccount(), currentProgram: getNextAccount(), game: getNextAccount(), identity: getNextAccount(), progress: getNextAccount(), receipt: getNextAccount(), character: getNextAccount(), }, data: getClaimDemocracyPtrLegacyRewardsInstructionDataDecoder().decode( instruction.data, ), }; }