@exagent/agent 0.1.47 → 0.1.48

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/cli.mjs CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  encryptEnvFile,
14
14
  formatSessionReport,
15
15
  getAllStrategyTemplates,
16
+ getStrategyTemplate,
16
17
  getTokenDecimals,
17
18
  init_adapter,
18
19
  init_executor,
@@ -29,7 +30,7 @@ import {
29
30
  results_exports,
30
31
  saveSessionResult,
31
32
  validateConfig
32
- } from "./chunk-ICTDJ7VX.mjs";
33
+ } from "./chunk-V5XCNJWM.mjs";
33
34
 
34
35
  // src/backtest/data-loader.ts
35
36
  import * as fs from "fs";
@@ -1107,6 +1108,95 @@ ${llmEnvVar}EXAGENT_LLM_MODEL=${config.llm?.model || ""}
1107
1108
  loadEnvFile({ path: envPath, override: true });
1108
1109
  }
1109
1110
  }
1111
+ program.command("init").description("Scaffold a new agent project with strategy template and config").option("-t, --template <template>", "Strategy template (momentum, value, arbitrage, custom)", "momentum").option("--force", "Overwrite existing files without prompting").action(async (options) => {
1112
+ try {
1113
+ const templateId = options.template;
1114
+ const template = getStrategyTemplate(templateId);
1115
+ if (!template) {
1116
+ const templates = getAllStrategyTemplates();
1117
+ console.error(`Unknown template: ${templateId}`);
1118
+ console.error(`Available templates: ${templates.map((t) => t.id).join(", ")}`);
1119
+ process.exit(1);
1120
+ }
1121
+ console.log("");
1122
+ console.log("=".repeat(50));
1123
+ console.log(" EXAGENT INIT");
1124
+ console.log("=".repeat(50));
1125
+ console.log("");
1126
+ console.log(` Template: ${template.name}`);
1127
+ console.log(` Risk: ${template.riskLevel}`);
1128
+ console.log("");
1129
+ const cwd = process.cwd();
1130
+ const strategyPath = path4.join(cwd, "strategy.ts");
1131
+ const configPath = path4.join(cwd, "agent-config.json");
1132
+ const existingFiles = [];
1133
+ if (fs3.existsSync(strategyPath)) existingFiles.push("strategy.ts");
1134
+ if (fs3.existsSync(configPath)) existingFiles.push("agent-config.json");
1135
+ if (existingFiles.length > 0 && !options.force) {
1136
+ console.log(` Files already exist: ${existingFiles.join(", ")}`);
1137
+ const answer = await prompt(" Overwrite? (y/n): ");
1138
+ if (answer.toLowerCase() !== "y") {
1139
+ console.log(" Aborted.");
1140
+ process.exit(0);
1141
+ }
1142
+ console.log("");
1143
+ }
1144
+ fs3.writeFileSync(strategyPath, template.exampleCode.trim() + "\n");
1145
+ console.log(" Created: strategy.ts");
1146
+ const defaultConfig = {
1147
+ agentId: 0,
1148
+ name: "my-agent",
1149
+ network: "mainnet",
1150
+ llm: {
1151
+ provider: "openai",
1152
+ model: "gpt-4o",
1153
+ temperature: 0.7,
1154
+ maxTokens: 4096
1155
+ },
1156
+ riskUniverse: "established",
1157
+ trading: {
1158
+ timeHorizon: "swing",
1159
+ maxPositionSizeBps: 1e3,
1160
+ maxDailyLossBps: 500,
1161
+ maxConcurrentPositions: 5,
1162
+ tradingIntervalMs: 6e4,
1163
+ maxSlippageBps: 100,
1164
+ minTradeValueUSD: 1
1165
+ },
1166
+ wallet: {
1167
+ setup: "generate"
1168
+ },
1169
+ relay: {
1170
+ enabled: true,
1171
+ apiUrl: "https://exagent-api.onrender.com"
1172
+ }
1173
+ };
1174
+ if (!fs3.existsSync(configPath) || options.force || existingFiles.includes("agent-config.json")) {
1175
+ fs3.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2) + "\n");
1176
+ console.log(" Created: agent-config.json");
1177
+ }
1178
+ console.log("");
1179
+ console.log("=".repeat(50));
1180
+ console.log(" NEXT STEPS");
1181
+ console.log("=".repeat(50));
1182
+ console.log("");
1183
+ console.log(" 1. Register your agent at https://exagent.io/deploy");
1184
+ console.log(" 2. Copy your agent ID into agent-config.json");
1185
+ console.log(" 3. Update agent-config.json with your name and LLM provider");
1186
+ console.log(" 4. Run: npx @exagent/agent paper");
1187
+ console.log(" (paper trade first to validate your strategy)");
1188
+ console.log("");
1189
+ console.log(" 5. When ready for real trading:");
1190
+ console.log(" npx @exagent/agent run");
1191
+ console.log("");
1192
+ console.log("=".repeat(50));
1193
+ console.log("");
1194
+ process.exit(0);
1195
+ } catch (error) {
1196
+ console.error("Error:", error instanceof Error ? error.message : error);
1197
+ process.exit(1);
1198
+ }
1199
+ });
1110
1200
  program.command("run").description("Start the trading agent").option("-c, --config <path>", "Path to agent-config.json", "agent-config.json").option("-p, --passphrase <passphrase>", "Passphrase to decrypt .env.enc").action(async (options) => {
1111
1201
  try {
1112
1202
  await checkFirstRunSetup(options.config);
package/dist/index.d.mts CHANGED
@@ -596,6 +596,7 @@ declare const AgentConfigSchema: z.ZodObject<{
596
596
  isVerified?: boolean | undefined;
597
597
  } | undefined;
598
598
  }>>;
599
+ strategyPrompt: z.ZodOptional<z.ZodString>;
599
600
  allowedTokens: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
600
601
  }, "strip", z.ZodTypeAny, {
601
602
  name: string;
@@ -668,6 +669,7 @@ declare const AgentConfigSchema: z.ZodObject<{
668
669
  vaultAddress?: string | undefined;
669
670
  } | undefined;
670
671
  } | undefined;
672
+ strategyPrompt?: string | undefined;
671
673
  allowedTokens?: string[] | undefined;
672
674
  }, {
673
675
  name: string;
@@ -740,6 +742,7 @@ declare const AgentConfigSchema: z.ZodObject<{
740
742
  isVerified?: boolean | undefined;
741
743
  } | undefined;
742
744
  } | undefined;
745
+ strategyPrompt?: string | undefined;
743
746
  allowedTokens?: string[] | undefined;
744
747
  }>;
745
748
  type AgentConfig = z.infer<typeof AgentConfigSchema>;
@@ -762,6 +765,11 @@ interface MarketData {
762
765
  chainId: number;
763
766
  blockNumber?: number;
764
767
  };
768
+ /** Hourly price history (last 24h) per token. Array ordered oldest→newest. */
769
+ priceHistory?: Record<string, Array<{
770
+ timestamp: number;
771
+ price: number;
772
+ }>>;
765
773
  }
766
774
  interface TradeSignal {
767
775
  action: 'buy' | 'sell' | 'hold';
@@ -1505,16 +1513,15 @@ declare function loadStrategy(strategyPath?: string): Promise<StrategyFunction>;
1505
1513
  declare function validateStrategy(fn: unknown): fn is StrategyFunction;
1506
1514
 
1507
1515
  /**
1508
- * Boilerplate Strategy Templates
1516
+ * Strategy Templates
1509
1517
  *
1510
- * These are example prompts and strategies users can customize.
1511
- * Each template includes:
1512
- * - A system prompt for the LLM
1513
- * - Risk warnings
1514
- * - Example implementation
1518
+ * Self-contained, runnable strategy templates that users can scaffold via `init`.
1519
+ * Each template includes all helper functions inline — no external imports needed
1520
+ * beyond the @exagent/agent types.
1515
1521
  *
1516
- * IMPORTANT: These are starting points. Users should customize
1517
- * the prompts and logic for their specific needs.
1522
+ * Templates output TradeSignal[] where amountIn is a bigint in token-native units (wei).
1523
+ * The LLM returns a percentage (0-100) of the relevant balance, and the template
1524
+ * converts it to the correct bigint amount.
1518
1525
  */
1519
1526
  interface StrategyTemplate {
1520
1527
  id: string;
@@ -1949,6 +1956,10 @@ declare class MarketDataService {
1949
1956
  private cachedVolume24h;
1950
1957
  /** Cached price change data */
1951
1958
  private cachedPriceChange24h;
1959
+ /** Cached 24h hourly price history per token address */
1960
+ private cachedPriceHistory;
1961
+ /** Timestamp of last successful price history fetch */
1962
+ private lastHistoryFetchAt;
1952
1963
  constructor(rpcUrl: string, store?: StrategyStore);
1953
1964
  /** Get the underlying TokenResolver for direct access */
1954
1965
  getResolver(): TokenResolver;
@@ -1971,6 +1982,12 @@ declare class MarketDataService {
1971
1982
  * Returns cached prices if still fresh (<60s old)
1972
1983
  */
1973
1984
  private fetchPrices;
1985
+ /**
1986
+ * Fetch 24h hourly price history from CoinGecko.
1987
+ * Returns cached data if still fresh (< 60 min old).
1988
+ * Only fetches for tokens with known CoinGecko IDs.
1989
+ */
1990
+ private fetchPriceHistory;
1974
1991
  /**
1975
1992
  * Fetch real on-chain balances: native ETH + ERC-20 tokens.
1976
1993
  * Uses Multicall3 to batch all balanceOf calls into a single RPC request.
@@ -3359,6 +3376,6 @@ declare function decryptEnvFile(encPath: string, passphrase: string): Record<str
3359
3376
  declare function loadSecureEnv(basePath: string, passphrase?: string): boolean;
3360
3377
 
3361
3378
  /** @exagent/agent package version — update alongside package.json */
3362
- declare const AGENT_VERSION = "0.1.47";
3379
+ declare const AGENT_VERSION = "0.1.48";
3363
3380
 
3364
3381
  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
@@ -596,6 +596,7 @@ declare const AgentConfigSchema: z.ZodObject<{
596
596
  isVerified?: boolean | undefined;
597
597
  } | undefined;
598
598
  }>>;
599
+ strategyPrompt: z.ZodOptional<z.ZodString>;
599
600
  allowedTokens: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
600
601
  }, "strip", z.ZodTypeAny, {
601
602
  name: string;
@@ -668,6 +669,7 @@ declare const AgentConfigSchema: z.ZodObject<{
668
669
  vaultAddress?: string | undefined;
669
670
  } | undefined;
670
671
  } | undefined;
672
+ strategyPrompt?: string | undefined;
671
673
  allowedTokens?: string[] | undefined;
672
674
  }, {
673
675
  name: string;
@@ -740,6 +742,7 @@ declare const AgentConfigSchema: z.ZodObject<{
740
742
  isVerified?: boolean | undefined;
741
743
  } | undefined;
742
744
  } | undefined;
745
+ strategyPrompt?: string | undefined;
743
746
  allowedTokens?: string[] | undefined;
744
747
  }>;
745
748
  type AgentConfig = z.infer<typeof AgentConfigSchema>;
@@ -762,6 +765,11 @@ interface MarketData {
762
765
  chainId: number;
763
766
  blockNumber?: number;
764
767
  };
768
+ /** Hourly price history (last 24h) per token. Array ordered oldest→newest. */
769
+ priceHistory?: Record<string, Array<{
770
+ timestamp: number;
771
+ price: number;
772
+ }>>;
765
773
  }
766
774
  interface TradeSignal {
767
775
  action: 'buy' | 'sell' | 'hold';
@@ -1505,16 +1513,15 @@ declare function loadStrategy(strategyPath?: string): Promise<StrategyFunction>;
1505
1513
  declare function validateStrategy(fn: unknown): fn is StrategyFunction;
1506
1514
 
1507
1515
  /**
1508
- * Boilerplate Strategy Templates
1516
+ * Strategy Templates
1509
1517
  *
1510
- * These are example prompts and strategies users can customize.
1511
- * Each template includes:
1512
- * - A system prompt for the LLM
1513
- * - Risk warnings
1514
- * - Example implementation
1518
+ * Self-contained, runnable strategy templates that users can scaffold via `init`.
1519
+ * Each template includes all helper functions inline — no external imports needed
1520
+ * beyond the @exagent/agent types.
1515
1521
  *
1516
- * IMPORTANT: These are starting points. Users should customize
1517
- * the prompts and logic for their specific needs.
1522
+ * Templates output TradeSignal[] where amountIn is a bigint in token-native units (wei).
1523
+ * The LLM returns a percentage (0-100) of the relevant balance, and the template
1524
+ * converts it to the correct bigint amount.
1518
1525
  */
1519
1526
  interface StrategyTemplate {
1520
1527
  id: string;
@@ -1949,6 +1956,10 @@ declare class MarketDataService {
1949
1956
  private cachedVolume24h;
1950
1957
  /** Cached price change data */
1951
1958
  private cachedPriceChange24h;
1959
+ /** Cached 24h hourly price history per token address */
1960
+ private cachedPriceHistory;
1961
+ /** Timestamp of last successful price history fetch */
1962
+ private lastHistoryFetchAt;
1952
1963
  constructor(rpcUrl: string, store?: StrategyStore);
1953
1964
  /** Get the underlying TokenResolver for direct access */
1954
1965
  getResolver(): TokenResolver;
@@ -1971,6 +1982,12 @@ declare class MarketDataService {
1971
1982
  * Returns cached prices if still fresh (<60s old)
1972
1983
  */
1973
1984
  private fetchPrices;
1985
+ /**
1986
+ * Fetch 24h hourly price history from CoinGecko.
1987
+ * Returns cached data if still fresh (< 60 min old).
1988
+ * Only fetches for tokens with known CoinGecko IDs.
1989
+ */
1990
+ private fetchPriceHistory;
1974
1991
  /**
1975
1992
  * Fetch real on-chain balances: native ETH + ERC-20 tokens.
1976
1993
  * Uses Multicall3 to batch all balanceOf calls into a single RPC request.
@@ -3359,6 +3376,6 @@ declare function decryptEnvFile(encPath: string, passphrase: string): Record<str
3359
3376
  declare function loadSecureEnv(basePath: string, passphrase?: string): boolean;
3360
3377
 
3361
3378
  /** @exagent/agent package version — update alongside package.json */
3362
- declare const AGENT_VERSION = "0.1.47";
3379
+ declare const AGENT_VERSION = "0.1.48";
3363
3380
 
3364
3381
  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 };