/** * 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, 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 { YVAULTS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const UPDATE_STRATEGY_CONFIG_DISCRIMINATOR = new Uint8Array([ 81, 217, 177, 65, 40, 227, 8, 165, ]); export function getUpdateStrategyConfigDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( UPDATE_STRATEGY_CONFIG_DISCRIMINATOR, ); } export type UpdateStrategyConfigInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountAdminAuthority extends string | AccountMeta = string, TAccountNewAccount extends string | AccountMeta = string, TAccountStrategy extends string | AccountMeta = string, TAccountGlobalConfig extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdminAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdminAuthority, TAccountNewAccount extends string ? ReadonlyAccount : TAccountNewAccount, TAccountStrategy extends string ? WritableAccount : TAccountStrategy, TAccountGlobalConfig extends string ? ReadonlyAccount : TAccountGlobalConfig, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type UpdateStrategyConfigInstructionData = { discriminator: ReadonlyUint8Array; mode: number; value: ReadonlyUint8Array; }; export type UpdateStrategyConfigInstructionDataArgs = { mode: number; value: ReadonlyUint8Array; }; export function getUpdateStrategyConfigInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["mode", getU16Encoder()], ["value", fixEncoderSize(getBytesEncoder(), 128)], ]), (value) => ({ ...value, discriminator: UPDATE_STRATEGY_CONFIG_DISCRIMINATOR, }), ); } export function getUpdateStrategyConfigInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["mode", getU16Decoder()], ["value", fixDecoderSize(getBytesDecoder(), 128)], ]); } export function getUpdateStrategyConfigInstructionDataCodec(): FixedSizeCodec< UpdateStrategyConfigInstructionDataArgs, UpdateStrategyConfigInstructionData > { return combineCodec( getUpdateStrategyConfigInstructionDataEncoder(), getUpdateStrategyConfigInstructionDataDecoder(), ); } export type UpdateStrategyConfigInput< TAccountAdminAuthority extends string = string, TAccountNewAccount extends string = string, TAccountStrategy extends string = string, TAccountGlobalConfig extends string = string, TAccountSystemProgram extends string = string, > = { adminAuthority: TransactionSigner; newAccount: Address; strategy: Address; globalConfig: Address; systemProgram?: Address; mode: UpdateStrategyConfigInstructionDataArgs["mode"]; value: UpdateStrategyConfigInstructionDataArgs["value"]; }; export function getUpdateStrategyConfigInstruction< TAccountAdminAuthority extends string, TAccountNewAccount extends string, TAccountStrategy extends string, TAccountGlobalConfig extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof YVAULTS_PROGRAM_ADDRESS, >( input: UpdateStrategyConfigInput< TAccountAdminAuthority, TAccountNewAccount, TAccountStrategy, TAccountGlobalConfig, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): UpdateStrategyConfigInstruction< TProgramAddress, TAccountAdminAuthority, TAccountNewAccount, TAccountStrategy, TAccountGlobalConfig, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? YVAULTS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { adminAuthority: { value: input.adminAuthority ?? null, isWritable: false }, newAccount: { value: input.newAccount ?? null, isWritable: false }, strategy: { value: input.strategy ?? null, isWritable: true }, globalConfig: { value: input.globalConfig ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.adminAuthority), getAccountMeta(accounts.newAccount), getAccountMeta(accounts.strategy), getAccountMeta(accounts.globalConfig), getAccountMeta(accounts.systemProgram), ], data: getUpdateStrategyConfigInstructionDataEncoder().encode( args as UpdateStrategyConfigInstructionDataArgs, ), programAddress, } as UpdateStrategyConfigInstruction< TProgramAddress, TAccountAdminAuthority, TAccountNewAccount, TAccountStrategy, TAccountGlobalConfig, TAccountSystemProgram >); } export type ParsedUpdateStrategyConfigInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { adminAuthority: TAccountMetas[0]; newAccount: TAccountMetas[1]; strategy: TAccountMetas[2]; globalConfig: TAccountMetas[3]; systemProgram: TAccountMetas[4]; }; data: UpdateStrategyConfigInstructionData; }; export function parseUpdateStrategyConfigInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedUpdateStrategyConfigInstruction { if (instruction.accounts.length < 5) { // TODO: Coded error. throw new Error("Not enough accounts"); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { adminAuthority: getNextAccount(), newAccount: getNextAccount(), strategy: getNextAccount(), globalConfig: getNextAccount(), systemProgram: getNextAccount(), }, data: getUpdateStrategyConfigInstructionDataDecoder().decode( instruction.data, ), }; }