/** * 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, getStructDecoder, getStructEncoder, getU8Decoder, getU8Encoder, 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 { SPL_STAKE_POOL_PROGRAM_ADDRESS } from "../programs/index.ts"; export const SET_STAKER_DISCRIMINATOR = 13; export function getSetStakerDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SET_STAKER_DISCRIMINATOR); } export type SetStakerInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountStakePool extends string | AccountMeta = string, TAccountAuthority extends string | AccountMeta = string, TAccountNewStakerPubkey extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountStakePool extends string ? WritableAccount : TAccountStakePool, TAccountAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAuthority, TAccountNewStakerPubkey extends string ? ReadonlyAccount : TAccountNewStakerPubkey, ...TRemainingAccounts, ] >; export type SetStakerInstructionData = { discriminator: number }; export type SetStakerInstructionDataArgs = {}; export function getSetStakerInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", getU8Encoder()]]), (value) => ({ ...value, discriminator: SET_STAKER_DISCRIMINATOR }), ); } export function getSetStakerInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([["discriminator", getU8Decoder()]]); } export function getSetStakerInstructionDataCodec(): FixedSizeCodec< SetStakerInstructionDataArgs, SetStakerInstructionData > { return combineCodec( getSetStakerInstructionDataEncoder(), getSetStakerInstructionDataDecoder(), ); } export type SetStakerInput< TAccountStakePool extends string = string, TAccountAuthority extends string = string, TAccountNewStakerPubkey extends string = string, > = { /** Stake pool */ stakePool: Address; /** Manager or current staker */ authority: TransactionSigner; /** New staker pubkey */ newStakerPubkey: Address; }; /** * (Manager or staker only) Update staker * 0. `[w]` Stake pool * 1. `[s]` Manager or current staker * 2. '[]` New staker pubkey */ export function getSetStakerInstruction< TAccountStakePool extends string, TAccountAuthority extends string, TAccountNewStakerPubkey extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: SetStakerInput< TAccountStakePool, TAccountAuthority, TAccountNewStakerPubkey >, config?: { programAddress?: TProgramAddress }, ): SetStakerInstruction< TProgramAddress, TAccountStakePool, TAccountAuthority, TAccountNewStakerPubkey > { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, newStakerPubkey: { value: input.newStakerPubkey ?? null, isWritable: false, }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("stakePool", accounts.stakePool), getAccountMeta("authority", accounts.authority), getAccountMeta("newStakerPubkey", accounts.newStakerPubkey), ], data: getSetStakerInstructionDataEncoder().encode({}), programAddress, } as SetStakerInstruction< TProgramAddress, TAccountStakePool, TAccountAuthority, TAccountNewStakerPubkey >); } export type ParsedSetStakerInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Stake pool */ stakePool: TAccountMetas[0]; /** Manager or current staker */ authority: TAccountMetas[1]; /** New staker pubkey */ newStakerPubkey: TAccountMetas[2]; }; data: SetStakerInstructionData; }; export function parseSetStakerInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetStakerInstruction { if (instruction.accounts.length < 3) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 3, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { stakePool: getNextAccount(), authority: getNextAccount(), newStakerPubkey: getNextAccount(), }, data: getSetStakerInstructionDataDecoder().decode(instruction.data), }; }