/** * 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, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findProtocolPda, findVaultLpMintPda } from "../pdas"; import { VOLTR_VAULT_PROGRAM_ADDRESS } from "../programs"; import { getProtocolFeeFieldDecoder, getProtocolFeeFieldEncoder, type ProtocolFeeField, type ProtocolFeeFieldArgs, } from "../types"; export const UPDATE_VAULT_PROTOCOL_FEE_DISCRIMINATOR = new Uint8Array([ 62, 83, 22, 192, 137, 86, 74, 18, ]); export function getUpdateVaultProtocolFeeDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( UPDATE_VAULT_PROTOCOL_FEE_DISCRIMINATOR, ); } export type UpdateVaultProtocolFeeInstruction< TProgram extends string = typeof VOLTR_VAULT_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountProtocol extends string | AccountMeta = string, TAccountVault extends string | AccountMeta = string, TAccountVaultLpMint extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdmin, TAccountProtocol extends string ? ReadonlyAccount : TAccountProtocol, TAccountVault extends string ? WritableAccount : TAccountVault, TAccountVaultLpMint extends string ? WritableAccount : TAccountVaultLpMint, ...TRemainingAccounts, ] >; export type UpdateVaultProtocolFeeInstructionData = { discriminator: ReadonlyUint8Array; field: ProtocolFeeField; feeBps: number; }; export type UpdateVaultProtocolFeeInstructionDataArgs = { field: ProtocolFeeFieldArgs; feeBps: number; }; export function getUpdateVaultProtocolFeeInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["field", getProtocolFeeFieldEncoder()], ["feeBps", getU16Encoder()], ]), (value) => ({ ...value, discriminator: UPDATE_VAULT_PROTOCOL_FEE_DISCRIMINATOR, }), ); } export function getUpdateVaultProtocolFeeInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["field", getProtocolFeeFieldDecoder()], ["feeBps", getU16Decoder()], ]); } export function getUpdateVaultProtocolFeeInstructionDataCodec(): FixedSizeCodec< UpdateVaultProtocolFeeInstructionDataArgs, UpdateVaultProtocolFeeInstructionData > { return combineCodec( getUpdateVaultProtocolFeeInstructionDataEncoder(), getUpdateVaultProtocolFeeInstructionDataDecoder(), ); } export type UpdateVaultProtocolFeeAsyncInput< TAccountAdmin extends string = string, TAccountProtocol extends string = string, TAccountVault extends string = string, TAccountVaultLpMint extends string = string, > = { admin: TransactionSigner; protocol?: Address; vault: Address; vaultLpMint?: Address; field: UpdateVaultProtocolFeeInstructionDataArgs["field"]; feeBps: UpdateVaultProtocolFeeInstructionDataArgs["feeBps"]; }; export async function getUpdateVaultProtocolFeeInstructionAsync< TAccountAdmin extends string, TAccountProtocol extends string, TAccountVault extends string, TAccountVaultLpMint extends string, TProgramAddress extends Address = typeof VOLTR_VAULT_PROGRAM_ADDRESS, >( input: UpdateVaultProtocolFeeAsyncInput< TAccountAdmin, TAccountProtocol, TAccountVault, TAccountVaultLpMint >, config?: { programAddress?: TProgramAddress }, ): Promise< UpdateVaultProtocolFeeInstruction< TProgramAddress, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountVaultLpMint > > { // Program address. const programAddress = config?.programAddress ?? VOLTR_VAULT_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: false }, protocol: { value: input.protocol ?? null, isWritable: false }, vault: { value: input.vault ?? null, isWritable: true }, vaultLpMint: { value: input.vaultLpMint ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.protocol.value) { accounts.protocol.value = await findProtocolPda(); } if (!accounts.vaultLpMint.value) { accounts.vaultLpMint.value = await findVaultLpMintPda({ vault: getAddressFromResolvedInstructionAccount( "vault", accounts.vault.value, ), }); } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("admin", accounts.admin), getAccountMeta("protocol", accounts.protocol), getAccountMeta("vault", accounts.vault), getAccountMeta("vaultLpMint", accounts.vaultLpMint), ], data: getUpdateVaultProtocolFeeInstructionDataEncoder().encode( args as UpdateVaultProtocolFeeInstructionDataArgs, ), programAddress, } as UpdateVaultProtocolFeeInstruction< TProgramAddress, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountVaultLpMint >); } export type UpdateVaultProtocolFeeInput< TAccountAdmin extends string = string, TAccountProtocol extends string = string, TAccountVault extends string = string, TAccountVaultLpMint extends string = string, > = { admin: TransactionSigner; protocol: Address; vault: Address; vaultLpMint: Address; field: UpdateVaultProtocolFeeInstructionDataArgs["field"]; feeBps: UpdateVaultProtocolFeeInstructionDataArgs["feeBps"]; }; export function getUpdateVaultProtocolFeeInstruction< TAccountAdmin extends string, TAccountProtocol extends string, TAccountVault extends string, TAccountVaultLpMint extends string, TProgramAddress extends Address = typeof VOLTR_VAULT_PROGRAM_ADDRESS, >( input: UpdateVaultProtocolFeeInput< TAccountAdmin, TAccountProtocol, TAccountVault, TAccountVaultLpMint >, config?: { programAddress?: TProgramAddress }, ): UpdateVaultProtocolFeeInstruction< TProgramAddress, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountVaultLpMint > { // Program address. const programAddress = config?.programAddress ?? VOLTR_VAULT_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: false }, protocol: { value: input.protocol ?? null, isWritable: false }, vault: { value: input.vault ?? null, isWritable: true }, vaultLpMint: { value: input.vaultLpMint ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("admin", accounts.admin), getAccountMeta("protocol", accounts.protocol), getAccountMeta("vault", accounts.vault), getAccountMeta("vaultLpMint", accounts.vaultLpMint), ], data: getUpdateVaultProtocolFeeInstructionDataEncoder().encode( args as UpdateVaultProtocolFeeInstructionDataArgs, ), programAddress, } as UpdateVaultProtocolFeeInstruction< TProgramAddress, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountVaultLpMint >); } export type ParsedUpdateVaultProtocolFeeInstruction< TProgram extends string = typeof VOLTR_VAULT_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; protocol: TAccountMetas[1]; vault: TAccountMetas[2]; vaultLpMint: TAccountMetas[3]; }; data: UpdateVaultProtocolFeeInstructionData; }; export function parseUpdateVaultProtocolFeeInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedUpdateVaultProtocolFeeInstruction { if (instruction.accounts.length < 4) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 4, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { admin: getNextAccount(), protocol: getNextAccount(), vault: getNextAccount(), vaultLpMint: getNextAccount(), }, data: getUpdateVaultProtocolFeeInstructionDataDecoder().decode( instruction.data, ), }; }