/** * 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 { WhirlpoolRewardInfo, WhirlpoolRewardInfoArgs, } from "../types/index.js"; import { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getI32Decoder, getI32Encoder, getStructDecoder, getStructEncoder, getU8Decoder, getU8Encoder, getU16Decoder, getU16Encoder, getU64Decoder, getU64Encoder, getU128Decoder, getU128Encoder, transformEncoder, } from "@solana/kit"; import { getWhirlpoolRewardInfoDecoder, getWhirlpoolRewardInfoEncoder, } from "../types/index.js"; export const WHIRLPOOL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 63, 149, 209, 12, 225, 128, 99, 9, ]); export function getWhirlpoolDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode(WHIRLPOOL_DISCRIMINATOR); } export interface Whirlpool { discriminator: ReadonlyUint8Array; whirlpoolsConfig: Address; whirlpoolBump: number[]; tickSpacing: number; tickSpacingSeed: number[]; feeRate: number; protocolFeeRate: number; liquidity: bigint; sqrtPrice: bigint; tickCurrentIndex: number; protocolFeeOwedA: bigint; protocolFeeOwedB: bigint; tokenMintA: Address; tokenVaultA: Address; feeGrowthGlobalA: bigint; tokenMintB: Address; tokenVaultB: Address; feeGrowthGlobalB: bigint; rewardLastUpdatedTimestamp: bigint; rewardInfos: WhirlpoolRewardInfo[]; } export interface WhirlpoolArgs { whirlpoolsConfig: Address; whirlpoolBump: number[]; tickSpacing: number; tickSpacingSeed: number[]; feeRate: number; protocolFeeRate: number; liquidity: number | bigint; sqrtPrice: number | bigint; tickCurrentIndex: number; protocolFeeOwedA: number | bigint; protocolFeeOwedB: number | bigint; tokenMintA: Address; tokenVaultA: Address; feeGrowthGlobalA: number | bigint; tokenMintB: Address; tokenVaultB: Address; feeGrowthGlobalB: number | bigint; rewardLastUpdatedTimestamp: number | bigint; rewardInfos: WhirlpoolRewardInfoArgs[]; } /** Gets the encoder for {@link WhirlpoolArgs} account data. */ export function getWhirlpoolEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["whirlpoolsConfig", getAddressEncoder()], ["whirlpoolBump", getArrayEncoder(getU8Encoder(), { size: 1 })], ["tickSpacing", getU16Encoder()], ["tickSpacingSeed", getArrayEncoder(getU8Encoder(), { size: 2 })], ["feeRate", getU16Encoder()], ["protocolFeeRate", getU16Encoder()], ["liquidity", getU128Encoder()], ["sqrtPrice", getU128Encoder()], ["tickCurrentIndex", getI32Encoder()], ["protocolFeeOwedA", getU64Encoder()], ["protocolFeeOwedB", getU64Encoder()], ["tokenMintA", getAddressEncoder()], ["tokenVaultA", getAddressEncoder()], ["feeGrowthGlobalA", getU128Encoder()], ["tokenMintB", getAddressEncoder()], ["tokenVaultB", getAddressEncoder()], ["feeGrowthGlobalB", getU128Encoder()], ["rewardLastUpdatedTimestamp", getU64Encoder()], [ "rewardInfos", getArrayEncoder(getWhirlpoolRewardInfoEncoder(), { size: 3 }), ], ]), (value) => ({ ...value, discriminator: WHIRLPOOL_DISCRIMINATOR }), ); } /** Gets the decoder for {@link Whirlpool} account data. */ export function getWhirlpoolDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["whirlpoolsConfig", getAddressDecoder()], ["whirlpoolBump", getArrayDecoder(getU8Decoder(), { size: 1 })], ["tickSpacing", getU16Decoder()], ["tickSpacingSeed", getArrayDecoder(getU8Decoder(), { size: 2 })], ["feeRate", getU16Decoder()], ["protocolFeeRate", getU16Decoder()], ["liquidity", getU128Decoder()], ["sqrtPrice", getU128Decoder()], ["tickCurrentIndex", getI32Decoder()], ["protocolFeeOwedA", getU64Decoder()], ["protocolFeeOwedB", getU64Decoder()], ["tokenMintA", getAddressDecoder()], ["tokenVaultA", getAddressDecoder()], ["feeGrowthGlobalA", getU128Decoder()], ["tokenMintB", getAddressDecoder()], ["tokenVaultB", getAddressDecoder()], ["feeGrowthGlobalB", getU128Decoder()], ["rewardLastUpdatedTimestamp", getU64Decoder()], [ "rewardInfos", getArrayDecoder(getWhirlpoolRewardInfoDecoder(), { size: 3 }), ], ]); } /** Gets the codec for {@link Whirlpool} account data. */ export function getWhirlpoolCodec(): FixedSizeCodec { return combineCodec(getWhirlpoolEncoder(), getWhirlpoolDecoder()); } export function decodeWhirlpool( encodedAccount: EncodedAccount, ): Account; export function decodeWhirlpool( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeWhirlpool( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getWhirlpoolDecoder(), ); } export async function fetchWhirlpool( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeWhirlpool(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeWhirlpool( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeWhirlpool(maybeAccount); } export async function fetchAllWhirlpool( rpc: Parameters[0], addresses: Address[], config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeWhirlpool(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeWhirlpool( rpc: Parameters[0], addresses: Address[], config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeWhirlpool(maybeAccount)); }