/** * 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, getI32Decoder, getI32Encoder, getStructDecoder, getStructEncoder, 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_TICK_ARRAY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([11, 188, 193, 214, 141, 91, 149, 184]); export function getInitializeTickArrayDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( INITIALIZE_TICK_ARRAY_DISCRIMINATOR, ); } export type InitializeTickArrayInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpool extends string | AccountMeta = string, TAccountFunder extends string | AccountMeta = string, TAccountTickArray extends string | AccountMeta = string, TAccountSystemProgram extends | string | AccountMeta = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountWhirlpool extends string ? ReadonlyAccount : TAccountWhirlpool, TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountTickArray extends string ? WritableAccount : TAccountTickArray, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export interface InitializeTickArrayInstructionData { discriminator: ReadonlyUint8Array; startTickIndex: number; } export interface InitializeTickArrayInstructionDataArgs { startTickIndex: number; } export function getInitializeTickArrayInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["startTickIndex", getI32Encoder()], ]), (value) => ({ ...value, discriminator: INITIALIZE_TICK_ARRAY_DISCRIMINATOR, }), ); } export function getInitializeTickArrayInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["startTickIndex", getI32Decoder()], ]); } export function getInitializeTickArrayInstructionDataCodec(): FixedSizeCodec< InitializeTickArrayInstructionDataArgs, InitializeTickArrayInstructionData > { return combineCodec( getInitializeTickArrayInstructionDataEncoder(), getInitializeTickArrayInstructionDataDecoder(), ); } export interface InitializeTickArrayInput< TAccountWhirlpool extends string = string, TAccountFunder extends string = string, TAccountTickArray extends string = string, TAccountSystemProgram extends string = string, > { whirlpool: Address; funder: TransactionSigner; tickArray: Address; systemProgram?: Address; startTickIndex: InitializeTickArrayInstructionDataArgs["startTickIndex"]; } export function getInitializeTickArrayInstruction< TAccountWhirlpool extends string, TAccountFunder extends string, TAccountTickArray extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: InitializeTickArrayInput< TAccountWhirlpool, TAccountFunder, TAccountTickArray, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): InitializeTickArrayInstruction< TProgramAddress, TAccountWhirlpool, TAccountFunder, TAccountTickArray, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpool: { value: input.whirlpool ?? null, isWritable: false }, funder: { value: input.funder ?? null, isWritable: true }, tickArray: { value: input.tickArray ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? 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">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("whirlpool", accounts.whirlpool), getAccountMeta("funder", accounts.funder), getAccountMeta("tickArray", accounts.tickArray), getAccountMeta("systemProgram", accounts.systemProgram), ], data: getInitializeTickArrayInstructionDataEncoder().encode( args as InitializeTickArrayInstructionDataArgs, ), programAddress, } as InitializeTickArrayInstruction< TProgramAddress, TAccountWhirlpool, TAccountFunder, TAccountTickArray, TAccountSystemProgram >); } export interface ParsedInitializeTickArrayInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { whirlpool: TAccountMetas[0]; funder: TAccountMetas[1]; tickArray: TAccountMetas[2]; systemProgram: TAccountMetas[3]; }; data: InitializeTickArrayInstructionData; } export function parseInitializeTickArrayInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInitializeTickArrayInstruction { 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: { whirlpool: getNextAccount(), funder: getNextAccount(), tickArray: getNextAccount(), systemProgram: getNextAccount(), }, data: getInitializeTickArrayInstructionDataDecoder().decode( instruction.data, ), }; }