/** * 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, getU128Decoder, getU128Encoder, 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, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findEventAuthorityPda } from "../pdas/index.js"; import { CP_AMM_PROGRAM_ADDRESS } from "../programs/index.js"; export const PERMANENT_LOCK_POSITION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([165, 176, 125, 6, 231, 171, 186, 213]); export function getPermanentLockPositionDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( PERMANENT_LOCK_POSITION_DISCRIMINATOR, ); } export type PermanentLockPositionInstruction< 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, TAccountEventAuthority extends string | AccountMeta = string, TAccountProgram extends string | AccountMeta = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPool extends string ? WritableAccount : TAccountPool, TAccountPosition extends string ? WritableAccount : TAccountPosition, TAccountPositionNftAccount extends string ? ReadonlyAccount : TAccountPositionNftAccount, TAccountOwner extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountOwner, TAccountEventAuthority extends string ? ReadonlyAccount : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount : TAccountProgram, ...TRemainingAccounts, ] >; export type PermanentLockPositionInstructionData = { discriminator: ReadonlyUint8Array; permanentLockLiquidity: bigint; }; export type PermanentLockPositionInstructionDataArgs = { permanentLockLiquidity: number | bigint; }; export function getPermanentLockPositionInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["permanentLockLiquidity", getU128Encoder()], ]), (value) => ({ ...value, discriminator: PERMANENT_LOCK_POSITION_DISCRIMINATOR, }), ); } export function getPermanentLockPositionInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["permanentLockLiquidity", getU128Decoder()], ]); } export function getPermanentLockPositionInstructionDataCodec(): FixedSizeCodec< PermanentLockPositionInstructionDataArgs, PermanentLockPositionInstructionData > { return combineCodec( getPermanentLockPositionInstructionDataEncoder(), getPermanentLockPositionInstructionDataDecoder(), ); } export type PermanentLockPositionAsyncInput< TAccountPool extends string = string, TAccountPosition extends string = string, TAccountPositionNftAccount extends string = string, TAccountOwner extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { pool: Address; position: Address; /** The token account for nft */ positionNftAccount: Address; /** owner of position */ owner: TransactionSigner; eventAuthority?: Address; program?: Address; permanentLockLiquidity: PermanentLockPositionInstructionDataArgs["permanentLockLiquidity"]; }; export async function getPermanentLockPositionInstructionAsync< TAccountPool extends string, TAccountPosition extends string, TAccountPositionNftAccount extends string, TAccountOwner extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: PermanentLockPositionAsyncInput< TAccountPool, TAccountPosition, TAccountPositionNftAccount, TAccountOwner, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< PermanentLockPositionInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountPositionNftAccount, TAccountOwner, TAccountEventAuthority, TAccountProgram > > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { pool: { value: input.pool ?? null, isWritable: true }, position: { value: input.position ?? null, isWritable: true }, positionNftAccount: { value: input.positionNftAccount ?? null, isWritable: false, }, owner: { value: input.owner ?? 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.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("positionNftAccount", accounts.positionNftAccount), getAccountMeta("owner", accounts.owner), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getPermanentLockPositionInstructionDataEncoder().encode( args as PermanentLockPositionInstructionDataArgs, ), programAddress, } as PermanentLockPositionInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountPositionNftAccount, TAccountOwner, TAccountEventAuthority, TAccountProgram >); } export type PermanentLockPositionInput< TAccountPool extends string = string, TAccountPosition extends string = string, TAccountPositionNftAccount extends string = string, TAccountOwner extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { pool: Address; position: Address; /** The token account for nft */ positionNftAccount: Address; /** owner of position */ owner: TransactionSigner; eventAuthority: Address; program?: Address; permanentLockLiquidity: PermanentLockPositionInstructionDataArgs["permanentLockLiquidity"]; }; export function getPermanentLockPositionInstruction< TAccountPool extends string, TAccountPosition extends string, TAccountPositionNftAccount extends string, TAccountOwner extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: PermanentLockPositionInput< TAccountPool, TAccountPosition, TAccountPositionNftAccount, TAccountOwner, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): PermanentLockPositionInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountPositionNftAccount, TAccountOwner, TAccountEventAuthority, TAccountProgram > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { pool: { value: input.pool ?? null, isWritable: true }, position: { value: input.position ?? null, isWritable: true }, positionNftAccount: { value: input.positionNftAccount ?? null, isWritable: false, }, owner: { value: input.owner ?? 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.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("positionNftAccount", accounts.positionNftAccount), getAccountMeta("owner", accounts.owner), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getPermanentLockPositionInstructionDataEncoder().encode( args as PermanentLockPositionInstructionDataArgs, ), programAddress, } as PermanentLockPositionInstruction< TProgramAddress, TAccountPool, TAccountPosition, TAccountPositionNftAccount, TAccountOwner, TAccountEventAuthority, TAccountProgram >); } export type ParsedPermanentLockPositionInstruction< 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 of position */ owner: TAccountMetas[3]; eventAuthority: TAccountMetas[4]; program: TAccountMetas[5]; }; data: PermanentLockPositionInstructionData; }; export function parsePermanentLockPositionInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedPermanentLockPositionInstruction { if (instruction.accounts.length < 6) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 6, }, ); } 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(), eventAuthority: getNextAccount(), program: getNextAccount(), }, data: getPermanentLockPositionInstructionDataDecoder().decode( instruction.data, ), }; }