import {z} from 'zod' export type GetApiProfileAssetsArgs = {assets?: Array | undefined, full_names?: Array | undefined, page_size?: number | undefined, paging_from?: ('start' | 'end') | undefined, next_page_token?: string | undefined, pretty?: boolean | undefined}; export type GetApiProfileAssetsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const assetId = z.string(); export const assetProfileFullName = z.string(); export const assetProfileDescription = z.string(); export const assetProfileOverview = z.string(); export const assetProfileTokenPurpose = z.string(); export const assetProfileProjectTeam = z.string(); export const assetProfileFoundation = z.string(); export const assetProfileWebsiteUrl = z.string(); export const assetProfileWhitepaperUrl = z.string(); export const assetProfileCreationDate = z.string(); export const assetProfileTokenGenerationEventSupply = z.string(); export const assetProfileSupplyCap = z.string(); export const assetProfileInitialSupplyAllocation = z.string(); export const assetProfileInitialSupplyDistribution = z.string(); export const assetProfileInitialSupplyProjectDistribution = z.object({initial_supply_allocation: assetProfileInitialSupplyAllocation.optional(), initial_supply_distribution: assetProfileInitialSupplyDistribution.optional()}); export const assetProfileVestingScheduleAllocation = z.string(); export const assetProfileVestingScheduleCliff = z.string(); export const assetProfileVestingScheduleTotalUnlockTime = z.string(); export const assetProfileVestingSchedule = z.object({vesting_schedule_allocation: assetProfileVestingScheduleAllocation.optional(), vesting_schedule_cliff: assetProfileVestingScheduleCliff.optional(), vesting_schedule_total_unlock_time: assetProfileVestingScheduleTotalUnlockTime.optional()}); export const assetProfileNewTokenIssuanceRecipient = z.string(); export const assetProfileIssuingNetwork = z.string(); export const assetProfileBridgedNetwork = z.string(); export const assetProfileIssuanceScheduleChanges = z.string(); export const assetProfileSignificantHistoricalChangesDate = z.string(); export const assetProfileSignificantHistoricalChangesDetails = z.string(); export const assetProfileSignificantHistoricalChanges = z.object({date: assetProfileSignificantHistoricalChangesDate.optional(), details: assetProfileSignificantHistoricalChangesDetails.optional()}); export const assetProfileUpgradeHistoryDate = z.string(); export const assetProfileUpgradeHistoryDetails = z.string(); export const assetProfileUpgradeHistory = z.object({date: assetProfileUpgradeHistoryDate.optional(), details: assetProfileUpgradeHistoryDetails.optional()}); export const assetProfileBlogUpdates = z.string(); export const profileRepository = z.string(); export const assetProfileAssetRegulation = z.string(); export const assetProfileAssetRegulatedProduct = z.string(); export const assetProfileEtpCustodian = z.string(); export const assetProfileInfo = z.object({asset: assetId, full_name: assetProfileFullName, description: assetProfileDescription, overview: assetProfileOverview, token_purpose: z.array(assetProfileTokenPurpose).optional(), project_team: assetProfileProjectTeam.optional(), foundation: assetProfileFoundation.optional(), website: assetProfileWebsiteUrl.optional(), whitepaper_url: assetProfileWhitepaperUrl.optional(), creation_date: assetProfileCreationDate, token_generation_event_supply: assetProfileTokenGenerationEventSupply.optional(), supply_cap: assetProfileSupplyCap.optional(), initial_supply_token_distribution: z.array(assetProfileInitialSupplyProjectDistribution).optional(), vesting_schedule: z.array(assetProfileVestingSchedule).optional(), new_token_issuance_recipient: z.array(assetProfileNewTokenIssuanceRecipient).optional(), issuing_networks: z.array(assetProfileIssuingNetwork).optional(), bridged_networks: z.array(assetProfileBridgedNetwork).optional(), issuance_schedule_changes: assetProfileIssuanceScheduleChanges.optional(), significant_historical_changes: z.array(assetProfileSignificantHistoricalChanges).optional(), upgrade_history: z.array(assetProfileUpgradeHistory).optional(), blog_updates: assetProfileBlogUpdates.optional(), project_github_repository: z.array(profileRepository).optional(), asset_regulation: assetProfileAssetRegulation.optional(), asset_regulated_products: z.array(assetProfileAssetRegulatedProduct).optional(), etp_custodians: z.array(assetProfileEtpCustodian).optional()}); export const nextPageToken = z.string(); export const nextPageUrl = z.string(); export const assetProfilesResponse = z.object({data: z.array(assetProfileInfo), next_page_token: nextPageToken.optional(), next_page_url: nextPageUrl.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 }; /** * Asset profiles data (experimental) * * GET /profile/assets */ export const getApiProfileAssets = async (args: GetApiProfileAssetsArgs, options?: GetApiProfileAssetsOptions) => { const {baseUrl = "https://api.coinmetrics.io/v4", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.assets != null) query.append("assets", args.assets.join(',')) if (args.full_names != null) query.append("full_names", args.full_names.join(',')) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.paging_from != null) query.append("paging_from", String(args.paging_from)) if (args.next_page_token != null) query.append("next_page_token", String(args.next_page_token)) if (args.pretty != null) query.append("pretty", String(args.pretty)) if (apiKey !== undefined) query.set("api_key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/profile/assets${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(assetProfilesResponse, await res.json()) };