import {z} from 'zod' export type GetApiDeployerWalletArgs = {wallet: string, page?: number | undefined, limit?: number | undefined, launchpad?: string | undefined, format?: 'full' | undefined}; export type GetApiDeployerWalletOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const deployerToken = z.object({name: z.string().optional(), symbol: z.string().optional(), mint: z.string().optional(), image: z.string().optional(), decimals: z.number().int().optional(), hasSocials: z.boolean().optional(), poolAddress: z.string().optional(), liquidityUsd: z.number().optional(), marketCapUsd: z.number().optional(), priceUsd: z.number().optional(), lpBurn: z.number().int().optional(), market: z.string().optional(), freezeAuthority: z.string().nullable().optional(), mintAuthority: z.string().nullable().optional(), createdAt: z.number().int().optional(), lastUpdated: z.number().int().optional(), holders: z.number().int().optional(), launchpad: z.object({name: z.string().optional(), url: z.string().optional(), logo: z.string().optional(), curvePercentage: z.number().optional(), fee: z.number().optional()}).optional(), buys: z.number().int().optional(), sells: z.number().int().optional(), totalTransactions: z.number().int().optional(), volume: z.number().optional(), volume_5m: z.number().optional(), volume_15m: z.number().optional(), volume_30m: z.number().optional(), volume_1h: z.number().optional(), volume_6h: z.number().optional(), volume_12h: z.number().optional(), volume_24h: z.number().optional(), top10: z.number().optional(), dev: z.number().optional(), insiders: z.number().optional(), snipers: z.number().optional(), bundlers: z.object({count: z.number().int().optional(), balance: z.number().optional(), percentage: z.number().optional()}).optional(), riskScore: z.number().int().optional(), socials: z.object({twitter: z.string().optional(), website: z.string().optional(), telegram: z.string().optional(), discord: z.string().optional(), facebook: z.string().optional(), instagram: z.string().optional(), youtube: z.string().optional(), reddit: z.string().optional(), tiktok: z.string().optional(), github: z.string().optional()}).optional(), tokenDetails: z.object({creator: z.string().optional(), tx: z.string().optional(), time: z.number().int().optional()}).optional(), creator: z.string().optional()}); export const deployerTokensResponse = z.object({total: z.number().int().optional(), tokens: z.array(deployerToken).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 }; /** * Get Tokens by Deployer * * GET /deployer/{wallet} */ export const getApiDeployerWallet = async (args: GetApiDeployerWalletArgs, options?: GetApiDeployerWalletOptions) => { const {baseUrl = "https://data.solanatracker.io", fetch: fetchFn = fetch, apiKey} = 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.limit != null) query.append("limit", String(args.limit)) if (args.launchpad != null) query.append("launchpad", String(args.launchpad)) if (args.format != null) query.append("format", String(args.format)) if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/deployer/${encodeURIComponent(String(args.wallet))}${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(deployerTokensResponse, await res.json()) };