/** * 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, 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 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'; export const INSTALL_STARBASE_UPGRADE_RESOURCE_DISCRIMINATOR = new Uint8Array([ 152, 176, 99, 29, 240, 6, 163, 111, ]); export function getInstallStarbaseUpgradeResourceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( INSTALL_STARBASE_UPGRADE_RESOURCE_DISCRIMINATOR, ); } export type InstallStarbaseUpgradeResourceInstruction< 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', TAccountStarSystem extends string | AccountMeta = string, TAccountStarbasePlayer extends string | AccountMeta = string, TAccountUpgradeProcess extends string | AccountMeta = string, TAccountRegionTracker extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountRewardsRegistry extends string | AccountMeta = string, TAccountRewardsConfig extends string | AccountMeta = string, TAccountRewardsEpoch extends string | AccountMeta = string, TAccountRewardsContribution extends string | AccountMeta = string, TAccountKingTracker extends string | AccountMeta = string, TAccountRentCatalog extends string | AccountMeta = string, TAccountRentHead extends string | AccountMeta = string, TAccountRentCurrentPage extends string | AccountMeta = string, TAccountRentNextPage extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TAccountDemocracyHistoryHistory extends string | AccountMeta = string, TAccountDemocracyHistoryPolicy extends string | AccountMeta = string, TAccountDemocracyHistoryGeneration extends string | AccountMeta = string, TAccountDemocracyFactionOwnership 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, TAccountStarSystem extends string ? WritableAccount : TAccountStarSystem, TAccountStarbasePlayer extends string ? WritableAccount : TAccountStarbasePlayer, TAccountUpgradeProcess extends string ? WritableAccount : TAccountUpgradeProcess, TAccountRegionTracker extends string ? WritableAccount : TAccountRegionTracker, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountRewardsRegistry extends string ? ReadonlyAccount : TAccountRewardsRegistry, TAccountRewardsConfig extends string ? ReadonlyAccount : TAccountRewardsConfig, TAccountRewardsEpoch extends string ? WritableAccount : TAccountRewardsEpoch, TAccountRewardsContribution extends string ? WritableAccount : TAccountRewardsContribution, TAccountKingTracker extends string ? WritableAccount : TAccountKingTracker, TAccountRentCatalog extends string ? ReadonlyAccount : TAccountRentCatalog, TAccountRentHead extends string ? WritableAccount : TAccountRentHead, TAccountRentCurrentPage extends string ? WritableAccount : TAccountRentCurrentPage, TAccountRentNextPage extends string ? WritableAccount : TAccountRentNextPage, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountDemocracyHistoryHistory extends string ? WritableAccount : TAccountDemocracyHistoryHistory, TAccountDemocracyHistoryPolicy extends string ? ReadonlyAccount : TAccountDemocracyHistoryPolicy, TAccountDemocracyHistoryGeneration extends string ? WritableAccount : TAccountDemocracyHistoryGeneration, TAccountDemocracyFactionOwnership extends string ? ReadonlyAccount : TAccountDemocracyFactionOwnership, ...TRemainingAccounts, ] >; export type InstallStarbaseUpgradeResourceInstructionData = { discriminator: ReadonlyUint8Array; /** The index of the key in the player profile */ keyIndex: number; }; export type InstallStarbaseUpgradeResourceInstructionDataArgs = { /** The index of the key in the player profile */ keyIndex: number; }; export function getInstallStarbaseUpgradeResourceInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ]), (value) => ({ ...value, discriminator: INSTALL_STARBASE_UPGRADE_RESOURCE_DISCRIMINATOR, }), ); } export function getInstallStarbaseUpgradeResourceInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ]); } export function getInstallStarbaseUpgradeResourceInstructionDataCodec(): FixedSizeCodec< InstallStarbaseUpgradeResourceInstructionDataArgs, InstallStarbaseUpgradeResourceInstructionData > { return combineCodec( getInstallStarbaseUpgradeResourceInstructionDataEncoder(), getInstallStarbaseUpgradeResourceInstructionDataDecoder(), ); } export type InstallStarbaseUpgradeResourceInput< TAccountProfileValidationSigner extends string = string, TAccountProfileValidationProfile extends string = string, TAccountProfileValidationCertificate extends string = string, TAccountProfileValidationProgram extends string = string, TAccountStarSystem extends string = string, TAccountStarbasePlayer extends string = string, TAccountUpgradeProcess extends string = string, TAccountRegionTracker extends string = string, TAccountGame extends string = string, TAccountRewardsRegistry extends string = string, TAccountRewardsConfig extends string = string, TAccountRewardsEpoch extends string = string, TAccountRewardsContribution extends string = string, TAccountKingTracker extends string = string, TAccountRentCatalog extends string = string, TAccountRentHead extends string = string, TAccountRentCurrentPage extends string = string, TAccountRentNextPage extends string = string, TAccountSystemProgram extends string = string, TAccountDemocracyHistoryHistory extends string = string, TAccountDemocracyHistoryPolicy extends string = string, TAccountDemocracyHistoryGeneration extends string = string, TAccountDemocracyFactionOwnership extends string = string, > = { profileValidationSigner: TransactionSigner; profileValidationProfile: Address; profileValidationCertificate?: Address; profileValidationProgram?: Address; /** The system account */ starSystem: Address; /** The starbase player account */ starbasePlayer: Address; /** The upgrade process */ upgradeProcess: Address; /** Region tracker account */ regionTracker: Address; /** The game account */ game: Address; rewardsRegistry: Address; rewardsConfig: Address; rewardsEpoch?: Address; rewardsContribution?: Address; kingTracker: Address; /** The game's rent catalog PDA (REQUIRED, may be uninitialized = Disabled). */ rentCatalog: Address; /** This system's LEVEL source-head PDA (REQUIRED, may be uninitialized = a legacy source). */ rentHead: Address; /** The page holding the head's latest record (required iff the head exists). */ rentCurrentPage?: Address; /** The following page, created on demand (required iff the head exists). */ rentNextPage?: Address; /** The Solana System program (creates the next history page). */ systemProgram?: Address; democracyHistoryHistory: Address; democracyHistoryPolicy?: Address; democracyHistoryGeneration?: Address; democracyFactionOwnership: Address; keyIndex: InstallStarbaseUpgradeResourceInstructionDataArgs['keyIndex']; }; export function getInstallStarbaseUpgradeResourceInstruction< TAccountProfileValidationSigner extends string, TAccountProfileValidationProfile extends string, TAccountProfileValidationCertificate extends string, TAccountProfileValidationProgram extends string, TAccountStarSystem extends string, TAccountStarbasePlayer extends string, TAccountUpgradeProcess extends string, TAccountRegionTracker extends string, TAccountGame extends string, TAccountRewardsRegistry extends string, TAccountRewardsConfig extends string, TAccountRewardsEpoch extends string, TAccountRewardsContribution extends string, TAccountKingTracker extends string, TAccountRentCatalog extends string, TAccountRentHead extends string, TAccountRentCurrentPage extends string, TAccountRentNextPage extends string, TAccountSystemProgram extends string, TAccountDemocracyHistoryHistory extends string, TAccountDemocracyHistoryPolicy extends string, TAccountDemocracyHistoryGeneration extends string, TAccountDemocracyFactionOwnership extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: InstallStarbaseUpgradeResourceInput< TAccountProfileValidationSigner, TAccountProfileValidationProfile, TAccountProfileValidationCertificate, TAccountProfileValidationProgram, TAccountStarSystem, TAccountStarbasePlayer, TAccountUpgradeProcess, TAccountRegionTracker, TAccountGame, TAccountRewardsRegistry, TAccountRewardsConfig, TAccountRewardsEpoch, TAccountRewardsContribution, TAccountKingTracker, TAccountRentCatalog, TAccountRentHead, TAccountRentCurrentPage, TAccountRentNextPage, TAccountSystemProgram, TAccountDemocracyHistoryHistory, TAccountDemocracyHistoryPolicy, TAccountDemocracyHistoryGeneration, TAccountDemocracyFactionOwnership >, config?: { programAddress?: TProgramAddress }, ): InstallStarbaseUpgradeResourceInstruction< TProgramAddress, TAccountProfileValidationSigner, TAccountProfileValidationProfile, TAccountProfileValidationCertificate, TAccountProfileValidationProgram, TAccountStarSystem, TAccountStarbasePlayer, TAccountUpgradeProcess, TAccountRegionTracker, TAccountGame, TAccountRewardsRegistry, TAccountRewardsConfig, TAccountRewardsEpoch, TAccountRewardsContribution, TAccountKingTracker, TAccountRentCatalog, TAccountRentHead, TAccountRentCurrentPage, TAccountRentNextPage, TAccountSystemProgram, TAccountDemocracyHistoryHistory, TAccountDemocracyHistoryPolicy, TAccountDemocracyHistoryGeneration, TAccountDemocracyFactionOwnership > { // 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, }, starSystem: { value: input.starSystem ?? null, isWritable: true }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, upgradeProcess: { value: input.upgradeProcess ?? null, isWritable: true }, regionTracker: { value: input.regionTracker ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, rewardsRegistry: { value: input.rewardsRegistry ?? null, isWritable: false, }, rewardsConfig: { value: input.rewardsConfig ?? null, isWritable: false }, rewardsEpoch: { value: input.rewardsEpoch ?? null, isWritable: true }, rewardsContribution: { value: input.rewardsContribution ?? null, isWritable: true, }, kingTracker: { value: input.kingTracker ?? null, isWritable: true }, rentCatalog: { value: input.rentCatalog ?? null, isWritable: false }, rentHead: { value: input.rentHead ?? null, isWritable: true }, rentCurrentPage: { value: input.rentCurrentPage ?? null, isWritable: true }, rentNextPage: { value: input.rentNextPage ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, democracyHistoryHistory: { value: input.democracyHistoryHistory ?? null, isWritable: true, }, democracyHistoryPolicy: { value: input.democracyHistoryPolicy ?? null, isWritable: false, }, democracyHistoryGeneration: { value: input.democracyHistoryGeneration ?? null, isWritable: true, }, democracyFactionOwnership: { value: input.democracyFactionOwnership ?? 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.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } 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('starSystem', accounts.starSystem), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('upgradeProcess', accounts.upgradeProcess), getAccountMeta('regionTracker', accounts.regionTracker), getAccountMeta('game', accounts.game), getAccountMeta('rewardsRegistry', accounts.rewardsRegistry), getAccountMeta('rewardsConfig', accounts.rewardsConfig), getAccountMeta('rewardsEpoch', accounts.rewardsEpoch), getAccountMeta('rewardsContribution', accounts.rewardsContribution), getAccountMeta('kingTracker', accounts.kingTracker), getAccountMeta('rentCatalog', accounts.rentCatalog), getAccountMeta('rentHead', accounts.rentHead), getAccountMeta('rentCurrentPage', accounts.rentCurrentPage), getAccountMeta('rentNextPage', accounts.rentNextPage), getAccountMeta('systemProgram', accounts.systemProgram), getAccountMeta( 'democracyHistoryHistory', accounts.democracyHistoryHistory, ), getAccountMeta('democracyHistoryPolicy', accounts.democracyHistoryPolicy), getAccountMeta( 'democracyHistoryGeneration', accounts.democracyHistoryGeneration, ), getAccountMeta( 'democracyFactionOwnership', accounts.democracyFactionOwnership, ), ], data: getInstallStarbaseUpgradeResourceInstructionDataEncoder().encode( args as InstallStarbaseUpgradeResourceInstructionDataArgs, ), programAddress, } as InstallStarbaseUpgradeResourceInstruction< TProgramAddress, TAccountProfileValidationSigner, TAccountProfileValidationProfile, TAccountProfileValidationCertificate, TAccountProfileValidationProgram, TAccountStarSystem, TAccountStarbasePlayer, TAccountUpgradeProcess, TAccountRegionTracker, TAccountGame, TAccountRewardsRegistry, TAccountRewardsConfig, TAccountRewardsEpoch, TAccountRewardsContribution, TAccountKingTracker, TAccountRentCatalog, TAccountRentHead, TAccountRentCurrentPage, TAccountRentNextPage, TAccountSystemProgram, TAccountDemocracyHistoryHistory, TAccountDemocracyHistoryPolicy, TAccountDemocracyHistoryGeneration, TAccountDemocracyFactionOwnership >); } export type ParsedInstallStarbaseUpgradeResourceInstruction< 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 system account */ starSystem: TAccountMetas[4]; /** The starbase player account */ starbasePlayer: TAccountMetas[5]; /** The upgrade process */ upgradeProcess: TAccountMetas[6]; /** Region tracker account */ regionTracker: TAccountMetas[7]; /** The game account */ game: TAccountMetas[8]; rewardsRegistry: TAccountMetas[9]; rewardsConfig: TAccountMetas[10]; rewardsEpoch?: TAccountMetas[11] | undefined; rewardsContribution?: TAccountMetas[12] | undefined; kingTracker: TAccountMetas[13]; /** The game's rent catalog PDA (REQUIRED, may be uninitialized = Disabled). */ rentCatalog: TAccountMetas[14]; /** This system's LEVEL source-head PDA (REQUIRED, may be uninitialized = a legacy source). */ rentHead: TAccountMetas[15]; /** The page holding the head's latest record (required iff the head exists). */ rentCurrentPage?: TAccountMetas[16] | undefined; /** The following page, created on demand (required iff the head exists). */ rentNextPage?: TAccountMetas[17] | undefined; /** The Solana System program (creates the next history page). */ systemProgram: TAccountMetas[18]; democracyHistoryHistory: TAccountMetas[19]; democracyHistoryPolicy?: TAccountMetas[20] | undefined; democracyHistoryGeneration?: TAccountMetas[21] | undefined; democracyFactionOwnership: TAccountMetas[22]; }; data: InstallStarbaseUpgradeResourceInstructionData; }; export function parseInstallStarbaseUpgradeResourceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInstallStarbaseUpgradeResourceInstruction { if (instruction.accounts.length < 23) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 23, }, ); } 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(), starSystem: getNextAccount(), starbasePlayer: getNextAccount(), upgradeProcess: getNextAccount(), regionTracker: getNextAccount(), game: getNextAccount(), rewardsRegistry: getNextAccount(), rewardsConfig: getNextAccount(), rewardsEpoch: getNextOptionalAccount(), rewardsContribution: getNextOptionalAccount(), kingTracker: getNextAccount(), rentCatalog: getNextAccount(), rentHead: getNextAccount(), rentCurrentPage: getNextOptionalAccount(), rentNextPage: getNextOptionalAccount(), systemProgram: getNextAccount(), democracyHistoryHistory: getNextAccount(), democracyHistoryPolicy: getNextOptionalAccount(), democracyHistoryGeneration: getNextOptionalAccount(), democracyFactionOwnership: getNextAccount(), }, data: getInstallStarbaseUpgradeResourceInstructionDataDecoder().decode( instruction.data, ), }; }