import {z} from 'zod' export type GetApiWalletsWalletLimitOrdersOpenPoolsArgs = {wallet: string, page: unknown, page_size: unknown}; export type GetApiWalletsWalletLimitOrdersOpenPoolsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const limitOrderPoolDetails = z.object({base_fee: z.string(), bin_step: z.number().int().gte(0), collect_fee_mode: z.number().int().gte(0), pair_name: z.string(), pool_address: z.string(), token_x: z.string(), token_x_icon: z.string(), token_x_mint: z.string(), token_y: z.string(), token_y_icon: z.string(), token_y_mint: z.string()}); export const paginationResponseOpenLimitOrderPoolSummary = z.object({current_page: z.number().int().gte(0), data: z.array(z.object({filled_pct: z.string(), fully_filled_orders: z.number().int().gte(0), pool: limitOrderPoolDetails, total_bonus_sol: z.string(), total_bonus_usd: z.string(), total_bonus_x: z.string(), total_bonus_y: z.string(), total_deposit_sol: z.string(), total_deposit_usd: z.string(), total_deposit_x: z.string(), total_deposit_x_sol: z.string(), total_deposit_x_usd: z.string(), total_deposit_y: z.string(), total_deposit_y_sol: z.string(), total_deposit_y_usd: z.string(), total_orders: z.number().int().gte(0), total_withdrawal_sol: z.string(), total_withdrawal_usd: z.string(), total_withdrawal_x: z.string(), total_withdrawal_x_sol: z.string(), total_withdrawal_x_usd: z.string(), total_withdrawal_y: z.string(), total_withdrawal_y_sol: z.string(), total_withdrawal_y_usd: z.string()})), page_size: z.number().int().gte(0), pages: z.number().int().gte(0), total: z.number().int().gte(0)}); 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 }; /** * Get Open Limit Order Pools * * GET /wallets/{wallet}/limit_orders/open/pools */ export const getApiWalletsWalletLimitOrdersOpenPools = async (args: GetApiWalletsWalletLimitOrdersOpenPoolsArgs, options?: GetApiWalletsWalletLimitOrdersOpenPoolsOptions) => { const {baseUrl = "https://damm-api.meteora.ag", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) const url = `${baseUrl.replace(/\/+$/, '')}/wallets/${encodeURIComponent(String(args.wallet))}/limit_orders/open/pools${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(paginationResponseOpenLimitOrderPoolSummary, await res.json()) };