import {z} from 'zod' export type GetApiApiOrdersOrderIdArgs = {orderId: string}; export type GetApiApiOrdersOrderIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; 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 addressPropertyDTO = z.object({Base64Value: z.string().nullable().optional(), bytesArrayValue: z.string().nullable().optional(), stringValue: z.string().nullable().optional()}); 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 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 offerWithMetadataDTO = z.object({chainId: intPropertyDTO.optional(), tokenAddress: addressPropertyDTO.optional(), amount: intPropertyDTO.optional(), finalAmount: intPropertyDTO.optional(), metadata: metadataDTO.optional(), decimals: z.number().int().optional(), name: z.string().nullable().optional(), symbol: z.string().nullable().optional(), logoURI: z.string().nullable().optional()}); export const orderState = z.enum(["None", "Created", "Fulfilled", "SentUnlock", "OrderCancelled", "SentOrderCancel", "ClaimedUnlock", "ClaimedOrderCancel"]); export const externalCallState = z.enum(["NoExtCall", "AwaitingOrderFulfillment", "AwaitingExecution", "Executing", "Completed", "Failed", "Cancelled", "OrderCancelled"]); export const affiliateFeeDTO = z.object({beneficiarySrc: addressPropertyDTO.optional(), amount: intPropertyDTO.optional()}); export const transactionMetadataDTO = z.object({transactionHash: transactionHashPropertyDto.optional(), blockNumber: z.number().int().optional(), blockHash: z.union([stringPropertyDTO, transactionHashPropertyDto]).nullable().optional(), blockTimeStamp: z.number().int().optional(), initiator: addressPropertyDTO.optional()}); export const orderEventDTO = z.object({transactionMetadata: transactionMetadataDTO.optional(), submissionId: z.union([stringPropertyDTO, transactionHashPropertyDto]).nullable().optional()}); export const swapExecutedEventDTO = z.object({chainId: intPropertyDTO.optional(), inTokenAddress: addressPropertyDTO.optional(), inAmount: intPropertyDTO.optional(), tokenInMetadata: metadataDTO.optional(), tokenInLogoURI: z.string().nullable().optional(), outTokenAddress: addressPropertyDTO.optional(), outAmount: intPropertyDTO.optional(), tokenOutMetadata: metadataDTO.optional(), tokenOutLogoURI: z.string().nullable().optional()}); export const orderRawMetadataDTO = z.object({}); export const orderParsedMetadataDTO = z.object({}); export const orderDTO = z.object({orderId: z.union([stringPropertyDTO, transactionHashPropertyDto]).nullable().optional(), makerOrderNonce: z.number().int().optional(), makerSrc: addressPropertyDTO.optional(), giveOfferWithMetadata: offerWithMetadataDTO.optional(), receiverDst: addressPropertyDTO.optional(), takeOfferWithMetadata: offerWithMetadataDTO.optional(), givePatchAuthoritySrc: addressPropertyDTO.optional(), orderAuthorityAddressDst: addressPropertyDTO.optional(), allowedTakerDst: addressPropertyDTO.optional(), allowedCancelBeneficiarySrc: addressPropertyDTO.optional(), state: orderState.optional(), externalCallState: externalCallState.optional(), referralCode: z.number().int().optional(), percentFee: intPropertyDTO.optional(), finalPercentFee: intPropertyDTO.optional(), fixFee: intPropertyDTO.optional(), unlockBeneficiarySrc: addressPropertyDTO.optional(), cancelBeneficiarySrc: addressPropertyDTO.optional(), taker: addressPropertyDTO.optional(), unlockAuthorityDst: addressPropertyDTO.optional(), affiliateFee: affiliateFeeDTO.optional(), createdSrcEventMetadata: transactionMetadataDTO.optional(), fulfilledDstEventMetadata: transactionMetadataDTO.optional(), sentUnlockDstEventInfo: orderEventDTO.optional(), claimedUnlockSrcEventInfo: orderEventDTO.optional(), orderCancelledDstEventMetadata: transactionMetadataDTO.optional(), sentOrderCancelDstEventInfo: orderEventDTO.optional(), claimedOrderCancelSrcEventInfo: orderEventDTO.optional(), preswapData: swapExecutedEventDTO.optional(), externalCallData: z.union([stringPropertyDTO, transactionHashPropertyDto]).nullable().optional(), orderMetadata: z.union([orderRawMetadataDTO, orderParsedMetadataDTO]).nullable().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 order by events by orderId * * GET /api/Orders/{orderId} */ export const getApiApiOrdersOrderId = async (args: GetApiApiOrdersOrderIdArgs, options?: GetApiApiOrdersOrderIdOptions) => { 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/Orders/${encodeURIComponent(String(args.orderId))}${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(orderDTO, await res.json()) };