import {z} from 'zod' export type GetApiDefiV3TokenExitLiquidityArgs = {'x-chain'?: 'base' | undefined, address: string}; export type GetApiDefiV3TokenExitLiquidityOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const defiTokenExitLiquidityObject = z.object({token: z.string(), exit_liquidity: z.number(), liquidity: z.number(), price: z.object({value: z.number(), update_unix_time: z.number().int(), update_human_time: z.string(), update_in_slot: z.number().int()}), currency: z.string(), address: z.string(), name: z.string(), symbol: z.string(), decimals: z.string(), extensions: z.object({}), logo_uri: z.string()}); export const defiTokenExitLiquidityResponse = z.object({success: z.boolean(), data: defiTokenExitLiquidityObject}); 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 }; /** * Token - Liquidity (Single) * * GET /defi/v3/token/exit-liquidity */ export const getApiDefiV3TokenExitLiquidity = async (args: GetApiDefiV3TokenExitLiquidityArgs, options?: GetApiDefiV3TokenExitLiquidityOptions) => { const {baseUrl = "https://public-api.birdeye.so", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-chain'] != null) headers.set("x-chain", String(args['x-chain'])) if (args.address != null) query.append("address", String(args.address)) if (apiKeyAuth !== undefined) headers.set("X-API-KEY", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/defi/v3/token/exit-liquidity${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(defiTokenExitLiquidityResponse, await res.json()) };