import {z} from 'zod' export type GetApiApiV1WormholeAssetsSecuredTokensOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const statsTokenType = z.enum(["NATIVE_TOKEN_TRANSFER", "PORTAL_TOKEN_BRIDGE"]); export const statsTokenInfoDTO = z.object({circulating_supply: z.number().optional(), coingecko_id: z.string().optional(), fully_diluted_valuation: z.number().optional(), image: z.string().optional(), market_cap: z.number().optional(), platforms: z.record(z.string(), z.string()).optional(), price: z.number().optional(), symbol: z.string().optional(), total_supply: z.number().optional(), total_value_locked: z.number().optional(), total_value_transferred: z.number().optional(), type: statsTokenType.optional(), volume_15d: z.number().optional(), volume_1y: z.number().optional(), volume_24h: z.number().optional(), volume_30d: z.number().optional(), volume_7d: z.number().optional(), volume_90d: z.number().optional()}); export const getApiApiV1WormholeAssetsSecuredTokensResponse = z.array(statsTokenInfoDTO); 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 }; /** * Returns a list of tokens secured by Wormhole, including Native Token Transfers and Portal Bridge tokens * * GET /api/v1/wormhole/assets/secured-tokens */ export const getApiApiV1WormholeAssetsSecuredTokens = async (options: GetApiApiV1WormholeAssetsSecuredTokensOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/wormhole/assets/secured-tokens${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(getApiApiV1WormholeAssetsSecuredTokensResponse, await res.json()) };