/** * 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 Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, 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"; import { getFeeTypeDecoder, getFeeTypeEncoder, type FeeType, type FeeTypeArgs, } from "../types/index.ts"; export const SET_FEE_DISCRIMINATOR = 12; export function getSetFeeDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SET_FEE_DISCRIMINATOR); } export type SetFeeInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountStakePool extends string | AccountMeta = string, TAccountManager extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountStakePool extends string ? WritableAccount : TAccountStakePool, TAccountManager extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountManager, ...TRemainingAccounts, ] >; export type SetFeeInstructionData = { discriminator: number; fee: FeeType }; export type SetFeeInstructionDataArgs = { fee: FeeTypeArgs }; export function getSetFeeInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", getU8Encoder()], ["fee", getFeeTypeEncoder()], ]), (value) => ({ ...value, discriminator: SET_FEE_DISCRIMINATOR }), ); } export function getSetFeeInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", getU8Decoder()], ["fee", getFeeTypeDecoder()], ]); } export function getSetFeeInstructionDataCodec(): Codec< SetFeeInstructionDataArgs, SetFeeInstructionData > { return combineCodec( getSetFeeInstructionDataEncoder(), getSetFeeInstructionDataDecoder(), ); } export type SetFeeInput< TAccountStakePool extends string = string, TAccountManager extends string = string, > = { /** Stake pool */ stakePool: Address; /** Manager */ manager: TransactionSigner; fee: SetFeeInstructionDataArgs["fee"]; }; /** * (Manager only) Update fee * 0. `[w]` Stake pool * 1. `[s]` Manager */ export function getSetFeeInstruction< TAccountStakePool extends string, TAccountManager extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: SetFeeInput, config?: { programAddress?: TProgramAddress }, ): SetFeeInstruction { // Program address. const programAddress = config?.programAddress ?? SPL_STAKE_POOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stakePool: { value: input.stakePool ?? null, isWritable: true }, manager: { value: input.manager ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("stakePool", accounts.stakePool), getAccountMeta("manager", accounts.manager), ], data: getSetFeeInstructionDataEncoder().encode( args as SetFeeInstructionDataArgs, ), programAddress, } as SetFeeInstruction); } export type ParsedSetFeeInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Stake pool */ stakePool: TAccountMetas[0]; /** Manager */ manager: TAccountMetas[1]; }; data: SetFeeInstructionData; }; export function parseSetFeeInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetFeeInstruction { if (instruction.accounts.length < 2) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { stakePool: getNextAccount(), manager: getNextAccount() }, data: getSetFeeInstructionDataDecoder().decode(instruction.data), }; }