/** * Heartbeat — condition-driven wake scheduler. * * NOT a dumb timer that tells the agent to "maybe do something." * Instead: periodically checks on-chain conditions and only wakes * the agent when there's something genuinely actionable. * * The check itself is cheap (a few RPC reads, no txs). The agent * run is expensive (inference + potential txs). So we gate the * expensive part behind the cheap check. * * Wake conditions: * 1. Fees are profitable to claim (WETH fees > gas cost + threshold) * 2. Survival danger (ETH low, but fees exist to claim) * 3. Operational runway < 24h * 4. Bunker runtime expiring / threat escalation * 5. Conditional order triggered * 6. XMTP messages received * 7. Analytics signal (strong_buy / strong_sell) * 8. Idle capital above reserve + threshold (yield deployment) * 9. Scheduled: periodic self-reflection (every 24h) * 10. Contract upgrade detected (Herd — every 4h, checks factory/hook/locker) * 11. Counterparty activity spike (Herd — checks active trade counterparties) */ import type { ClawtomatonConfig } from '../types.js'; import type { ClawtomatonAgent } from '../agent/index.js'; export declare class Heartbeat { private timer; private agent; private config; private market; private bunkerClient; private lastRunTime; private lastReflectionTime; private lastThreatCheckTime; private lastAnalyticsCheckTime; private lastIdleCapitalCheckTime; private lastHerdUpgradeCheckTime; private lastHerdCounterpartyCheckTime; private herdIntelligence; private currentThrottleMultiplier; constructor(agent: ClawtomatonAgent, config: ClawtomatonConfig); /** * Lazily initialize HerdIntelligence. * Returns null if HERD_ACCESS_TOKEN is not set — Herd checks will be skipped. */ private getHerd; /** * Start the heartbeat loop. */ start(): void; stop(): void; /** * Check conditions. Only wake the agent if something is actionable. */ private check; /** * Record a portfolio snapshot and update drawdown tracking. * Called on each heartbeat cycle that gets past the condition checks. */ private recordPortfolioSnapshot; /** * Check conditional orders against the current on-chain price. * If any orders trigger, return wake=true with the triggered orders. * * This is cheap: reads price from the already-available snapshot data, * then does a pure in-memory comparison against stored orders. */ private checkOrderTriggers; /** * Check XMTP inbox for unread messages. * Drains the message queue — messages are included in the wake prompt. */ private checkXmtpInbox; /** * Check if there's idle capital that could be deployed to yield. * Rate-limited to once per IDLE_CAPITAL_CHECK_INTERVAL_MS (4h default). * Gated behind config.autonomy.idleCapital. * * Logic: * surplus = ethBalance - reserve - threshold * If surplus > 0, query Wayfinder for best yield pools. */ private checkIdleCapital; /** * Fetch best yield pools from Wayfinder, formatted for the agent prompt. */ private fetchYieldPools; /** * Recompute the earning-adjusted throttle multiplier. * If 7-day net earnings are negative, the heartbeat slows down. */ private updateEarningThrottle; /** * Check analytics signals for the agent's token. * Rate-limited to avoid expensive operations on every heartbeat. * Gated behind config.autonomy.analyticsWake. */ private checkAnalyticsSignal; /** * Check for contract upgrades on key Clawncher contracts via Herd. * Rate-limited to once per HERD_UPGRADE_CHECK_INTERVAL_MS (4h). * Only runs if HERD_ACCESS_TOKEN is set. * * Checks: factory, feeLocker, and hook contracts. * If any have been upgraded since last check, wakes the agent. */ private checkHerdUpgrades; /** * Check counterparty wallet activity via Herd. * Rate-limited to once per HERD_COUNTERPARTY_CHECK_INTERVAL_MS (1h). * Only runs if HERD_ACCESS_TOKEN is set and there are active counterparties. * * "Active counterparties" are wallets the agent has recent interactions with, * tracked via the state store's trade records. */ private checkHerdCounterparty; /** * Check bunker-specific wake conditions: * 1. Runtime expiring within BUNKER_EXPIRY_WARN_HOURS * 2. Threat level escalation * * Returns { wake: false } if bunker is not configured. */ private checkBunkerConditions; } //# sourceMappingURL=index.d.ts.map