/** * 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, getOptionDecoder, getOptionEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU64Decoder, getU64Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type Option, type OptionOrNullable, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; import { getGovernanceParamsDecoder, getGovernanceParamsEncoder, type GovernanceParams, type GovernanceParamsArgs, } from '../types'; export const REQUEST_DEMOCRACY_PTR_ALLOCATION_DISCRIMINATOR = new Uint8Array([ 127, 229, 233, 67, 212, 94, 229, 236, ]); export function getRequestDemocracyPtrAllocationDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( REQUEST_DEMOCRACY_PTR_ALLOCATION_DISCRIMINATOR, ); } export type RequestDemocracyPtrAllocationInstruction< 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', 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, TAccountPolicy extends string | AccountMeta = string, TAccountCurrentStarbasePlayer extends string | AccountMeta = string, TAccountOwnerFactionAccount extends string | AccountMeta = string, TAccountRequirements extends string | AccountMeta = string, TAccountCurve extends string | AccountMeta = string, TAccountHousingMap extends string | AccountMeta = string, TAccountActiveCurve extends string | AccountMeta = string, TAccountActiveHousingMap 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, 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, TAccountPolicy extends string ? ReadonlyAccount : TAccountPolicy, TAccountCurrentStarbasePlayer extends string ? ReadonlyAccount : TAccountCurrentStarbasePlayer, TAccountOwnerFactionAccount extends string ? ReadonlyAccount : TAccountOwnerFactionAccount, TAccountRequirements extends string ? WritableAccount : TAccountRequirements, TAccountCurve extends string ? ReadonlyAccount : TAccountCurve, TAccountHousingMap extends string ? ReadonlyAccount : TAccountHousingMap, TAccountActiveCurve extends string ? ReadonlyAccount : TAccountActiveCurve, TAccountActiveHousingMap extends string ? ReadonlyAccount : TAccountActiveHousingMap, ...TRemainingAccounts, ] >; export type RequestDemocracyPtrAllocationInstructionData = { discriminator: ReadonlyUint8Array; keyIndex: number; expectedAuthorizationRevision: bigint; expectedRootRevision: bigint; expectedAllocationRevision: bigint; expectedBackingRevision: bigint; targetPvp: bigint; /** None is standing abstention; Some replaces the complete four-parameter ballot. */ preference: Option; }; export type RequestDemocracyPtrAllocationInstructionDataArgs = { keyIndex: number; expectedAuthorizationRevision: number | bigint; expectedRootRevision: number | bigint; expectedAllocationRevision: number | bigint; expectedBackingRevision: number | bigint; targetPvp: number | bigint; /** None is standing abstention; Some replaces the complete four-parameter ballot. */ preference: OptionOrNullable; }; export function getRequestDemocracyPtrAllocationInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ['expectedAuthorizationRevision', getU64Encoder()], ['expectedRootRevision', getU64Encoder()], ['expectedAllocationRevision', getU64Encoder()], ['expectedBackingRevision', getU64Encoder()], ['targetPvp', getU64Encoder()], ['preference', getOptionEncoder(getGovernanceParamsEncoder())], ]), (value) => ({ ...value, discriminator: REQUEST_DEMOCRACY_PTR_ALLOCATION_DISCRIMINATOR, }), ); } export function getRequestDemocracyPtrAllocationInstructionDataDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ['expectedAuthorizationRevision', getU64Decoder()], ['expectedRootRevision', getU64Decoder()], ['expectedAllocationRevision', getU64Decoder()], ['expectedBackingRevision', getU64Decoder()], ['targetPvp', getU64Decoder()], ['preference', getOptionDecoder(getGovernanceParamsDecoder())], ]); } export function getRequestDemocracyPtrAllocationInstructionDataCodec(): Codec< RequestDemocracyPtrAllocationInstructionDataArgs, RequestDemocracyPtrAllocationInstructionData > { return combineCodec( getRequestDemocracyPtrAllocationInstructionDataEncoder(), getRequestDemocracyPtrAllocationInstructionDataDecoder(), ); } export type RequestDemocracyPtrAllocationInput< TAccountCurrentSigner extends string = string, TAccountCurrentProfile extends string = string, TAccountCurrentCertificate extends string = string, TAccountCurrentProgram 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, TAccountPolicy extends string = string, TAccountCurrentStarbasePlayer extends string = string, TAccountOwnerFactionAccount extends string = string, TAccountRequirements extends string = string, TAccountCurve extends string = string, TAccountHousingMap extends string = string, TAccountActiveCurve extends string = string, TAccountActiveHousingMap extends string = string, > = { currentSigner: TransactionSigner; currentProfile: Address; currentCertificate?: Address; currentProgram?: Address; positionAuthorityGame: Address; positionAuthorityIdentity: Address; positionAuthorityRoot: Address; positionAllocation: Address; positionClaimHistory: Address; positionGeneration: Address; history: Address; policy: Address; /** * Only needed for a positive target or a changed explicit ballot. A zero exit needs no * current StarbasePlayer, controller signature, active requirements version or live tier. */ currentStarbasePlayer?: Address; ownerFactionAccount?: Address; requirements?: Address; curve?: Address; housingMap?: Address; activeCurve?: Address; activeHousingMap?: Address; keyIndex: RequestDemocracyPtrAllocationInstructionDataArgs['keyIndex']; expectedAuthorizationRevision: RequestDemocracyPtrAllocationInstructionDataArgs['expectedAuthorizationRevision']; expectedRootRevision: RequestDemocracyPtrAllocationInstructionDataArgs['expectedRootRevision']; expectedAllocationRevision: RequestDemocracyPtrAllocationInstructionDataArgs['expectedAllocationRevision']; expectedBackingRevision: RequestDemocracyPtrAllocationInstructionDataArgs['expectedBackingRevision']; targetPvp: RequestDemocracyPtrAllocationInstructionDataArgs['targetPvp']; preference: RequestDemocracyPtrAllocationInstructionDataArgs['preference']; }; export function getRequestDemocracyPtrAllocationInstruction< TAccountCurrentSigner extends string, TAccountCurrentProfile extends string, TAccountCurrentCertificate extends string, TAccountCurrentProgram extends string, TAccountPositionAuthorityGame extends string, TAccountPositionAuthorityIdentity extends string, TAccountPositionAuthorityRoot extends string, TAccountPositionAllocation extends string, TAccountPositionClaimHistory extends string, TAccountPositionGeneration extends string, TAccountHistory extends string, TAccountPolicy extends string, TAccountCurrentStarbasePlayer extends string, TAccountOwnerFactionAccount extends string, TAccountRequirements extends string, TAccountCurve extends string, TAccountHousingMap extends string, TAccountActiveCurve extends string, TAccountActiveHousingMap extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: RequestDemocracyPtrAllocationInput< TAccountCurrentSigner, TAccountCurrentProfile, TAccountCurrentCertificate, TAccountCurrentProgram, TAccountPositionAuthorityGame, TAccountPositionAuthorityIdentity, TAccountPositionAuthorityRoot, TAccountPositionAllocation, TAccountPositionClaimHistory, TAccountPositionGeneration, TAccountHistory, TAccountPolicy, TAccountCurrentStarbasePlayer, TAccountOwnerFactionAccount, TAccountRequirements, TAccountCurve, TAccountHousingMap, TAccountActiveCurve, TAccountActiveHousingMap >, config?: { programAddress?: TProgramAddress }, ): RequestDemocracyPtrAllocationInstruction< TProgramAddress, TAccountCurrentSigner, TAccountCurrentProfile, TAccountCurrentCertificate, TAccountCurrentProgram, TAccountPositionAuthorityGame, TAccountPositionAuthorityIdentity, TAccountPositionAuthorityRoot, TAccountPositionAllocation, TAccountPositionClaimHistory, TAccountPositionGeneration, TAccountHistory, TAccountPolicy, TAccountCurrentStarbasePlayer, TAccountOwnerFactionAccount, TAccountRequirements, TAccountCurve, TAccountHousingMap, TAccountActiveCurve, TAccountActiveHousingMap > { // 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 }, 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 }, policy: { value: input.policy ?? null, isWritable: false }, currentStarbasePlayer: { value: input.currentStarbasePlayer ?? null, isWritable: false, }, ownerFactionAccount: { value: input.ownerFactionAccount ?? null, isWritable: false, }, requirements: { value: input.requirements ?? null, isWritable: true }, curve: { value: input.curve ?? null, isWritable: false }, housingMap: { value: input.housingMap ?? null, isWritable: false }, activeCurve: { value: input.activeCurve ?? null, isWritable: false }, activeHousingMap: { value: input.activeHousingMap ?? null, isWritable: false, }, }; 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('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('policy', accounts.policy), getAccountMeta('currentStarbasePlayer', accounts.currentStarbasePlayer), getAccountMeta('ownerFactionAccount', accounts.ownerFactionAccount), getAccountMeta('requirements', accounts.requirements), getAccountMeta('curve', accounts.curve), getAccountMeta('housingMap', accounts.housingMap), getAccountMeta('activeCurve', accounts.activeCurve), getAccountMeta('activeHousingMap', accounts.activeHousingMap), ], data: getRequestDemocracyPtrAllocationInstructionDataEncoder().encode( args as RequestDemocracyPtrAllocationInstructionDataArgs, ), programAddress, } as RequestDemocracyPtrAllocationInstruction< TProgramAddress, TAccountCurrentSigner, TAccountCurrentProfile, TAccountCurrentCertificate, TAccountCurrentProgram, TAccountPositionAuthorityGame, TAccountPositionAuthorityIdentity, TAccountPositionAuthorityRoot, TAccountPositionAllocation, TAccountPositionClaimHistory, TAccountPositionGeneration, TAccountHistory, TAccountPolicy, TAccountCurrentStarbasePlayer, TAccountOwnerFactionAccount, TAccountRequirements, TAccountCurve, TAccountHousingMap, TAccountActiveCurve, TAccountActiveHousingMap >); } export type ParsedRequestDemocracyPtrAllocationInstruction< 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]; positionAuthorityGame: TAccountMetas[4]; positionAuthorityIdentity: TAccountMetas[5]; positionAuthorityRoot: TAccountMetas[6]; positionAllocation: TAccountMetas[7]; positionClaimHistory: TAccountMetas[8]; positionGeneration: TAccountMetas[9]; history: TAccountMetas[10]; policy: TAccountMetas[11]; /** * Only needed for a positive target or a changed explicit ballot. A zero exit needs no * current StarbasePlayer, controller signature, active requirements version or live tier. */ currentStarbasePlayer?: TAccountMetas[12] | undefined; ownerFactionAccount?: TAccountMetas[13] | undefined; requirements?: TAccountMetas[14] | undefined; curve?: TAccountMetas[15] | undefined; housingMap?: TAccountMetas[16] | undefined; activeCurve?: TAccountMetas[17] | undefined; activeHousingMap?: TAccountMetas[18] | undefined; }; data: RequestDemocracyPtrAllocationInstructionData; }; export function parseRequestDemocracyPtrAllocationInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedRequestDemocracyPtrAllocationInstruction { if (instruction.accounts.length < 19) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 19, }, ); } 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(), positionAuthorityGame: getNextAccount(), positionAuthorityIdentity: getNextAccount(), positionAuthorityRoot: getNextAccount(), positionAllocation: getNextAccount(), positionClaimHistory: getNextAccount(), positionGeneration: getNextAccount(), history: getNextAccount(), policy: getNextAccount(), currentStarbasePlayer: getNextOptionalAccount(), ownerFactionAccount: getNextOptionalAccount(), requirements: getNextOptionalAccount(), curve: getNextOptionalAccount(), housingMap: getNextOptionalAccount(), activeCurve: getNextOptionalAccount(), activeHousingMap: getNextOptionalAccount(), }, data: getRequestDemocracyPtrAllocationInstructionDataDecoder().decode( instruction.data, ), }; }