/** * 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"; import { getFundingTypeDecoder, getFundingTypeEncoder, type FundingType, type FundingTypeArgs, } from "../types/index.ts"; export const SET_FUNDING_AUTHORITY_DISCRIMINATOR = 15; export function getSetFundingAuthorityDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SET_FUNDING_AUTHORITY_DISCRIMINATOR); } export type SetFundingAuthorityInstruction< TProgram extends string = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, TAccountStakePool extends string | AccountMeta = string, TAccountManager extends string | AccountMeta = string, TAccountNewAuthorityPubkey extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountStakePool extends string ? WritableAccount : TAccountStakePool, TAccountManager extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountManager, TAccountNewAuthorityPubkey extends string ? ReadonlyAccount : TAccountNewAuthorityPubkey, ...TRemainingAccounts, ] >; export type SetFundingAuthorityInstructionData = { discriminator: number; fundingType: FundingType; }; export type SetFundingAuthorityInstructionDataArgs = { fundingType: FundingTypeArgs; }; export function getSetFundingAuthorityInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", getU8Encoder()], ["fundingType", getFundingTypeEncoder()], ]), (value) => ({ ...value, discriminator: SET_FUNDING_AUTHORITY_DISCRIMINATOR, }), ); } export function getSetFundingAuthorityInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", getU8Decoder()], ["fundingType", getFundingTypeDecoder()], ]); } export function getSetFundingAuthorityInstructionDataCodec(): FixedSizeCodec< SetFundingAuthorityInstructionDataArgs, SetFundingAuthorityInstructionData > { return combineCodec( getSetFundingAuthorityInstructionDataEncoder(), getSetFundingAuthorityInstructionDataDecoder(), ); } export type SetFundingAuthorityInput< TAccountStakePool extends string = string, TAccountManager extends string = string, TAccountNewAuthorityPubkey extends string = string, > = { /** Stake pool */ stakePool: Address; /** Manager */ manager: TransactionSigner; /** New authority pubkey */ newAuthorityPubkey: Address; fundingType: SetFundingAuthorityInstructionDataArgs["fundingType"]; }; /** * (Manager only) Update SOL deposit, stake deposit, or SOL withdrawal * authority. * 0. `[w]` Stake pool * 1. `[s]` Manager * 2. '[]` New authority pubkey or none */ export function getSetFundingAuthorityInstruction< TAccountStakePool extends string, TAccountManager extends string, TAccountNewAuthorityPubkey extends string, TProgramAddress extends Address = typeof SPL_STAKE_POOL_PROGRAM_ADDRESS, >( input: SetFundingAuthorityInput< TAccountStakePool, TAccountManager, TAccountNewAuthorityPubkey >, config?: { programAddress?: TProgramAddress }, ): SetFundingAuthorityInstruction< TProgramAddress, TAccountStakePool, TAccountManager, TAccountNewAuthorityPubkey > { // 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 }, newAuthorityPubkey: { value: input.newAuthorityPubkey ?? 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), getAccountMeta("newAuthorityPubkey", accounts.newAuthorityPubkey), ], data: getSetFundingAuthorityInstructionDataEncoder().encode( args as SetFundingAuthorityInstructionDataArgs, ), programAddress, } as SetFundingAuthorityInstruction< TProgramAddress, TAccountStakePool, TAccountManager, TAccountNewAuthorityPubkey >); } export type ParsedSetFundingAuthorityInstruction< 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]; /** New authority pubkey */ newAuthorityPubkey: TAccountMetas[2]; }; data: SetFundingAuthorityInstructionData; }; export function parseSetFundingAuthorityInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetFundingAuthorityInstruction { 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(), manager: getNextAccount(), newAuthorityPubkey: getNextAccount(), }, data: getSetFundingAuthorityInstructionDataDecoder().decode( instruction.data, ), }; }