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