/** * 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, getU8Decoder, getU8Encoder, getU128Decoder, getU128Encoder, 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_REWARD_EMISSIONS_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([13, 197, 86, 168, 109, 176, 27, 244]); export function getSetRewardEmissionsDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( SET_REWARD_EMISSIONS_DISCRIMINATOR, ); } export type SetRewardEmissionsInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpool extends string | AccountMeta = string, TAccountRewardAuthority extends string | AccountMeta = string, TAccountRewardVault extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountWhirlpool extends string ? WritableAccount : TAccountWhirlpool, TAccountRewardAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountRewardAuthority, TAccountRewardVault extends string ? ReadonlyAccount : TAccountRewardVault, ...TRemainingAccounts, ] >; export interface SetRewardEmissionsInstructionData { discriminator: ReadonlyUint8Array; rewardIndex: number; emissionsPerSecondX64: bigint; } export interface SetRewardEmissionsInstructionDataArgs { rewardIndex: number; emissionsPerSecondX64: number | bigint; } export function getSetRewardEmissionsInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["rewardIndex", getU8Encoder()], ["emissionsPerSecondX64", getU128Encoder()], ]), (value) => ({ ...value, discriminator: SET_REWARD_EMISSIONS_DISCRIMINATOR, }), ); } export function getSetRewardEmissionsInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["rewardIndex", getU8Decoder()], ["emissionsPerSecondX64", getU128Decoder()], ]); } export function getSetRewardEmissionsInstructionDataCodec(): FixedSizeCodec< SetRewardEmissionsInstructionDataArgs, SetRewardEmissionsInstructionData > { return combineCodec( getSetRewardEmissionsInstructionDataEncoder(), getSetRewardEmissionsInstructionDataDecoder(), ); } export interface SetRewardEmissionsInput< TAccountWhirlpool extends string = string, TAccountRewardAuthority extends string = string, TAccountRewardVault extends string = string, > { whirlpool: Address; rewardAuthority: TransactionSigner; rewardVault: Address; rewardIndex: SetRewardEmissionsInstructionDataArgs["rewardIndex"]; emissionsPerSecondX64: SetRewardEmissionsInstructionDataArgs["emissionsPerSecondX64"]; } export function getSetRewardEmissionsInstruction< TAccountWhirlpool extends string, TAccountRewardAuthority extends string, TAccountRewardVault extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: SetRewardEmissionsInput< TAccountWhirlpool, TAccountRewardAuthority, TAccountRewardVault >, config?: { programAddress?: TProgramAddress }, ): SetRewardEmissionsInstruction< TProgramAddress, TAccountWhirlpool, TAccountRewardAuthority, TAccountRewardVault > { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpool: { value: input.whirlpool ?? null, isWritable: true }, rewardAuthority: { value: input.rewardAuthority ?? null, isWritable: false, }, rewardVault: { value: input.rewardVault ?? 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("whirlpool", accounts.whirlpool), getAccountMeta("rewardAuthority", accounts.rewardAuthority), getAccountMeta("rewardVault", accounts.rewardVault), ], data: getSetRewardEmissionsInstructionDataEncoder().encode( args as SetRewardEmissionsInstructionDataArgs, ), programAddress, } as SetRewardEmissionsInstruction< TProgramAddress, TAccountWhirlpool, TAccountRewardAuthority, TAccountRewardVault >); } export interface ParsedSetRewardEmissionsInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { whirlpool: TAccountMetas[0]; rewardAuthority: TAccountMetas[1]; rewardVault: TAccountMetas[2]; }; data: SetRewardEmissionsInstructionData; } export function parseSetRewardEmissionsInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetRewardEmissionsInstruction { 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: { whirlpool: getNextAccount(), rewardAuthority: getNextAccount(), rewardVault: getNextAccount(), }, data: getSetRewardEmissionsInstructionDataDecoder().decode( instruction.data, ), }; }