@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
45 lines (36 loc) • 2.75 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 { combineCodec, getBooleanDecoder, getBooleanEncoder, getDiscriminatedUnionDecoder, getDiscriminatedUnionEncoder, getStructDecoder, getStructEncoder, getTupleDecoder, getTupleEncoder, getU64Decoder, getU64Encoder, type Codec, type Decoder, type Encoder, type GetDiscriminatedUnionVariant, type GetDiscriminatedUnionVariantContent } from '@solana/kit';
export type SwapLimit = { __kind: "Bps", fields: readonly [bigint]; } | { __kind: "Absolute",
/** Amount of src token expected by the user to perform the swap */
srcAmountToSwap: bigint;
/** Amount of dst token the user provides in exchange */
dstAmountToVault: bigint; aToB: boolean; };
export type SwapLimitArgs = { __kind: "Bps", fields: readonly [number | bigint]; } | { __kind: "Absolute",
/** Amount of src token expected by the user to perform the swap */
srcAmountToSwap: number | bigint;
/** Amount of dst token the user provides in exchange */
dstAmountToVault: number | bigint; aToB: boolean; };
export function getSwapLimitEncoder(): Encoder<SwapLimitArgs> {
return getDiscriminatedUnionEncoder([['Bps', getStructEncoder([['fields', getTupleEncoder([getU64Encoder()])]])], ['Absolute', getStructEncoder([['srcAmountToSwap', getU64Encoder()], ['dstAmountToVault', getU64Encoder()], ['aToB', getBooleanEncoder()]])]]);
}
export function getSwapLimitDecoder(): Decoder<SwapLimit> {
return getDiscriminatedUnionDecoder([['Bps', getStructDecoder([['fields', getTupleDecoder([getU64Decoder()])]])], ['Absolute', getStructDecoder([['srcAmountToSwap', getU64Decoder()], ['dstAmountToVault', getU64Decoder()], ['aToB', getBooleanDecoder()]])]]);
}
export function getSwapLimitCodec(): Codec<SwapLimitArgs, SwapLimit> {
return combineCodec(getSwapLimitEncoder(), getSwapLimitDecoder());
}
// Data Enum Helpers.
export function swapLimit(kind: 'Bps', data: GetDiscriminatedUnionVariantContent<SwapLimitArgs, '__kind', 'Bps'>['fields']): GetDiscriminatedUnionVariant<SwapLimitArgs, '__kind', 'Bps'>;
export function swapLimit(kind: 'Absolute', data: GetDiscriminatedUnionVariantContent<SwapLimitArgs, '__kind', 'Absolute'>): GetDiscriminatedUnionVariant<SwapLimitArgs, '__kind', 'Absolute'>;
export function swapLimit<K extends SwapLimitArgs['__kind'], Data>(kind: K, data?: Data) {
return Array.isArray(data) ? { __kind: kind, fields: data } : { __kind: kind, ...(data ?? {}) };
}
export function isSwapLimit<K extends SwapLimit['__kind']>(kind: K, value: SwapLimit): value is SwapLimit & { __kind: K } {
return value.__kind === kind;
};