/**
* 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,
getU16Decoder,
getU16Encoder,
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 {
getTwapEnabledBitmaskDecoder,
getTwapEnabledBitmaskEncoder,
type TwapEnabledBitmask,
type TwapEnabledBitmaskArgs,
} from "../types";
export const ORACLE_MAPPINGS_DISCRIMINATOR = new Uint8Array([
40, 244, 110, 80, 255, 214, 243, 188,
]);
export function getOracleMappingsDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(
ORACLE_MAPPINGS_DISCRIMINATOR,
);
}
export type OracleMappings = {
discriminator: ReadonlyUint8Array;
priceInfoAccounts: Array
;
priceTypes: ReadonlyUint8Array;
twapSourceOrRefPriceToleranceBps: Array;
twapEnabledBitmask: Array;
refPrice: Array;
generic: Array;
};
export type OracleMappingsArgs = {
priceInfoAccounts: Array;
priceTypes: ReadonlyUint8Array;
twapSourceOrRefPriceToleranceBps: Array;
twapEnabledBitmask: Array;
refPrice: Array;
generic: Array;
};
/** Gets the encoder for {@link OracleMappingsArgs} account data. */
export function getOracleMappingsEncoder(): FixedSizeEncoder {
return transformEncoder(
getStructEncoder([
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
[
"priceInfoAccounts",
getArrayEncoder(getAddressEncoder(), { size: 512 }),
],
["priceTypes", fixEncoderSize(getBytesEncoder(), 512)],
[
"twapSourceOrRefPriceToleranceBps",
getArrayEncoder(getU16Encoder(), { size: 512 }),
],
[
"twapEnabledBitmask",
getArrayEncoder(getTwapEnabledBitmaskEncoder(), { size: 512 }),
],
["refPrice", getArrayEncoder(getU16Encoder(), { size: 512 })],
[
"generic",
getArrayEncoder(fixEncoderSize(getBytesEncoder(), 20), { size: 512 }),
],
]),
(value) => ({ ...value, discriminator: ORACLE_MAPPINGS_DISCRIMINATOR }),
);
}
/** Gets the decoder for {@link OracleMappings} account data. */
export function getOracleMappingsDecoder(): FixedSizeDecoder {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
["priceInfoAccounts", getArrayDecoder(getAddressDecoder(), { size: 512 })],
["priceTypes", fixDecoderSize(getBytesDecoder(), 512)],
[
"twapSourceOrRefPriceToleranceBps",
getArrayDecoder(getU16Decoder(), { size: 512 }),
],
[
"twapEnabledBitmask",
getArrayDecoder(getTwapEnabledBitmaskDecoder(), { size: 512 }),
],
["refPrice", getArrayDecoder(getU16Decoder(), { size: 512 })],
[
"generic",
getArrayDecoder(fixDecoderSize(getBytesDecoder(), 20), { size: 512 }),
],
]);
}
/** Gets the codec for {@link OracleMappings} account data. */
export function getOracleMappingsCodec(): FixedSizeCodec<
OracleMappingsArgs,
OracleMappings
> {
return combineCodec(getOracleMappingsEncoder(), getOracleMappingsDecoder());
}
export function decodeOracleMappings(
encodedAccount: EncodedAccount,
): Account;
export function decodeOracleMappings(
encodedAccount: MaybeEncodedAccount,
): MaybeAccount;
export function decodeOracleMappings(
encodedAccount: EncodedAccount | MaybeEncodedAccount,
): Account | MaybeAccount {
return decodeAccount(
encodedAccount as MaybeEncodedAccount,
getOracleMappingsDecoder(),
);
}
export async function fetchOracleMappings(
rpc: Parameters[0],
address: Address,
config?: FetchAccountConfig,
): Promise> {
const maybeAccount = await fetchMaybeOracleMappings(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybeOracleMappings<
TAddress extends string = string,
>(
rpc: Parameters[0],
address: Address,
config?: FetchAccountConfig,
): Promise> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeOracleMappings(maybeAccount);
}
export async function fetchAllOracleMappings(
rpc: Parameters[0],
addresses: Array,
config?: FetchAccountsConfig,
): Promise[]> {
const maybeAccounts = await fetchAllMaybeOracleMappings(
rpc,
addresses,
config,
);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybeOracleMappings(
rpc: Parameters[0],
addresses: Array,
config?: FetchAccountsConfig,
): Promise[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) =>
decodeOracleMappings(maybeAccount),
);
}
export function getOracleMappingsSize(): number {
return 29704;
}