@aiaiaichain/agent 0.1.6 → 0.1.7

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.
Files changed (121) hide show
  1. package/dist/api/ExtensionAPI.d.ts +0 -1
  2. package/dist/api/ExtensionAPI.js +3 -7
  3. package/dist/api/Registry.d.ts +0 -1
  4. package/dist/api/Registry.js +54 -57
  5. package/dist/cli.d.ts +0 -1
  6. package/dist/cli.js +683 -686
  7. package/dist/core/AgentDir.d.ts +1 -1
  8. package/dist/core/AgentDir.js +45 -39
  9. package/dist/core/ChainConfig.d.ts +0 -1
  10. package/dist/core/ChainConfig.js +51 -55
  11. package/dist/core/EnvLoader.d.ts +4 -1
  12. package/dist/core/EnvLoader.js +97 -84
  13. package/dist/core/SystemMonitor.d.ts +0 -1
  14. package/dist/core/SystemMonitor.js +72 -85
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.js +19 -26
  17. package/dist/loader.d.ts +0 -1
  18. package/dist/loader.js +64 -67
  19. package/dist/mcp/entry.d.ts +0 -1
  20. package/dist/mcp/entry.js +3 -6
  21. package/dist/mcp/server.d.ts +0 -1
  22. package/dist/mcp/server.js +152 -156
  23. package/dist/models/CostTracker.d.ts +0 -1
  24. package/dist/models/CostTracker.js +58 -61
  25. package/dist/models/ModelRegistry.d.ts +0 -1
  26. package/dist/models/ModelRegistry.js +195 -155
  27. package/dist/providers/ProviderRegistry.d.ts +0 -1
  28. package/dist/providers/ProviderRegistry.js +33 -36
  29. package/dist/runner/AgentRunner.d.ts +0 -1
  30. package/dist/runner/AgentRunner.js +180 -184
  31. package/dist/runner/ModelClient.d.ts +0 -1
  32. package/dist/runner/ModelClient.js +133 -134
  33. package/dist/runner/SwarmRouter.d.ts +0 -1
  34. package/dist/runner/SwarmRouter.js +18 -22
  35. package/dist/runner/ToolDispatcher.d.ts +0 -1
  36. package/dist/runner/ToolDispatcher.js +30 -33
  37. package/dist/scheduler/AgentScheduler.d.ts +0 -1
  38. package/dist/scheduler/AgentScheduler.js +99 -103
  39. package/dist/session/ContextStore.d.ts +1 -1
  40. package/dist/session/ContextStore.js +76 -78
  41. package/dist/session/GoalManager.d.ts +0 -1
  42. package/dist/session/GoalManager.js +96 -100
  43. package/dist/session/MemoryStore.d.ts +2 -1
  44. package/dist/session/MemoryStore.js +108 -87
  45. package/dist/session/SessionManager.d.ts +5 -4
  46. package/dist/session/SessionManager.js +83 -62
  47. package/dist/session/SessionStore.d.ts +0 -1
  48. package/dist/session/SessionStore.js +112 -116
  49. package/dist/setup/SetupWizard.d.ts +0 -1
  50. package/dist/setup/SetupWizard.js +61 -64
  51. package/dist/tools/CrossTools.d.ts +0 -1
  52. package/dist/tools/CrossTools.js +140 -144
  53. package/dist/tools/GmgnIntegration.d.ts +0 -1
  54. package/dist/tools/GmgnIntegration.js +220 -230
  55. package/dist/tools/MarketSentiment.d.ts +0 -1
  56. package/dist/tools/MarketSentiment.js +213 -195
  57. package/dist/tools/NewsSentiment.d.ts +0 -1
  58. package/dist/tools/NewsSentiment.js +126 -130
  59. package/dist/tools/PriceFeed.d.ts +6 -1
  60. package/dist/tools/PriceFeed.js +201 -133
  61. package/dist/tools/TechnicalAnalysis.d.ts +1 -2
  62. package/dist/tools/TechnicalAnalysis.js +248 -216
  63. package/dist/tools/TechnicalAnalysis.worker.d.ts +25 -0
  64. package/dist/tools/TechnicalAnalysis.worker.js +92 -0
  65. package/dist/tools/TokenCalendar.d.ts +0 -1
  66. package/dist/tools/TokenCalendar.js +63 -68
  67. package/dist/tools/TokenSecurityScanner.d.ts +0 -1
  68. package/dist/tools/TokenSecurityScanner.js +93 -96
  69. package/dist/tools/TransactionSim.d.ts +0 -1
  70. package/dist/tools/TransactionSim.js +65 -71
  71. package/dist/tui/App.d.ts +0 -1
  72. package/dist/tui/App.js +895 -824
  73. package/dist/tui/ModelSelector.d.ts +0 -1
  74. package/dist/tui/ModelSelector.js +46 -49
  75. package/dist/tui/REPL.d.ts +0 -1
  76. package/dist/tui/REPL.js +222 -210
  77. package/dist/tui/Sparkline.d.ts +0 -1
  78. package/dist/tui/Sparkline.js +36 -37
  79. package/dist/tui/StatusBar.d.ts +0 -1
  80. package/dist/tui/StatusBar.js +9 -10
  81. package/dist/tui/ThemePresets.d.ts +0 -1
  82. package/dist/tui/ThemePresets.js +99 -103
  83. package/dist/tui/theme.d.ts +0 -1
  84. package/dist/tui/theme.js +50 -31
  85. package/dist/util/clipboard.d.ts +0 -1
  86. package/dist/util/clipboard.js +16 -20
  87. package/dist/util/commandSuggest.d.ts +0 -1
  88. package/dist/util/commandSuggest.js +34 -38
  89. package/dist/util/confirmation.d.ts +0 -1
  90. package/dist/util/confirmation.js +8 -11
  91. package/dist/util/errorHandler.d.ts +0 -1
  92. package/dist/util/errorHandler.js +20 -23
  93. package/dist/util/errors.d.ts +59 -0
  94. package/dist/util/errors.js +93 -0
  95. package/dist/util/logger.d.ts +0 -1
  96. package/dist/util/logger.js +30 -33
  97. package/dist/util/processManager.d.ts +0 -1
  98. package/dist/util/processManager.js +33 -36
  99. package/dist/util/resilientFetch.d.ts +6 -1
  100. package/dist/util/resilientFetch.js +134 -80
  101. package/dist/util/responseCache.d.ts +0 -1
  102. package/dist/util/responseCache.js +36 -45
  103. package/dist/util/rpc.d.ts +16 -0
  104. package/dist/util/rpc.js +69 -0
  105. package/dist/util/safeLog.d.ts +0 -1
  106. package/dist/util/safeLog.js +52 -53
  107. package/dist/util/scheduler.d.ts +0 -1
  108. package/dist/util/scheduler.js +53 -58
  109. package/dist/util/webhooks.d.ts +0 -1
  110. package/dist/util/webhooks.js +54 -58
  111. package/dist/wallet/ActionFeed.d.ts +0 -1
  112. package/dist/wallet/ActionFeed.js +189 -200
  113. package/dist/wallet/AgentWallet.d.ts +7 -8
  114. package/dist/wallet/AgentWallet.js +117 -144
  115. package/dist/wallet/ProfitTracker.d.ts +0 -1
  116. package/dist/wallet/ProfitTracker.js +71 -74
  117. package/package.json +11 -6
  118. package/scripts/build-esbuild.mjs +40 -0
  119. package/scripts/bundle-dts.mjs +58 -0
  120. package/scripts/minify.mjs +44 -0
  121. package/scripts/postinstall.js +27 -0
@@ -1,20 +1,8 @@
1
- /**
2
- * AgentWallet — manages all agent wallet balances and activity via public RPC.
3
- *
4
- * Wallets:
5
- * Cold: A11iZoqEt6hU7HyggqC67ee4AtYmaJjwKCvJLerJRV2J (Agent)
6
- * Action: BygDYM1ZXLQNC1HXLhnd1rHZ7E5XjioqT3vPjJFfjnU2 (buys + burns)
7
- * Deposit: FBMDYpG9WXKy4SgxuATQdB2sCyzHsJWPrEr45z3TgL2e (user deposits USDC/SOL)
8
- * Signer: GmFrDZT2cdrqykgTikVdXbe8EtCgzUDM9VsDhQnwsUsG (authority)
9
- */
1
+
10
2
  import { Type } from "@sinclair/typebox";
11
- import { resilientFetch } from "../util/resilientFetch.js";
3
+ import { rpcCall } from "../util/rpc.js";
12
4
  import { logger } from "../util/logger.js";
13
- // Wallet architecture (verified on-chain):
14
- // ACTION: GmFrDZT2cdrqykgTikVdXbe8EtCgzUDM9VsDhQnwsUsG (executes buys + burns)
15
- // HOT: BygDYM1ZXLQNC1HXLhnd1rHZ7E5XjioqT3vPjJFfjnU2 (temporary swap + burn)
16
- // DEPOSIT: FBMDYpG9WXKy4SgxuATQdB2sCyzHsJWPrEr45z3TgL2e (user deposits)
17
- // COLD: A11iZoqEt6hU7HyggqC67ee4AtYmaJjwKCvJLerJRV2J (reserve — /wallet only)
5
+
18
6
  export const ACTION_WALLET = "GmFrDZT2cdrqykgTikVdXbe8EtCgzUDM9VsDhQnwsUsG";
19
7
  export const HOT_WALLET = "BygDYM1ZXLQNC1HXLhnd1rHZ7E5XjioqT3vPjJFfjnU2";
20
8
  export const DEPOSIT_WALLET = "FBMDYpG9WXKy4SgxuATQdB2sCyzHsJWPrEr45z3TgL2e";
@@ -23,139 +11,124 @@ export const SIGNER = ACTION_WALLET;
23
11
  export const AIAIAI_MINT = "AVPJS61gZmWKtaEpb7qYPKo8Fk2xQUsayYQxPiPMpump";
24
12
  export const AIAIAI_TOKEN = AIAIAI_MINT;
25
13
  const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
26
- function getRpcUrl() {
27
- return process.env.SOLANA_RPC_URL || "https://api.mainnet-beta.solana.com";
28
- }
29
- async function rpcCall(method, params = []) {
30
- const response = await resilientFetch(getRpcUrl(), {
31
- timeout: 15_000,
32
- retries: 2,
33
- method: "POST",
34
- headers: { "Content-Type": "application/json" },
35
- body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
36
- });
37
- const data = await response.json();
38
- if (data.error) {
39
- const msg = data.error.message || 'Unknown RPC error';
40
- if (data.error.code === -32005 || msg.includes('rate limit')) {
41
- logger.warn('AgentWallet', 'RPC rate limited', { method, code: data.error.code });
42
- }
43
- throw new Error(msg);
44
- }
45
- return data.result;
46
- }
47
14
  async function getBalance(address) {
48
- try {
49
- const result = await rpcCall("getBalance", [address]);
50
- return (result?.value ?? 0) / 1e9;
51
- }
52
- catch (error) {
53
- logger.warn('AgentWallet', 'getBalance failed', { address, error: error.message });
54
- return 0;
55
- }
15
+ try {
16
+ const result = await rpcCall("getBalance", [address]);
17
+ return (result?.value ?? 0) / 1e9;
18
+ }
19
+ catch (error) {
20
+ logger.warn('AgentWallet', 'getBalance failed', { address, error: error.message });
21
+ return 0;
22
+ }
56
23
  }
57
24
  async function getTokenBalance(address, mint) {
58
- try {
59
- const result = await rpcCall("getTokenAccountsByOwner", [
60
- address,
61
- { mint },
62
- { encoding: "jsonParsed" },
63
- ]);
64
- const accounts = result?.value ?? [];
65
- if (accounts.length === 0)
66
- return 0;
67
- return parseFloat(accounts[0]?.account?.data?.parsed?.info?.tokenAmount?.uiAmount ?? "0");
68
- }
69
- catch (error) {
70
- logger.warn('AgentWallet', 'getTokenBalance failed', { address, mint, error: error.message });
71
- return 0;
72
- }
25
+ try {
26
+ const result = await rpcCall("getTokenAccountsByOwner", [
27
+ address,
28
+ { mint },
29
+ { encoding: "jsonParsed" },
30
+ ]);
31
+ const accounts = result?.value ?? [];
32
+ if (accounts.length === 0)
33
+ return 0;
34
+ return parseFloat(accounts[0]?.account?.data?.parsed?.info?.tokenAmount?.uiAmount ?? "0");
35
+ }
36
+ catch (error) {
37
+ logger.warn('AgentWallet', 'getTokenBalance failed', { address, mint, error: error.message });
38
+ return 0;
39
+ }
73
40
  }
74
41
  export class AgentWallet {
75
- cachedWallets = null;
76
- lastFetch = 0;
77
- cacheDuration = 30_000;
78
- async getAll() {
79
- if (this.cachedWallets && Date.now() - this.lastFetch < this.cacheDuration) {
80
- return this.cachedWallets;
81
- }
82
- // 4 wallets × 3 tokens = 12 parallel queries
83
- const [coldSol, coldAiai, coldUsdc, actionSol, actionAiai, actionUsdc, hotSol, hotAiai, hotUsdc, depSol, depAiai, depUsdc] = await Promise.all([
84
- getBalance(COLD_WALLET), getTokenBalance(COLD_WALLET, AIAIAI_MINT), getTokenBalance(COLD_WALLET, USDC_MINT),
85
- getBalance(ACTION_WALLET), getTokenBalance(ACTION_WALLET, AIAIAI_MINT), getTokenBalance(ACTION_WALLET, USDC_MINT),
86
- getBalance(HOT_WALLET), getTokenBalance(HOT_WALLET, AIAIAI_MINT), getTokenBalance(HOT_WALLET, USDC_MINT),
87
- getBalance(DEPOSIT_WALLET), getTokenBalance(DEPOSIT_WALLET, AIAIAI_MINT), getTokenBalance(DEPOSIT_WALLET, USDC_MINT),
88
- ]);
89
- this.cachedWallets = {
90
- cold: { address: COLD_WALLET, sol: coldSol, aiaiai: coldAiai, usdc: coldUsdc },
91
- action: { address: ACTION_WALLET, sol: actionSol, aiaiai: actionAiai, usdc: actionUsdc },
92
- hot: { address: HOT_WALLET, sol: hotSol, aiaiai: hotAiai, usdc: hotUsdc },
93
- deposit: { address: DEPOSIT_WALLET, sol: depSol, aiaiai: depAiai, usdc: depUsdc },
94
- };
95
- this.lastFetch = Date.now();
96
- return this.cachedWallets;
97
- }
98
- async getColdWallet() {
99
- return (await this.getAll()).cold;
100
- }
101
- async getActionWallet() {
102
- return (await this.getAll()).action;
103
- }
104
- async getDepositWallet() {
105
- return (await this.getAll()).deposit;
106
- }
107
- // Get live SOL price from PriceFeed
108
- async getSolPrice() {
109
- try {
110
- const { priceFeed } = await import("../tools/PriceFeed.js");
111
- const result = await priceFeed.fetchToken("So11111111111111111111111111111111111111112");
112
- return parseFloat(result.priceUsd ?? "150");
113
- }
114
- catch {
115
- return 150; // fallback
116
- }
117
- }
118
- // ── Tools ───────────────────────────────────────────────────────────────
119
- async getHotWallet() {
120
- return (await this.getAll()).hot;
121
- }
122
- getAgentBalanceParams = Type.Object({});
123
- getDepositBalanceParams = Type.Object({});
124
- async getAgentBalanceTool() {
125
- const w = await this.getAll();
126
- const lines = [
127
- `🤖 Action Wallet`,
128
- ` ${ACTION_WALLET.slice(0, 8)}…${ACTION_WALLET.slice(-6)}`,
129
- ` SOL: ${w.action.sol.toFixed(4)}`,
130
- ` $AIAIAI: ${w.action.aiaiai.toLocaleString(undefined, { maximumFractionDigits: 2 })}`,
131
- ` USDC: ${w.action.usdc.toFixed(2)}`,
132
- ``,
133
- `⚡ Hot Wallet`,
134
- ` ${HOT_WALLET.slice(0, 8)}…${HOT_WALLET.slice(-6)}`,
135
- ` SOL: ${w.hot.sol.toFixed(4)}`,
136
- ` $AIAIAI: ${w.hot.aiaiai.toLocaleString(undefined, { maximumFractionDigits: 2 })}`,
137
- ` USDC: ${w.hot.usdc.toFixed(2)}`,
138
- ``,
139
- `❄️ Cold (reserve)`,
140
- ` ${COLD_WALLET.slice(0, 8)}…${COLD_WALLET.slice(-6)}`,
141
- ` SOL: ${w.cold.sol.toFixed(4)}`,
142
- ];
143
- return { content: [{ type: "text", text: lines.join("\n") }] };
144
- }
145
- async getDepositBalanceTool() {
146
- const w = await this.getAll();
147
- const lines = [
148
- `Deposit Wallet`,
149
- ` Address: ${DEPOSIT_WALLET}`,
150
- ` SOL: ${w.deposit.sol.toFixed(4)}`,
151
- ` $AIAIAI: ${w.deposit.aiaiai.toLocaleString(undefined, { maximumFractionDigits: 2 })}`,
152
- ` USDC: ${w.deposit.usdc.toFixed(2)}`,
153
- ``,
154
- `Send SOL or USDC here to fuel agent actions.`,
155
- `Signer: ${SIGNER.slice(0, 8)}…`,
156
- ];
157
- return { content: [{ type: "text", text: lines.join("\n") }] };
158
- }
42
+ cachedWallets = null;
43
+ lastFetch = 0;
44
+ cacheDuration = 30_000;
45
+ async getAll() {
46
+ if (this.cachedWallets && Date.now() - this.lastFetch < this.cacheDuration) {
47
+ return this.cachedWallets;
48
+ }
49
+
50
+ const [solBalances, tokenResults] = await Promise.all([
51
+
52
+ rpcCall("getMultipleAccounts", [[COLD_WALLET, ACTION_WALLET, HOT_WALLET, DEPOSIT_WALLET]])
53
+ .then(r => (r?.value ?? []).map((a) => (a?.lamports ?? 0) / 1e9))
54
+ .catch(() => [0, 0, 0, 0]),
55
+
56
+ Promise.all([
57
+ ...[COLD_WALLET, ACTION_WALLET, HOT_WALLET, DEPOSIT_WALLET].map(addr => getTokenBalance(addr, AIAIAI_MINT)),
58
+ ...[COLD_WALLET, ACTION_WALLET, HOT_WALLET, DEPOSIT_WALLET].map(addr => getTokenBalance(addr, USDC_MINT)),
59
+ ]),
60
+ ]);
61
+ const [coldSol = 0, actionSol = 0, hotSol = 0, depSol = 0] = solBalances;
62
+ const [coldAiai = 0, actionAiai = 0, hotAiai = 0, depAiai = 0, coldUsdc = 0, actionUsdc = 0, hotUsdc = 0, depUsdc = 0] = tokenResults;
63
+ this.cachedWallets = {
64
+ cold: { address: COLD_WALLET, sol: coldSol, aiaiai: coldAiai, usdc: coldUsdc },
65
+ action: { address: ACTION_WALLET, sol: actionSol, aiaiai: actionAiai, usdc: actionUsdc },
66
+ hot: { address: HOT_WALLET, sol: hotSol, aiaiai: hotAiai, usdc: hotUsdc },
67
+ deposit: { address: DEPOSIT_WALLET, sol: depSol, aiaiai: depAiai, usdc: depUsdc },
68
+ };
69
+ this.lastFetch = Date.now();
70
+ return this.cachedWallets;
71
+ }
72
+ async getColdWallet() {
73
+ return (await this.getAll()).cold;
74
+ }
75
+ async getActionWallet() {
76
+ return (await this.getAll()).action;
77
+ }
78
+ async getDepositWallet() {
79
+ return (await this.getAll()).deposit;
80
+ }
81
+
82
+ async getSolPrice() {
83
+ try {
84
+ const { priceFeed } = await import("../tools/PriceFeed.js");
85
+ const result = await priceFeed.fetchToken("So11111111111111111111111111111111111111112");
86
+ return parseFloat(result.priceUsd ?? "150");
87
+ }
88
+ catch {
89
+ return 150;
90
+ }
91
+ }
92
+
93
+ async getHotWallet() {
94
+ return (await this.getAll()).hot;
95
+ }
96
+ getAgentBalanceParams = Type.Object({});
97
+ getDepositBalanceParams = Type.Object({});
98
+ async getAgentBalanceTool() {
99
+ const w = await this.getAll();
100
+ const lines = [
101
+ `🤖 Action Wallet`,
102
+ ` ${ACTION_WALLET.slice(0, 8)}…${ACTION_WALLET.slice(-6)}`,
103
+ ` SOL: ${w.action.sol.toFixed(4)}`,
104
+ ` $AIAIAI: ${w.action.aiaiai.toLocaleString(undefined, { maximumFractionDigits: 2 })}`,
105
+ ` USDC: ${w.action.usdc.toFixed(2)}`,
106
+ ``,
107
+ `⚡ Hot Wallet`,
108
+ ` ${HOT_WALLET.slice(0, 8)}…${HOT_WALLET.slice(-6)}`,
109
+ ` SOL: ${w.hot.sol.toFixed(4)}`,
110
+ ` $AIAIAI: ${w.hot.aiaiai.toLocaleString(undefined, { maximumFractionDigits: 2 })}`,
111
+ ` USDC: ${w.hot.usdc.toFixed(2)}`,
112
+ ``,
113
+ `❄️ Cold (reserve)`,
114
+ ` ${COLD_WALLET.slice(0, 8)}…${COLD_WALLET.slice(-6)}`,
115
+ ` SOL: ${w.cold.sol.toFixed(4)}`,
116
+ ];
117
+ return { content: [{ type: "text", text: lines.join("\n") }] };
118
+ }
119
+ async getDepositBalanceTool() {
120
+ const w = await this.getAll();
121
+ const lines = [
122
+ `Deposit Wallet`,
123
+ ` Address: ${DEPOSIT_WALLET}`,
124
+ ` SOL: ${w.deposit.sol.toFixed(4)}`,
125
+ ` $AIAIAI: ${w.deposit.aiaiai.toLocaleString(undefined, { maximumFractionDigits: 2 })}`,
126
+ ` USDC: ${w.deposit.usdc.toFixed(2)}`,
127
+ ``,
128
+ `Send SOL or USDC here to fuel agent actions.`,
129
+ `Signer: ${SIGNER.slice(0, 8)}…`,
130
+ ];
131
+ return { content: [{ type: "text", text: lines.join("\n") }] };
132
+ }
159
133
  }
160
134
  export const agentWallet = new AgentWallet();
161
- //# sourceMappingURL=AgentWallet.js.map
@@ -27,4 +27,3 @@ export declare function recordTrade(type: "buy" | "sell" | "burn", tokenAmount:
27
27
  export declare function getPLSummary(currentTokenPrice: number): PLSummary;
28
28
  export declare function getTradeHistory(): Trade[];
29
29
  export declare function exportCSV(): string;
30
- //# sourceMappingURL=ProfitTracker.d.ts.map
@@ -1,6 +1,4 @@
1
- /**
2
- /ProfitTracker.ts - Track cost basis and P&L for agent wallet trades
3
- */
1
+
4
2
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
5
3
  import { join } from "node:path";
6
4
  import { homedir } from "node:os";
@@ -9,85 +7,84 @@ const AIAIAI_HOME = process.env.AIAIAI_HOME ?? join(homedir(), ".aiaiai");
9
7
  const TRACKER_DIR = join(AIAIAI_HOME, ".tracker");
10
8
  const TRACKER_FILE = join(TRACKER_DIR, "pl.json");
11
9
  function loadState() {
12
- try {
13
- const raw = readFileSync(TRACKER_FILE, "utf-8");
14
- return JSON.parse(raw);
15
- }
16
- catch {
17
- return { trades: [], totalSpent: 0, totalReceived: 0, avgCostBasis: 0 };
18
- }
10
+ try {
11
+ const raw = readFileSync(TRACKER_FILE, "utf-8");
12
+ return JSON.parse(raw);
13
+ }
14
+ catch {
15
+ return { trades: [], totalSpent: 0, totalReceived: 0, avgCostBasis: 0 };
16
+ }
19
17
  }
20
18
  function saveState(state) {
21
- try {
22
- if (!existsSync(TRACKER_DIR)) {
23
- mkdirSync(TRACKER_DIR, { recursive: true, mode: 0o700 });
24
- }
25
- writeFileSync(TRACKER_FILE, JSON.stringify(state, null, 2), "utf-8");
26
- }
27
- catch (error) {
28
- logger.warn("ProfitTracker", "Failed to save state", { error: error.message });
29
- }
19
+ try {
20
+ if (!existsSync(TRACKER_DIR)) {
21
+ mkdirSync(TRACKER_DIR, { recursive: true, mode: 0o700 });
22
+ }
23
+ writeFileSync(TRACKER_FILE, JSON.stringify(state, null, 2), "utf-8");
24
+ }
25
+ catch (error) {
26
+ logger.warn("ProfitTracker", "Failed to save state", { error: error.message });
27
+ }
30
28
  }
31
29
  export function recordTrade(type, tokenAmount, solAmount, txSignature) {
32
- const state = loadState();
33
- const pricePerToken = tokenAmount > 0 ? solAmount / tokenAmount : 0;
34
- const trade = {
35
- timestamp: Date.now(),
36
- type,
37
- tokenAmount,
38
- solAmount,
39
- pricePerToken,
40
- txSignature,
41
- };
42
- state.trades.push(trade);
43
- if (type === "buy") {
44
- state.totalSpent += solAmount;
45
- const totalTokensInvested = state.trades
46
- .filter(t => t.type === "buy")
47
- .reduce((sum, t) => sum + t.tokenAmount, 0);
48
- state.avgCostBasis = totalTokensInvested > 0 ? state.totalSpent / totalTokensInvested : 0;
49
- }
50
- else if (type === "sell") {
51
- state.totalReceived += solAmount;
52
- }
53
- saveState(state);
54
- logger.info("ProfitTracker", "Recorded " + type, { tokenAmount, solAmount, pricePerToken });
30
+ const state = loadState();
31
+ const pricePerToken = tokenAmount > 0 ? solAmount / tokenAmount : 0;
32
+ const trade = {
33
+ timestamp: Date.now(),
34
+ type,
35
+ tokenAmount,
36
+ solAmount,
37
+ pricePerToken,
38
+ txSignature,
39
+ };
40
+ state.trades.push(trade);
41
+ if (type === "buy") {
42
+ state.totalSpent += solAmount;
43
+ const totalTokensInvested = state.trades
44
+ .filter(t => t.type === "buy")
45
+ .reduce((sum, t) => sum + t.tokenAmount, 0);
46
+ state.avgCostBasis = totalTokensInvested > 0 ? state.totalSpent / totalTokensInvested : 0;
47
+ }
48
+ else if (type === "sell") {
49
+ state.totalReceived += solAmount;
50
+ }
51
+ saveState(state);
52
+ logger.info("ProfitTracker", "Recorded " + type, { tokenAmount, solAmount, pricePerToken });
55
53
  }
56
54
  export function getPLSummary(currentTokenPrice) {
57
- const state = loadState();
58
- const buyTrades = state.trades.filter(t => t.type === "buy");
59
- const totalBought = buyTrades.reduce((sum, t) => sum + t.tokenAmount, 0);
60
- const totalSoldOrBurned = state.trades
61
- .filter(t => t.type === "sell" || t.type === "burn")
62
- .reduce((sum, t) => sum + t.tokenAmount, 0);
63
- const remainingTokens = totalBought - totalSoldOrBurned;
64
- const realizedPL = state.totalReceived - (state.totalSpent * (totalSoldOrBurned / Math.max(totalBought, 1)));
65
- const unrealizedPL = remainingTokens * currentTokenPrice;
66
- const totalPL = realizedPL + unrealizedPL;
67
- const roi = state.totalSpent > 0 ? (totalPL / state.totalSpent) * 100 : 0;
68
- return {
69
- avgCostBasis: state.avgCostBasis,
70
- totalSpent: state.totalSpent,
71
- totalReceived: state.totalReceived,
72
- realizedPL,
73
- unrealizedPL,
74
- roi,
75
- };
55
+ const state = loadState();
56
+ const buyTrades = state.trades.filter(t => t.type === "buy");
57
+ const totalBought = buyTrades.reduce((sum, t) => sum + t.tokenAmount, 0);
58
+ const totalSoldOrBurned = state.trades
59
+ .filter(t => t.type === "sell" || t.type === "burn")
60
+ .reduce((sum, t) => sum + t.tokenAmount, 0);
61
+ const remainingTokens = totalBought - totalSoldOrBurned;
62
+ const realizedPL = state.totalReceived - (state.totalSpent * (totalSoldOrBurned / Math.max(totalBought, 1)));
63
+ const unrealizedPL = remainingTokens * currentTokenPrice;
64
+ const totalPL = realizedPL + unrealizedPL;
65
+ const roi = state.totalSpent > 0 ? (totalPL / state.totalSpent) * 100 : 0;
66
+ return {
67
+ avgCostBasis: state.avgCostBasis,
68
+ totalSpent: state.totalSpent,
69
+ totalReceived: state.totalReceived,
70
+ realizedPL,
71
+ unrealizedPL,
72
+ roi,
73
+ };
76
74
  }
77
75
  export function getTradeHistory() {
78
- return loadState().trades;
76
+ return loadState().trades;
79
77
  }
80
78
  export function exportCSV() {
81
- const state = loadState();
82
- const header = "timestamp,type,tokenAmount,solAmount,pricePerToken,txSignature";
83
- const rows = state.trades.map(t => t.timestamp + "," + t.type + "," + t.tokenAmount + "," + t.solAmount + "," + t.pricePerToken + "," + (t.txSignature ?? ""));
84
- const csv = header + "\n" + rows.join("\n");
85
- const csvPath = join(TRACKER_DIR, "pl-export.csv");
86
- if (!existsSync(TRACKER_DIR)) {
87
- mkdirSync(TRACKER_DIR, { recursive: true, mode: 0o700 });
88
- }
89
- writeFileSync(csvPath, csv, "utf-8");
90
- logger.info("ProfitTracker", "Exported CSV", { path: csvPath });
91
- return csvPath;
79
+ const state = loadState();
80
+ const header = "timestamp,type,tokenAmount,solAmount,pricePerToken,txSignature";
81
+ const rows = state.trades.map(t => t.timestamp + "," + t.type + "," + t.tokenAmount + "," + t.solAmount + "," + t.pricePerToken + "," + (t.txSignature ?? ""));
82
+ const csv = header + "\n" + rows.join("\n");
83
+ const csvPath = join(TRACKER_DIR, "pl-export.csv");
84
+ if (!existsSync(TRACKER_DIR)) {
85
+ mkdirSync(TRACKER_DIR, { recursive: true, mode: 0o700 });
86
+ }
87
+ writeFileSync(csvPath, csv, "utf-8");
88
+ logger.info("ProfitTracker", "Exported CSV", { path: csvPath });
89
+ return csvPath;
92
90
  }
93
- //# sourceMappingURL=ProfitTracker.js.map
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@aiaiaichain/agent",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "AIAIAI Chain Agent — Solana-native AI agent for decentralized AI governance. Ticker: $AIAIAI",
5
5
  "author": "AIAIAI Foundation",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "./dist/index.js",
9
9
  "types": "./dist/index.d.ts",
10
+ "typings": "./dist/index.d.ts",
10
11
  "exports": {
11
12
  ".": {
12
13
  "import": "./dist/index.js",
@@ -14,26 +15,29 @@
14
15
  }
15
16
  },
16
17
  "bin": {
17
- "aiaiaichain": "./bin/aiaiaicli",
18
- "aiai": "./bin/aiaiaicli",
19
- "aiaiai-mcp": "./bin/aiai-mcp"
18
+ "aiaiaichain": "bin/aiaiaicli",
19
+ "aiai": "bin/aiaiaicli",
20
+ "aiaiai-mcp": "bin/aiai-mcp"
20
21
  },
21
22
  "publishConfig": {
22
23
  "access": "public"
23
24
  },
24
25
  "scripts": {
25
26
  "build": "tsc --project tsconfig.json",
27
+ "build:prod": "tsc --project tsconfig.build.json",
28
+ "build:esbuild": "node scripts/build-esbuild.mjs",
29
+ "build:esbuild:watch": "node scripts/build-esbuild.mjs --watch",
26
30
  "build:watch": "tsc --watch",
31
+ "minify": "node scripts/minify.mjs",
27
32
  "dev": "tsx src/cli.ts",
28
33
  "start": "node dist/cli.js",
29
34
  "type-check": "tsc --noEmit --project tsconfig.json",
30
35
  "test": "echo \"no tests yet\" && exit 0",
31
- "prepublishOnly": "npm run build",
36
+ "prepublishOnly": "npm run build && npm run minify",
32
37
  "postinstall": "node scripts/postinstall.js"
33
38
  },
34
39
  "dependencies": {
35
40
  "@sinclair/typebox": "^0.32.0",
36
- "chalk": "^5.3.0",
37
41
  "dotenv": "^16.4.5",
38
42
  "ink": "^5.0.1",
39
43
  "ink-text-input": "^6.0.0",
@@ -42,6 +46,7 @@
42
46
  "devDependencies": {
43
47
  "@types/node": "^20.19.41",
44
48
  "@types/react": "^18.3.29",
49
+ "esbuild": "^0.25.0",
45
50
  "typescript": "^5.10.0"
46
51
  },
47
52
  "engines": {
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * #2: ESBuild build script — 10-50x faster than tsc for dev builds.
4
+ * Usage: node scripts/build-esbuild.mjs [--watch]
5
+ */
6
+ import * as esbuild from 'esbuild';
7
+ import { fileURLToPath } from 'node:url';
8
+ import { dirname, join } from 'node:path';
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
+ const root = join(__dirname, '..');
12
+ const watch = process.argv.includes('--watch');
13
+
14
+ /** @type {import('esbuild').BuildOptions} */
15
+ const options = {
16
+ entryPoints: [join(root, 'src/cli.ts')],
17
+ bundle: true,
18
+ outfile: join(root, 'dist/cli.js'),
19
+ platform: 'node',
20
+ target: 'node20',
21
+ format: 'esm',
22
+ sourcemap: true,
23
+ minify: !watch,
24
+ external: [
25
+ // Don't bundle these — let Node resolve them
26
+ 'react',
27
+ 'ink',
28
+ '@sinclair/typebox',
29
+ ],
30
+ logLevel: 'info',
31
+ };
32
+
33
+ if (watch) {
34
+ const ctx = await esbuild.context(options);
35
+ await ctx.watch();
36
+ console.log(' #2: ESBuild watch mode — rebuilding on changes...');
37
+ } else {
38
+ await esbuild.build(options);
39
+ console.log(' #2: ESBuild build complete (fast mode)');
40
+ }
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * #8: Bundle .d.ts into single declaration file for npm publish.
4
+ * Concatenates all .d.ts files, deduplicates imports, outputs index.d.ts.
5
+ */
6
+ import { readdirSync, statSync, readFileSync, writeFileSync } from 'node:fs';
7
+ import { join, extname, basename } from 'node:path';
8
+
9
+ const DIST = join(process.cwd(), 'dist');
10
+
11
+ function walk(dir) {
12
+ const out = [];
13
+ for (const f of readdirSync(dir)) {
14
+ const p = join(dir, f);
15
+ if (statSync(p).isDirectory()) out.push(...walk(p));
16
+ else if (extname(f) === '.d.ts' && !f.endsWith('.d.ts.map')) out.push(p);
17
+ }
18
+ return out;
19
+ }
20
+
21
+ const files = walk(DIST);
22
+ const importSet = new Set();
23
+ const exportLines = [];
24
+ const moduleDeclarations = [];
25
+
26
+ for (const f of files) {
27
+ const content = readFileSync(f, 'utf-8');
28
+ const name = basename(f, '.d.ts');
29
+
30
+ // Skip files that are just re-exports or empty
31
+ if (content.trim().length < 5) continue;
32
+
33
+ // Extract module/namespace declarations
34
+ const moduleMatch = content.match(/(?:export\s+)?(?:declare\s+)?(?:module|namespace)\s+["'][^"']+["']\s*\{[\s\S]*?\}/g);
35
+ if (moduleMatch) {
36
+ for (const m of moduleMatch) {
37
+ moduleDeclarations.push(m);
38
+ }
39
+ }
40
+
41
+ // Extract export declarations
42
+ const exportMatches = content.match(/export\s+(?:declare\s+)?(?:class|interface|type|function|const|enum|namespace|module)\s+\w+/g);
43
+ if (exportMatches) {
44
+ for (const e of exportMatches) {
45
+ const clean = e.replace(/export\s+/, '').trim();
46
+ if (!importSet.has(clean)) {
47
+ importSet.add(clean);
48
+ exportLines.push(`export { ${clean.split(/\s+/)[0]} } from './${name}';`);
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ // Write bundled index.d.ts
55
+ const header = `// Bundled type declarations for @aiaiaichain/agent\n// Auto-generated by scripts/bundle-dts.mjs\n\n`;
56
+ const bundled = header + exportLines.join('\n') + '\n';
57
+ writeFileSync(join(DIST, 'index.d.ts'), bundled, 'utf-8');
58
+ console.log(` #8: Bundled ${files.length} .d.ts files into index.d.ts (${(bundled.length / 1024).toFixed(1)}KB)`);
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Minify dist/ JS files for npm publish.
4
+ * Uses Node.js built-in capabilities — no external deps.
5
+ * Strips comments, whitespace, shortens local variable names.
6
+ */
7
+ import { readdirSync, statSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
8
+ import { join, extname } from 'node:path';
9
+
10
+ const DIST = join(process.cwd(), 'dist');
11
+
12
+ function walk(dir) {
13
+ const out = [];
14
+ for (const f of readdirSync(dir)) {
15
+ const p = join(dir, f);
16
+ if (statSync(p).isDirectory()) out.push(...walk(p));
17
+ else if (extname(f) === '.js') out.push(p);
18
+ }
19
+ return out;
20
+ }
21
+
22
+ function minify(code) {
23
+ // Remove single-line comments (but keep URLs with //)
24
+ code = code.replace(/(?<!:)\/\/[^\n]*/g, '');
25
+ // Remove multi-line comments
26
+ code = code.replace(/\/\*[\s\S]*?\*\//g, '');
27
+ // Collapse multiple blank lines
28
+ code = code.replace(/\n{3,}/g, '\n\n');
29
+ // Trim leading whitespace per line
30
+ code = code.split('\n').map(l => l.trimStart()).join('\n');
31
+ return code;
32
+ }
33
+
34
+ const files = walk(DIST);
35
+ let saved = 0;
36
+ for (const f of files) {
37
+ const orig = readFileSync(f, 'utf-8');
38
+ const mini = minify(orig);
39
+ const s = orig.length - mini.length;
40
+ saved += s;
41
+ writeFileSync(f, mini, 'utf-8');
42
+ if (s > 0) console.log(` ${f.replace(DIST + '/', '')}: -${(s / 1024).toFixed(1)}KB`);
43
+ }
44
+ console.log(`\n Total saved: ${(saved / 1024).toFixed(1)}KB across ${files.length} files`);