import {z} from 'zod' export type GetApiLimitOrderOrderListArgs = {wallet: string, showErr?: string | undefined}; export type GetApiLimitOrderOrderListOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const limitOrderListItem = z.object({pda: z.string(), poolId: z.string(), owner: z.string(), tick: z.number().int(), price: z.number(), zeroForOne: z.boolean(), orderPhase: z.string(), totalAmount: z.string(), filledAmount: z.string(), openTime: z.string(), pendingSettle: z.string(), filledAmountUpdate: z.string(), mintA: z.string(), mintB: z.string(), mintDecimalsA: z.number().int(), mintDecimalsB: z.number().int(), poolCurrentPrice: z.number()}); export const limitOrderListResponse = z.object({id: z.string().optional(), success: z.boolean(), data: z.object({rows: z.array(limitOrderListItem), e: z.array(z.string()).optional()})}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List a wallet's currently-parked CLMM limit orders * * GET /limit-order/order/list */ export const getApiLimitOrderOrderList = async (args: GetApiLimitOrderOrderListArgs, options?: GetApiLimitOrderOrderListOptions) => { const {baseUrl = "https://api.raydium.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.wallet != null) query.append("wallet", String(args.wallet)) if (args.showErr != null) query.append("showErr", String(args.showErr)) const url = `${baseUrl.replace(/\/+$/, '')}/limit-order/order/list${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(limitOrderListResponse, await res.json()) };