import { SwapQuote } from '../types/index.js'; import { CLOBClient } from './clob.js'; import { Result } from '../utils/result.js'; /** Router address and lowercase maker addresses it forwards to. */ export interface RfqTargets { router: string | null; allowed: Set; } export interface RfqSwapResult { txHash: string; operation: string; /** Contract `simpleSwap` was sent to: the router (`tx.to`) or `order.maker`. */ target: string; maker: string; } export interface RfqApprovalResult { approved: boolean; txHash?: string; amount?: bigint; allowance?: bigint; spender: string; token: string; operation: string; } export declare class SwapClient extends CLOBClient { rfqPairs: Record; /** Resolve a chain name or id string to a numeric chain ID for RFQ routing. */ protected _resolveChainIdResult(chainIdentifier: number | string): Result; /** * Normalize a Dexalot firm-quote response. * * The HTTP response wraps the executable firm quote inside * `{"success": true, "quote": {...}}`. This helper unwraps that * envelope so downstream code operates on the inner dict, then * applies snake_case → camelCase aliases for top-level * identifiers and normalizes the inner `order` dict. * * Original keys are preserved; nothing is popped or renamed. * Envelope-layer failures (`{"success": false, "reason": ...}`) * are caught at the fetch site in `_getSwapQuoteBase` BEFORE the * transform runs, so this method never sees them. */ private _transformQuoteFromAPI; /** * Transform order data object fields to camelCase aliases. The * original snake_case keys are preserved alongside the aliases * so callers reading either shape continue to work. */ private _transformOrderDataFromAPI; /** * Get available swap pairs for a specific chain. * Cached for 15 minutes (semi-static data). * @param chainIdentifier Numeric chain ID or chain display name. */ getSwapPairs(chainIdentifier: number | string): Promise>; /** * Shared implementation for firm and soft quotes. Public callers use * `getSwapFirmQuote` / `getSwapSoftQuote`; this helper centralizes * pair resolution, parameter packing, envelope unwrap, and error * sanitization so the two public surfaces stay aligned. */ private _getSwapQuoteBase; /** * Get a firm quote for swap execution. */ getSwapFirmQuote(fromToken: string, toToken: string, amount: number, chainId?: number): Promise>; /** * Get an indicative (soft) quote. */ getSwapSoftQuote(fromToken: string, toToken: string, amount: number, chainId?: number): Promise>; _resolvePair(from: string, to: string, chainId: number): Promise<{ name: string; tradeSide: number; isBase: boolean; } | null>; /** * Coerce an order field to bigint, accepting decimal or 0x-hex * strings. `nonceAndMeta` arrives 0x-prefixed; `makerAmount` / * `takerAmount` arrive as decimal strings; `expiry` arrives as a * JSON number. `BigInt()` itself accepts both 0x-hex and decimal * representations so a single call covers all of them. */ protected _orderFieldToBigInt(value: unknown): bigint; /** * Compute the `msg.value` to attach to a SimpleSwap call. * * MainnetRFQ requires `msg.value == takerAmount` when the taker * is sending the chain's native token (`takerAsset` is the zero * address), and `msg.value == 0` otherwise. Passing the wrong * value here causes the contract's `_checkValue` to revert. */ protected _computeMsgValue(orderData: any): bigint; /** * Best-effort extraction of the on-chain revert reason for a * failed tx. Re-runs the original transaction as `eth_call` * against the block in which it reverted; the node returns the * revert message (e.g. `execution reverted: RF-EXP-01`) which is * otherwise dropped from the receipt. Returns `null` if the call * cannot be replayed or the node refuses to surface a reason. */ protected _extractRevertReason(provider: any, tx: any, receipt: any): Promise; /** * Execute an RFQ swap using a firm quote. * * Accepts either the inner firm-quote dict (with top-level * `signature` and `order` fields) or the raw envelope from * the firm-quote API (`{"success": true, "quote": {...}}`) — * the envelope is unwrapped automatically. */ executeRFQSwap(quote: any, waitForReceipt?: boolean): Promise>; /** * Grant the quote's maker contract an ERC20 allowance for the taker asset. * * Firm quotes are served by several maker contracts and each one pulls * the taker asset with `transferFrom` itself, so the allowance has to * be granted to `order.maker` — approving the router or the legacy * MainnetRFQ address does nothing for a quote from another maker. * Call this before `executeRFQSwap` when selling an ERC20 token. * * The maker is validated against the router's on-chain allow-list * before any approval is sent. Native-asset sells need no allowance * and are rejected. * * @param quote Firm quote (or its `{success, quote}` envelope). * @param amountWei Allowance to grant in base units; defaults to the * quote's `takerAmount`. * @param waitForReceipt Block until the approval is mined. * @returns `approved=false` with the current `allowance` when nothing * had to be sent, or `approved=true` with the approval `txHash`. */ approveRfqMaker(quote: any, amountWei?: bigint, waitForReceipt?: boolean): Promise>; /** * Discover the RFQ router and the maker contracts it forwards to. * * The router address comes from the deployments endpoint * (`DexalotRouter` for the chain) when the backend publishes it, and * otherwise from `trustedForwarder()` on the deployments (legacy * MainnetRFQ) contract. The allowed makers always come from * `getAllowedRFQs()` on that router — the API does not list them and * the router's own allow-list is what it enforces. The deployments * address is always part of the allowed set. * * Cached in the static tier (1h) per API base URL and deployment * address. Lookup failures are not cached and degrade to * `{ router: null, allowed: {deployment} }` — the legacy behaviour — * so a quote from another maker is refused rather than sent to the * wrong contract. */ protected _getRfqTargets(chainName: string, deploymentAddress: string): Promise; /** * Pick and validate the contract `simpleSwap` must be sent to. * * `order.maker` must be on the router's allow-list (or be the * deployments address). If the quote carries `tx.to` it must be the * router or the maker; it is then used as the target so the call * follows the API's own routing. Otherwise the maker is called directly. */ protected _resolveRfqExecutionTarget(chainName: string, deploymentAddress: string, quote: any, orderData: any): Promise>; /** * Cross-check the API's `tx` envelope against the call the SDK encodes. * The SDK always builds the calldata itself; the envelope is only used * to detect disagreement. Returns an error message when `tx.data` or * `tx.value` are present and differ, `null` otherwise. */ protected _checkTxEnvelope(quote: any, orderTuple: unknown[], sig: string, msgValue: bigint): string | null; /** ABI-encode `simpleSwap(order, signature)` calldata. */ protected _encodeSimpleSwap(orderTuple: unknown[], sig: string): string; /** `allowance(owner, spender)` of an ERC20 token in base units. */ protected _getErc20Allowance(chainName: string, token: string, owner: string, spender: string): Promise; /** Compact `key=value` trail appended to swap errors for diagnosis. */ protected _rfqErrorContext(quote: any, orderData: any, target: string): string; /** `Transaction reverted: ...` message for a failed receipt, or `null` on success. */ protected _describeReceiptFailure(provider: any, tx: any, receipt: any): Promise; } //# sourceMappingURL=swap.d.ts.map