/** * 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, ReadonlyUint8Array, TransactionSigner, WritableAccount, WritableSignerAccount, } from "@solana/kit"; import type { ResolvedInstructionAccount } from "@solana/program-client-core"; import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, 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 INITIALIZE_POOL_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([207, 45, 87, 242, 27, 63, 204, 67]); export function getInitializePoolV2DiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( INITIALIZE_POOL_V2_DISCRIMINATOR, ); } export type InitializePoolV2Instruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolsConfig extends string | AccountMeta = string, TAccountTokenMintA extends string | AccountMeta = string, TAccountTokenMintB extends string | AccountMeta = string, TAccountTokenBadgeA extends string | AccountMeta = string, TAccountTokenBadgeB extends string | AccountMeta = string, TAccountFunder extends string | AccountMeta = string, TAccountWhirlpool extends string | AccountMeta = string, TAccountTokenVaultA extends string | AccountMeta = string, TAccountTokenVaultB extends string | AccountMeta = string, TAccountFeeTier extends string | AccountMeta = string, TAccountTokenProgramA extends string | AccountMeta = string, TAccountTokenProgramB extends string | AccountMeta = string, TAccountSystemProgram extends | string | AccountMeta = "11111111111111111111111111111111", TAccountRent extends | string | AccountMeta = "SysvarRent111111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountWhirlpoolsConfig extends string ? ReadonlyAccount : TAccountWhirlpoolsConfig, TAccountTokenMintA extends string ? ReadonlyAccount : TAccountTokenMintA, TAccountTokenMintB extends string ? ReadonlyAccount : TAccountTokenMintB, TAccountTokenBadgeA extends string ? ReadonlyAccount : TAccountTokenBadgeA, TAccountTokenBadgeB extends string ? ReadonlyAccount : TAccountTokenBadgeB, TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountWhirlpool extends string ? WritableAccount : TAccountWhirlpool, TAccountTokenVaultA extends string ? WritableSignerAccount & AccountSignerMeta : TAccountTokenVaultA, TAccountTokenVaultB extends string ? WritableSignerAccount & AccountSignerMeta : TAccountTokenVaultB, TAccountFeeTier extends string ? ReadonlyAccount : TAccountFeeTier, TAccountTokenProgramA extends string ? ReadonlyAccount : TAccountTokenProgramA, TAccountTokenProgramB extends string ? ReadonlyAccount : TAccountTokenProgramB, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountRent extends string ? ReadonlyAccount : TAccountRent, ...TRemainingAccounts, ] >; export interface InitializePoolV2InstructionData { discriminator: ReadonlyUint8Array; tickSpacing: number; initialSqrtPrice: bigint; } export interface InitializePoolV2InstructionDataArgs { tickSpacing: number; initialSqrtPrice: number | bigint; } export function getInitializePoolV2InstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["tickSpacing", getU16Encoder()], ["initialSqrtPrice", getU128Encoder()], ]), (value) => ({ ...value, discriminator: INITIALIZE_POOL_V2_DISCRIMINATOR }), ); } export function getInitializePoolV2InstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["tickSpacing", getU16Decoder()], ["initialSqrtPrice", getU128Decoder()], ]); } export function getInitializePoolV2InstructionDataCodec(): FixedSizeCodec< InitializePoolV2InstructionDataArgs, InitializePoolV2InstructionData > { return combineCodec( getInitializePoolV2InstructionDataEncoder(), getInitializePoolV2InstructionDataDecoder(), ); } export interface InitializePoolV2Input< TAccountWhirlpoolsConfig extends string = string, TAccountTokenMintA extends string = string, TAccountTokenMintB extends string = string, TAccountTokenBadgeA extends string = string, TAccountTokenBadgeB extends string = string, TAccountFunder extends string = string, TAccountWhirlpool extends string = string, TAccountTokenVaultA extends string = string, TAccountTokenVaultB extends string = string, TAccountFeeTier extends string = string, TAccountTokenProgramA extends string = string, TAccountTokenProgramB extends string = string, TAccountSystemProgram extends string = string, TAccountRent extends string = string, > { whirlpoolsConfig: Address; tokenMintA: Address; tokenMintB: Address; tokenBadgeA: Address; tokenBadgeB: Address; funder: TransactionSigner; whirlpool: Address; tokenVaultA: TransactionSigner; tokenVaultB: TransactionSigner; feeTier: Address; tokenProgramA: Address; tokenProgramB: Address; systemProgram?: Address; rent?: Address; tickSpacing: InitializePoolV2InstructionDataArgs["tickSpacing"]; initialSqrtPrice: InitializePoolV2InstructionDataArgs["initialSqrtPrice"]; } export function getInitializePoolV2Instruction< TAccountWhirlpoolsConfig extends string, TAccountTokenMintA extends string, TAccountTokenMintB extends string, TAccountTokenBadgeA extends string, TAccountTokenBadgeB extends string, TAccountFunder extends string, TAccountWhirlpool extends string, TAccountTokenVaultA extends string, TAccountTokenVaultB extends string, TAccountFeeTier extends string, TAccountTokenProgramA extends string, TAccountTokenProgramB extends string, TAccountSystemProgram extends string, TAccountRent extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: InitializePoolV2Input< TAccountWhirlpoolsConfig, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenBadgeA, TAccountTokenBadgeB, TAccountFunder, TAccountWhirlpool, TAccountTokenVaultA, TAccountTokenVaultB, TAccountFeeTier, TAccountTokenProgramA, TAccountTokenProgramB, TAccountSystemProgram, TAccountRent >, config?: { programAddress?: TProgramAddress }, ): InitializePoolV2Instruction< TProgramAddress, TAccountWhirlpoolsConfig, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenBadgeA, TAccountTokenBadgeB, TAccountFunder, TAccountWhirlpool, TAccountTokenVaultA, TAccountTokenVaultB, TAccountFeeTier, TAccountTokenProgramA, TAccountTokenProgramB, TAccountSystemProgram, TAccountRent > { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpoolsConfig: { value: input.whirlpoolsConfig ?? null, isWritable: false, }, tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, tokenBadgeA: { value: input.tokenBadgeA ?? null, isWritable: false }, tokenBadgeB: { value: input.tokenBadgeB ?? null, isWritable: false }, funder: { value: input.funder ?? null, isWritable: true }, whirlpool: { value: input.whirlpool ?? null, isWritable: true }, tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, feeTier: { value: input.feeTier ?? null, isWritable: false }, tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? 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.rent.value) { accounts.rent.value = "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("whirlpoolsConfig", accounts.whirlpoolsConfig), getAccountMeta("tokenMintA", accounts.tokenMintA), getAccountMeta("tokenMintB", accounts.tokenMintB), getAccountMeta("tokenBadgeA", accounts.tokenBadgeA), getAccountMeta("tokenBadgeB", accounts.tokenBadgeB), getAccountMeta("funder", accounts.funder), getAccountMeta("whirlpool", accounts.whirlpool), getAccountMeta("tokenVaultA", accounts.tokenVaultA), getAccountMeta("tokenVaultB", accounts.tokenVaultB), getAccountMeta("feeTier", accounts.feeTier), getAccountMeta("tokenProgramA", accounts.tokenProgramA), getAccountMeta("tokenProgramB", accounts.tokenProgramB), getAccountMeta("systemProgram", accounts.systemProgram), getAccountMeta("rent", accounts.rent), ], data: getInitializePoolV2InstructionDataEncoder().encode( args as InitializePoolV2InstructionDataArgs, ), programAddress, } as InitializePoolV2Instruction< TProgramAddress, TAccountWhirlpoolsConfig, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenBadgeA, TAccountTokenBadgeB, TAccountFunder, TAccountWhirlpool, TAccountTokenVaultA, TAccountTokenVaultB, TAccountFeeTier, TAccountTokenProgramA, TAccountTokenProgramB, TAccountSystemProgram, TAccountRent >); } export interface ParsedInitializePoolV2Instruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { whirlpoolsConfig: TAccountMetas[0]; tokenMintA: TAccountMetas[1]; tokenMintB: TAccountMetas[2]; tokenBadgeA: TAccountMetas[3]; tokenBadgeB: TAccountMetas[4]; funder: TAccountMetas[5]; whirlpool: TAccountMetas[6]; tokenVaultA: TAccountMetas[7]; tokenVaultB: TAccountMetas[8]; feeTier: TAccountMetas[9]; tokenProgramA: TAccountMetas[10]; tokenProgramB: TAccountMetas[11]; systemProgram: TAccountMetas[12]; rent: TAccountMetas[13]; }; data: InitializePoolV2InstructionData; } export function parseInitializePoolV2Instruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInitializePoolV2Instruction { if (instruction.accounts.length < 14) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 14, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { whirlpoolsConfig: getNextAccount(), tokenMintA: getNextAccount(), tokenMintB: getNextAccount(), tokenBadgeA: getNextAccount(), tokenBadgeB: getNextAccount(), funder: getNextAccount(), whirlpool: getNextAccount(), tokenVaultA: getNextAccount(), tokenVaultB: getNextAccount(), feeTier: getNextAccount(), tokenProgramA: getNextAccount(), tokenProgramB: getNextAccount(), systemProgram: getNextAccount(), rent: getNextAccount(), }, data: getInitializePoolV2InstructionDataDecoder().decode(instruction.data), }; }