import type { ExchangeAdapter, ExchangeMarketInfo, ExchangePosition, ExchangeOrder, ExchangeBalance, ExchangeTrade, ExchangeFundingPayment, ExchangeKline } from "./interface.js"; import type { EvmSigner } from "../signer/index.js"; import type { AgentMeta } from "../settings.js"; import type { WasmSignerClient as WasmSignerClientType } from "lighter-ts-sdk"; /** Lighter trigger orderType enum (matches WASM signer). */ export declare const LIGHTER_ORDER_TYPE: { readonly STOP_LOSS: 2; readonly STOP_LOSS_LIMIT: 3; readonly TAKE_PROFIT: 4; readonly TAKE_PROFIT_LIMIT: 5; }; export type LighterTriggerOrderType = typeof LIGHTER_ORDER_TYPE.STOP_LOSS | typeof LIGHTER_ORDER_TYPE.STOP_LOSS_LIMIT | typeof LIGHTER_ORDER_TYPE.TAKE_PROFIT | typeof LIGHTER_ORDER_TYPE.TAKE_PROFIT_LIMIT; /** * Pick Lighter trigger orderType from side, trigger price, and current mark. * * STOP_LOSS protects against adverse moves; TAKE_PROFIT locks in favorable moves. * buy + trigger >= mark → STOP_LOSS (close short on rise / breakout entry) * buy + trigger < mark → TAKE_PROFIT (close short on fall) * sell + trigger <= mark → STOP_LOSS (close long on fall) * sell + trigger > mark → TAKE_PROFIT (close long on rise) * * Tied trigger==mark is classified as STOP_LOSS — the protective default. */ export declare function classifyTriggerOrderType(side: "buy" | "sell", triggerPrice: number, markPrice: number, isMarket: boolean): LighterTriggerOrderType; export declare class LighterAdapter implements ExchangeAdapter { readonly name = "lighter"; readonly chain = "ethereum"; readonly aliases: readonly ["lt"]; private _signer; private _accountIndex; private _apiKeyIndex; private _address; private _marketMap; private _marketDecimals; private _clientOrderCounter; private _evmKey; private _apiKey; private _accountIndexInit; private _baseUrl; private _chainId; private _testnet; private _readOnly; private _evmSigner?; private _marketsCache; private _marketsCacheTime; private static readonly CACHE_TTL; /** Tier 1 metadata (Phase 2d). When set + not expired + !_useNoAgent, agent * apiKeyIndex/publicKey/accountIndex take priority over master/PK env. */ private _agentMeta?; /** Tier 1 secp256k1 hex private key (40 bytes) for the agent slot. Lighter * has no OWS curve binding for raw L2 keys; this is held in-memory only when * passed by the caller (e.g. immediately after `setupApiKey()` or via env). */ private _agentApiKey?; /** --no-agent bypass flag. */ private _useNoAgent; /** * @param evmKey EVM private key (0x-prefixed, 32 bytes) — for deposits & key registration * @param testnet Use testnet (chain ID 300) instead of mainnet (chain ID 304) * @param opts Optional: apiKey (40-byte Lighter signing key), accountIndex */ constructor(evmKey: string, testnet?: boolean, opts?: { apiKey?: string; accountIndex?: number; apiKeyIndex?: number; }); get signer(): { createAuthToken(deadline: number): Promise<{ authToken: string; }>; } & WasmSignerClientType; get accountIndex(): number; get address(): string; /** @internal — evmKey is intentionally not exposed publicly for security */ get isReadOnly(): boolean; /** Inject an external EVM signer. Call before init() to skip LocalEvmSigner creation. */ setSigner(signer: EvmSigner): void; /** * Tier 1: inject a Lighter agent's slot+L2 key (Phase 2d). * * Caller supplies the AgentMeta (settings.agents.lighter[name]) plus the * 40-byte L2 private key (hex). Adapter swaps `_apiKey`/`_apiKeyIndex` to * the agent's slot/key so all subsequent `signCreateOrder`/`signCancelOrder` * etc. flow through the agent identity. * * NOTE: when the agent path is active, `_address` (master EVM) is left * unchanged because Lighter REST queries (account, balance, positions) use * `account_index` not address. The L1 EVM identity is irrelevant for the * hot-path; only the L2 secp256k1 key is consulted. */ setAgentSigner(meta: AgentMeta, agentApiKey: string): void; /** Bypass Tier 1 (agent) — used for `--no-agent` flag. */ setNoAgent(noAgent: boolean): void; /** Which signer tier is currently active (for debug/diagnostics). */ get activeSignerTier(): "agent" | "master" | "pk" | null; /** * Resolve the active signer tier across three tiers (Phase 2d). * * Tier 1 (agent): active when AgentMeta + agent L2 key set, not expired, * and `--no-agent` NOT set. The actual swap of `_apiKeyIndex`/`_apiKey` * happens in `init()` (or via `_activateAgentTier()` post-init). * Tier 2 (master): active when an OWS master EVM signer was injected via * `setSigner()`. Used for the L1 ChangePubKey path (auto-setup at slot 4). * Tier 3 (pk): active when constructor was supplied an evmKey. Same role * as Tier 2 — signs L1 ChangePubKey for auto-setup. * * Lighter is unique among the 4 DEXs in that the actual order-signing is * always done by the L2 secp256k1 key (`_apiKey`), regardless of tier. The * tiers differ in WHICH L2 key is loaded: Tier 1 uses the agent's slot/key * from AgentMeta; Tier 2/3 use whatever the env/auto-setup produced. */ private _resolveSigner; init(): Promise; /** Populate marketMap + decimals from /orderBooks API (safe to call multiple times) */ private _refreshMarketMap; getMarketIndex(symbol: string): number; /** Ensure market map is populated; lazy-refresh if empty */ private ensureMarketMap; private getMarkPrice; private toTicks; getMarkets(): Promise; private fetchAccount; getOrderbook(symbol: string): Promise<{ bids: [string, string][]; asks: [string, string][]; }>; getBalance(): Promise; getPositions(): Promise; private getAuthToken; private restGetAuth; getOpenOrders(): Promise; marketOrder(symbol: string, side: "buy" | "sell", size: string, opts?: { reduceOnly?: boolean; }): Promise; limitOrder(symbol: string, side: "buy" | "sell", price: string, size: string, opts?: { reduceOnly?: boolean; tif?: string; }): Promise; cancelOrder(symbol: string, orderId: string): Promise; cancelAllOrders(symbol?: string): Promise; modifyOrder(symbol: string, orderId: string, price: string, size: string): Promise; stopOrder(symbol: string, side: "buy" | "sell", size: string, triggerPrice: string, opts?: { limitPrice?: string; reduceOnly?: boolean; }): Promise; updateLeverage(symbol: string, leverage: number, marginMode?: "cross" | "isolated"): Promise; withdraw(amount: string, destination: string, opts?: { assetId?: number; routeType?: number; }): Promise; private _withdrawRaw; editOrder(symbol: string, orderId: string, price: string, size: string): Promise; setLeverage(symbol: string, leverage: number, marginMode?: "cross" | "isolated"): Promise; getRecentTrades(symbol: string, limit?: number): Promise; getFundingHistory(symbol: string, limit?: number): Promise<{ time: number; rate: string; price: string | null; }[]>; getKlines(symbol: string, interval: string, startTime: number, endTime: number): Promise; getOrderHistory(limit?: number): Promise; getTradeHistory(limit?: number): Promise; getFundingPayments(limit?: number): Promise; /** * Get funding rates for all markets. * API: GET /api/v1/funding-rates */ getFundingRates(): Promise>; /** * Get candle data for a market. */ getCandles(symbol: string, resolution: string, startTime: number, endTime: number, countBack?: number): Promise; /** * Get order history (inactive orders) — raw response. */ private _getOrderHistoryRaw; /** * Get trade history — raw response. */ private _getTradeHistoryRaw; /** * Get position funding history — raw response. */ private _getPositionFundingRaw; /** * Get PnL chart data. */ getPnl(period?: string): Promise; /** * Get deposit history. */ getDepositHistory(): Promise; /** * Get withdrawal history. */ getWithdrawHistory(): Promise; /** * Get transfer history. */ getTransferHistory(): Promise; /** * Get asset details. */ getAssetDetails(assetId?: number): Promise; /** * Get exchange metrics. */ getExchangeMetrics(symbol?: string): Promise; /** * Get account limits. */ getAccountLimits(): Promise; /** * Create CCTP intent address for cross-chain deposit. */ createIntentAddress(chainId: number): Promise; /** * Use a referral code. */ useReferralCode(code: string): Promise; /** * Direct REST GET helper. */ private getNextNonce; private signOrder; private sendTx; private restGet; /** Generate a unique client order index (uint48). */ private nextClientOrderIndex; private ensureSigner; private static _wasmClient; private static getWasmClient; /** * Generate a new Lighter API key pair using the WASM signer. * Returns { privateKey, publicKey } (both 0x-prefixed, 40 bytes). */ static generateApiKey(): Promise<{ privateKey: string; publicKey: string; }>; /** * Generate an API key and register it on-chain via ChangePubKey. * Uses WASM signer to sign + ETH key for L1 signature. * Returns the generated key pair. */ setupApiKey(apiKeyIndex?: number): Promise<{ privateKey: string; publicKey: string; }>; }