import {z} from 'zod' export type AssetsBetweenChainsRequest = {source_chain_id?: string | undefined, dest_chain_id?: string | undefined, include_no_metadata_assets?: boolean | undefined, include_cw20_assets?: boolean | undefined, include_evm_assets?: boolean | undefined, allow_multi_tx?: boolean | undefined}; export type CreateApiV2FungibleAssetsBetweenChainsArgs = {body: AssetsBetweenChainsRequest}; export type CreateApiV2FungibleAssetsBetweenChainsOptions = {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 bridgeType = z.enum(["IBC", "AXELAR", "CCTP", "HYPERLANE", "OPINIT", "GO_FAST", "STARGATE", "LAYER_ZERO", "EUREKA"]); export const assetBetweenChains = z.object({asset_on_source: asset.optional(), asset_on_dest: asset.optional(), txs_required: z.number().int(), bridges: z.array(bridgeType).optional()}); export const createApiV2FungibleAssetsBetweenChainsResponse = z.object({assets_between_chains: z.array(assetBetweenChains).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 }; /** * Given 2 chain IDs, returns a list of equivalent assets that can be transferred * * POST /v2/fungible/assets_between_chains */ export const createApiV2FungibleAssetsBetweenChains = async (args: CreateApiV2FungibleAssetsBetweenChainsArgs, options?: CreateApiV2FungibleAssetsBetweenChainsOptions) => { 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/assets_between_chains${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(createApiV2FungibleAssetsBetweenChainsResponse, await res.json()) };