/** * 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, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, 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 ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from "@solana/kit"; import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findEventAuthorityPda, findPoolAuthorityPda, findPositionNftAccountPda, } from "../pdas/index.js"; import { CP_AMM_PROGRAM_ADDRESS } from "../programs/index.js"; export const CREATE_POSITION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( [48, 215, 197, 153, 96, 203, 180, 133], ); export function getCreatePositionDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( CREATE_POSITION_DISCRIMINATOR, ); } export type CreatePositionInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountOwner extends string | AccountMeta = string, TAccountPositionNftMint extends string | AccountMeta = string, TAccountPositionNftAccount extends string | AccountMeta = string, TAccountPool extends string | AccountMeta = string, TAccountPosition extends string | AccountMeta = string, TAccountPoolAuthority extends string | AccountMeta = string, TAccountPayer extends string | AccountMeta = string, TAccountTokenProgram extends string | AccountMeta = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb", TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TAccountEventAuthority extends string | AccountMeta = string, TAccountProgram extends string | AccountMeta = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountOwner extends string ? ReadonlyAccount : TAccountOwner, TAccountPositionNftMint extends string ? WritableSignerAccount & AccountSignerMeta : TAccountPositionNftMint, TAccountPositionNftAccount extends string ? WritableAccount : TAccountPositionNftAccount, TAccountPool extends string ? WritableAccount : TAccountPool, TAccountPosition extends string ? WritableAccount : TAccountPosition, TAccountPoolAuthority extends string ? ReadonlyAccount : TAccountPoolAuthority, TAccountPayer extends string ? WritableSignerAccount & AccountSignerMeta : TAccountPayer, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountEventAuthority extends string ? ReadonlyAccount : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount : TAccountProgram, ...TRemainingAccounts, ] >; export type CreatePositionInstructionData = { discriminator: ReadonlyUint8Array; }; export type CreatePositionInstructionDataArgs = {}; export function getCreatePositionInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CREATE_POSITION_DISCRIMINATOR }), ); } export function getCreatePositionInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCreatePositionInstructionDataCodec(): FixedSizeCodec< CreatePositionInstructionDataArgs, CreatePositionInstructionData > { return combineCodec( getCreatePositionInstructionDataEncoder(), getCreatePositionInstructionDataDecoder(), ); } export type CreatePositionAsyncInput< TAccountOwner extends string = string, TAccountPositionNftMint extends string = string, TAccountPositionNftAccount extends string = string, TAccountPool extends string = string, TAccountPosition extends string = string, TAccountPoolAuthority extends string = string, TAccountPayer extends string = string, TAccountTokenProgram extends string = string, TAccountSystemProgram extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { owner: Address; /** position_nft_mint */ positionNftMint: TransactionSigner; /** position nft account */ positionNftAccount?: Address; pool: Address; position?: Address; poolAuthority?: Address; /** Address paying to create the position. Can be anyone */ payer: TransactionSigner; /** Program to create NFT mint/token account and transfer for token22 account */ tokenProgram?: Address; systemProgram?: Address; eventAuthority?: Address; program?: Address; }; export async function getCreatePositionInstructionAsync< TAccountOwner extends string, TAccountPositionNftMint extends string, TAccountPositionNftAccount extends string, TAccountPool extends string, TAccountPosition extends string, TAccountPoolAuthority extends string, TAccountPayer extends string, TAccountTokenProgram extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CreatePositionAsyncInput< TAccountOwner, TAccountPositionNftMint, TAccountPositionNftAccount, TAccountPool, TAccountPosition, TAccountPoolAuthority, TAccountPayer, TAccountTokenProgram, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< CreatePositionInstruction< TProgramAddress, TAccountOwner, TAccountPositionNftMint, TAccountPositionNftAccount, TAccountPool, TAccountPosition, TAccountPoolAuthority, TAccountPayer, TAccountTokenProgram, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram > > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { owner: { value: input.owner ?? null, isWritable: false }, positionNftMint: { value: input.positionNftMint ?? null, isWritable: true }, positionNftAccount: { value: input.positionNftAccount ?? null, isWritable: true, }, pool: { value: input.pool ?? null, isWritable: true }, position: { value: input.position ?? null, isWritable: true }, poolAuthority: { value: input.poolAuthority ?? null, isWritable: false }, payer: { value: input.payer ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, 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 >; // Resolve default values. if (!accounts.positionNftAccount.value) { accounts.positionNftAccount.value = await findPositionNftAccountPda({ positionNftMint: getAddressFromResolvedInstructionAccount( "positionNftMint", accounts.positionNftMint.value, ), }); } if (!accounts.position.value) { accounts.position.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([112, 111, 115, 105, 116, 105, 111, 110]), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( "positionNftMint", accounts.positionNftMint.value, ), ), ], }); } if (!accounts.poolAuthority.value) { accounts.poolAuthority.value = await findPoolAuthorityPda(); } if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" as Address<"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb">; } 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("owner", accounts.owner), getAccountMeta("positionNftMint", accounts.positionNftMint), getAccountMeta("positionNftAccount", accounts.positionNftAccount), getAccountMeta("pool", accounts.pool), getAccountMeta("position", accounts.position), getAccountMeta("poolAuthority", accounts.poolAuthority), getAccountMeta("payer", accounts.payer), getAccountMeta("tokenProgram", accounts.tokenProgram), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCreatePositionInstructionDataEncoder().encode({}), programAddress, } as CreatePositionInstruction< TProgramAddress, TAccountOwner, TAccountPositionNftMint, TAccountPositionNftAccount, TAccountPool, TAccountPosition, TAccountPoolAuthority, TAccountPayer, TAccountTokenProgram, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type CreatePositionInput< TAccountOwner extends string = string, TAccountPositionNftMint extends string = string, TAccountPositionNftAccount extends string = string, TAccountPool extends string = string, TAccountPosition extends string = string, TAccountPoolAuthority extends string = string, TAccountPayer extends string = string, TAccountTokenProgram extends string = string, TAccountSystemProgram extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string, > = { owner: Address; /** position_nft_mint */ positionNftMint: TransactionSigner; /** position nft account */ positionNftAccount: Address; pool: Address; position: Address; poolAuthority: Address; /** Address paying to create the position. Can be anyone */ payer: TransactionSigner; /** Program to create NFT mint/token account and transfer for token22 account */ tokenProgram?: Address; systemProgram?: Address; eventAuthority: Address; program?: Address; }; export function getCreatePositionInstruction< TAccountOwner extends string, TAccountPositionNftMint extends string, TAccountPositionNftAccount extends string, TAccountPool extends string, TAccountPosition extends string, TAccountPoolAuthority extends string, TAccountPayer extends string, TAccountTokenProgram extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof CP_AMM_PROGRAM_ADDRESS, >( input: CreatePositionInput< TAccountOwner, TAccountPositionNftMint, TAccountPositionNftAccount, TAccountPool, TAccountPosition, TAccountPoolAuthority, TAccountPayer, TAccountTokenProgram, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >, config?: { programAddress?: TProgramAddress }, ): CreatePositionInstruction< TProgramAddress, TAccountOwner, TAccountPositionNftMint, TAccountPositionNftAccount, TAccountPool, TAccountPosition, TAccountPoolAuthority, TAccountPayer, TAccountTokenProgram, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram > { // Program address. const programAddress = config?.programAddress ?? CP_AMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { owner: { value: input.owner ?? null, isWritable: false }, positionNftMint: { value: input.positionNftMint ?? null, isWritable: true }, positionNftAccount: { value: input.positionNftAccount ?? null, isWritable: true, }, pool: { value: input.pool ?? null, isWritable: true }, position: { value: input.position ?? null, isWritable: true }, poolAuthority: { value: input.poolAuthority ?? null, isWritable: false }, payer: { value: input.payer ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, 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 >; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" as Address<"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb">; } 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("owner", accounts.owner), getAccountMeta("positionNftMint", accounts.positionNftMint), getAccountMeta("positionNftAccount", accounts.positionNftAccount), getAccountMeta("pool", accounts.pool), getAccountMeta("position", accounts.position), getAccountMeta("poolAuthority", accounts.poolAuthority), getAccountMeta("payer", accounts.payer), getAccountMeta("tokenProgram", accounts.tokenProgram), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("eventAuthority", accounts.eventAuthority), getAccountMeta("program", accounts.program), ], data: getCreatePositionInstructionDataEncoder().encode({}), programAddress, } as CreatePositionInstruction< TProgramAddress, TAccountOwner, TAccountPositionNftMint, TAccountPositionNftAccount, TAccountPool, TAccountPosition, TAccountPoolAuthority, TAccountPayer, TAccountTokenProgram, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram >); } export type ParsedCreatePositionInstruction< TProgram extends string = typeof CP_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { owner: TAccountMetas[0]; /** position_nft_mint */ positionNftMint: TAccountMetas[1]; /** position nft account */ positionNftAccount: TAccountMetas[2]; pool: TAccountMetas[3]; position: TAccountMetas[4]; poolAuthority: TAccountMetas[5]; /** Address paying to create the position. Can be anyone */ payer: TAccountMetas[6]; /** Program to create NFT mint/token account and transfer for token22 account */ tokenProgram: TAccountMetas[7]; systemProgram: TAccountMetas[8]; eventAuthority: TAccountMetas[9]; program: TAccountMetas[10]; }; data: CreatePositionInstructionData; }; export function parseCreatePositionInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCreatePositionInstruction { if (instruction.accounts.length < 11) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 11, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { owner: getNextAccount(), positionNftMint: getNextAccount(), positionNftAccount: getNextAccount(), pool: getNextAccount(), position: getNextAccount(), poolAuthority: getNextAccount(), payer: getNextAccount(), tokenProgram: getNextAccount(), systemProgram: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount(), }, data: getCreatePositionInstructionDataDecoder().decode(instruction.data), }; }