import {z} from 'zod' export type GetApiApiSatisticsTakerAddressLockedAssetsArgs = {takerAddress: string}; export type GetApiApiSatisticsTakerAddressLockedAssetsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const intPropertyDTO = z.object({bytesValue: z.string().nullable().optional(), bytesArrayValue: z.string().nullable().optional(), bigIntegerValue: z.number().nullable().optional(), stringValue: z.string().nullable().optional()}); export const addressPropertyDTO = z.object({Base64Value: z.string().nullable().optional(), bytesArrayValue: z.string().nullable().optional(), stringValue: z.string().nullable().optional()}); export const metadataDTO = z.object({decimals: z.number().int().optional(), name: z.string().nullable().optional(), symbol: z.string().nullable().optional(), logoURI: z.string().nullable().optional()}); export const stringPropertyDTO = z.object({bytesValue: z.string().nullable().optional(), bytesArrayValue: z.string().nullable().optional(), stringValue: z.string().nullable().optional()}); export const transactionHashPropertyDto = z.object({bytesValue: z.string().nullable().optional(), bytesArrayValue: z.string().nullable().optional(), stringValue: z.string().nullable().optional()}); export const dstChainLockedAmountDTO = z.object({targetChainId: intPropertyDTO.optional(), dstChainAmount: z.number().nullable().optional(), dstChainTokenAmount: z.number().nullable().optional(), ordersToUnlock: z.array(z.union([stringPropertyDTO, transactionHashPropertyDto])).nullable().optional()}); export const lockedAssetTokenDTO = z.object({tokenAddress: addressPropertyDTO.optional(), tokenMetadata: metadataDTO.optional(), amount: z.number().optional(), tokenAmount: z.number().nullable().optional(), dstChainsLockedAmounts: z.array(dstChainLockedAmountDTO).nullable().optional()}); export const lockedAssetChainDTO = z.object({chainId: intPropertyDTO.optional(), lockedTokens: z.array(lockedAssetTokenDTO).nullable().optional()}); export const getApiApiSatisticsTakerAddressLockedAssetsResponse = z.array(lockedAssetChainDTO); 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 locked assets statistics for given address * * GET /api/Satistics/{takerAddress}/lockedAssets */ export const getApiApiSatisticsTakerAddressLockedAssets = async (args: GetApiApiSatisticsTakerAddressLockedAssetsArgs, options?: GetApiApiSatisticsTakerAddressLockedAssetsOptions) => { const {baseUrl = "https://dln.debridge.finance", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/Satistics/${encodeURIComponent(String(args.takerAddress))}/lockedAssets${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(getApiApiSatisticsTakerAddressLockedAssetsResponse, await res.json()) };