/** * 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 AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from "@solana/kit"; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findEventAuthorityPda } from "../pdas/index.js"; import { CP_AMM_PROGRAM_ADDRESS } from "../programs/index.js"; import { getVestingParametersDecoder, getVestingParametersEncoder, type VestingParameters, type VestingParametersArgs, } from "../types/index.js"; export const LOCK_POSITION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 227, 62, 2, 252, 247, 10, 171, 185, ]); export function getLockPositionDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( LOCK_POSITION_DISCRIMINATOR, ); } export type LockPositionInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountPool extends string | AccountMeta = string, TAccountPosition extends string | AccountMeta = string, TAccountVesting extends string | AccountMeta = string, TAccountPositionNftAccount extends string | AccountMeta = string, TAccountOwner extends string | AccountMeta = string, TAccountPayer extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TAccountEventAuthority extends string | AccountMeta = string, TAccountProgram extends string | AccountMeta = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPool extends string ? ReadonlyAccount : TAccountPool, TAccountPosition extends string ? WritableAccount : TAccountPosition, TAccountVesting extends string ? WritableSignerAccount & AccountSignerMeta : TAccountVesting, TAccountPositionNftAccount extends string ? ReadonlyAccount : TAccountPositionNftAccount, TAccountOwner extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountOwner, TAccountPayer extends string ? WritableSignerAccount & AccountSignerMeta : TAccountPayer, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountEventAuthority extends string ? ReadonlyAccount : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount : TAccountProgram, ...TRemainingAccounts, ] >; export type LockPositionInstructionData = { discriminator: ReadonlyUint8Array; params: VestingParameters; }; export type LockPositionInstructionDataArgs = { params: VestingParametersArgs }; export function getLockPositionInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["params", getVestingParametersEncoder()], ]), (value) => ({ ...value, discriminator: LOCK_POSITION_DISCRIMINATOR }), ); } export function getLockPositionInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["params", getVestingParametersDecoder()], ]); } export function getLockPositionInstructionDataCodec(): Codec< LockPositionInstructionDataArgs, LockPositionInstructionData > { return combineCodec( getLockPositionInstructionDataEncoder(), getLockPositionInstructionDataDecoder(), ); } export type LockPositionAsyncInput< TAccountPool extends string = string, TAccountPosition extends string = string, TAccountVesting extends string = string, TAccountPositionNftAccount extends string = string, TAccountOwner extends string = string, TAccountPayer extends string = string, TAccountSystemProgram extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { pool: Address; position: Address; vesting: TransactionSigner; /** The token account for nft */ positionNftAccount: Address; /** owner of position */ owner: TransactionSigner; payer: TransactionSigner; systemProgram?: Address; eventAuthority?: Address; program?: Address; params: LockPositionInstructionDataArgs["params"]; }; export async function getLockPositionInstructionAsync< TAccountPool extends string, TAccountPosition extends string, TAccountVesting extends string, TAccountPositionNftAccount extends string, TAccountOwner extends string, TAccountPayer extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: LockPositionAsyncInput< TAccountPool, TAccountPosition, TAccountVesting, TAccountPositionNftAccount, TAccountOwner, TAccountPayer, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< LockPositionInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountVesting, TAccountPositionNftAccount, TAccountOwner, TAccountPayer, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram > > { // 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 }, vesting: { value: input.vesting ?? null, isWritable: true }, positionNftAccount: { value: input.positionNftAccount ?? null, isWritable: false, }, owner: { value: input.owner ?? null, isWritable: false }, payer: { value: input.payer ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, program: { value: input.program ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } if (!accounts.eventAuthority.value) { accounts.eventAuthority.value = await findEventAuthorityPda(); } if (!accounts.program.value) { accounts.program.value = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG" as Address<"cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("pool", accounts.pool), getAccountMeta("position", accounts.position), getAccountMeta("vesting", accounts.vesting), getAccountMeta("positionNftAccount", accounts.positionNftAccount), getAccountMeta("owner", accounts.owner), getAccountMeta("payer", accounts.payer), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getLockPositionInstructionDataEncoder().encode( args as LockPositionInstructionDataArgs, ), programAddress, } as LockPositionInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountVesting, TAccountPositionNftAccount, TAccountOwner, TAccountPayer, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type LockPositionInput< TAccountPool extends string = string, TAccountPosition extends string = string, TAccountVesting extends string = string, TAccountPositionNftAccount extends string = string, TAccountOwner extends string = string, TAccountPayer extends string = string, TAccountSystemProgram extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { pool: Address; position: Address; vesting: TransactionSigner; /** The token account for nft */ positionNftAccount: Address; /** owner of position */ owner: TransactionSigner; payer: TransactionSigner; systemProgram?: Address; eventAuthority: Address; program?: Address; params: LockPositionInstructionDataArgs["params"]; }; export function getLockPositionInstruction< TAccountPool extends string, TAccountPosition extends string, TAccountVesting extends string, TAccountPositionNftAccount extends string, TAccountOwner extends string, TAccountPayer extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: LockPositionInput< TAccountPool, TAccountPosition, TAccountVesting, TAccountPositionNftAccount, TAccountOwner, TAccountPayer, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): LockPositionInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountVesting, TAccountPositionNftAccount, TAccountOwner, TAccountPayer, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram > { // 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 }, vesting: { value: input.vesting ?? null, isWritable: true }, positionNftAccount: { value: input.positionNftAccount ?? null, isWritable: false, }, owner: { value: input.owner ?? null, isWritable: false }, payer: { value: input.payer ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, program: { value: input.program ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } if (!accounts.program.value) { accounts.program.value = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG" as Address<"cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("pool", accounts.pool), getAccountMeta("position", accounts.position), getAccountMeta("vesting", accounts.vesting), getAccountMeta("positionNftAccount", accounts.positionNftAccount), getAccountMeta("owner", accounts.owner), getAccountMeta("payer", accounts.payer), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getLockPositionInstructionDataEncoder().encode( args as LockPositionInstructionDataArgs, ), programAddress, } as LockPositionInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountVesting, TAccountPositionNftAccount, TAccountOwner, TAccountPayer, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type ParsedLockPositionInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { pool: TAccountMetas[0]; position: TAccountMetas[1]; vesting: TAccountMetas[2]; /** The token account for nft */ positionNftAccount: TAccountMetas[3]; /** owner of position */ owner: TAccountMetas[4]; payer: TAccountMetas[5]; systemProgram: TAccountMetas[6]; eventAuthority: TAccountMetas[7]; program: TAccountMetas[8]; }; data: LockPositionInstructionData; }; export function parseLockPositionInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedLockPositionInstruction { if (instruction.accounts.length < 9) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 9, }, ); } 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(), vesting: getNextAccount(), positionNftAccount: getNextAccount(), owner: getNextAccount(), payer: getNextAccount(), systemProgram: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount(), }, data: getLockPositionInstructionDataDecoder().decode(instruction.data), }; }