/** * 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, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type WritableAccount, } from "@solana/kit"; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { CP_AMM_PROGRAM_ADDRESS } from "../programs/index.js"; export const REFRESH_VESTING_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( [9, 94, 216, 14, 116, 204, 247, 0], ); export function getRefreshVestingDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( REFRESH_VESTING_DISCRIMINATOR, ); } export type RefreshVestingInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountPool extends string | AccountMeta = string, TAccountPosition extends string | AccountMeta = string, TAccountPositionNftAccount extends string | AccountMeta = string, TAccountOwner extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPool extends string ? ReadonlyAccount : TAccountPool, TAccountPosition extends string ? WritableAccount : TAccountPosition, TAccountPositionNftAccount extends string ? ReadonlyAccount : TAccountPositionNftAccount, TAccountOwner extends string ? ReadonlyAccount : TAccountOwner, ...TRemainingAccounts, ] >; export type RefreshVestingInstructionData = { discriminator: ReadonlyUint8Array; }; export type RefreshVestingInstructionDataArgs = {}; export function getRefreshVestingInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: REFRESH_VESTING_DISCRIMINATOR }), ); } export function getRefreshVestingInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getRefreshVestingInstructionDataCodec(): FixedSizeCodec< RefreshVestingInstructionDataArgs, RefreshVestingInstructionData > { return combineCodec( getRefreshVestingInstructionDataEncoder(), getRefreshVestingInstructionDataDecoder(), ); } export type RefreshVestingInput< TAccountPool extends string = string, TAccountPosition extends string = string, TAccountPositionNftAccount extends string = string, TAccountOwner extends string = string, > = { pool: Address; position: Address; /** The token account for nft */ positionNftAccount: Address; owner: Address; }; export function getRefreshVestingInstruction< TAccountPool extends string, TAccountPosition extends string, TAccountPositionNftAccount extends string, TAccountOwner extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: RefreshVestingInput< TAccountPool, TAccountPosition, TAccountPositionNftAccount, TAccountOwner >, config?: { programAddress?: TProgramAddress }, ): RefreshVestingInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountPositionNftAccount, TAccountOwner > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { pool: { value: input.pool ?? null, isWritable: false }, position: { value: input.position ?? null, isWritable: true }, positionNftAccount: { value: input.positionNftAccount ?? null, isWritable: false, }, owner: { value: input.owner ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("pool", accounts.pool), getAccountMeta("position", accounts.position), getAccountMeta("positionNftAccount", accounts.positionNftAccount), getAccountMeta("owner", accounts.owner), ], data: getRefreshVestingInstructionDataEncoder().encode({}), programAddress, } as RefreshVestingInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountPositionNftAccount, TAccountOwner >); } export type ParsedRefreshVestingInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { pool: TAccountMetas[0]; position: TAccountMetas[1]; /** The token account for nft */ positionNftAccount: TAccountMetas[2]; owner: TAccountMetas[3]; }; data: RefreshVestingInstructionData; }; export function parseRefreshVestingInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedRefreshVestingInstruction { 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: { pool: getNextAccount(), position: getNextAccount(), positionNftAccount: getNextAccount(), owner: getNextAccount(), }, data: getRefreshVestingInstructionDataDecoder().decode(instruction.data), }; }