/** * 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, 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 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 SETTLE_DEMOCRACY_PTR_ALLOCATION_DISCRIMINATOR = new Uint8Array([ 235, 104, 190, 254, 233, 230, 107, 241, ]); export function getSettleDemocracyPtrAllocationDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SETTLE_DEMOCRACY_PTR_ALLOCATION_DISCRIMINATOR, ); } export type SettleDemocracyPtrAllocationInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountPositionAuthorityGame extends string | AccountMeta = string, TAccountPositionAuthorityIdentity extends string | AccountMeta = string, TAccountPositionAuthorityRoot extends string | AccountMeta = string, TAccountPositionAllocation extends string | AccountMeta = string, TAccountPositionClaimHistory extends string | AccountMeta = string, TAccountPositionGeneration extends string | AccountMeta = string, TAccountHistory extends string | AccountMeta = string, TAccountBoundary extends string | AccountMeta = string, TAccountSettlement extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountPositionAuthorityGame extends string ? ReadonlyAccount : TAccountPositionAuthorityGame, TAccountPositionAuthorityIdentity extends string ? ReadonlyAccount : TAccountPositionAuthorityIdentity, TAccountPositionAuthorityRoot extends string ? WritableAccount : TAccountPositionAuthorityRoot, TAccountPositionAllocation extends string ? WritableAccount : TAccountPositionAllocation, TAccountPositionClaimHistory extends string ? WritableAccount : TAccountPositionClaimHistory, TAccountPositionGeneration extends string ? WritableAccount : TAccountPositionGeneration, TAccountHistory extends string ? ReadonlyAccount : TAccountHistory, TAccountBoundary extends string ? ReadonlyAccount : TAccountBoundary, TAccountSettlement extends string ? WritableAccount : TAccountSettlement, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type SettleDemocracyPtrAllocationInstructionData = { discriminator: ReadonlyUint8Array; expectedRootRevision: bigint; expectedAllocationRevision: bigint; }; export type SettleDemocracyPtrAllocationInstructionDataArgs = { expectedRootRevision: number | bigint; expectedAllocationRevision: number | bigint; }; export function getSettleDemocracyPtrAllocationInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['expectedRootRevision', getU64Encoder()], ['expectedAllocationRevision', getU64Encoder()], ]), (value) => ({ ...value, discriminator: SETTLE_DEMOCRACY_PTR_ALLOCATION_DISCRIMINATOR, }), ); } export function getSettleDemocracyPtrAllocationInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['expectedRootRevision', getU64Decoder()], ['expectedAllocationRevision', getU64Decoder()], ]); } export function getSettleDemocracyPtrAllocationInstructionDataCodec(): FixedSizeCodec< SettleDemocracyPtrAllocationInstructionDataArgs, SettleDemocracyPtrAllocationInstructionData > { return combineCodec( getSettleDemocracyPtrAllocationInstructionDataEncoder(), getSettleDemocracyPtrAllocationInstructionDataDecoder(), ); } export type SettleDemocracyPtrAllocationInput< TAccountFunder extends string = string, TAccountPositionAuthorityGame extends string = string, TAccountPositionAuthorityIdentity extends string = string, TAccountPositionAuthorityRoot extends string = string, TAccountPositionAllocation extends string = string, TAccountPositionClaimHistory extends string = string, TAccountPositionGeneration extends string = string, TAccountHistory extends string = string, TAccountBoundary extends string = string, TAccountSettlement extends string = string, TAccountSystemProgram extends string = string, > = { funder: TransactionSigner; positionAuthorityGame: Address; positionAuthorityIdentity: Address; positionAuthorityRoot: Address; positionAllocation: Address; positionClaimHistory: Address; positionGeneration: Address; history: Address; /** * The last old-power day for a matured scheduled change. Not needed for a target canceled * before activation by capture, or for explicitly configured capture-close activation. */ boundary?: Address; settlement: Address; systemProgram?: Address; expectedRootRevision: SettleDemocracyPtrAllocationInstructionDataArgs['expectedRootRevision']; expectedAllocationRevision: SettleDemocracyPtrAllocationInstructionDataArgs['expectedAllocationRevision']; }; export function getSettleDemocracyPtrAllocationInstruction< TAccountFunder extends string, TAccountPositionAuthorityGame extends string, TAccountPositionAuthorityIdentity extends string, TAccountPositionAuthorityRoot extends string, TAccountPositionAllocation extends string, TAccountPositionClaimHistory extends string, TAccountPositionGeneration extends string, TAccountHistory extends string, TAccountBoundary extends string, TAccountSettlement extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: SettleDemocracyPtrAllocationInput< TAccountFunder, TAccountPositionAuthorityGame, TAccountPositionAuthorityIdentity, TAccountPositionAuthorityRoot, TAccountPositionAllocation, TAccountPositionClaimHistory, TAccountPositionGeneration, TAccountHistory, TAccountBoundary, TAccountSettlement, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): SettleDemocracyPtrAllocationInstruction< TProgramAddress, TAccountFunder, TAccountPositionAuthorityGame, TAccountPositionAuthorityIdentity, TAccountPositionAuthorityRoot, TAccountPositionAllocation, TAccountPositionClaimHistory, TAccountPositionGeneration, TAccountHistory, TAccountBoundary, TAccountSettlement, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, positionAuthorityGame: { value: input.positionAuthorityGame ?? null, isWritable: false, }, positionAuthorityIdentity: { value: input.positionAuthorityIdentity ?? null, isWritable: false, }, positionAuthorityRoot: { value: input.positionAuthorityRoot ?? null, isWritable: true, }, positionAllocation: { value: input.positionAllocation ?? null, isWritable: true, }, positionClaimHistory: { value: input.positionClaimHistory ?? null, isWritable: true, }, positionGeneration: { value: input.positionGeneration ?? null, isWritable: true, }, history: { value: input.history ?? null, isWritable: false }, boundary: { value: input.boundary ?? null, isWritable: false }, settlement: { value: input.settlement ?? null, isWritable: true }, 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('positionAuthorityGame', accounts.positionAuthorityGame), getAccountMeta( 'positionAuthorityIdentity', accounts.positionAuthorityIdentity, ), getAccountMeta('positionAuthorityRoot', accounts.positionAuthorityRoot), getAccountMeta('positionAllocation', accounts.positionAllocation), getAccountMeta('positionClaimHistory', accounts.positionClaimHistory), getAccountMeta('positionGeneration', accounts.positionGeneration), getAccountMeta('history', accounts.history), getAccountMeta('boundary', accounts.boundary), getAccountMeta('settlement', accounts.settlement), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getSettleDemocracyPtrAllocationInstructionDataEncoder().encode( args as SettleDemocracyPtrAllocationInstructionDataArgs, ), programAddress, } as SettleDemocracyPtrAllocationInstruction< TProgramAddress, TAccountFunder, TAccountPositionAuthorityGame, TAccountPositionAuthorityIdentity, TAccountPositionAuthorityRoot, TAccountPositionAllocation, TAccountPositionClaimHistory, TAccountPositionGeneration, TAccountHistory, TAccountBoundary, TAccountSettlement, TAccountSystemProgram >); } export type ParsedSettleDemocracyPtrAllocationInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { funder: TAccountMetas[0]; positionAuthorityGame: TAccountMetas[1]; positionAuthorityIdentity: TAccountMetas[2]; positionAuthorityRoot: TAccountMetas[3]; positionAllocation: TAccountMetas[4]; positionClaimHistory: TAccountMetas[5]; positionGeneration: TAccountMetas[6]; history: TAccountMetas[7]; /** * The last old-power day for a matured scheduled change. Not needed for a target canceled * before activation by capture, or for explicitly configured capture-close activation. */ boundary?: TAccountMetas[8] | undefined; settlement: TAccountMetas[9]; systemProgram: TAccountMetas[10]; }; data: SettleDemocracyPtrAllocationInstructionData; }; export function parseSettleDemocracyPtrAllocationInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSettleDemocracyPtrAllocationInstruction { if (instruction.accounts.length < 11) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 11, }, ); } 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: { funder: getNextAccount(), positionAuthorityGame: getNextAccount(), positionAuthorityIdentity: getNextAccount(), positionAuthorityRoot: getNextAccount(), positionAllocation: getNextAccount(), positionClaimHistory: getNextAccount(), positionGeneration: getNextAccount(), history: getNextAccount(), boundary: getNextOptionalAccount(), settlement: getNextAccount(), systemProgram: getNextAccount(), }, data: getSettleDemocracyPtrAllocationInstructionDataDecoder().decode( instruction.data, ), }; }