@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
80 lines (66 loc) • 4.85 kB
text/typescript
/**
* 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, 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';
export const WHIRLPOOLS_CONFIG_DISCRIMINATOR = new Uint8Array([157, 20, 49, 224, 217, 87, 193, 254]);
export function getWhirlpoolsConfigDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(WHIRLPOOLS_CONFIG_DISCRIMINATOR); }
export type WhirlpoolsConfig = { discriminator: ReadonlyUint8Array; feeAuthority: Address; collectProtocolFeesAuthority: Address; rewardEmissionsSuperAuthority: Address; defaultProtocolFeeRate: number; };
export type WhirlpoolsConfigArgs = { feeAuthority: Address; collectProtocolFeesAuthority: Address; rewardEmissionsSuperAuthority: Address; defaultProtocolFeeRate: number; };
/** Gets the encoder for {@link WhirlpoolsConfigArgs} account data. */
export function getWhirlpoolsConfigEncoder(): FixedSizeEncoder<WhirlpoolsConfigArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['feeAuthority', getAddressEncoder()], ['collectProtocolFeesAuthority', getAddressEncoder()], ['rewardEmissionsSuperAuthority', getAddressEncoder()], ['defaultProtocolFeeRate', getU16Encoder()]]), (value) => ({ ...value, discriminator: WHIRLPOOLS_CONFIG_DISCRIMINATOR }));
}
/** Gets the decoder for {@link WhirlpoolsConfig} account data. */
export function getWhirlpoolsConfigDecoder(): FixedSizeDecoder<WhirlpoolsConfig> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['feeAuthority', getAddressDecoder()], ['collectProtocolFeesAuthority', getAddressDecoder()], ['rewardEmissionsSuperAuthority', getAddressDecoder()], ['defaultProtocolFeeRate', getU16Decoder()]]);
}
/** Gets the codec for {@link WhirlpoolsConfig} account data. */
export function getWhirlpoolsConfigCodec(): FixedSizeCodec<WhirlpoolsConfigArgs, WhirlpoolsConfig> {
return combineCodec(getWhirlpoolsConfigEncoder(), getWhirlpoolsConfigDecoder());
}
export function decodeWhirlpoolsConfig<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<WhirlpoolsConfig, TAddress>;
export function decodeWhirlpoolsConfig<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<WhirlpoolsConfig, TAddress>;
export function decodeWhirlpoolsConfig<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<WhirlpoolsConfig, TAddress> | MaybeAccount<WhirlpoolsConfig, TAddress> {
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getWhirlpoolsConfigDecoder());
}
export async function fetchWhirlpoolsConfig<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<Account<WhirlpoolsConfig, TAddress>> {
const maybeAccount = await fetchMaybeWhirlpoolsConfig(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybeWhirlpoolsConfig<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<MaybeAccount<WhirlpoolsConfig, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeWhirlpoolsConfig(maybeAccount);
}
export async function fetchAllWhirlpoolsConfig(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<Account<WhirlpoolsConfig>[]> {
const maybeAccounts = await fetchAllMaybeWhirlpoolsConfig(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybeWhirlpoolsConfig(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<MaybeAccount<WhirlpoolsConfig>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeWhirlpoolsConfig(maybeAccount));
}
export function getWhirlpoolsConfigSize(): number {
return 106;
}