/** * 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 { Account, Address, EncodedAccount, FetchAccountConfig, FetchAccountsConfig, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, MaybeAccount, MaybeEncodedAccount, ReadonlyUint8Array, } from "@solana/kit"; import type { PositionRewardInfo, PositionRewardInfoArgs, } from "../types/index.js"; import { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getI32Decoder, getI32Encoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU128Decoder, getU128Encoder, transformEncoder, } from "@solana/kit"; import { getPositionRewardInfoDecoder, getPositionRewardInfoEncoder, } from "../types/index.js"; export const POSITION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 170, 188, 143, 228, 122, 64, 247, 208, ]); export function getPositionDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode(POSITION_DISCRIMINATOR); } export interface Position { discriminator: ReadonlyUint8Array; whirlpool: Address; positionMint: Address; liquidity: bigint; tickLowerIndex: number; tickUpperIndex: number; feeGrowthCheckpointA: bigint; feeOwedA: bigint; feeGrowthCheckpointB: bigint; feeOwedB: bigint; rewardInfos: PositionRewardInfo[]; } export interface PositionArgs { whirlpool: Address; positionMint: Address; liquidity: number | bigint; tickLowerIndex: number; tickUpperIndex: number; feeGrowthCheckpointA: number | bigint; feeOwedA: number | bigint; feeGrowthCheckpointB: number | bigint; feeOwedB: number | bigint; rewardInfos: PositionRewardInfoArgs[]; } /** Gets the encoder for {@link PositionArgs} account data. */ export function getPositionEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["whirlpool", getAddressEncoder()], ["positionMint", getAddressEncoder()], ["liquidity", getU128Encoder()], ["tickLowerIndex", getI32Encoder()], ["tickUpperIndex", getI32Encoder()], ["feeGrowthCheckpointA", getU128Encoder()], ["feeOwedA", getU64Encoder()], ["feeGrowthCheckpointB", getU128Encoder()], ["feeOwedB", getU64Encoder()], [ "rewardInfos", getArrayEncoder(getPositionRewardInfoEncoder(), { size: 3 }), ], ]), (value) => ({ ...value, discriminator: POSITION_DISCRIMINATOR }), ); } /** Gets the decoder for {@link Position} account data. */ export function getPositionDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["whirlpool", getAddressDecoder()], ["positionMint", getAddressDecoder()], ["liquidity", getU128Decoder()], ["tickLowerIndex", getI32Decoder()], ["tickUpperIndex", getI32Decoder()], ["feeGrowthCheckpointA", getU128Decoder()], ["feeOwedA", getU64Decoder()], ["feeGrowthCheckpointB", getU128Decoder()], ["feeOwedB", getU64Decoder()], [ "rewardInfos", getArrayDecoder(getPositionRewardInfoDecoder(), { size: 3 }), ], ]); } /** Gets the codec for {@link Position} account data. */ export function getPositionCodec(): FixedSizeCodec { return combineCodec(getPositionEncoder(), getPositionDecoder()); } export function decodePosition( encodedAccount: EncodedAccount, ): Account; export function decodePosition( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodePosition( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getPositionDecoder(), ); } export async function fetchPosition( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybePosition(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybePosition( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodePosition(maybeAccount); } export async function fetchAllPosition( rpc: Parameters[0], addresses: Address[], config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybePosition(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybePosition( rpc: Parameters[0], addresses: Address[], config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodePosition(maybeAccount)); }