@exagent/agent 0.1.40 → 0.1.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -9,6 +9,24 @@ interface RiskState {
9
9
  dailyFees: number;
10
10
  lastResetDate: string;
11
11
  }
12
+ /** Stuck position detection result */
13
+ interface StuckPosition {
14
+ token: string;
15
+ symbol: string;
16
+ consecutiveFailures: number;
17
+ lastFailureReason: string;
18
+ holdingDurationMs: number;
19
+ estimatedValueUSD: number;
20
+ }
21
+ /** Result of an inferred exit detected during balance sync */
22
+ interface InferredExit {
23
+ token: string;
24
+ symbol: string;
25
+ amountExited: number;
26
+ exitValueUSD: number;
27
+ realizedPnL: number;
28
+ costBasis: number;
29
+ }
12
30
  /**
13
31
  * PositionTracker — automatic position tracking with persistence.
14
32
  *
@@ -25,6 +43,7 @@ declare class PositionTracker {
25
43
  private store;
26
44
  private positions;
27
45
  private tradeHistory;
46
+ private sellFailures;
28
47
  private maxTradeHistory;
29
48
  constructor(store: StrategyStore, options?: {
30
49
  maxTradeHistory?: number;
@@ -55,9 +74,20 @@ declare class PositionTracker {
55
74
  private handleSell;
56
75
  /**
57
76
  * Sync tracked positions with on-chain balances.
58
- * Updates currentAmount, detects new tokens (airdrops), removes zeroed positions.
77
+ * Updates currentAmount, detects new tokens (airdrops), and handles position exits.
78
+ *
79
+ * CRITICAL: When a tracked position's balance decreases without a corresponding
80
+ * sell trade, we infer a manual exit and record it with realized PnL calculated
81
+ * at current market price. This prevents PnL manipulation via off-router sells.
82
+ *
83
+ * Returns array of inferred exits for the runtime to report to Command Center.
84
+ */
85
+ syncBalances(balances: Record<string, bigint>, prices: Record<string, number>): InferredExit[];
86
+ /**
87
+ * Record an inferred exit in trade history.
88
+ * These are exits detected from balance changes, not from tracked sell executions.
59
89
  */
60
- syncBalances(balances: Record<string, bigint>, prices: Record<string, number>): void;
90
+ private recordInferredExit;
61
91
  /** Get all tracked positions (backfills missing symbols from resolver) */
62
92
  getPositions(): TrackedPosition[];
63
93
  /** Get a single position by token address */
@@ -68,6 +98,31 @@ declare class PositionTracker {
68
98
  getUnrealizedPnL(prices: Record<string, number>): Record<string, number>;
69
99
  /** Get total unrealized PnL across all positions */
70
100
  getTotalUnrealizedPnL(prices: Record<string, number>): number;
101
+ /**
102
+ * Record a sell failure for a token. Called when a sell attempt fails
103
+ * due to liquidity issues, route simulation failure, or excessive price impact.
104
+ */
105
+ recordSellFailure(token: string, reason: string): void;
106
+ /**
107
+ * Clear sell failure tracking for a token (called after successful sell).
108
+ */
109
+ clearSellFailure(token: string): void;
110
+ /**
111
+ * Detect positions that are "stuck" — we've tried and failed to sell them
112
+ * multiple times, likely due to insufficient liquidity.
113
+ *
114
+ * Returns positions that have failed to sell >= STUCK_FAILURE_THRESHOLD times.
115
+ */
116
+ getStuckPositions(prices: Record<string, number>): StuckPosition[];
117
+ /**
118
+ * Check if a specific position is stuck.
119
+ */
120
+ isPositionStuck(token: string): boolean;
121
+ /**
122
+ * Check if we should alert about a stuck position (rate-limited to once per 24h).
123
+ * Returns true if we should alert, and marks the alert as sent.
124
+ */
125
+ shouldAlertStuckPosition(token: string): boolean;
71
126
  /** Load persisted risk state */
72
127
  getRiskState(): RiskState;
73
128
  /** Save risk state to persistent store */
@@ -271,29 +326,21 @@ declare const PredictionConfigSchema: z.ZodOptional<z.ZodObject<{
271
326
  maxTotalExposureUSD: number;
272
327
  polygonAllocationUSD: number;
273
328
  feeBridgeThresholdUSD: number;
274
- vault?: {
275
- enabled: boolean;
276
- factoryAddress: string;
277
- isVerified: boolean;
278
- feeRecipient?: string | undefined;
279
- feeCollectorAddress?: string | undefined;
280
- vaultAddress?: string | undefined;
281
- } | undefined;
282
329
  polygonRpcUrl?: string | undefined;
283
330
  clobApiKey?: string | undefined;
284
331
  clobApiSecret?: string | undefined;
285
332
  clobApiPassphrase?: string | undefined;
286
333
  predictionRelayerKey?: string | undefined;
287
334
  allowedCategories?: string[] | undefined;
288
- }, {
289
335
  vault?: {
336
+ enabled: boolean;
290
337
  factoryAddress: string;
338
+ isVerified: boolean;
291
339
  feeRecipient?: string | undefined;
292
- enabled?: boolean | undefined;
293
340
  feeCollectorAddress?: string | undefined;
294
341
  vaultAddress?: string | undefined;
295
- isVerified?: boolean | undefined;
296
342
  } | undefined;
343
+ }, {
297
344
  enabled?: boolean | undefined;
298
345
  maxNotionalUSD?: number | undefined;
299
346
  clobApiUrl?: string | undefined;
@@ -307,6 +354,14 @@ declare const PredictionConfigSchema: z.ZodOptional<z.ZodObject<{
307
354
  polygonAllocationUSD?: number | undefined;
308
355
  allowedCategories?: string[] | undefined;
309
356
  feeBridgeThresholdUSD?: number | undefined;
357
+ vault?: {
358
+ factoryAddress: string;
359
+ feeRecipient?: string | undefined;
360
+ enabled?: boolean | undefined;
361
+ feeCollectorAddress?: string | undefined;
362
+ vaultAddress?: string | undefined;
363
+ isVerified?: boolean | undefined;
364
+ } | undefined;
310
365
  }>>;
311
366
  type PredictionConfig$1 = z.infer<typeof PredictionConfigSchema>;
312
367
  declare const AgentConfigSchema: z.ZodObject<{
@@ -504,29 +559,21 @@ declare const AgentConfigSchema: z.ZodObject<{
504
559
  maxTotalExposureUSD: number;
505
560
  polygonAllocationUSD: number;
506
561
  feeBridgeThresholdUSD: number;
507
- vault?: {
508
- enabled: boolean;
509
- factoryAddress: string;
510
- isVerified: boolean;
511
- feeRecipient?: string | undefined;
512
- feeCollectorAddress?: string | undefined;
513
- vaultAddress?: string | undefined;
514
- } | undefined;
515
562
  polygonRpcUrl?: string | undefined;
516
563
  clobApiKey?: string | undefined;
517
564
  clobApiSecret?: string | undefined;
518
565
  clobApiPassphrase?: string | undefined;
519
566
  predictionRelayerKey?: string | undefined;
520
567
  allowedCategories?: string[] | undefined;
521
- }, {
522
568
  vault?: {
569
+ enabled: boolean;
523
570
  factoryAddress: string;
571
+ isVerified: boolean;
524
572
  feeRecipient?: string | undefined;
525
- enabled?: boolean | undefined;
526
573
  feeCollectorAddress?: string | undefined;
527
574
  vaultAddress?: string | undefined;
528
- isVerified?: boolean | undefined;
529
575
  } | undefined;
576
+ }, {
530
577
  enabled?: boolean | undefined;
531
578
  maxNotionalUSD?: number | undefined;
532
579
  clobApiUrl?: string | undefined;
@@ -540,12 +587,27 @@ declare const AgentConfigSchema: z.ZodObject<{
540
587
  polygonAllocationUSD?: number | undefined;
541
588
  allowedCategories?: string[] | undefined;
542
589
  feeBridgeThresholdUSD?: number | undefined;
590
+ vault?: {
591
+ factoryAddress: string;
592
+ feeRecipient?: string | undefined;
593
+ enabled?: boolean | undefined;
594
+ feeCollectorAddress?: string | undefined;
595
+ vaultAddress?: string | undefined;
596
+ isVerified?: boolean | undefined;
597
+ } | undefined;
543
598
  }>>;
544
599
  allowedTokens: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
545
600
  }, "strip", z.ZodTypeAny, {
546
- agentId: string | number;
547
601
  name: string;
548
602
  network: "mainnet";
603
+ vault: {
604
+ policy: "disabled" | "manual";
605
+ preferVaultTrading: boolean;
606
+ defaultName?: string | undefined;
607
+ defaultSymbol?: string | undefined;
608
+ feeRecipient?: string | undefined;
609
+ };
610
+ agentId: string | number;
549
611
  llm: {
550
612
  provider: "custom" | "openai" | "anthropic" | "google" | "deepseek" | "mistral" | "groq" | "together" | "ollama";
551
613
  temperature: number;
@@ -564,13 +626,6 @@ declare const AgentConfigSchema: z.ZodObject<{
564
626
  maxSlippageBps: number;
565
627
  minTradeValueUSD: number;
566
628
  };
567
- vault: {
568
- policy: "disabled" | "manual";
569
- preferVaultTrading: boolean;
570
- defaultName?: string | undefined;
571
- defaultSymbol?: string | undefined;
572
- feeRecipient?: string | undefined;
573
- };
574
629
  wallet?: {
575
630
  setup: "generate" | "provide";
576
631
  } | undefined;
@@ -598,6 +653,12 @@ declare const AgentConfigSchema: z.ZodObject<{
598
653
  maxTotalExposureUSD: number;
599
654
  polygonAllocationUSD: number;
600
655
  feeBridgeThresholdUSD: number;
656
+ polygonRpcUrl?: string | undefined;
657
+ clobApiKey?: string | undefined;
658
+ clobApiSecret?: string | undefined;
659
+ clobApiPassphrase?: string | undefined;
660
+ predictionRelayerKey?: string | undefined;
661
+ allowedCategories?: string[] | undefined;
601
662
  vault?: {
602
663
  enabled: boolean;
603
664
  factoryAddress: string;
@@ -606,17 +667,11 @@ declare const AgentConfigSchema: z.ZodObject<{
606
667
  feeCollectorAddress?: string | undefined;
607
668
  vaultAddress?: string | undefined;
608
669
  } | undefined;
609
- polygonRpcUrl?: string | undefined;
610
- clobApiKey?: string | undefined;
611
- clobApiSecret?: string | undefined;
612
- clobApiPassphrase?: string | undefined;
613
- predictionRelayerKey?: string | undefined;
614
- allowedCategories?: string[] | undefined;
615
670
  } | undefined;
616
671
  allowedTokens?: string[] | undefined;
617
672
  }, {
618
- agentId: string | number;
619
673
  name: string;
674
+ agentId: string | number;
620
675
  llm: {
621
676
  provider: "custom" | "openai" | "anthropic" | "google" | "deepseek" | "mistral" | "groq" | "together" | "ollama";
622
677
  model?: string | undefined;
@@ -626,6 +681,13 @@ declare const AgentConfigSchema: z.ZodObject<{
626
681
  maxTokens?: number | undefined;
627
682
  };
628
683
  network?: "mainnet" | undefined;
684
+ vault?: {
685
+ policy?: "disabled" | "manual" | undefined;
686
+ defaultName?: string | undefined;
687
+ defaultSymbol?: string | undefined;
688
+ feeRecipient?: string | undefined;
689
+ preferVaultTrading?: boolean | undefined;
690
+ } | undefined;
629
691
  wallet?: {
630
692
  setup?: "generate" | "provide" | undefined;
631
693
  } | undefined;
@@ -639,13 +701,6 @@ declare const AgentConfigSchema: z.ZodObject<{
639
701
  maxSlippageBps?: number | undefined;
640
702
  minTradeValueUSD?: number | undefined;
641
703
  } | undefined;
642
- vault?: {
643
- policy?: "disabled" | "manual" | undefined;
644
- defaultName?: string | undefined;
645
- defaultSymbol?: string | undefined;
646
- feeRecipient?: string | undefined;
647
- preferVaultTrading?: boolean | undefined;
648
- } | undefined;
649
704
  relay?: {
650
705
  apiUrl: string;
651
706
  enabled?: boolean | undefined;
@@ -663,14 +718,6 @@ declare const AgentConfigSchema: z.ZodObject<{
663
718
  allowedInstruments?: string[] | undefined;
664
719
  } | undefined;
665
720
  prediction?: {
666
- vault?: {
667
- factoryAddress: string;
668
- feeRecipient?: string | undefined;
669
- enabled?: boolean | undefined;
670
- feeCollectorAddress?: string | undefined;
671
- vaultAddress?: string | undefined;
672
- isVerified?: boolean | undefined;
673
- } | undefined;
674
721
  enabled?: boolean | undefined;
675
722
  maxNotionalUSD?: number | undefined;
676
723
  clobApiUrl?: string | undefined;
@@ -684,6 +731,14 @@ declare const AgentConfigSchema: z.ZodObject<{
684
731
  polygonAllocationUSD?: number | undefined;
685
732
  allowedCategories?: string[] | undefined;
686
733
  feeBridgeThresholdUSD?: number | undefined;
734
+ vault?: {
735
+ factoryAddress: string;
736
+ feeRecipient?: string | undefined;
737
+ enabled?: boolean | undefined;
738
+ feeCollectorAddress?: string | undefined;
739
+ vaultAddress?: string | undefined;
740
+ isVerified?: boolean | undefined;
741
+ } | undefined;
687
742
  } | undefined;
688
743
  allowedTokens?: string[] | undefined;
689
744
  }>;
@@ -783,6 +838,13 @@ interface TradeRecord {
783
838
  /** Realized PnL in USD (only for sells) */
784
839
  realizedPnL?: number;
785
840
  success: boolean;
841
+ /**
842
+ * True if this trade was inferred from balance changes, not from a tracked execution.
843
+ * Inferred exits occur when a position's balance decreases without a corresponding
844
+ * sell trade — typically from manual swaps outside the ExagentRouter.
845
+ * PnL is calculated at current market price and counts toward total realized PnL.
846
+ */
847
+ inferred?: boolean;
786
848
  }
787
849
  /**
788
850
  * Compact position summary for relay heartbeats.
@@ -936,7 +998,7 @@ interface RelayCommand {
936
998
  type: CommandType;
937
999
  params?: Record<string, unknown>;
938
1000
  }
939
- type MessageType = 'trade_executed' | 'trade_failed' | 'paper_trade_executed' | 'paper_trade_failed' | 'perp_fill' | 'perp_liquidation_warning' | 'perp_funding' | 'prediction_fill' | 'prediction_market_resolved' | 'prediction_vault_created' | 'prediction_vault_deposit' | 'prediction_vault_withdraw' | 'funds_low' | 'risk_limit_hit' | 'vault_created' | 'config_updated' | 'llm_error' | 'command_result' | 'system';
1001
+ type MessageType = 'trade_executed' | 'trade_failed' | 'paper_trade_executed' | 'paper_trade_failed' | 'perp_fill' | 'perp_liquidation_warning' | 'perp_funding' | 'prediction_fill' | 'prediction_market_resolved' | 'prediction_vault_created' | 'prediction_vault_deposit' | 'prediction_vault_withdraw' | 'funds_low' | 'risk_limit_hit' | 'position_stuck' | 'position_inferred_exit' | 'vault_created' | 'config_updated' | 'llm_error' | 'command_result' | 'system';
940
1002
  type MessageLevel = 'info' | 'warning' | 'error' | 'success';
941
1003
  interface AgentStatusPayload {
942
1004
  mode: AgentMode;
@@ -3283,6 +3345,6 @@ declare function decryptEnvFile(encPath: string, passphrase: string): Record<str
3283
3345
  declare function loadSecureEnv(basePath: string, passphrase?: string): boolean;
3284
3346
 
3285
3347
  /** @exagent/agent package version — update alongside package.json */
3286
- declare const AGENT_VERSION = "0.1.40";
3348
+ declare const AGENT_VERSION = "0.1.42";
3287
3349
 
3288
- export { AGENT_VERSION, type AccountSummary, type AgentConfig, AgentConfigSchema, type AgentMode, AgentRuntime, type AgentStatusPayload, AnthropicAdapter, BaseLLMAdapter, type BridgeResult, type BridgeStep, type CommandType, DeepSeekAdapter, FileStore, type FillCallback, type FundingCallback, type FundingPayment, GoogleAdapter, GroqAdapter, HYPERLIQUID_DOMAIN, HyperliquidClient, HyperliquidSigner, HyperliquidWebSocket, type LLMAdapter, type LLMConfig, LLMConfigSchema, type LLMMessage, type LLMMetadata, type LLMProvider, LLMProviderSchema, type LLMResponse, type LiquidationCallback, type LocalPosition, MARKET_CATEGORIES, MarketBrowser, type MarketCategory, type MarketData, MarketDataService, type MessageLevel, type MessageType, MistralAdapter, OllamaAdapter, type OnboardingStatus, OpenAIAdapter, OrderManager, type OrderResult, type PerpAction, type PerpConfig$1 as PerpConfig, PerpConfigSchema, type PerpFill, type PerpMarketData, PerpOnboarding, type PerpPosition, type PerpStrategyFunction, PerpTradeRecorder, type PerpTradeSignal, type PerpConfig as PerpTradingConfig, PolymarketClient, PositionManager, type PositionSummary, PositionTracker, type PredictionAccountSummary, type PredictionAction, type PredictionConfig$1 as PredictionConfig, PredictionConfigSchema, type PredictionFill, PredictionFunding, type PredictionFundingConfig, type PredictionMarket, PredictionOrderManager, type PredictionPosition, PredictionPositionManager, type PredictionStrategyFunction, PredictionTradeRecorder, type PredictionTradeSignal, type PredictionConfig as PredictionTradingConfig, type RecordPerpTradeParams, type RecordPredictionTradeParams, RelayClient, type RelayCommand, type RelayConfig$1 as RelayConfig, RelayConfigSchema, RiskManager, type RiskState, type RiskUniverse, RiskUniverseSchema, type RuntimeConfig, STRATEGY_TEMPLATES, type StrategyContext, type StrategyFunction, type StrategyStore, type StrategyTemplate, TogetherAdapter, type TrackedPosition, TradeExecutor, type TradeRecord, type TradeSignal, type TradingConfig, TradingConfigSchema, type VaultConfig, VaultConfigSchema, VaultManager, type VaultManagerConfig, type VaultPolicy, VaultPolicySchema, type VaultStatus, calculatePredictionFee, createLLMAdapter, createSampleConfig, decodePredictionInstrument, decryptEnvFile, encodePredictionInstrument, encryptEnvFile, fillHashToBytes32, fillOidToBytes32, getAllStrategyTemplates, getNextNonce, getStrategyTemplate, loadConfig, loadSecureEnv, loadStrategy, orderIdToBytes32, tradeIdToBytes32, validateConfig, validateStrategy };
3350
+ export { AGENT_VERSION, type AccountSummary, type AgentConfig, AgentConfigSchema, type AgentMode, AgentRuntime, type AgentStatusPayload, AnthropicAdapter, BaseLLMAdapter, type BridgeResult, type BridgeStep, type CommandType, DeepSeekAdapter, FileStore, type FillCallback, type FundingCallback, type FundingPayment, GoogleAdapter, GroqAdapter, HYPERLIQUID_DOMAIN, HyperliquidClient, HyperliquidSigner, HyperliquidWebSocket, type InferredExit, type LLMAdapter, type LLMConfig, LLMConfigSchema, type LLMMessage, type LLMMetadata, type LLMProvider, LLMProviderSchema, type LLMResponse, type LiquidationCallback, type LocalPosition, MARKET_CATEGORIES, MarketBrowser, type MarketCategory, type MarketData, MarketDataService, type MessageLevel, type MessageType, MistralAdapter, OllamaAdapter, type OnboardingStatus, OpenAIAdapter, OrderManager, type OrderResult, type PerpAction, type PerpConfig$1 as PerpConfig, PerpConfigSchema, type PerpFill, type PerpMarketData, PerpOnboarding, type PerpPosition, type PerpStrategyFunction, PerpTradeRecorder, type PerpTradeSignal, type PerpConfig as PerpTradingConfig, PolymarketClient, PositionManager, type PositionSummary, PositionTracker, type PredictionAccountSummary, type PredictionAction, type PredictionConfig$1 as PredictionConfig, PredictionConfigSchema, type PredictionFill, PredictionFunding, type PredictionFundingConfig, type PredictionMarket, PredictionOrderManager, type PredictionPosition, PredictionPositionManager, type PredictionStrategyFunction, PredictionTradeRecorder, type PredictionTradeSignal, type PredictionConfig as PredictionTradingConfig, type RecordPerpTradeParams, type RecordPredictionTradeParams, RelayClient, type RelayCommand, type RelayConfig$1 as RelayConfig, RelayConfigSchema, RiskManager, type RiskState, type RiskUniverse, RiskUniverseSchema, type RuntimeConfig, STRATEGY_TEMPLATES, type StrategyContext, type StrategyFunction, type StrategyStore, type StrategyTemplate, type StuckPosition, TogetherAdapter, type TrackedPosition, TradeExecutor, type TradeRecord, type TradeSignal, type TradingConfig, TradingConfigSchema, type VaultConfig, VaultConfigSchema, VaultManager, type VaultManagerConfig, type VaultPolicy, VaultPolicySchema, type VaultStatus, calculatePredictionFee, createLLMAdapter, createSampleConfig, decodePredictionInstrument, decryptEnvFile, encodePredictionInstrument, encryptEnvFile, fillHashToBytes32, fillOidToBytes32, getAllStrategyTemplates, getNextNonce, getStrategyTemplate, loadConfig, loadSecureEnv, loadStrategy, orderIdToBytes32, tradeIdToBytes32, validateConfig, validateStrategy };
package/dist/index.d.ts CHANGED
@@ -9,6 +9,24 @@ interface RiskState {
9
9
  dailyFees: number;
10
10
  lastResetDate: string;
11
11
  }
12
+ /** Stuck position detection result */
13
+ interface StuckPosition {
14
+ token: string;
15
+ symbol: string;
16
+ consecutiveFailures: number;
17
+ lastFailureReason: string;
18
+ holdingDurationMs: number;
19
+ estimatedValueUSD: number;
20
+ }
21
+ /** Result of an inferred exit detected during balance sync */
22
+ interface InferredExit {
23
+ token: string;
24
+ symbol: string;
25
+ amountExited: number;
26
+ exitValueUSD: number;
27
+ realizedPnL: number;
28
+ costBasis: number;
29
+ }
12
30
  /**
13
31
  * PositionTracker — automatic position tracking with persistence.
14
32
  *
@@ -25,6 +43,7 @@ declare class PositionTracker {
25
43
  private store;
26
44
  private positions;
27
45
  private tradeHistory;
46
+ private sellFailures;
28
47
  private maxTradeHistory;
29
48
  constructor(store: StrategyStore, options?: {
30
49
  maxTradeHistory?: number;
@@ -55,9 +74,20 @@ declare class PositionTracker {
55
74
  private handleSell;
56
75
  /**
57
76
  * Sync tracked positions with on-chain balances.
58
- * Updates currentAmount, detects new tokens (airdrops), removes zeroed positions.
77
+ * Updates currentAmount, detects new tokens (airdrops), and handles position exits.
78
+ *
79
+ * CRITICAL: When a tracked position's balance decreases without a corresponding
80
+ * sell trade, we infer a manual exit and record it with realized PnL calculated
81
+ * at current market price. This prevents PnL manipulation via off-router sells.
82
+ *
83
+ * Returns array of inferred exits for the runtime to report to Command Center.
84
+ */
85
+ syncBalances(balances: Record<string, bigint>, prices: Record<string, number>): InferredExit[];
86
+ /**
87
+ * Record an inferred exit in trade history.
88
+ * These are exits detected from balance changes, not from tracked sell executions.
59
89
  */
60
- syncBalances(balances: Record<string, bigint>, prices: Record<string, number>): void;
90
+ private recordInferredExit;
61
91
  /** Get all tracked positions (backfills missing symbols from resolver) */
62
92
  getPositions(): TrackedPosition[];
63
93
  /** Get a single position by token address */
@@ -68,6 +98,31 @@ declare class PositionTracker {
68
98
  getUnrealizedPnL(prices: Record<string, number>): Record<string, number>;
69
99
  /** Get total unrealized PnL across all positions */
70
100
  getTotalUnrealizedPnL(prices: Record<string, number>): number;
101
+ /**
102
+ * Record a sell failure for a token. Called when a sell attempt fails
103
+ * due to liquidity issues, route simulation failure, or excessive price impact.
104
+ */
105
+ recordSellFailure(token: string, reason: string): void;
106
+ /**
107
+ * Clear sell failure tracking for a token (called after successful sell).
108
+ */
109
+ clearSellFailure(token: string): void;
110
+ /**
111
+ * Detect positions that are "stuck" — we've tried and failed to sell them
112
+ * multiple times, likely due to insufficient liquidity.
113
+ *
114
+ * Returns positions that have failed to sell >= STUCK_FAILURE_THRESHOLD times.
115
+ */
116
+ getStuckPositions(prices: Record<string, number>): StuckPosition[];
117
+ /**
118
+ * Check if a specific position is stuck.
119
+ */
120
+ isPositionStuck(token: string): boolean;
121
+ /**
122
+ * Check if we should alert about a stuck position (rate-limited to once per 24h).
123
+ * Returns true if we should alert, and marks the alert as sent.
124
+ */
125
+ shouldAlertStuckPosition(token: string): boolean;
71
126
  /** Load persisted risk state */
72
127
  getRiskState(): RiskState;
73
128
  /** Save risk state to persistent store */
@@ -271,29 +326,21 @@ declare const PredictionConfigSchema: z.ZodOptional<z.ZodObject<{
271
326
  maxTotalExposureUSD: number;
272
327
  polygonAllocationUSD: number;
273
328
  feeBridgeThresholdUSD: number;
274
- vault?: {
275
- enabled: boolean;
276
- factoryAddress: string;
277
- isVerified: boolean;
278
- feeRecipient?: string | undefined;
279
- feeCollectorAddress?: string | undefined;
280
- vaultAddress?: string | undefined;
281
- } | undefined;
282
329
  polygonRpcUrl?: string | undefined;
283
330
  clobApiKey?: string | undefined;
284
331
  clobApiSecret?: string | undefined;
285
332
  clobApiPassphrase?: string | undefined;
286
333
  predictionRelayerKey?: string | undefined;
287
334
  allowedCategories?: string[] | undefined;
288
- }, {
289
335
  vault?: {
336
+ enabled: boolean;
290
337
  factoryAddress: string;
338
+ isVerified: boolean;
291
339
  feeRecipient?: string | undefined;
292
- enabled?: boolean | undefined;
293
340
  feeCollectorAddress?: string | undefined;
294
341
  vaultAddress?: string | undefined;
295
- isVerified?: boolean | undefined;
296
342
  } | undefined;
343
+ }, {
297
344
  enabled?: boolean | undefined;
298
345
  maxNotionalUSD?: number | undefined;
299
346
  clobApiUrl?: string | undefined;
@@ -307,6 +354,14 @@ declare const PredictionConfigSchema: z.ZodOptional<z.ZodObject<{
307
354
  polygonAllocationUSD?: number | undefined;
308
355
  allowedCategories?: string[] | undefined;
309
356
  feeBridgeThresholdUSD?: number | undefined;
357
+ vault?: {
358
+ factoryAddress: string;
359
+ feeRecipient?: string | undefined;
360
+ enabled?: boolean | undefined;
361
+ feeCollectorAddress?: string | undefined;
362
+ vaultAddress?: string | undefined;
363
+ isVerified?: boolean | undefined;
364
+ } | undefined;
310
365
  }>>;
311
366
  type PredictionConfig$1 = z.infer<typeof PredictionConfigSchema>;
312
367
  declare const AgentConfigSchema: z.ZodObject<{
@@ -504,29 +559,21 @@ declare const AgentConfigSchema: z.ZodObject<{
504
559
  maxTotalExposureUSD: number;
505
560
  polygonAllocationUSD: number;
506
561
  feeBridgeThresholdUSD: number;
507
- vault?: {
508
- enabled: boolean;
509
- factoryAddress: string;
510
- isVerified: boolean;
511
- feeRecipient?: string | undefined;
512
- feeCollectorAddress?: string | undefined;
513
- vaultAddress?: string | undefined;
514
- } | undefined;
515
562
  polygonRpcUrl?: string | undefined;
516
563
  clobApiKey?: string | undefined;
517
564
  clobApiSecret?: string | undefined;
518
565
  clobApiPassphrase?: string | undefined;
519
566
  predictionRelayerKey?: string | undefined;
520
567
  allowedCategories?: string[] | undefined;
521
- }, {
522
568
  vault?: {
569
+ enabled: boolean;
523
570
  factoryAddress: string;
571
+ isVerified: boolean;
524
572
  feeRecipient?: string | undefined;
525
- enabled?: boolean | undefined;
526
573
  feeCollectorAddress?: string | undefined;
527
574
  vaultAddress?: string | undefined;
528
- isVerified?: boolean | undefined;
529
575
  } | undefined;
576
+ }, {
530
577
  enabled?: boolean | undefined;
531
578
  maxNotionalUSD?: number | undefined;
532
579
  clobApiUrl?: string | undefined;
@@ -540,12 +587,27 @@ declare const AgentConfigSchema: z.ZodObject<{
540
587
  polygonAllocationUSD?: number | undefined;
541
588
  allowedCategories?: string[] | undefined;
542
589
  feeBridgeThresholdUSD?: number | undefined;
590
+ vault?: {
591
+ factoryAddress: string;
592
+ feeRecipient?: string | undefined;
593
+ enabled?: boolean | undefined;
594
+ feeCollectorAddress?: string | undefined;
595
+ vaultAddress?: string | undefined;
596
+ isVerified?: boolean | undefined;
597
+ } | undefined;
543
598
  }>>;
544
599
  allowedTokens: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
545
600
  }, "strip", z.ZodTypeAny, {
546
- agentId: string | number;
547
601
  name: string;
548
602
  network: "mainnet";
603
+ vault: {
604
+ policy: "disabled" | "manual";
605
+ preferVaultTrading: boolean;
606
+ defaultName?: string | undefined;
607
+ defaultSymbol?: string | undefined;
608
+ feeRecipient?: string | undefined;
609
+ };
610
+ agentId: string | number;
549
611
  llm: {
550
612
  provider: "custom" | "openai" | "anthropic" | "google" | "deepseek" | "mistral" | "groq" | "together" | "ollama";
551
613
  temperature: number;
@@ -564,13 +626,6 @@ declare const AgentConfigSchema: z.ZodObject<{
564
626
  maxSlippageBps: number;
565
627
  minTradeValueUSD: number;
566
628
  };
567
- vault: {
568
- policy: "disabled" | "manual";
569
- preferVaultTrading: boolean;
570
- defaultName?: string | undefined;
571
- defaultSymbol?: string | undefined;
572
- feeRecipient?: string | undefined;
573
- };
574
629
  wallet?: {
575
630
  setup: "generate" | "provide";
576
631
  } | undefined;
@@ -598,6 +653,12 @@ declare const AgentConfigSchema: z.ZodObject<{
598
653
  maxTotalExposureUSD: number;
599
654
  polygonAllocationUSD: number;
600
655
  feeBridgeThresholdUSD: number;
656
+ polygonRpcUrl?: string | undefined;
657
+ clobApiKey?: string | undefined;
658
+ clobApiSecret?: string | undefined;
659
+ clobApiPassphrase?: string | undefined;
660
+ predictionRelayerKey?: string | undefined;
661
+ allowedCategories?: string[] | undefined;
601
662
  vault?: {
602
663
  enabled: boolean;
603
664
  factoryAddress: string;
@@ -606,17 +667,11 @@ declare const AgentConfigSchema: z.ZodObject<{
606
667
  feeCollectorAddress?: string | undefined;
607
668
  vaultAddress?: string | undefined;
608
669
  } | undefined;
609
- polygonRpcUrl?: string | undefined;
610
- clobApiKey?: string | undefined;
611
- clobApiSecret?: string | undefined;
612
- clobApiPassphrase?: string | undefined;
613
- predictionRelayerKey?: string | undefined;
614
- allowedCategories?: string[] | undefined;
615
670
  } | undefined;
616
671
  allowedTokens?: string[] | undefined;
617
672
  }, {
618
- agentId: string | number;
619
673
  name: string;
674
+ agentId: string | number;
620
675
  llm: {
621
676
  provider: "custom" | "openai" | "anthropic" | "google" | "deepseek" | "mistral" | "groq" | "together" | "ollama";
622
677
  model?: string | undefined;
@@ -626,6 +681,13 @@ declare const AgentConfigSchema: z.ZodObject<{
626
681
  maxTokens?: number | undefined;
627
682
  };
628
683
  network?: "mainnet" | undefined;
684
+ vault?: {
685
+ policy?: "disabled" | "manual" | undefined;
686
+ defaultName?: string | undefined;
687
+ defaultSymbol?: string | undefined;
688
+ feeRecipient?: string | undefined;
689
+ preferVaultTrading?: boolean | undefined;
690
+ } | undefined;
629
691
  wallet?: {
630
692
  setup?: "generate" | "provide" | undefined;
631
693
  } | undefined;
@@ -639,13 +701,6 @@ declare const AgentConfigSchema: z.ZodObject<{
639
701
  maxSlippageBps?: number | undefined;
640
702
  minTradeValueUSD?: number | undefined;
641
703
  } | undefined;
642
- vault?: {
643
- policy?: "disabled" | "manual" | undefined;
644
- defaultName?: string | undefined;
645
- defaultSymbol?: string | undefined;
646
- feeRecipient?: string | undefined;
647
- preferVaultTrading?: boolean | undefined;
648
- } | undefined;
649
704
  relay?: {
650
705
  apiUrl: string;
651
706
  enabled?: boolean | undefined;
@@ -663,14 +718,6 @@ declare const AgentConfigSchema: z.ZodObject<{
663
718
  allowedInstruments?: string[] | undefined;
664
719
  } | undefined;
665
720
  prediction?: {
666
- vault?: {
667
- factoryAddress: string;
668
- feeRecipient?: string | undefined;
669
- enabled?: boolean | undefined;
670
- feeCollectorAddress?: string | undefined;
671
- vaultAddress?: string | undefined;
672
- isVerified?: boolean | undefined;
673
- } | undefined;
674
721
  enabled?: boolean | undefined;
675
722
  maxNotionalUSD?: number | undefined;
676
723
  clobApiUrl?: string | undefined;
@@ -684,6 +731,14 @@ declare const AgentConfigSchema: z.ZodObject<{
684
731
  polygonAllocationUSD?: number | undefined;
685
732
  allowedCategories?: string[] | undefined;
686
733
  feeBridgeThresholdUSD?: number | undefined;
734
+ vault?: {
735
+ factoryAddress: string;
736
+ feeRecipient?: string | undefined;
737
+ enabled?: boolean | undefined;
738
+ feeCollectorAddress?: string | undefined;
739
+ vaultAddress?: string | undefined;
740
+ isVerified?: boolean | undefined;
741
+ } | undefined;
687
742
  } | undefined;
688
743
  allowedTokens?: string[] | undefined;
689
744
  }>;
@@ -783,6 +838,13 @@ interface TradeRecord {
783
838
  /** Realized PnL in USD (only for sells) */
784
839
  realizedPnL?: number;
785
840
  success: boolean;
841
+ /**
842
+ * True if this trade was inferred from balance changes, not from a tracked execution.
843
+ * Inferred exits occur when a position's balance decreases without a corresponding
844
+ * sell trade — typically from manual swaps outside the ExagentRouter.
845
+ * PnL is calculated at current market price and counts toward total realized PnL.
846
+ */
847
+ inferred?: boolean;
786
848
  }
787
849
  /**
788
850
  * Compact position summary for relay heartbeats.
@@ -936,7 +998,7 @@ interface RelayCommand {
936
998
  type: CommandType;
937
999
  params?: Record<string, unknown>;
938
1000
  }
939
- type MessageType = 'trade_executed' | 'trade_failed' | 'paper_trade_executed' | 'paper_trade_failed' | 'perp_fill' | 'perp_liquidation_warning' | 'perp_funding' | 'prediction_fill' | 'prediction_market_resolved' | 'prediction_vault_created' | 'prediction_vault_deposit' | 'prediction_vault_withdraw' | 'funds_low' | 'risk_limit_hit' | 'vault_created' | 'config_updated' | 'llm_error' | 'command_result' | 'system';
1001
+ type MessageType = 'trade_executed' | 'trade_failed' | 'paper_trade_executed' | 'paper_trade_failed' | 'perp_fill' | 'perp_liquidation_warning' | 'perp_funding' | 'prediction_fill' | 'prediction_market_resolved' | 'prediction_vault_created' | 'prediction_vault_deposit' | 'prediction_vault_withdraw' | 'funds_low' | 'risk_limit_hit' | 'position_stuck' | 'position_inferred_exit' | 'vault_created' | 'config_updated' | 'llm_error' | 'command_result' | 'system';
940
1002
  type MessageLevel = 'info' | 'warning' | 'error' | 'success';
941
1003
  interface AgentStatusPayload {
942
1004
  mode: AgentMode;
@@ -3283,6 +3345,6 @@ declare function decryptEnvFile(encPath: string, passphrase: string): Record<str
3283
3345
  declare function loadSecureEnv(basePath: string, passphrase?: string): boolean;
3284
3346
 
3285
3347
  /** @exagent/agent package version — update alongside package.json */
3286
- declare const AGENT_VERSION = "0.1.40";
3348
+ declare const AGENT_VERSION = "0.1.42";
3287
3349
 
3288
- export { AGENT_VERSION, type AccountSummary, type AgentConfig, AgentConfigSchema, type AgentMode, AgentRuntime, type AgentStatusPayload, AnthropicAdapter, BaseLLMAdapter, type BridgeResult, type BridgeStep, type CommandType, DeepSeekAdapter, FileStore, type FillCallback, type FundingCallback, type FundingPayment, GoogleAdapter, GroqAdapter, HYPERLIQUID_DOMAIN, HyperliquidClient, HyperliquidSigner, HyperliquidWebSocket, type LLMAdapter, type LLMConfig, LLMConfigSchema, type LLMMessage, type LLMMetadata, type LLMProvider, LLMProviderSchema, type LLMResponse, type LiquidationCallback, type LocalPosition, MARKET_CATEGORIES, MarketBrowser, type MarketCategory, type MarketData, MarketDataService, type MessageLevel, type MessageType, MistralAdapter, OllamaAdapter, type OnboardingStatus, OpenAIAdapter, OrderManager, type OrderResult, type PerpAction, type PerpConfig$1 as PerpConfig, PerpConfigSchema, type PerpFill, type PerpMarketData, PerpOnboarding, type PerpPosition, type PerpStrategyFunction, PerpTradeRecorder, type PerpTradeSignal, type PerpConfig as PerpTradingConfig, PolymarketClient, PositionManager, type PositionSummary, PositionTracker, type PredictionAccountSummary, type PredictionAction, type PredictionConfig$1 as PredictionConfig, PredictionConfigSchema, type PredictionFill, PredictionFunding, type PredictionFundingConfig, type PredictionMarket, PredictionOrderManager, type PredictionPosition, PredictionPositionManager, type PredictionStrategyFunction, PredictionTradeRecorder, type PredictionTradeSignal, type PredictionConfig as PredictionTradingConfig, type RecordPerpTradeParams, type RecordPredictionTradeParams, RelayClient, type RelayCommand, type RelayConfig$1 as RelayConfig, RelayConfigSchema, RiskManager, type RiskState, type RiskUniverse, RiskUniverseSchema, type RuntimeConfig, STRATEGY_TEMPLATES, type StrategyContext, type StrategyFunction, type StrategyStore, type StrategyTemplate, TogetherAdapter, type TrackedPosition, TradeExecutor, type TradeRecord, type TradeSignal, type TradingConfig, TradingConfigSchema, type VaultConfig, VaultConfigSchema, VaultManager, type VaultManagerConfig, type VaultPolicy, VaultPolicySchema, type VaultStatus, calculatePredictionFee, createLLMAdapter, createSampleConfig, decodePredictionInstrument, decryptEnvFile, encodePredictionInstrument, encryptEnvFile, fillHashToBytes32, fillOidToBytes32, getAllStrategyTemplates, getNextNonce, getStrategyTemplate, loadConfig, loadSecureEnv, loadStrategy, orderIdToBytes32, tradeIdToBytes32, validateConfig, validateStrategy };
3350
+ export { AGENT_VERSION, type AccountSummary, type AgentConfig, AgentConfigSchema, type AgentMode, AgentRuntime, type AgentStatusPayload, AnthropicAdapter, BaseLLMAdapter, type BridgeResult, type BridgeStep, type CommandType, DeepSeekAdapter, FileStore, type FillCallback, type FundingCallback, type FundingPayment, GoogleAdapter, GroqAdapter, HYPERLIQUID_DOMAIN, HyperliquidClient, HyperliquidSigner, HyperliquidWebSocket, type InferredExit, type LLMAdapter, type LLMConfig, LLMConfigSchema, type LLMMessage, type LLMMetadata, type LLMProvider, LLMProviderSchema, type LLMResponse, type LiquidationCallback, type LocalPosition, MARKET_CATEGORIES, MarketBrowser, type MarketCategory, type MarketData, MarketDataService, type MessageLevel, type MessageType, MistralAdapter, OllamaAdapter, type OnboardingStatus, OpenAIAdapter, OrderManager, type OrderResult, type PerpAction, type PerpConfig$1 as PerpConfig, PerpConfigSchema, type PerpFill, type PerpMarketData, PerpOnboarding, type PerpPosition, type PerpStrategyFunction, PerpTradeRecorder, type PerpTradeSignal, type PerpConfig as PerpTradingConfig, PolymarketClient, PositionManager, type PositionSummary, PositionTracker, type PredictionAccountSummary, type PredictionAction, type PredictionConfig$1 as PredictionConfig, PredictionConfigSchema, type PredictionFill, PredictionFunding, type PredictionFundingConfig, type PredictionMarket, PredictionOrderManager, type PredictionPosition, PredictionPositionManager, type PredictionStrategyFunction, PredictionTradeRecorder, type PredictionTradeSignal, type PredictionConfig as PredictionTradingConfig, type RecordPerpTradeParams, type RecordPredictionTradeParams, RelayClient, type RelayCommand, type RelayConfig$1 as RelayConfig, RelayConfigSchema, RiskManager, type RiskState, type RiskUniverse, RiskUniverseSchema, type RuntimeConfig, STRATEGY_TEMPLATES, type StrategyContext, type StrategyFunction, type StrategyStore, type StrategyTemplate, type StuckPosition, TogetherAdapter, type TrackedPosition, TradeExecutor, type TradeRecord, type TradeSignal, type TradingConfig, TradingConfigSchema, type VaultConfig, VaultConfigSchema, VaultManager, type VaultManagerConfig, type VaultPolicy, VaultPolicySchema, type VaultStatus, calculatePredictionFee, createLLMAdapter, createSampleConfig, decodePredictionInstrument, decryptEnvFile, encodePredictionInstrument, encryptEnvFile, fillHashToBytes32, fillOidToBytes32, getAllStrategyTemplates, getNextNonce, getStrategyTemplate, loadConfig, loadSecureEnv, loadStrategy, orderIdToBytes32, tradeIdToBytes32, validateConfig, validateStrategy };