/** * 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, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, 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 { getSideDecoder, getSideEncoder, type Side, type SideArgs, } 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; owner: Address; pool: Address; custody: Address; collateralCustody: Address; openTime: bigint; updateTime: bigint; side: Side; price: bigint; sizeUsd: bigint; collateralUsd: bigint; realisedPnlUsd: bigint; cumulativeInterestSnapshot: bigint; lockedAmount: bigint; bump: number; }; export type PositionArgs = { owner: Address; pool: Address; custody: Address; collateralCustody: Address; openTime: number | bigint; updateTime: number | bigint; side: SideArgs; price: number | bigint; sizeUsd: number | bigint; collateralUsd: number | bigint; realisedPnlUsd: number | bigint; cumulativeInterestSnapshot: number | bigint; lockedAmount: number | bigint; bump: number; }; /** Gets the encoder for {@link PositionArgs} account data. */ export function getPositionEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["owner", getAddressEncoder()], ["pool", getAddressEncoder()], ["custody", getAddressEncoder()], ["collateralCustody", getAddressEncoder()], ["openTime", getI64Encoder()], ["updateTime", getI64Encoder()], ["side", getSideEncoder()], ["price", getU64Encoder()], ["sizeUsd", getU64Encoder()], ["collateralUsd", getU64Encoder()], ["realisedPnlUsd", getI64Encoder()], ["cumulativeInterestSnapshot", getU128Encoder()], ["lockedAmount", getU64Encoder()], ["bump", getU8Encoder()], ]), (value) => ({ ...value, discriminator: POSITION_DISCRIMINATOR }), ); } /** Gets the decoder for {@link Position} account data. */ export function getPositionDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["owner", getAddressDecoder()], ["pool", getAddressDecoder()], ["custody", getAddressDecoder()], ["collateralCustody", getAddressDecoder()], ["openTime", getI64Decoder()], ["updateTime", getI64Decoder()], ["side", getSideDecoder()], ["price", getU64Decoder()], ["sizeUsd", getU64Decoder()], ["collateralUsd", getU64Decoder()], ["realisedPnlUsd", getI64Decoder()], ["cumulativeInterestSnapshot", getU128Decoder()], ["lockedAmount", getU64Decoder()], ["bump", getU8Decoder()], ]); } /** 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 210; }