import {z} from 'zod' export type GetApiTokenV1HolderProfileArgs = {'x-chain'?: 'solana' | undefined, token_address: string, interval?: '1h' | undefined, ui_amount_mode?: ('scaled' | 'raw') | undefined, include_zero_balance?: boolean | undefined}; export type GetApiTokenV1HolderProfileOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const tokenHolderProfileResponse = z.object({success: z.boolean(), data: z.object({token: z.object({creation_time: z.number().int().optional(), market_cap: z.number().optional(), liquidity: z.number().optional(), volume_1h: z.number().optional(), volume_1h_usd: z.number().optional(), buy_volume_1h: z.number().optional(), buy_volume_1h_usd: z.number().optional(), sell_volume_1h: z.number().optional(), sell_volume_1h_usd: z.number().optional(), is_scaled_ui_token: z.boolean().optional(), top10_holder: z.object({hold_amount: z.string().optional(), percent_of_supply: z.number().optional()}).optional()}).optional(), holder_summary: z.object({total_holder: z.number().int().optional(), total_holding: z.number().optional(), percent_of_supply: z.number().optional()}).optional(), tags: z.array(z.object({tag: z.enum(["bundler", "sniper", "insider", "dev", "smart_trader"]).optional(), holder_count: z.number().int().optional(), hold_amount: z.string().optional(), percent_of_supply: z.number().optional(), buy_volume: z.string().optional(), sell_volume: z.string().optional(), buy_volume_usd: z.string().optional(), sell_volume_usd: z.string().optional(), avg_buy_price: z.string().optional(), pnl: z.string().optional()})).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 }; /** * Token - Holder Profile * * GET /token/v1/holder-profile */ export const getApiTokenV1HolderProfile = async (args: GetApiTokenV1HolderProfileArgs, options?: GetApiTokenV1HolderProfileOptions) => { 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.token_address != null) query.append("token_address", String(args.token_address)) if (args.interval != null) query.append("interval", String(args.interval)) if (args.ui_amount_mode != null) query.append("ui_amount_mode", String(args.ui_amount_mode)) if (args.include_zero_balance != null) query.append("include_zero_balance", String(args.include_zero_balance)) if (apiKeyAuth !== undefined) headers.set("X-API-KEY", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/token/v1/holder-profile${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(tokenHolderProfileResponse, await res.json()) };