import { Contract, Provider } from 'ethers'; import { TokenBalance, PricePoint, Transfer } from '../types/index.js'; import { SwapClient } from './swap.js'; import { Result } from '../utils/result.js'; export type { PricePoint, Transfer, TransferActionType, TransferBridge, TransferStatus, } from '../types/index.js'; export declare class TransferClient extends SwapClient { /** * Resolve ERC-20 contract address/decimals for a chain from cached token data (no RPC). */ private _resolveErc20TokenInfo; private _resolveQueryAddress; /** * Fetch token metadata keyed by environment (semi-static cache). */ getTokenDetails(token: string): Promise>>; /** * Get portfolio balance for a specific token. */ getPortfolioBalance(token: string, address?: string): Promise>; /** * Estimate bridge fee for a deposit on the source chain (fee returned as native-token float, wei ÷ 1e18). */ getDepositBridgeFee(token: string, amount: number, sourceChain: string): Promise>; /** * Deposit tokens from a mainnet chain to Dexalot. */ deposit(token: string, amount: number, sourceChain: string, useLayerZero?: boolean, waitForReceipt?: boolean): Promise>; /** * Withdraw tokens from Dexalot to a mainnet chain. */ withdraw(token: string, amount: number, destinationChain: string, useLayerZero?: boolean, waitForReceipt?: boolean): Promise>; /** * Transfer tokens within portfolio to another address. */ transferPortfolio(token: string, amount: number, toAddress: string, waitForReceipt?: boolean): Promise>; /** * Transfer tokens from the signer portfolio to another address on Dexalot L1 (`token`, `toAddress`, `amount`). */ transferToken(token: string, toAddress: string, amount: number, waitForReceipt?: boolean): Promise>; /** * Add gas (withdraw native ALOT to wallet). */ addGas(amount: number, waitForReceipt?: boolean): Promise>; /** * Remove gas (deposit native ALOT from wallet). */ removeGas(amount: number, waitForReceipt?: boolean): Promise>; /** * Get wallet balance for a specific token on a specific chain. */ getChainWalletBalance(chain: string, token: string, address?: string): Promise>; /** * Get balances for an explicit list of tokens on one chain. * * Returns a flat `token -> balance` map. The caller specifies exactly * which tokens to read; unknown tokens produce an aggregated error * rather than being silently skipped. Cached for 10 seconds (balance * cache tier); cache keys are order-insensitive — `['AVAX', 'USDC']` * and `['USDC', 'AVAX']` share a cache slot because tokens are * sorted and deduplicated before delegating to the cached internal. */ getChainTokenBalances(chain: string, tokens: string[], address?: string): Promise>>; /** * Cached internal: fetch each requested token's balance in parallel * and aggregate. Sorted+deduped `tokens` keeps the cache key stable * for caller-order variations of the same set. */ private _getChainTokenBalancesCached; /** * Get all token balances on a specific chain. */ getChainWalletBalances(chain: string, address?: string): Promise>; /** * Read the native balance and every ERC20 balance for one connected * chain into `info`. The two reads run as separate `withRpcFailover` * calls so that a native-read failure (after provider failover is * exhausted) is recorded in `info.errors` and the ERC20 reads still * run, and vice versa. */ _collectChainBalances(info: any, chain: string, queryAddress: string): Promise; /** * Get all token balances across all connected chains. */ getAllChainWalletBalances(address?: string): Promise>; /** * Build a balance entry describing a failed lookup. * * `balance` is always `null` on failure; the reason lives in `error`. * Exceptions are sanitized and logged at `warn` (a per-token RPC blip * is tolerated, not fatal). A plain string is used verbatim for * non-exception conditions such as "not connected" and is not logged. */ _balanceErrorEntry(chain: string, symbol: string, kind: string, failure: unknown, context: string, extra?: Record): any; /** * Route one balance entry into `info.chain_balances` (numeric balance) * or `info.errors` (`" : "`), so every balance * in a plural result is numeric. */ _collectBalanceEntry(info: any, entry: any): void; /** * `Result.fail` only when every lookup failed; otherwise `Result.ok` * with partial failures listed in `info.errors`. */ _balancesResult(info: any): Result; _getL1NativeBalance(address: string): Promise; _getNativeBalance(chainName: string, provider: Provider, address: string, nativeSymbol: string): Promise; _getErc20Balance(chainName: string, chainId: number, provider: Provider, address: string, token: string): Promise; _fetchErc20Balances(info: any, chainId: number, chainName: string, provider: Provider, address: string): Promise; /** * Get all portfolio balances. */ getAllPortfolioBalances(address?: string): Promise>>; /** * Resolve token decimals: try subnet chain, then connected chain, default 18. */ _resolveTokenDecimals(token: string): number; _getBridgeId(chainName: string, useLayerZero: boolean): number; _getBridgeFee(portfolioContract: Contract, bridgeId: number, symbolBytes: string, amount: bigint): Promise; _ensureAllowance(token: string, spender: string, amount: bigint, runner?: any): Promise; /** * Unconditionally set ERC20 allowance for `spender` to 0. Used as a * best-effort cleanup when a deposit/withdraw transaction reverts after * `_ensureAllowance` has already granted `MaxUint256` — leaving the * granted allowance in place would expose the user to a stale approval. * Callers wrap this in their own try/catch; secondary failures must be * logged at debug and never override the original transaction error. */ _revokeAllowance(token: string, spender: string, runner?: any): Promise; /** * Coerce a single price value into a finite positive number. Returns * `null` for anything we cannot confidently interpret as a price * (non-string/non-number, empty string, NaN, ±Infinity, negative). * The backend currently emits decimal strings (including scientific * notation e.g. `"1.04662e-7"`), so `parseFloat` is the right primitive * — but we tolerate plain numbers too in case the shape ever flips. */ private _coerceUsdPrice; /** * Fetch current USD prices for every Dexalot-listed token. Public * endpoint, no signed auth required. Cached for 15 minutes (semi-static * tier). * * Returns a `Record` map of token symbol → USD price. * The backend currently emits the map shape directly as * `Record` (string prices, including scientific * notation for very small values); we coerce to `number` and silently * drop entries we cannot interpret. An array-of-objects fallback * (`[{symbol, price}, ...]`) is also accepted in case the backend * shape ever changes. * * The `env` query parameter is forwarded for parity with the Python * SDK and to namespace the cache key per network; the backend itself * currently determines the network from the API host and does not * consult the parameter. */ getTokenUsdPrices(env?: string): Promise>>; /** * Coerce a raw timestamp value (number or numeric string) into unix * seconds. Heuristic: anything ≥ 1e12 is treated as milliseconds and * divided by 1000 (a 32-bit second-precision unix epoch maxes out at * `2^31 ≈ 2.1e9`, so 1e12 is a safe boundary that catches both * `Date.now()` and 13-digit string forms). Returns `null` if the * input cannot be parsed as a finite non-negative integer. */ private _coerceTimestampSeconds; /** * Coerce a raw price value into a finite non-negative number. Mirrors * `_coerceUsdPrice` above but exposed as a separate helper so future * tightening of the price-history shape (e.g. requiring strictly * positive prices) is local to one branch. */ private _coerceHistoryPrice; /** * Pull a timestamp out of a raw row. The backend currently emits * `date` as an ISO-8601 string; we additionally accept `ts`, * `timestamp`, and `time` (numeric or numeric-string) so the contract * is stable if the shape ever flips. Returns unix seconds (UTC), or * `null` if no recognised field parses. */ private _extractHistoryTimestamp; /** * Shared implementation for daily / hourly USD price history. Public * methods only vary in the REST endpoint constant they pass here, so * the cache key, normalization, sort order, and client-side * `[from, to]` filter are guaranteed to behave identically across * both surfaces. * * Cache: static tier (1h TTL) — past prices don't change. Cache key * includes `path` so daily and hourly never collide on the same slot * even with identical `(token, from, to)` tuples. */ private _fetchPriceHistory; /** * Daily USD price history for one token. Returns an ascending-time * ordered `PricePoint[]` from the public `token-usd-price-history` * endpoint. Past prices don't change, so results are cached in the * static tier (1h TTL); the cache key is path-namespaced so daily * and hourly never collide. * * The optional `from`/`to` window is in unix seconds. The backend * currently ignores it (the host fixes the network and the * lookback) but the SDK forwards both for forward-compat and * additionally filters the returned series client-side so the * caller's range contract holds regardless of backend behavior. * * No authentication required (public endpoint). */ getTokenPriceHistory(token: string, opts?: { from?: number; to?: number; }): Promise>; /** * Hourly USD price history for one token. Same contract as * `getTokenPriceHistory` (ascending-time `PricePoint[]`, static-tier * 1h cache, optional `from`/`to` window applied client-side) but * routes through the hourly endpoint. Useful when a more granular * series is needed than the daily variant — backend currently * returns the trailing ~24h at 3-hour granularity. * * No authentication required (public endpoint). */ getTokenHourlyPriceHistory(token: string, opts?: { from?: number; to?: number; }): Promise>; /** * Coerce a Big-string display-decimal numeric value (e.g. `"100.5"`) * into a finite non-negative `number`. The backend's * `transferscombined` rows ship `quantity` and `fee` as already- * display-decimal numeric strings — there is no wei→human * conversion to apply. Returns `null` for non-string/non-number * input, empty strings, or anything that does not parse to a * finite non-negative float (mirroring how the frontend's * NumberHelper guards against malformed rows). */ private _coerceTransferAmount; /** ISO-8601 string OR numeric/numeric-string -> unix seconds (UTC), or null. */ private _coerceTransferTs; /** * Normalize one raw `DBTransfer`-shaped row from the backend into * the canonical `Transfer` type. Returns `null` for any row that * is missing required fields or carries an unknown * `action_type` / `status` enum — the public method silently * drops these so a single bad row doesn't poison the page. * * `bridge` falls back to `"NATIVE"` for unknown enum values * because the frontend treats unrecognised bridges the same way * (display-only label, no behavior depends on the precise id), * and the row is otherwise valid. */ private _normalizeTransfer; /** * Paginated history of every deposit, withdrawal, gas top-up, * portfolio P2P send/receive, and bridge recovery involving the * connected wallet. Returns canonical `Transfer[]` rows with * camelCase fields and human-readable `actionType` / `status` * / `bridge` labels lifted from the backend's numeric enums. * * Routes through the signed REST endpoint * `/api/trading/signed/transferscombined`; `x-signature` is * attached via the shared `_getAuthHeaders()` helper. The * backend's request shape uses `itemsperpage` / `pageno` / * `periodfrom` / `periodto` / `symbol` query params (NOT the * `limit`/`offset`/`from`/`to`/`kind` shape suggested by a * plan-only reading of the trade-kit tool wrapper) — the * trade-kit's MCP tool forwards `limit`/`offset` blindly but * the actual backend ignores them. * * Cached for 10 seconds (balance tier) per `(address, opts)` * tuple — distinct signers and distinct filter combinations * never share a cache slot. Returned amounts (`quantity`, * `fee`) are already display-decimal numbers; no * wei→human conversion is applied because the backend has * already done it. * * @param opts - Optional ergonomic filters: * - `symbol` — token symbol to filter by; canonicalized via * `normalizeToken` (casing variants and known aliases collapse). * - `fromTs` / `toTs` — inclusive time window as unix **seconds**. * - `limit` — page size (rows per page); defaults to 100. * - `offset` — number of rows to skip; defaults to 0. * * `limit`/`offset` translate to the backend's `itemsperpage` / * `pageno` shape internally (`itemsperpage = max(1, limit)`, * `pageno = floor(offset / itemsperpage) + 1`), and `fromTs`/`toTs` * translate to `periodfrom` / `periodto`. The cache key is built * from the translated values, so equivalent `limit`/`offset` * combinations that map to the same page share a cache slot * (matching the Python SDK). */ getCombinedTransfers(opts?: { symbol?: string; fromTs?: number; toTs?: number; limit?: number; offset?: number; }): Promise>; } //# sourceMappingURL=transfer.d.ts.map