import {z} from 'zod' export type GetApiCoinsMintInsightsArgs = {mint: string}; export type GetApiCoinsMintInsightsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const coinInsights = z.object({address: z.string().optional(), decimals: z.number().int().optional(), symbol: z.string().optional(), name: z.string().optional(), marketCap: z.number(), fdv: z.number(), extensions: z.object({coingeckoId: z.string().optional(), description: z.string().optional(), twitter: z.string().optional(), website: z.string().optional(), discord: z.string().optional()}).optional(), liquidity: z.number(), lastTradeUnixTime: z.number().int(), lastTradeHumanTime: z.string(), price: z.number(), history24hPrice: z.number(), priceChange24hPercent: z.number(), uniqueWallet24h: z.number().int(), uniqueWalletHistory24h: z.number().int(), uniqueWallet24hChangePercent: z.number(), totalSupply: z.number(), circulatingSupply: z.number(), holder: z.number().int(), trade24h: z.number().int(), tradeHistory24h: z.number().int(), trade24hChangePercent: z.number(), sell24h: z.number().int(), sellHistory24h: z.number().int(), sell24hChangePercent: z.number(), buy24h: z.number().int(), buyHistory24h: z.number().int(), buy24hChangePercent: z.number(), v24h: z.number(), v24hUSD: z.number(), vHistory24h: z.number(), vHistory24hUSD: z.number().optional(), v24hChangePercent: z.number().optional(), vBuy24h: z.number().optional(), vBuy24hUSD: z.number().optional(), vBuyHistory24h: z.number().optional(), vBuyHistory24hUSD: z.number().optional(), vBuy24hChangePercent: z.number().optional(), vSell24h: z.number().optional(), vSell24hUSD: z.number().optional(), vSellHistory24h: z.number().optional(), vSellHistory24hUSD: z.number().optional(), vSell24hChangePercent: z.number().optional(), numberMarkets: z.number().int().optional(), totalVolume: z.number(), totalVolumeUSD: z.number(), volumeBuy: z.number(), volumeBuyUSD: z.number(), volumeSell: z.number(), volumeSellUSD: z.number(), totalTrade: z.number().int(), buy: z.number().int(), sell: z.number().int(), dynamicBondingCurve: z.object({address: z.string(), price: z.number(), priceUSD: z.number(), curveProgress: z.number(), isMigrated: z.boolean().optional(), creatorQuoteFee: z.number(), totalTradingQuoteFee: z.number(), creatorWalletAddress: z.string()})}); export const coinInsightsResponse = z.object({data: coinInsights.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 }; /** * Gets insights about a specific coin by its mint address * * GET /coins/{mint}/insights */ export const getApiCoinsMintInsights = async (args: GetApiCoinsMintInsightsArgs, options: GetApiCoinsMintInsightsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/coins/${encodeURIComponent(String(args.mint))}/insights${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(coinInsightsResponse, await res.json()) };