import {z} from 'zod' export type GetApiApiV1RelayersRelayerIdArgs = {relayer_id: string}; export type GetApiApiV1RelayersRelayerIdOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const maskedRpcConfig = z.object({url: z.string(), weight: z.number().int().gte(0).lte(100)}); export const disabledReason = z.union([z.object({details: z.string(), type: z.literal("NonceSyncFailed")}), z.object({details: z.string(), type: z.literal("RpcValidationFailed")}), z.object({details: z.string(), type: z.literal("BalanceCheckFailed")}), z.object({details: z.string(), type: z.literal("SequenceSyncFailed")}), z.object({details: z.array(z.string()), type: z.literal("Multiple")})]); export const relayerNetworkType = z.enum(["evm", "solana", "stellar"]); export const evmPolicyResponse = z.object({eip1559_pricing: z.boolean().optional(), gas_limit_estimation: z.boolean().optional(), gas_price_cap: z.number().int().gte(0).optional(), include_revert_data: z.boolean().optional(), min_balance: z.number().int().gte(0).optional(), private_transactions: z.boolean().optional(), whitelist_receivers: z.array(z.string()).optional()}); export const stellarTokenKind = z.union([z.literal("native"), z.object({classic: z.object({code: z.string(), issuer: z.string()})}), z.object({contract: z.object({contract_id: z.string()})})]); export const stellarTokenMetadata = z.object({canonical_asset_id: z.string(), decimals: z.number().int().gte(0), kind: stellarTokenKind}); export const stellarAllowedTokensSwapConfig = z.object({max_amount: z.number().int().gte(0).optional(), min_amount: z.number().int().gte(0).optional(), retain_min_amount: z.number().int().gte(0).optional(), slippage_percentage: z.number().optional()}); export const stellarAllowedTokensPolicy = z.object({asset: z.string(), max_allowed_fee: z.number().int().gte(0).optional(), metadata: stellarTokenMetadata.optional(), swap_config: stellarAllowedTokensSwapConfig.optional()}); export const stellarFeePaymentStrategy = z.enum(["user", "relayer"]); export const stellarSwapStrategy = z.enum(["order-book", "soroswap"]); export const relayerStellarSwapConfig = z.object({cron_schedule: z.string().optional(), min_balance_threshold: z.number().int().gte(0).optional(), strategies: z.array(stellarSwapStrategy).optional()}); export const stellarPolicyResponse = z.object({allowed_tokens: z.array(stellarAllowedTokensPolicy).optional(), concurrent_transactions: z.boolean().optional(), fee_margin_percentage: z.number().optional(), fee_payment_strategy: stellarFeePaymentStrategy.optional(), max_fee: z.number().int().gte(0).optional(), min_balance: z.number().int().gte(0).optional(), slippage_percentage: z.number().optional(), swap_config: relayerStellarSwapConfig.optional(), timeout_seconds: z.number().int().gte(0).optional()}); export const solanaAllowedTokensSwapConfig = z.object({max_amount: z.number().int().gte(0).optional(), min_amount: z.number().int().gte(0).optional(), retain_min_amount: z.number().int().gte(0).optional(), slippage_percentage: z.number().optional()}); export const solanaAllowedTokensPolicy = z.object({decimals: z.number().int().gte(0).optional(), max_allowed_fee: z.number().int().gte(0).optional(), mint: z.string(), swap_config: solanaAllowedTokensSwapConfig.optional(), symbol: z.string().optional()}); export const solanaFeePaymentStrategy = z.enum(["user", "relayer"]); export const jupiterSwapOptions = z.object({dynamic_compute_unit_limit: z.boolean().optional(), priority_fee_max_lamports: z.number().int().gte(0).optional(), priority_level: z.string().optional()}); export const solanaSwapStrategy = z.enum(["jupiter-swap", "jupiter-ultra", "noop"]); export const relayerSolanaSwapConfig = z.object({cron_schedule: z.string().optional(), jupiter_swap_options: jupiterSwapOptions.optional(), min_balance_threshold: z.number().int().gte(0).optional(), strategy: solanaSwapStrategy.optional()}); export const solanaPolicyResponse = z.object({allowed_accounts: z.array(z.string()).optional(), allowed_programs: z.array(z.string()).optional(), allowed_tokens: z.array(solanaAllowedTokensPolicy).optional(), disallowed_accounts: z.array(z.string()).optional(), fee_margin_percentage: z.number().optional(), fee_payment_strategy: solanaFeePaymentStrategy.optional(), max_allowed_fee_lamports: z.number().int().gte(0).optional(), max_signatures: z.number().int().gte(0).optional(), max_tx_data_size: z.number().int().gte(0).optional(), min_balance: z.number().int().gte(0).optional(), swap_config: relayerSolanaSwapConfig.optional()}); export const relayerNetworkPolicyResponse = z.union([evmPolicyResponse, stellarPolicyResponse, solanaPolicyResponse]); export const logLevel = z.enum(["log", "info", "error", "warn", "debug", "result"]); export const logEntry = z.object({level: logLevel, message: z.string()}); export const pluginMetadata = z.object({logs: z.array(logEntry).nullable().optional(), traces: z.array(z.unknown()).nullable().optional()}); export const paginationMeta = z.object({current_page: z.number().int().gte(0), per_page: z.number().int().gte(0), total_items: z.number().int().gte(0)}); export const apiResponseRelayerResponse = z.object({data: z.object({address: z.string().optional(), custom_rpc_urls: z.array(maskedRpcConfig).optional(), disabled_reason: disabledReason.optional(), id: z.string(), name: z.string(), network: z.string(), network_type: relayerNetworkType, notification_id: z.string().optional(), paused: z.boolean(), policies: relayerNetworkPolicyResponse.optional(), signer_id: z.string(), system_disabled: z.boolean().optional()}).optional(), error: z.string().optional(), metadata: pluginMetadata.optional(), pagination: paginationMeta.optional(), success: z.boolean()}); 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 }; /** * Retrieves details of a specific relayer by ID. * * GET /api/v1/relayers/{relayer_id} */ export const getApiApiV1RelayersRelayerId = async (args: GetApiApiV1RelayersRelayerIdArgs, options: GetApiApiV1RelayersRelayerIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/relayers/${encodeURIComponent(String(args.relayer_id))}${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(apiResponseRelayerResponse, await res.json()) };