/** * 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 type { AccountMeta, AccountSignerMeta, Address, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, Instruction, InstructionWithAccounts, InstructionWithData, ReadonlyAccount, ReadonlySignerAccount, ReadonlyUint8Array, TransactionSigner, WritableAccount, } from "@solana/kit"; import type { ResolvedInstructionAccount } from "@solana/program-client-core"; import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, } from "@solana/kit"; import { getAccountMetaFactory } from "@solana/program-client-core"; import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; export const SET_DEFAULT_FEE_RATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([118, 215, 214, 157, 182, 229, 208, 228]); export function getSetDefaultFeeRateDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( SET_DEFAULT_FEE_RATE_DISCRIMINATOR, ); } export type SetDefaultFeeRateInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolsConfig extends string | AccountMeta = string, TAccountFeeTier extends string | AccountMeta = string, TAccountFeeAuthority extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountWhirlpoolsConfig extends string ? ReadonlyAccount : TAccountWhirlpoolsConfig, TAccountFeeTier extends string ? WritableAccount : TAccountFeeTier, TAccountFeeAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountFeeAuthority, ...TRemainingAccounts, ] >; export interface SetDefaultFeeRateInstructionData { discriminator: ReadonlyUint8Array; defaultFeeRate: number; } export interface SetDefaultFeeRateInstructionDataArgs { defaultFeeRate: number; } export function getSetDefaultFeeRateInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["defaultFeeRate", getU16Encoder()], ]), (value) => ({ ...value, discriminator: SET_DEFAULT_FEE_RATE_DISCRIMINATOR, }), ); } export function getSetDefaultFeeRateInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["defaultFeeRate", getU16Decoder()], ]); } export function getSetDefaultFeeRateInstructionDataCodec(): FixedSizeCodec< SetDefaultFeeRateInstructionDataArgs, SetDefaultFeeRateInstructionData > { return combineCodec( getSetDefaultFeeRateInstructionDataEncoder(), getSetDefaultFeeRateInstructionDataDecoder(), ); } export interface SetDefaultFeeRateInput< TAccountWhirlpoolsConfig extends string = string, TAccountFeeTier extends string = string, TAccountFeeAuthority extends string = string, > { whirlpoolsConfig: Address; feeTier: Address; feeAuthority: TransactionSigner; defaultFeeRate: SetDefaultFeeRateInstructionDataArgs["defaultFeeRate"]; } export function getSetDefaultFeeRateInstruction< TAccountWhirlpoolsConfig extends string, TAccountFeeTier extends string, TAccountFeeAuthority extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: SetDefaultFeeRateInput< TAccountWhirlpoolsConfig, TAccountFeeTier, TAccountFeeAuthority >, config?: { programAddress?: TProgramAddress }, ): SetDefaultFeeRateInstruction< TProgramAddress, TAccountWhirlpoolsConfig, TAccountFeeTier, TAccountFeeAuthority > { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpoolsConfig: { value: input.whirlpoolsConfig ?? null, isWritable: false, }, feeTier: { value: input.feeTier ?? null, isWritable: true }, feeAuthority: { value: input.feeAuthority ?? 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("whirlpoolsConfig", accounts.whirlpoolsConfig), getAccountMeta("feeTier", accounts.feeTier), getAccountMeta("feeAuthority", accounts.feeAuthority), ], data: getSetDefaultFeeRateInstructionDataEncoder().encode( args as SetDefaultFeeRateInstructionDataArgs, ), programAddress, } as SetDefaultFeeRateInstruction< TProgramAddress, TAccountWhirlpoolsConfig, TAccountFeeTier, TAccountFeeAuthority >); } export interface ParsedSetDefaultFeeRateInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { whirlpoolsConfig: TAccountMetas[0]; feeTier: TAccountMetas[1]; feeAuthority: TAccountMetas[2]; }; data: SetDefaultFeeRateInstructionData; } export function parseSetDefaultFeeRateInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetDefaultFeeRateInstruction { 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: { whirlpoolsConfig: getNextAccount(), feeTier: getNextAccount(), feeAuthority: getNextAccount(), }, data: getSetDefaultFeeRateInstructionDataDecoder().decode(instruction.data), }; }