/** * 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, getStructDecoder, getStructEncoder, 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 { getEmaTwapDecoder, getEmaTwapEncoder, type EmaTwap, type EmaTwapArgs, } from "../types"; export const ORACLE_TWAPS_DISCRIMINATOR = new Uint8Array([ 192, 139, 27, 250, 53, 166, 101, 61, ]); export function getOracleTwapsDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( ORACLE_TWAPS_DISCRIMINATOR, ); } export type OracleTwaps = { discriminator: ReadonlyUint8Array; oraclePrices: Address; oracleMappings: Address; twaps: Array; }; export type OracleTwapsArgs = { oraclePrices: Address; oracleMappings: Address; twaps: Array; }; /** Gets the encoder for {@link OracleTwapsArgs} account data. */ export function getOracleTwapsEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["oraclePrices", getAddressEncoder()], ["oracleMappings", getAddressEncoder()], ["twaps", getArrayEncoder(getEmaTwapEncoder(), { size: 512 })], ]), (value) => ({ ...value, discriminator: ORACLE_TWAPS_DISCRIMINATOR }), ); } /** Gets the decoder for {@link OracleTwaps} account data. */ export function getOracleTwapsDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["oraclePrices", getAddressDecoder()], ["oracleMappings", getAddressDecoder()], ["twaps", getArrayDecoder(getEmaTwapDecoder(), { size: 512 })], ]); } /** Gets the codec for {@link OracleTwaps} account data. */ export function getOracleTwapsCodec(): FixedSizeCodec< OracleTwapsArgs, OracleTwaps > { return combineCodec(getOracleTwapsEncoder(), getOracleTwapsDecoder()); } export function decodeOracleTwaps( encodedAccount: EncodedAccount, ): Account; export function decodeOracleTwaps( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeOracleTwaps( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getOracleTwapsDecoder(), ); } export async function fetchOracleTwaps( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeOracleTwaps(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeOracleTwaps( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeOracleTwaps(maybeAccount); } export async function fetchAllOracleTwaps( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeOracleTwaps(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeOracleTwaps( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeOracleTwaps(maybeAccount)); } export function getOracleTwapsSize(): number { return 344136; }