import {z} from 'zod' export type EthAddressSchema = string; export type TronAddressBasic = string; export type SolanaAddress = string; export type StellarMuxedAddress = string; export type From = string; export type GetApiDepositAddressesDepositAddressDepositChainHistoryArgs = {depositAddress: EthAddressSchema | TronAddressBasic | SolanaAddress | StellarMuxedAddress, depositChain: string, from?: From | undefined, to?: From | undefined}; export type GetApiDepositAddressesDepositAddressDepositChainHistoryOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const nonEmptyString = z.string().min(1); export const amountWithDecimals = z.string(); export const bigDecimalFromNumber = z.number(); export const bigInt = z.string(); export const dateTimeUtc = z.string(); export const depositAddressBridgeFailedApi = z.object({_id: nonEmptyString, tokenSymbol: nonEmptyString, tokenAddress: nonEmptyString, amount: amountWithDecimals, amountUsd: bigDecimalFromNumber, amountWei: bigInt, sender: nonEmptyString, txHash: nonEmptyString, originalErrorTag: nonEmptyString.optional(), createdAt: dateTimeUtc, _tag: z.literal("failed")}); export const nonNegativeInt = z.number().int().gte(0); export const depositAddressBridgeRejectedApi = z.object({_id: nonEmptyString, tokenSymbol: nonEmptyString, tokenAddress: nonEmptyString, amount: amountWithDecimals, amountUsd: bigDecimalFromNumber, amountWei: bigInt, sender: z.string(), txHash: z.string(), originalErrorTag: nonEmptyString.optional(), originalErrorJson: z.string().optional(), reason: z.enum(["OVER_MAX", "UNDER_MIN", "OPERATION_UNAVAILABLE", "TERMINAL_PROCESSING_ISSUE", "NO_ROUTE_FOUND", "UNSUPPORTED_TOKEN", "SDA_PAUSED"]), txUid: nonEmptyString, createdAt: dateTimeUtc, blockNumber: nonNegativeInt.optional(), _tag: z.literal("rejected")}); export const bigDecimalFromString = z.string(); export const bigDecimal = z.string(); export const dateFromString = z.string(); 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 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 int = z.number().int(); export const depositAddressBridgeAcceptedApi = z.object({_id: nonEmptyString, tokenSymbol: nonEmptyString, tokenAddress: nonEmptyString, amount: amountWithDecimals, amountUsd: bigDecimalFromNumber, amountWei: bigInt, sender: nonEmptyString, txHash: nonEmptyString, history: z.union([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().optional(), preSwap: swapQuote.optional(), postSwap: swapQuote.optional(), state: z.literal("PENDING")}), 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().optional(), preSwap: swapQuote.optional(), postSwap: swapQuote.optional(), depositTxHash: z.string(), depositDiscoveredAt: dateFromString, expectedDepositConfirmedAt: dateFromString, expectedDepositConfirmedAtBlock: int, state: z.literal("PENDING_CONFIRMATION")}), 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().optional(), 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(), failedAt: dateFromString, state: z.literal("FAILED")}), 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().optional(), 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(), state: z.literal("DEPOSIT_ACCEPTED")}), 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().optional(), 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(), state: z.literal("ACCEPTED")}), 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")})]), createdAt: dateTimeUtc, _tag: z.literal("accepted")}); export const depositAddressHistoryResponse = z.object({depositAddress: z.string().min(1), depositChain: z.string().min(1), bridges: z.array(z.union([depositAddressBridgeFailedApi, depositAddressBridgeRejectedApi, depositAddressBridgeAcceptedApi]))}); 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 deposit address history * * GET /deposit-addresses/{depositAddress}/{depositChain}/history * * Also accepts auth: legacyApiKey */ export const getApiDepositAddressesDepositAddressDepositChainHistory = async (args: GetApiDepositAddressesDepositAddressDepositChainHistoryArgs, options?: GetApiDepositAddressesDepositAddressDepositChainHistoryOptions) => { 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 (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/deposit-addresses/${encodeURIComponent(String(args.depositAddress))}/${encodeURIComponent(String(args.depositChain))}/history${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(depositAddressHistoryResponse, await res.json()) };