/** * 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 { return getDiscriminatedUnionEncoder([ ["Bps", getStructEncoder([["fields", getTupleEncoder([getU64Encoder()])]])], [ "Absolute", getStructEncoder([ ["srcAmountToSwap", getU64Encoder()], ["dstAmountToVault", getU64Encoder()], ["aToB", getBooleanEncoder()], ]), ], ]); } export function getSwapLimitDecoder(): Decoder { return getDiscriminatedUnionDecoder([ ["Bps", getStructDecoder([["fields", getTupleDecoder([getU64Decoder()])]])], [ "Absolute", getStructDecoder([ ["srcAmountToSwap", getU64Decoder()], ["dstAmountToVault", getU64Decoder()], ["aToB", getBooleanDecoder()], ]), ], ]); } export function getSwapLimitCodec(): Codec { return combineCodec(getSwapLimitEncoder(), getSwapLimitDecoder()); } // Data Enum Helpers. export function swapLimit( kind: "Bps", data: GetDiscriminatedUnionVariantContent< SwapLimitArgs, "__kind", "Bps" >["fields"], ): GetDiscriminatedUnionVariant; export function swapLimit( kind: "Absolute", data: GetDiscriminatedUnionVariantContent< SwapLimitArgs, "__kind", "Absolute" >, ): GetDiscriminatedUnionVariant; export function swapLimit( kind: K, data?: Data, ) { return Array.isArray(data) ? { __kind: kind, fields: data } : { __kind: kind, ...(data ?? {}) }; } export function isSwapLimit( kind: K, value: SwapLimit, ): value is SwapLimit & { __kind: K } { return value.__kind === kind; }