@exagent/agent 0.1.13 → 0.1.15
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/chunk-W2FU5T46.mjs +3058 -0
- package/dist/chunk-YWPRVCRB.mjs +3009 -0
- package/dist/cli.js +221 -168
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +250 -197
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -878,14 +878,197 @@ function getAllStrategyTemplates() {
|
|
|
878
878
|
return STRATEGY_TEMPLATES;
|
|
879
879
|
}
|
|
880
880
|
|
|
881
|
+
// src/config.ts
|
|
882
|
+
var import_fs2 = require("fs");
|
|
883
|
+
var import_path2 = require("path");
|
|
884
|
+
var import_dotenv = require("dotenv");
|
|
885
|
+
|
|
886
|
+
// src/types.ts
|
|
887
|
+
var import_zod = require("zod");
|
|
888
|
+
var WalletSetupSchema = import_zod.z.enum(["generate", "provide"]);
|
|
889
|
+
var LLMProviderSchema = import_zod.z.enum(["openai", "anthropic", "google", "deepseek", "mistral", "groq", "together", "ollama", "custom"]);
|
|
890
|
+
var LLMConfigSchema = import_zod.z.object({
|
|
891
|
+
provider: LLMProviderSchema,
|
|
892
|
+
model: import_zod.z.string().optional(),
|
|
893
|
+
apiKey: import_zod.z.string().optional(),
|
|
894
|
+
endpoint: import_zod.z.string().url().optional(),
|
|
895
|
+
temperature: import_zod.z.number().min(0).max(2).default(0.7),
|
|
896
|
+
maxTokens: import_zod.z.number().positive().default(4096)
|
|
897
|
+
});
|
|
898
|
+
var RiskUniverseSchema = import_zod.z.enum(["core", "established", "derivatives", "emerging", "frontier"]);
|
|
899
|
+
var TradingConfigSchema = import_zod.z.object({
|
|
900
|
+
timeHorizon: import_zod.z.enum(["intraday", "swing", "position"]).default("swing"),
|
|
901
|
+
maxPositionSizeBps: import_zod.z.number().min(100).max(1e4).default(1e3),
|
|
902
|
+
// 1-100%
|
|
903
|
+
maxDailyLossBps: import_zod.z.number().min(0).max(1e4).default(500),
|
|
904
|
+
// 0-100%
|
|
905
|
+
maxConcurrentPositions: import_zod.z.number().min(1).max(100).default(5),
|
|
906
|
+
tradingIntervalMs: import_zod.z.number().min(1e3).default(6e4),
|
|
907
|
+
// minimum 1 second
|
|
908
|
+
maxSlippageBps: import_zod.z.number().min(10).max(1e3).default(100),
|
|
909
|
+
// 0.1-10%, default 1%
|
|
910
|
+
minTradeValueUSD: import_zod.z.number().min(0).default(1)
|
|
911
|
+
// minimum trade value in USD
|
|
912
|
+
});
|
|
913
|
+
var VaultPolicySchema = import_zod.z.enum([
|
|
914
|
+
"disabled",
|
|
915
|
+
// Never create a vault - trade with agent's own capital only
|
|
916
|
+
"manual"
|
|
917
|
+
// Only create vault when explicitly directed by owner
|
|
918
|
+
]);
|
|
919
|
+
var VaultConfigSchema = import_zod.z.object({
|
|
920
|
+
// Policy for vault creation (asked during deployment)
|
|
921
|
+
policy: VaultPolicySchema.default("manual"),
|
|
922
|
+
// Default vault name (auto-generated from agent name if not set)
|
|
923
|
+
defaultName: import_zod.z.string().optional(),
|
|
924
|
+
// Default vault symbol (auto-generated if not set)
|
|
925
|
+
defaultSymbol: import_zod.z.string().optional(),
|
|
926
|
+
// Fee recipient for vault fees (default: agent wallet)
|
|
927
|
+
feeRecipient: import_zod.z.string().optional(),
|
|
928
|
+
// When vault exists, trade through vault instead of direct trading
|
|
929
|
+
// This pools depositors' capital with the agent's trades
|
|
930
|
+
preferVaultTrading: import_zod.z.boolean().default(true)
|
|
931
|
+
});
|
|
932
|
+
var WalletConfigSchema = import_zod.z.object({
|
|
933
|
+
setup: WalletSetupSchema.default("provide")
|
|
934
|
+
}).optional();
|
|
935
|
+
var RelayConfigSchema = import_zod.z.object({
|
|
936
|
+
enabled: import_zod.z.boolean().default(false),
|
|
937
|
+
apiUrl: import_zod.z.string().url(),
|
|
938
|
+
heartbeatIntervalMs: import_zod.z.number().min(5e3).default(3e4)
|
|
939
|
+
}).optional();
|
|
940
|
+
var AgentConfigSchema = import_zod.z.object({
|
|
941
|
+
// Identity (from on-chain registration)
|
|
942
|
+
agentId: import_zod.z.union([import_zod.z.number().positive(), import_zod.z.string()]),
|
|
943
|
+
name: import_zod.z.string().min(3).max(32),
|
|
944
|
+
// Network
|
|
945
|
+
network: import_zod.z.literal("mainnet").default("mainnet"),
|
|
946
|
+
// Wallet setup preference
|
|
947
|
+
wallet: WalletConfigSchema,
|
|
948
|
+
// LLM
|
|
949
|
+
llm: LLMConfigSchema,
|
|
950
|
+
// Trading parameters
|
|
951
|
+
riskUniverse: RiskUniverseSchema.default("established"),
|
|
952
|
+
trading: TradingConfigSchema.default({}),
|
|
953
|
+
// Vault configuration (copy trading)
|
|
954
|
+
vault: VaultConfigSchema.default({}),
|
|
955
|
+
// Relay configuration (command center)
|
|
956
|
+
relay: RelayConfigSchema,
|
|
957
|
+
// Allowed tokens (addresses)
|
|
958
|
+
allowedTokens: import_zod.z.array(import_zod.z.string()).optional()
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
// src/config.ts
|
|
962
|
+
function loadConfig(configPath) {
|
|
963
|
+
(0, import_dotenv.config)();
|
|
964
|
+
const configFile = configPath || process.env.EXAGENT_CONFIG || "agent-config.json";
|
|
965
|
+
const fullPath = configFile.startsWith("/") ? configFile : (0, import_path2.join)(process.cwd(), configFile);
|
|
966
|
+
if (!(0, import_fs2.existsSync)(fullPath)) {
|
|
967
|
+
throw new Error(`Config file not found: ${fullPath}`);
|
|
968
|
+
}
|
|
969
|
+
const rawConfig = JSON.parse((0, import_fs2.readFileSync)(fullPath, "utf-8"));
|
|
970
|
+
const config = AgentConfigSchema.parse(rawConfig);
|
|
971
|
+
const privateKey = process.env.EXAGENT_PRIVATE_KEY;
|
|
972
|
+
if (privateKey && (!privateKey.startsWith("0x") || privateKey.length !== 66)) {
|
|
973
|
+
throw new Error("EXAGENT_PRIVATE_KEY must be a valid 32-byte hex string starting with 0x");
|
|
974
|
+
}
|
|
975
|
+
const llmConfig = { ...config.llm };
|
|
976
|
+
if (process.env.OPENAI_API_KEY && config.llm.provider === "openai") {
|
|
977
|
+
llmConfig.apiKey = process.env.OPENAI_API_KEY;
|
|
978
|
+
}
|
|
979
|
+
if (process.env.ANTHROPIC_API_KEY && config.llm.provider === "anthropic") {
|
|
980
|
+
llmConfig.apiKey = process.env.ANTHROPIC_API_KEY;
|
|
981
|
+
}
|
|
982
|
+
if (process.env.GOOGLE_AI_API_KEY && config.llm.provider === "google") {
|
|
983
|
+
llmConfig.apiKey = process.env.GOOGLE_AI_API_KEY;
|
|
984
|
+
}
|
|
985
|
+
if (process.env.DEEPSEEK_API_KEY && config.llm.provider === "deepseek") {
|
|
986
|
+
llmConfig.apiKey = process.env.DEEPSEEK_API_KEY;
|
|
987
|
+
}
|
|
988
|
+
if (process.env.MISTRAL_API_KEY && config.llm.provider === "mistral") {
|
|
989
|
+
llmConfig.apiKey = process.env.MISTRAL_API_KEY;
|
|
990
|
+
}
|
|
991
|
+
if (process.env.GROQ_API_KEY && config.llm.provider === "groq") {
|
|
992
|
+
llmConfig.apiKey = process.env.GROQ_API_KEY;
|
|
993
|
+
}
|
|
994
|
+
if (process.env.TOGETHER_API_KEY && config.llm.provider === "together") {
|
|
995
|
+
llmConfig.apiKey = process.env.TOGETHER_API_KEY;
|
|
996
|
+
}
|
|
997
|
+
if (process.env.EXAGENT_LLM_URL) {
|
|
998
|
+
llmConfig.endpoint = process.env.EXAGENT_LLM_URL;
|
|
999
|
+
}
|
|
1000
|
+
if (process.env.EXAGENT_LLM_MODEL) {
|
|
1001
|
+
llmConfig.model = process.env.EXAGENT_LLM_MODEL;
|
|
1002
|
+
}
|
|
1003
|
+
const network = process.env.EXAGENT_NETWORK || config.network;
|
|
1004
|
+
return {
|
|
1005
|
+
...config,
|
|
1006
|
+
llm: llmConfig,
|
|
1007
|
+
network,
|
|
1008
|
+
privateKey: privateKey || ""
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
function validateConfig(config) {
|
|
1012
|
+
if (!config.privateKey) {
|
|
1013
|
+
throw new Error("Private key is required");
|
|
1014
|
+
}
|
|
1015
|
+
if (config.llm.provider !== "ollama" && !config.llm.apiKey) {
|
|
1016
|
+
throw new Error(`API key required for ${config.llm.provider} provider`);
|
|
1017
|
+
}
|
|
1018
|
+
if (config.llm.provider === "ollama" && !config.llm.endpoint) {
|
|
1019
|
+
config.llm.endpoint = "http://localhost:11434";
|
|
1020
|
+
}
|
|
1021
|
+
if (config.llm.provider === "custom" && !config.llm.endpoint) {
|
|
1022
|
+
throw new Error("Endpoint required for custom LLM provider");
|
|
1023
|
+
}
|
|
1024
|
+
if (!config.agentId || Number(config.agentId) <= 0) {
|
|
1025
|
+
throw new Error("Valid agent ID required");
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
var DEFAULT_RPC_URL = "https://base-rpc.publicnode.com";
|
|
1029
|
+
function getRpcUrl() {
|
|
1030
|
+
return process.env.BASE_RPC_URL || process.env.EXAGENT_RPC_URL || DEFAULT_RPC_URL;
|
|
1031
|
+
}
|
|
1032
|
+
function createSampleConfig(agentId, name) {
|
|
1033
|
+
return {
|
|
1034
|
+
agentId,
|
|
1035
|
+
name,
|
|
1036
|
+
network: "mainnet",
|
|
1037
|
+
llm: {
|
|
1038
|
+
provider: "openai",
|
|
1039
|
+
model: "gpt-4.1",
|
|
1040
|
+
temperature: 0.7,
|
|
1041
|
+
maxTokens: 4096
|
|
1042
|
+
},
|
|
1043
|
+
riskUniverse: "established",
|
|
1044
|
+
trading: {
|
|
1045
|
+
timeHorizon: "swing",
|
|
1046
|
+
maxPositionSizeBps: 1e3,
|
|
1047
|
+
maxDailyLossBps: 500,
|
|
1048
|
+
maxConcurrentPositions: 5,
|
|
1049
|
+
tradingIntervalMs: 6e4,
|
|
1050
|
+
maxSlippageBps: 100,
|
|
1051
|
+
minTradeValueUSD: 1
|
|
1052
|
+
},
|
|
1053
|
+
vault: {
|
|
1054
|
+
// Default to manual - user must explicitly enable auto-creation
|
|
1055
|
+
policy: "manual",
|
|
1056
|
+
// Will use agent name for vault name if not set
|
|
1057
|
+
preferVaultTrading: true
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
|
|
881
1062
|
// src/trading/executor.ts
|
|
882
1063
|
var TradeExecutor = class {
|
|
883
1064
|
client;
|
|
884
1065
|
config;
|
|
885
1066
|
allowedTokens;
|
|
886
|
-
|
|
1067
|
+
configHashFn;
|
|
1068
|
+
constructor(client, config, configHashFn) {
|
|
887
1069
|
this.client = client;
|
|
888
1070
|
this.config = config;
|
|
1071
|
+
this.configHashFn = configHashFn;
|
|
889
1072
|
this.allowedTokens = new Set(
|
|
890
1073
|
(config.allowedTokens || []).map((t) => t.toLowerCase())
|
|
891
1074
|
);
|
|
@@ -903,11 +1086,13 @@ var TradeExecutor = class {
|
|
|
903
1086
|
if (!this.validateSignal(signal)) {
|
|
904
1087
|
return { success: false, error: "Signal exceeds position limits" };
|
|
905
1088
|
}
|
|
1089
|
+
const configHash = this.configHashFn?.();
|
|
906
1090
|
const result = await this.client.trade({
|
|
907
1091
|
tokenIn: signal.tokenIn,
|
|
908
1092
|
tokenOut: signal.tokenOut,
|
|
909
1093
|
amountIn: signal.amountIn,
|
|
910
|
-
maxSlippageBps: this.config.trading?.maxSlippageBps ?? 100
|
|
1094
|
+
maxSlippageBps: this.config.trading?.maxSlippageBps ?? 100,
|
|
1095
|
+
...configHash && { configHash }
|
|
911
1096
|
});
|
|
912
1097
|
console.log(`Trade executed: ${result.hash}`);
|
|
913
1098
|
return { success: true, txHash: result.hash };
|
|
@@ -1446,7 +1631,7 @@ var VaultManager = class {
|
|
|
1446
1631
|
this.addresses = ADDRESSES[config.network];
|
|
1447
1632
|
this.account = (0, import_accounts.privateKeyToAccount)(config.walletKey);
|
|
1448
1633
|
this.chain = import_chains.base;
|
|
1449
|
-
const rpcUrl =
|
|
1634
|
+
const rpcUrl = getRpcUrl();
|
|
1450
1635
|
this.publicClient = (0, import_viem2.createPublicClient)({
|
|
1451
1636
|
chain: this.chain,
|
|
1452
1637
|
transport: (0, import_viem2.http)(rpcUrl)
|
|
@@ -1969,7 +2154,7 @@ var AgentRuntime = class {
|
|
|
1969
2154
|
console.log(`LLM ready: ${llmMeta.provider} (${llmMeta.model})`);
|
|
1970
2155
|
await this.syncConfigHash();
|
|
1971
2156
|
this.strategy = await loadStrategy();
|
|
1972
|
-
this.executor = new TradeExecutor(this.client, this.config);
|
|
2157
|
+
this.executor = new TradeExecutor(this.client, this.config, () => this.getConfigHash());
|
|
1973
2158
|
this.riskManager = new RiskManager(this.config.trading);
|
|
1974
2159
|
this.marketData = new MarketDataService(this.getRpcUrl());
|
|
1975
2160
|
await this.initializeVaultManager();
|
|
@@ -2574,10 +2759,10 @@ var AgentRuntime = class {
|
|
|
2574
2759
|
}
|
|
2575
2760
|
}
|
|
2576
2761
|
/**
|
|
2577
|
-
* Get RPC URL
|
|
2762
|
+
* Get RPC URL from environment or default
|
|
2578
2763
|
*/
|
|
2579
2764
|
getRpcUrl() {
|
|
2580
|
-
return
|
|
2765
|
+
return getRpcUrl();
|
|
2581
2766
|
}
|
|
2582
2767
|
/**
|
|
2583
2768
|
* Default tokens to track.
|
|
@@ -2586,35 +2771,80 @@ var AgentRuntime = class {
|
|
|
2586
2771
|
*/
|
|
2587
2772
|
getDefaultTokens() {
|
|
2588
2773
|
return [
|
|
2589
|
-
// Core
|
|
2774
|
+
// Core (0)
|
|
2590
2775
|
"0x4200000000000000000000000000000000000006",
|
|
2591
2776
|
// WETH
|
|
2592
2777
|
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
2593
2778
|
// USDC
|
|
2594
2779
|
"0x2Ae3F1Ec7F1F5012CFEab0185bFC7aa3cf0DEC22",
|
|
2595
2780
|
// cbETH
|
|
2596
|
-
"0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA",
|
|
2597
|
-
// USDbC
|
|
2598
|
-
"0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
|
|
2599
|
-
// DAI
|
|
2600
|
-
// Established
|
|
2601
|
-
"0x940181a94A35A4569E4529A3CDfB74e38FD98631",
|
|
2602
|
-
// AERO
|
|
2603
2781
|
"0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
|
|
2604
2782
|
// cbBTC
|
|
2605
2783
|
"0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452",
|
|
2606
2784
|
// wstETH
|
|
2785
|
+
"0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
|
|
2786
|
+
// DAI
|
|
2787
|
+
"0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2",
|
|
2788
|
+
// USDT
|
|
2789
|
+
"0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA",
|
|
2790
|
+
// USDbC
|
|
2791
|
+
"0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
|
|
2792
|
+
// EURC
|
|
2793
|
+
"0xB6fe221Fe9EeF5aBa221c348bA20A1Bf5e73624c",
|
|
2794
|
+
// rETH
|
|
2795
|
+
"0x0555E30da8f98308EdB960aa94C0Db47230d2B9c",
|
|
2796
|
+
// WBTC
|
|
2797
|
+
// Established (1) - filtered by risk universe at init
|
|
2798
|
+
"0x940181a94A35A4569E4529A3CDfB74e38FD98631",
|
|
2799
|
+
// AERO
|
|
2800
|
+
"0x04C0599Ae5A44757c0af6F9eC3b93da8976c150A",
|
|
2801
|
+
// weETH
|
|
2607
2802
|
"0x2416092f143378750bb29b79eD961ab195CcEea5",
|
|
2608
2803
|
// ezETH
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2804
|
+
"0xA88594D404727625A9437C3f886C7643872296AE",
|
|
2805
|
+
// WELL
|
|
2806
|
+
"0xBAa5CC21fd487B8Fcc2F632f3F4E8D37262a0842",
|
|
2807
|
+
// MORPHO
|
|
2808
|
+
"0x88Fb150BDc53A65fe94Dea0c9BA0a6dAf8C6e196",
|
|
2809
|
+
// LINK
|
|
2810
|
+
"0xc3De830EA07524a0761646a6a4e4be0e114a3C83",
|
|
2811
|
+
// UNI
|
|
2812
|
+
"0x63706e401c06ac8513145b7687A14804d17f814b",
|
|
2813
|
+
// AAVE
|
|
2814
|
+
"0x9e1028F5F1D5eDE59748FFceE5532509976840E0",
|
|
2815
|
+
// COMP
|
|
2816
|
+
"0x4158734D47Fc9692176B5085E0F52ee0Da5d47F1",
|
|
2817
|
+
// BAL
|
|
2818
|
+
"0x8Ee73c484A26e0A5df2Ee2a4960B789967dd0415",
|
|
2819
|
+
// CRV
|
|
2820
|
+
"0x22e6966B799c4D5B13BE962E1D117b56327FDa66",
|
|
2821
|
+
// SNX
|
|
2822
|
+
// Derivatives (2) - filtered by risk universe at init
|
|
2614
2823
|
"0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b",
|
|
2615
2824
|
// VIRTUAL
|
|
2616
|
-
"
|
|
2825
|
+
"0x4F9Fd6Be4a90f2620860d680c0d4d5Fb53d1A825",
|
|
2826
|
+
// AIXBT
|
|
2827
|
+
"0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed",
|
|
2828
|
+
// DEGEN
|
|
2829
|
+
"0x0578d8A44db98B23BF096A382e016e29a5Ce0ffe",
|
|
2830
|
+
// HIGHER
|
|
2831
|
+
"0x1bc0c42215582d5A085795f4baDbaC3ff36d1Bcb",
|
|
2832
|
+
// CLANKER
|
|
2833
|
+
// Emerging (3) - filtered by risk universe at init
|
|
2834
|
+
"0x532f27101965dd16442E59d40670FaF5eBB142E4",
|
|
2835
|
+
// BRETT
|
|
2836
|
+
"0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4",
|
|
2617
2837
|
// TOSHI
|
|
2838
|
+
"0x6921B130D297cc43754afba22e5EAc0FBf8Db75b",
|
|
2839
|
+
// DOGINME
|
|
2840
|
+
"0xB1a03EdA10342529bBF8EB700a06C60441fEf25d",
|
|
2841
|
+
// MIGGLES
|
|
2842
|
+
"0x7F12d13B34F5F4f0a9449c16Bcd42f0da47AF200",
|
|
2843
|
+
// NORMIE
|
|
2844
|
+
"0x27D2DECb4bFC9C76F0309b8E88dec3a601Fe25a8",
|
|
2845
|
+
// BALD
|
|
2846
|
+
"0x768BE13e1680b5ebE0024C42c896E3dB59ec0149"
|
|
2847
|
+
// SKI
|
|
2618
2848
|
];
|
|
2619
2849
|
}
|
|
2620
2850
|
sleep(ms) {
|
|
@@ -2672,183 +2902,6 @@ var AgentRuntime = class {
|
|
|
2672
2902
|
}
|
|
2673
2903
|
};
|
|
2674
2904
|
|
|
2675
|
-
// src/config.ts
|
|
2676
|
-
var import_fs2 = require("fs");
|
|
2677
|
-
var import_path2 = require("path");
|
|
2678
|
-
var import_dotenv = require("dotenv");
|
|
2679
|
-
|
|
2680
|
-
// src/types.ts
|
|
2681
|
-
var import_zod = require("zod");
|
|
2682
|
-
var WalletSetupSchema = import_zod.z.enum(["generate", "provide"]);
|
|
2683
|
-
var LLMProviderSchema = import_zod.z.enum(["openai", "anthropic", "google", "deepseek", "mistral", "groq", "together", "ollama", "custom"]);
|
|
2684
|
-
var LLMConfigSchema = import_zod.z.object({
|
|
2685
|
-
provider: LLMProviderSchema,
|
|
2686
|
-
model: import_zod.z.string().optional(),
|
|
2687
|
-
apiKey: import_zod.z.string().optional(),
|
|
2688
|
-
endpoint: import_zod.z.string().url().optional(),
|
|
2689
|
-
temperature: import_zod.z.number().min(0).max(2).default(0.7),
|
|
2690
|
-
maxTokens: import_zod.z.number().positive().default(4096)
|
|
2691
|
-
});
|
|
2692
|
-
var RiskUniverseSchema = import_zod.z.enum(["core", "established", "derivatives", "emerging", "frontier"]);
|
|
2693
|
-
var TradingConfigSchema = import_zod.z.object({
|
|
2694
|
-
timeHorizon: import_zod.z.enum(["intraday", "swing", "position"]).default("swing"),
|
|
2695
|
-
maxPositionSizeBps: import_zod.z.number().min(100).max(1e4).default(1e3),
|
|
2696
|
-
// 1-100%
|
|
2697
|
-
maxDailyLossBps: import_zod.z.number().min(0).max(1e4).default(500),
|
|
2698
|
-
// 0-100%
|
|
2699
|
-
maxConcurrentPositions: import_zod.z.number().min(1).max(100).default(5),
|
|
2700
|
-
tradingIntervalMs: import_zod.z.number().min(1e3).default(6e4),
|
|
2701
|
-
// minimum 1 second
|
|
2702
|
-
maxSlippageBps: import_zod.z.number().min(10).max(1e3).default(100),
|
|
2703
|
-
// 0.1-10%, default 1%
|
|
2704
|
-
minTradeValueUSD: import_zod.z.number().min(0).default(1)
|
|
2705
|
-
// minimum trade value in USD
|
|
2706
|
-
});
|
|
2707
|
-
var VaultPolicySchema = import_zod.z.enum([
|
|
2708
|
-
"disabled",
|
|
2709
|
-
// Never create a vault - trade with agent's own capital only
|
|
2710
|
-
"manual"
|
|
2711
|
-
// Only create vault when explicitly directed by owner
|
|
2712
|
-
]);
|
|
2713
|
-
var VaultConfigSchema = import_zod.z.object({
|
|
2714
|
-
// Policy for vault creation (asked during deployment)
|
|
2715
|
-
policy: VaultPolicySchema.default("manual"),
|
|
2716
|
-
// Default vault name (auto-generated from agent name if not set)
|
|
2717
|
-
defaultName: import_zod.z.string().optional(),
|
|
2718
|
-
// Default vault symbol (auto-generated if not set)
|
|
2719
|
-
defaultSymbol: import_zod.z.string().optional(),
|
|
2720
|
-
// Fee recipient for vault fees (default: agent wallet)
|
|
2721
|
-
feeRecipient: import_zod.z.string().optional(),
|
|
2722
|
-
// When vault exists, trade through vault instead of direct trading
|
|
2723
|
-
// This pools depositors' capital with the agent's trades
|
|
2724
|
-
preferVaultTrading: import_zod.z.boolean().default(true)
|
|
2725
|
-
});
|
|
2726
|
-
var WalletConfigSchema = import_zod.z.object({
|
|
2727
|
-
setup: WalletSetupSchema.default("provide")
|
|
2728
|
-
}).optional();
|
|
2729
|
-
var RelayConfigSchema = import_zod.z.object({
|
|
2730
|
-
enabled: import_zod.z.boolean().default(false),
|
|
2731
|
-
apiUrl: import_zod.z.string().url(),
|
|
2732
|
-
heartbeatIntervalMs: import_zod.z.number().min(5e3).default(3e4)
|
|
2733
|
-
}).optional();
|
|
2734
|
-
var AgentConfigSchema = import_zod.z.object({
|
|
2735
|
-
// Identity (from on-chain registration)
|
|
2736
|
-
agentId: import_zod.z.union([import_zod.z.number().positive(), import_zod.z.string()]),
|
|
2737
|
-
name: import_zod.z.string().min(3).max(32),
|
|
2738
|
-
// Network
|
|
2739
|
-
network: import_zod.z.literal("mainnet").default("mainnet"),
|
|
2740
|
-
// Wallet setup preference
|
|
2741
|
-
wallet: WalletConfigSchema,
|
|
2742
|
-
// LLM
|
|
2743
|
-
llm: LLMConfigSchema,
|
|
2744
|
-
// Trading parameters
|
|
2745
|
-
riskUniverse: RiskUniverseSchema.default("established"),
|
|
2746
|
-
trading: TradingConfigSchema.default({}),
|
|
2747
|
-
// Vault configuration (copy trading)
|
|
2748
|
-
vault: VaultConfigSchema.default({}),
|
|
2749
|
-
// Relay configuration (command center)
|
|
2750
|
-
relay: RelayConfigSchema,
|
|
2751
|
-
// Allowed tokens (addresses)
|
|
2752
|
-
allowedTokens: import_zod.z.array(import_zod.z.string()).optional()
|
|
2753
|
-
});
|
|
2754
|
-
|
|
2755
|
-
// src/config.ts
|
|
2756
|
-
function loadConfig(configPath) {
|
|
2757
|
-
(0, import_dotenv.config)();
|
|
2758
|
-
const configFile = configPath || process.env.EXAGENT_CONFIG || "agent-config.json";
|
|
2759
|
-
const fullPath = configFile.startsWith("/") ? configFile : (0, import_path2.join)(process.cwd(), configFile);
|
|
2760
|
-
if (!(0, import_fs2.existsSync)(fullPath)) {
|
|
2761
|
-
throw new Error(`Config file not found: ${fullPath}`);
|
|
2762
|
-
}
|
|
2763
|
-
const rawConfig = JSON.parse((0, import_fs2.readFileSync)(fullPath, "utf-8"));
|
|
2764
|
-
const config = AgentConfigSchema.parse(rawConfig);
|
|
2765
|
-
const privateKey = process.env.EXAGENT_PRIVATE_KEY;
|
|
2766
|
-
if (privateKey && (!privateKey.startsWith("0x") || privateKey.length !== 66)) {
|
|
2767
|
-
throw new Error("EXAGENT_PRIVATE_KEY must be a valid 32-byte hex string starting with 0x");
|
|
2768
|
-
}
|
|
2769
|
-
const llmConfig = { ...config.llm };
|
|
2770
|
-
if (process.env.OPENAI_API_KEY && config.llm.provider === "openai") {
|
|
2771
|
-
llmConfig.apiKey = process.env.OPENAI_API_KEY;
|
|
2772
|
-
}
|
|
2773
|
-
if (process.env.ANTHROPIC_API_KEY && config.llm.provider === "anthropic") {
|
|
2774
|
-
llmConfig.apiKey = process.env.ANTHROPIC_API_KEY;
|
|
2775
|
-
}
|
|
2776
|
-
if (process.env.GOOGLE_AI_API_KEY && config.llm.provider === "google") {
|
|
2777
|
-
llmConfig.apiKey = process.env.GOOGLE_AI_API_KEY;
|
|
2778
|
-
}
|
|
2779
|
-
if (process.env.DEEPSEEK_API_KEY && config.llm.provider === "deepseek") {
|
|
2780
|
-
llmConfig.apiKey = process.env.DEEPSEEK_API_KEY;
|
|
2781
|
-
}
|
|
2782
|
-
if (process.env.MISTRAL_API_KEY && config.llm.provider === "mistral") {
|
|
2783
|
-
llmConfig.apiKey = process.env.MISTRAL_API_KEY;
|
|
2784
|
-
}
|
|
2785
|
-
if (process.env.GROQ_API_KEY && config.llm.provider === "groq") {
|
|
2786
|
-
llmConfig.apiKey = process.env.GROQ_API_KEY;
|
|
2787
|
-
}
|
|
2788
|
-
if (process.env.TOGETHER_API_KEY && config.llm.provider === "together") {
|
|
2789
|
-
llmConfig.apiKey = process.env.TOGETHER_API_KEY;
|
|
2790
|
-
}
|
|
2791
|
-
if (process.env.EXAGENT_LLM_URL) {
|
|
2792
|
-
llmConfig.endpoint = process.env.EXAGENT_LLM_URL;
|
|
2793
|
-
}
|
|
2794
|
-
if (process.env.EXAGENT_LLM_MODEL) {
|
|
2795
|
-
llmConfig.model = process.env.EXAGENT_LLM_MODEL;
|
|
2796
|
-
}
|
|
2797
|
-
const network = process.env.EXAGENT_NETWORK || config.network;
|
|
2798
|
-
return {
|
|
2799
|
-
...config,
|
|
2800
|
-
llm: llmConfig,
|
|
2801
|
-
network,
|
|
2802
|
-
privateKey: privateKey || ""
|
|
2803
|
-
};
|
|
2804
|
-
}
|
|
2805
|
-
function validateConfig(config) {
|
|
2806
|
-
if (!config.privateKey) {
|
|
2807
|
-
throw new Error("Private key is required");
|
|
2808
|
-
}
|
|
2809
|
-
if (config.llm.provider !== "ollama" && !config.llm.apiKey) {
|
|
2810
|
-
throw new Error(`API key required for ${config.llm.provider} provider`);
|
|
2811
|
-
}
|
|
2812
|
-
if (config.llm.provider === "ollama" && !config.llm.endpoint) {
|
|
2813
|
-
config.llm.endpoint = "http://localhost:11434";
|
|
2814
|
-
}
|
|
2815
|
-
if (config.llm.provider === "custom" && !config.llm.endpoint) {
|
|
2816
|
-
throw new Error("Endpoint required for custom LLM provider");
|
|
2817
|
-
}
|
|
2818
|
-
if (!config.agentId || Number(config.agentId) <= 0) {
|
|
2819
|
-
throw new Error("Valid agent ID required");
|
|
2820
|
-
}
|
|
2821
|
-
}
|
|
2822
|
-
function createSampleConfig(agentId, name) {
|
|
2823
|
-
return {
|
|
2824
|
-
agentId,
|
|
2825
|
-
name,
|
|
2826
|
-
network: "mainnet",
|
|
2827
|
-
llm: {
|
|
2828
|
-
provider: "openai",
|
|
2829
|
-
model: "gpt-4.1",
|
|
2830
|
-
temperature: 0.7,
|
|
2831
|
-
maxTokens: 4096
|
|
2832
|
-
},
|
|
2833
|
-
riskUniverse: "established",
|
|
2834
|
-
trading: {
|
|
2835
|
-
timeHorizon: "swing",
|
|
2836
|
-
maxPositionSizeBps: 1e3,
|
|
2837
|
-
maxDailyLossBps: 500,
|
|
2838
|
-
maxConcurrentPositions: 5,
|
|
2839
|
-
tradingIntervalMs: 6e4,
|
|
2840
|
-
maxSlippageBps: 100,
|
|
2841
|
-
minTradeValueUSD: 1
|
|
2842
|
-
},
|
|
2843
|
-
vault: {
|
|
2844
|
-
// Default to manual - user must explicitly enable auto-creation
|
|
2845
|
-
policy: "manual",
|
|
2846
|
-
// Will use agent name for vault name if not set
|
|
2847
|
-
preferVaultTrading: true
|
|
2848
|
-
}
|
|
2849
|
-
};
|
|
2850
|
-
}
|
|
2851
|
-
|
|
2852
2905
|
// src/secure-env.ts
|
|
2853
2906
|
var crypto = __toESM(require("crypto"));
|
|
2854
2907
|
var fs = __toESM(require("fs"));
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exagent/agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Autonomous trading agent runtime for Exagent",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"clean": "rm -rf dist"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@exagent/sdk": "^0.1.
|
|
32
|
+
"@exagent/sdk": "^0.1.8",
|
|
33
33
|
"chalk": "^5.3.0",
|
|
34
34
|
"commander": "^12.0.0",
|
|
35
35
|
"dotenv": "^16.4.0",
|