import {z} from 'zod' export type GetApiHistoryBridgeByWithdrawHashWithdrawTxHashArgs = {withdrawTxHash: string}; export type GetApiHistoryBridgeByWithdrawHashWithdrawTxHashOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const bigDecimalFromString = z.string(); export const bigDecimalFromNumber = z.number(); export const bigDecimal = z.string(); export const dateFromString = z.string(); export const nonNegativeInt = z.number().int().gte(0); export const extendedPostBridgeData = z.object({_tag: z.literal("extended"), vaultId: nonNegativeInt}); export const starkwareBtcfiCampaignPostBridgeData = z.object({_tag: z.literal("starkwarebtcfi")}); export const wirexWrapPostBridgeData = z.object({_tag: z.literal("wirexwrap")}); export const wirexWrapSandboxPostBridgeData = z.object({_tag: z.literal("wirexwrapsandbox")}); export const starknetFelt = z.string(); export const starkwareBtcfiCampaignV2PostBridgeData = z.object({_tag: z.literal("starkwarebtcfiv2"), spans: z.array(starknetFelt)}); export const aaveV3SupplyPostBridgeData = z.object({_tag: z.literal("aavev3supply")}); export const rocketFoundationDepositPostBridgeData = z.object({_tag: z.literal("rocketfoundationdeposit")}); export const mapleDepositPostBridgeData = z.object({_tag: z.literal("mapledeposit")}); export const int = z.number().int(); export const swapQuote = z.object({tokenIn: z.string(), tokenOut: z.string(), amountIn: bigDecimalFromString, amountInUsd: bigDecimalFromNumber, amountOut: bigDecimalFromString, amountOutUsd: bigDecimalFromNumber, minAmountOut: bigDecimalFromString, minAmountOutUsd: bigDecimalFromNumber, aggregator: z.union([z.literal("KYBERSWAP"), z.literal("RHINO"), z.literal("ONEINCH"), z.literal("BEBOP")])}); export const getApiHistoryBridgeByWithdrawHashWithdrawTxHashResponse = z.union([z.object({_id: z.string(), userId: z.string(), chainIn: z.string(), chainOut: z.string(), amountIn: bigDecimalFromString, amountInUsd: bigDecimalFromNumber, amountOut: bigDecimalFromString, amountOutUsd: bigDecimalFromNumber, amountNative: bigDecimalFromString.nullable(), amountNativeUsd: bigDecimalFromNumber.nullable(), fee: bigDecimal, feeUsd: bigDecimalFromNumber, gasFee: bigDecimalFromString, gasFeeUsd: bigDecimalFromNumber, platformFee: bigDecimal, platformFeeUsd: bigDecimalFromNumber, percentageFee: bigDecimal, percentageFeeUsd: bigDecimalFromNumber, sourceGasFee: bigDecimalFromString, sourceGasFeeUsd: bigDecimalFromNumber, sponsoredFees: z.object({fee: bigDecimal, feeUsd: bigDecimalFromNumber, gasFee: bigDecimalFromString, gasFeeUsd: bigDecimalFromNumber, platformFee: bigDecimal, platformFeeUsd: bigDecimalFromNumber, percentageFee: bigDecimal, percentageFeeUsd: bigDecimalFromNumber, sourceGasFee: bigDecimalFromString, sourceGasFeeUsd: bigDecimalFromNumber}), recipient: z.string(), depositor: z.string(), createdAt: dateFromString, commitmentDate: dateFromString, speed: z.enum(["fast", "standard", "slow"]).optional(), estimatedDuration: z.number().gte(0).optional(), postBridgeData: z.union([extendedPostBridgeData, starkwareBtcfiCampaignPostBridgeData, wirexWrapPostBridgeData, wirexWrapSandboxPostBridgeData, starkwareBtcfiCampaignV2PostBridgeData, aaveV3SupplyPostBridgeData, rocketFoundationDepositPostBridgeData, mapleDepositPostBridgeData]).optional(), flowCredits: bigDecimalFromNumber.optional(), token: z.string(), usdPrice: bigDecimalFromNumber, _tag: z.literal("bridge").optional(), depositTxHash: z.string(), depositCommittedAt: dateFromString, depositDiscoveredAt: dateFromString.optional(), depositConfirmedAt: dateFromString.optional(), expectedDepositConfirmedAt: dateFromString.optional(), expectedDepositConfirmedAtBlock: int.optional(), preSwapTxHash: z.string().optional(), preSwapCommittedAt: dateFromString.optional(), isConfirmed: z.boolean().optional(), withdrawTxHash: z.string(), withdrawCommittedAt: dateFromString, state: z.literal("EXECUTED")}), z.object({_tag: z.literal("bridgeSwap"), _id: z.string(), userId: z.string(), chainIn: z.string(), chainOut: z.string(), amountIn: bigDecimalFromString, amountInUsd: bigDecimalFromNumber, amountOut: bigDecimalFromString, amountOutUsd: bigDecimalFromNumber, amountNative: bigDecimalFromString.nullable(), amountNativeUsd: bigDecimalFromNumber.nullable(), fee: bigDecimal, feeUsd: bigDecimalFromNumber, gasFee: bigDecimalFromString, gasFeeUsd: bigDecimalFromNumber, platformFee: bigDecimal, platformFeeUsd: bigDecimalFromNumber, percentageFee: bigDecimal, percentageFeeUsd: bigDecimalFromNumber, sourceGasFee: bigDecimalFromString, sourceGasFeeUsd: bigDecimalFromNumber, sponsoredFees: z.object({fee: bigDecimal, feeUsd: bigDecimalFromNumber, gasFee: bigDecimalFromString, gasFeeUsd: bigDecimalFromNumber, platformFee: bigDecimal, platformFeeUsd: bigDecimalFromNumber, percentageFee: bigDecimal, percentageFeeUsd: bigDecimalFromNumber, sourceGasFee: bigDecimalFromString, sourceGasFeeUsd: bigDecimalFromNumber}), recipient: z.string(), depositor: z.string(), createdAt: dateFromString, commitmentDate: dateFromString, speed: z.enum(["fast", "standard", "slow"]).optional(), estimatedDuration: z.number().gte(0).optional(), postBridgeData: z.union([extendedPostBridgeData, starkwareBtcfiCampaignPostBridgeData, wirexWrapPostBridgeData, wirexWrapSandboxPostBridgeData, starkwareBtcfiCampaignV2PostBridgeData, aaveV3SupplyPostBridgeData, rocketFoundationDepositPostBridgeData, mapleDepositPostBridgeData]).optional(), flowCredits: bigDecimalFromNumber.optional(), tokenIn: z.string(), tokenOut: z.string(), minAmountOut: bigDecimalFromString, minAmountOutUsd: bigDecimalFromNumber, usdPriceTokenIn: bigDecimalFromNumber, usdPriceTokenOut: bigDecimalFromNumber, preSwap: swapQuote.optional(), postSwap: swapQuote.optional(), mode: z.enum(["pay", "receive"]).optional(), isAtomicSwap: z.boolean().optional(), swapFeeMultiplier: bigDecimal.optional(), depositTxHash: z.string(), depositCommittedAt: dateFromString, depositDiscoveredAt: dateFromString.optional(), depositConfirmedAt: dateFromString.optional(), expectedDepositConfirmedAt: dateFromString.optional(), expectedDepositConfirmedAtBlock: int.optional(), preSwapTxHash: z.string().optional(), preSwapCommittedAt: dateFromString.optional(), isConfirmed: z.boolean().optional(), withdrawTxHash: z.string(), withdrawCommittedAt: dateFromString, state: z.literal("EXECUTED")}), z.object({_tag: z.literal("depositAddressBridge"), _id: z.string(), userId: z.string(), chainIn: z.string(), chainOut: z.string(), amountIn: bigDecimalFromString, amountInUsd: bigDecimalFromNumber, amountOut: bigDecimalFromString, amountOutUsd: bigDecimalFromNumber, amountNative: bigDecimalFromString.nullable(), amountNativeUsd: bigDecimalFromNumber.nullable(), fee: bigDecimal, feeUsd: bigDecimalFromNumber, gasFee: bigDecimalFromString, gasFeeUsd: bigDecimalFromNumber, platformFee: bigDecimal, platformFeeUsd: bigDecimalFromNumber, percentageFee: bigDecimal, percentageFeeUsd: bigDecimalFromNumber, sourceGasFee: bigDecimalFromString, sourceGasFeeUsd: bigDecimalFromNumber, sponsoredFees: z.object({fee: bigDecimal, feeUsd: bigDecimalFromNumber, gasFee: bigDecimalFromString, gasFeeUsd: bigDecimalFromNumber, platformFee: bigDecimal, platformFeeUsd: bigDecimalFromNumber, percentageFee: bigDecimal, percentageFeeUsd: bigDecimalFromNumber, sourceGasFee: bigDecimalFromString, sourceGasFeeUsd: bigDecimalFromNumber}), recipient: z.string(), depositor: z.string(), createdAt: dateFromString, commitmentDate: dateFromString, speed: z.enum(["fast", "standard", "slow"]).optional(), estimatedDuration: z.number().gte(0).optional(), postBridgeData: z.union([extendedPostBridgeData, starkwareBtcfiCampaignPostBridgeData, wirexWrapPostBridgeData, wirexWrapSandboxPostBridgeData, starkwareBtcfiCampaignV2PostBridgeData, aaveV3SupplyPostBridgeData, rocketFoundationDepositPostBridgeData, mapleDepositPostBridgeData]).optional(), flowCredits: bigDecimalFromNumber.optional(), token: z.string(), tokenOut: z.string().optional(), usdPrice: bigDecimalFromNumber, depositAddress: z.string(), preSwap: swapQuote.optional(), postSwap: swapQuote.optional(), depositTxHash: z.string(), depositCommittedAt: dateFromString, depositDiscoveredAt: dateFromString.optional(), depositConfirmedAt: dateFromString.optional(), expectedDepositConfirmedAt: dateFromString.optional(), expectedDepositConfirmedAtBlock: int.optional(), preSwapTxHash: z.string().optional(), preSwapCommittedAt: dateFromString.optional(), isConfirmed: z.boolean().optional(), withdrawTxHash: z.string(), withdrawCommittedAt: dateFromString, state: z.literal("EXECUTED")})]); 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 }; /** * Bridge Status (Withdraw Hash) * * GET /history/bridge/by-withdraw-hash/{withdrawTxHash} * * Also accepts auth: legacyApiKey */ export const getApiHistoryBridgeByWithdrawHashWithdrawTxHash = async (args: GetApiHistoryBridgeByWithdrawHashWithdrawTxHashArgs, options?: GetApiHistoryBridgeByWithdrawHashWithdrawTxHashOptions) => { const {baseUrl = "https://api.rhino.fi/bridge", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/history/bridge/by-withdraw-hash/${encodeURIComponent(String(args.withdrawTxHash))}${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(getApiHistoryBridgeByWithdrawHashWithdrawTxHashResponse, await res.json()) };