import {z} from 'zod' export type IbcOriginAssetsRequest = {assets?: (Array<{denom?: string | undefined, chain_id?: string | undefined}>) | undefined}; export type CreateApiV2FungibleIbcOriginAssetsArgs = {body: IbcOriginAssetsRequest}; export type CreateApiV2FungibleIbcOriginAssetsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const asset = z.object({denom: z.string(), chain_id: z.string(), origin_denom: z.string(), origin_chain_id: z.string(), trace: z.string(), is_cw20: z.boolean(), is_evm: z.boolean(), is_svm: z.boolean(), symbol: z.string().nullable().optional(), name: z.string().nullable().optional(), logo_uri: z.string().nullable().optional(), decimals: z.number().nullable().optional(), token_contract: z.string().nullable().optional(), description: z.string().nullable().optional(), coingecko_id: z.string().nullable().optional(), recommended_symbol: z.string().nullable().optional()}); export const optionalAsset = z.object({asset: asset.optional(), asset_found: z.boolean().optional()}); export const createApiV2FungibleIbcOriginAssetsResponse = z.object({origin_assets: z.array(optionalAsset).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 origin assets from a given list of denoms and chain IDs. * * POST /v2/fungible/ibc_origin_assets */ export const createApiV2FungibleIbcOriginAssets = async (args: CreateApiV2FungibleIbcOriginAssetsArgs, options?: CreateApiV2FungibleIbcOriginAssetsOptions) => { const {baseUrl = "https://api.skip.build", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/fungible/ibc_origin_assets${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV2FungibleIbcOriginAssetsResponse, await res.json()) };