//#region extensions/crypto/src/services/tx-ledger.d.ts /** * Event-Sourced Transaction Ledger — append-only log of every on-chain action. * * Inspired by Lemon's event-sourced game engine and IronClaw's audit boundary. * * Every on-chain action the agent takes (swap, transfer, bridge, approve, launch, * etc.) is recorded as an immutable event. The ledger provides: * * 1. Complete audit trail for regulatory/tax purposes * 2. Foundation for heartbeat monitoring (knows all open positions) * 3. Replay capability — can reconstruct portfolio state from events * 4. Cross-session continuity — survives restarts * * Events are append-only: once written, they are never modified or deleted. * Each event gets a monotonically increasing sequence number. */ type TxEventType = 'swap' | 'transfer' | 'bridge' | 'approve' | 'launch' | 'claim_fees' | 'add_liquidity' | 'remove_liquidity' | 'compound_action' | 'bankr_swap' | 'bankr_launch' | 'bankr_automate' | 'bankr_polymarket' | 'bankr_leverage' | 'permit2' | 'lend_supply' | 'lend_borrow' | 'lend_repay' | 'lend_withdraw' | 'approval_revoke' | 'stake' | 'stake_unstake' | 'stake_wrap' | 'stake_unwrap' | 'nft_transfer' | 'nft_buy' | 'nft_list' | 'privacy_deposit' | 'privacy_withdraw' | 'privacy_transfer' | 'yield_deposit' | 'yield_withdraw' | 'governance_vote' | 'governance_delegate' | 'safe_propose' | 'safe_confirm' | 'airdrop_check' | 'airdrop_claim' | 'order_create' | 'order_cancel' | 'hummingbot_action' | 'molten_action' | 'clawnx_post' | 'unknown'; interface TxEvent { /** Monotonically increasing sequence number (assigned by ledger). */ seq: number; /** Event type. */ type: TxEventType; /** ISO-8601 timestamp. */ timestamp: string; /** Unix timestamp in ms. */ timestampMs: number; /** User/session that triggered this action. */ userId: string; /** On-chain transaction hash (null if tx hasn't been submitted yet). */ txHash: string | null; /** Chain ID. */ chainId: number; /** Chain name (base, ethereum, arbitrum, etc.). */ chain: string; /** Wallet address that signed the tx. */ from: string; /** Target contract/address. */ to: string | null; /** Status of the action. */ status: 'pending' | 'confirmed' | 'failed' | 'cancelled'; /** Human-readable summary (e.g., "Swap 1.5 ETH → 4200 USDC on Base"). */ summary: string; /** Structured payload — differs per event type. */ data: Record; /** Gas cost in USD (filled after confirmation). */ gasCostUsd?: number; /** Tool that generated this event. */ tool: string; /** Error message if the action failed. */ error?: string; } interface LedgerQuery { /** Filter by user ID. */ userId?: string; /** Filter by event type(s). */ types?: TxEventType[]; /** Filter by chain ID. */ chainId?: number; /** Filter by status. */ status?: TxEvent['status']; /** Only events after this timestamp (ms). */ afterMs?: number; /** Only events before this timestamp (ms). */ beforeMs?: number; /** Max number of events to return (most recent first). */ limit?: number; /** Starting sequence number (for pagination). */ afterSeq?: number; } interface LedgerStats { totalEvents: number; byType: Record; byStatus: Record; byChain: Record; oldestEventMs: number | null; newestEventMs: number | null; } /** * Map defi_lend action names to specific event types. * Used by the lending tool to record granular events. */ declare const LEND_ACTION_EVENT_MAP: Record; /** * Map defi_stake action names to specific event types. */ declare const STAKE_ACTION_EVENT_MAP: Record; /** * Map nft action names to specific event types. */ declare const NFT_ACTION_EVENT_MAP: Record; /** * Map privacy action names to specific event types. */ declare const PRIVACY_ACTION_EVENT_MAP: Record; /** * Map yield action names to specific event types. */ declare const YIELD_ACTION_EVENT_MAP: Record; /** * Map governance action names to specific event types. */ declare const GOVERNANCE_ACTION_EVENT_MAP: Record; /** * Map safe action names to specific event types. * Safe operations are off-chain (REST API) but recorded for audit trail. */ declare const SAFE_ACTION_EVENT_MAP: Record; /** * Map airdrop action names to specific event types. */ declare const AIRDROP_ACTION_EVENT_MAP: Record; /** * Map manage_orders action names to specific event types. */ declare const ORDER_ACTION_EVENT_MAP: Record; declare function toolToEventType(toolName: string): TxEventType; declare function chainIdToName(chainId: number): string; declare class TxLedger { private events; private nextSeq; private dirty; private readonly ledgerPath; constructor(); /** * Append a new event to the ledger. Returns the assigned sequence number. */ append(event: Omit): TxEvent; /** * Update the status of an existing event (e.g., pending → confirmed). * This is the ONLY mutation allowed — and it creates a new event rather * than modifying the original, preserving the append-only invariant. */ updateStatus(seq: number, status: TxEvent['status'], updates?: { txHash?: string; gasCostUsd?: number; error?: string; }): TxEvent | null; /** * Query events with optional filters. Returns newest-first. */ query(q?: LedgerQuery): TxEvent[]; /** * Get a single event by sequence number. */ getBySeq(seq: number): TxEvent | null; /** * Get the most recent event for a given tx hash. */ getByTxHash(txHash: string): TxEvent | null; /** * Get aggregate statistics. */ getStats(): LedgerStats; /** * Get the total number of events. */ get size(): number; private getLedgerPath; private loadFromDisk; private persistAppend; } declare function getTxLedger(): TxLedger; declare function resetTxLedger(): void; //#endregion export { AIRDROP_ACTION_EVENT_MAP, GOVERNANCE_ACTION_EVENT_MAP, LEND_ACTION_EVENT_MAP, LedgerQuery, LedgerStats, NFT_ACTION_EVENT_MAP, ORDER_ACTION_EVENT_MAP, PRIVACY_ACTION_EVENT_MAP, SAFE_ACTION_EVENT_MAP, STAKE_ACTION_EVENT_MAP, TxEvent, TxEventType, YIELD_ACTION_EVENT_MAP, chainIdToName, getTxLedger, resetTxLedger, toolToEventType }; //# sourceMappingURL=tx-ledger.d.mts.map