/** * 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, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, type Account, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, } from '@solana/kit'; import { getAddressDecoder, getAddressEncoder, type Address } from '@solana/kit'; import { combineCodec, fixDecoderSize, fixEncoderSize, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, transformEncoder, type Codec, type Decoder, type Encoder, type ReadonlyUint8Array, } from '@solana/kit'; export const LIMIT_ORDER_DISCRIMINATOR = new Uint8Array([137, 183, 212, 91, 115, 29, 141, 227]); export function getLimitOrderDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(LIMIT_ORDER_DISCRIMINATOR); } export type LimitOrder = { discriminator: ReadonlyUint8Array; /** User address, that created this order */ user: Address; /** Guard address, that will protect this order execution */ guard: Address; /** Token IN that user wants to spend */ tokenInMint: Address; /** Amount of tokens In locked */ amountIn: bigint; /** Minimum amount of tokens OUT to receive */ amountOutMin: bigint; /** * Keccak256 hash of (token_out,receiver,extra_transfers_tokens_and_receivers,secret_number) * Since we want to hide tokens OUT right until execution moment to protect user from * any sort of MEV attack */ secretHash: ReadonlyUint8Array; /** * Array of requested extra transfers amounts * Since we want to hide tokens OUT and receivers right until execution moment * to protect user from any sort of MEV attack * Tokens and receivers will be collected from `remaining_accounts` * during fulfillment and checked against `secret_hash` value */ extraTransfersAmounts: Array; /** Deadline for the operation, in Unix timestamp format, in SECONDS */ deadline: number; }; export type LimitOrderArgs = { /** User address, that created this order */ user: Address; /** Guard address, that will protect this order execution */ guard: Address; /** Token IN that user wants to spend */ tokenInMint: Address; /** Amount of tokens In locked */ amountIn: number | bigint; /** Minimum amount of tokens OUT to receive */ amountOutMin: number | bigint; /** * Keccak256 hash of (token_out,receiver,extra_transfers_tokens_and_receivers,secret_number) * Since we want to hide tokens OUT right until execution moment to protect user from * any sort of MEV attack */ secretHash: ReadonlyUint8Array; /** * Array of requested extra transfers amounts * Since we want to hide tokens OUT and receivers right until execution moment * to protect user from any sort of MEV attack * Tokens and receivers will be collected from `remaining_accounts` * during fulfillment and checked against `secret_hash` value */ extraTransfersAmounts: Array; /** Deadline for the operation, in Unix timestamp format, in SECONDS */ deadline: number; }; export function getLimitOrderEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['user', getAddressEncoder()], ['guard', getAddressEncoder()], ['tokenInMint', getAddressEncoder()], ['amountIn', getU64Encoder()], ['amountOutMin', getU64Encoder()], ['secretHash', fixEncoderSize(getBytesEncoder(), 32)], ['extraTransfersAmounts', getArrayEncoder(getU64Encoder())], ['deadline', getU32Encoder()], ]), (value) => ({ ...value, discriminator: LIMIT_ORDER_DISCRIMINATOR }), ); } export function getLimitOrderDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['user', getAddressDecoder()], ['guard', getAddressDecoder()], ['tokenInMint', getAddressDecoder()], ['amountIn', getU64Decoder()], ['amountOutMin', getU64Decoder()], ['secretHash', fixDecoderSize(getBytesDecoder(), 32)], ['extraTransfersAmounts', getArrayDecoder(getU64Decoder())], ['deadline', getU32Decoder()], ]); } export function getLimitOrderCodec(): Codec { return combineCodec(getLimitOrderEncoder(), getLimitOrderDecoder()); } export function decodeLimitOrder( encodedAccount: EncodedAccount, ): Account; export function decodeLimitOrder( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeLimitOrder( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount(encodedAccount as MaybeEncodedAccount, getLimitOrderDecoder()); } export async function fetchLimitOrder( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeLimitOrder(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeLimitOrder( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeLimitOrder(maybeAccount); } export async function fetchAllLimitOrder( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeLimitOrder(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeLimitOrder( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeLimitOrder(maybeAccount)); }