@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
80 lines (66 loc) • 4.21 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, 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';
export const TERMS_SIGNATURE_DISCRIMINATOR = new Uint8Array([197, 173, 136, 91, 182, 49, 113, 19]);
export function getTermsSignatureDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(TERMS_SIGNATURE_DISCRIMINATOR); }
export type TermsSignature = { discriminator: ReadonlyUint8Array; signature: ReadonlyUint8Array; };
export type TermsSignatureArgs = { signature: ReadonlyUint8Array; };
/** Gets the encoder for {@link TermsSignatureArgs} account data. */
export function getTermsSignatureEncoder(): FixedSizeEncoder<TermsSignatureArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['signature', fixEncoderSize(getBytesEncoder(), 64)]]), (value) => ({ ...value, discriminator: TERMS_SIGNATURE_DISCRIMINATOR }));
}
/** Gets the decoder for {@link TermsSignature} account data. */
export function getTermsSignatureDecoder(): FixedSizeDecoder<TermsSignature> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['signature', fixDecoderSize(getBytesDecoder(), 64)]]);
}
/** Gets the codec for {@link TermsSignature} account data. */
export function getTermsSignatureCodec(): FixedSizeCodec<TermsSignatureArgs, TermsSignature> {
return combineCodec(getTermsSignatureEncoder(), getTermsSignatureDecoder());
}
export function decodeTermsSignature<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<TermsSignature, TAddress>;
export function decodeTermsSignature<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<TermsSignature, TAddress>;
export function decodeTermsSignature<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<TermsSignature, TAddress> | MaybeAccount<TermsSignature, TAddress> {
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getTermsSignatureDecoder());
}
export async function fetchTermsSignature<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<Account<TermsSignature, TAddress>> {
const maybeAccount = await fetchMaybeTermsSignature(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybeTermsSignature<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<MaybeAccount<TermsSignature, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeTermsSignature(maybeAccount);
}
export async function fetchAllTermsSignature(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<Account<TermsSignature>[]> {
const maybeAccounts = await fetchAllMaybeTermsSignature(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybeTermsSignature(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<MaybeAccount<TermsSignature>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeTermsSignature(maybeAccount));
}
export function getTermsSignatureSize(): number {
return 72;
}