nyxora 26.7.2 → 26.7.4

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 (192) hide show
  1. package/CHANGELOG.md +112 -47
  2. package/README.md +25 -21
  3. package/bin/nyxora.mjs +4 -6
  4. package/dist/launcher.js +44 -8
  5. package/dist/packages/core/src/agent/bridgeWatcher.js +3 -2
  6. package/dist/packages/core/src/agent/cronManager.js +2 -2
  7. package/dist/packages/core/src/agent/llmProvider.js +245 -0
  8. package/dist/packages/core/src/agent/nyxDaemon.js +97 -0
  9. package/dist/packages/core/src/agent/osAgent.js +351 -29
  10. package/dist/packages/core/src/agent/reasoning.js +353 -60
  11. package/dist/packages/core/src/agent/reasoningScratchpad.js +47 -0
  12. package/dist/packages/core/src/agent/transactionManager.js +36 -31
  13. package/dist/packages/core/src/agent/web3Agent.js +263 -37
  14. package/dist/packages/core/src/cognitive/cognitiveManager.js +63 -10
  15. package/dist/packages/core/src/config/parser.js +10 -4
  16. package/dist/packages/core/src/gateway/chat.js +56 -13
  17. package/dist/packages/core/src/gateway/cli.js +3 -0
  18. package/dist/packages/core/src/gateway/discordAdapter.js +81 -0
  19. package/dist/packages/core/src/gateway/googleAuthModule.js +2 -0
  20. package/dist/packages/core/src/gateway/server.js +58 -9
  21. package/dist/packages/core/src/gateway/setup-ml.js +64 -0
  22. package/dist/packages/core/src/gateway/setup.js +39 -3
  23. package/dist/packages/core/src/gateway/telegram.js +123 -27
  24. package/dist/packages/core/src/memory/episodic.js +58 -3
  25. package/dist/packages/core/src/memory/logger.js +120 -2
  26. package/dist/packages/core/src/memory/promotionEngine.js +18 -5
  27. package/dist/packages/core/src/system/agentskills.js +10 -0
  28. package/dist/packages/core/src/system/plugins/GoogleWorkspacePlugin.js +10 -2
  29. package/dist/packages/core/src/system/plugins/SystemCorePlugin.js +1 -1
  30. package/dist/packages/core/src/system/plugins/SystemExternalPlugin.js +1 -1
  31. package/dist/packages/core/src/system/plugins/SystemPluginInstallerPlugin.js +1 -1
  32. package/dist/packages/core/src/system/plugins/SystemSocialPlugin.js +1 -1
  33. package/dist/packages/core/src/system/plugins/SystemWebPlugin.js +1 -1
  34. package/dist/packages/core/src/system/plugins/SystemWorkspacePlugin.js +3 -3
  35. package/dist/packages/core/src/system/plugins/createSkill.js +1 -1
  36. package/dist/packages/core/src/system/skillExtractor.js +16 -5
  37. package/dist/packages/core/src/system/skills/executeShell.js +31 -4
  38. package/dist/packages/core/src/system/skills/forgetMemory.js +6 -4
  39. package/dist/packages/core/src/system/skills/googleWorkspace.js +106 -1
  40. package/dist/packages/core/src/system/skills/scheduleTask.js +7 -2
  41. package/dist/packages/core/src/system/skills/searchWeb.js +13 -6
  42. package/dist/packages/core/src/test_mainnet.js +45 -0
  43. package/dist/packages/core/src/utils/contextSummarizer.js +82 -0
  44. package/dist/packages/core/src/utils/skillManager.js +1 -1
  45. package/dist/packages/core/src/utils/streamSimulator.js +85 -0
  46. package/dist/packages/core/src/web3/aggregator/providers/ArbitrumBridgeProvider.js +28 -11
  47. package/dist/packages/core/src/web3/aggregator/providers/OpBridgeProvider.js +41 -27
  48. package/dist/packages/core/src/web3/aggregator/providers/TestnetSwapProvider.js +65 -0
  49. package/dist/packages/core/src/web3/aggregator/routeSelector.js +7 -1
  50. package/dist/packages/core/src/web3/plugins/Web3DefiPlugin.js +1 -1
  51. package/dist/packages/core/src/web3/plugins/Web3MarketPlugin.js +5 -125
  52. package/dist/packages/core/src/web3/plugins/Web3SecurityPlugin.js +1 -1
  53. package/dist/packages/core/src/web3/plugins/Web3WalletPlugin.js +1 -1
  54. package/dist/packages/core/src/web3/skills/bridgeToken.js +19 -4
  55. package/dist/packages/core/src/web3/skills/checkAddress.js +2 -0
  56. package/dist/packages/core/src/web3/skills/checkPortfolio.js +22 -2
  57. package/dist/packages/core/src/web3/skills/checkSecurity.js +2 -0
  58. package/dist/packages/core/src/web3/skills/confirmPendingTx.js +1 -1
  59. package/dist/packages/core/src/web3/skills/createLimitOrder.js +15 -1
  60. package/dist/packages/core/src/web3/skills/customTx.js +3 -0
  61. package/dist/packages/core/src/web3/skills/defiLending.js +2 -0
  62. package/dist/packages/core/src/web3/skills/getBalance.js +2 -0
  63. package/dist/packages/core/src/web3/skills/getPrice.js +134 -27
  64. package/dist/packages/core/src/web3/skills/getTxHistory.js +2 -0
  65. package/dist/packages/core/src/web3/skills/marketAnalysis.js +28 -191
  66. package/dist/packages/core/src/web3/skills/mintNft.js +3 -0
  67. package/dist/packages/core/src/web3/skills/provideLiquidity.js +16 -12
  68. package/dist/packages/core/src/web3/skills/revokeApprovals.js +2 -0
  69. package/dist/packages/core/src/web3/skills/swapToken.js +20 -2
  70. package/dist/packages/core/src/web3/skills/transfer.js +2 -0
  71. package/dist/packages/core/src/web3/skills/yieldVault.js +2 -0
  72. package/dist/packages/core/src/web3/utils/chains.js +19 -0
  73. package/dist/packages/core/src/web3/utils/marketEngine.js +26 -33
  74. package/dist/packages/signer/src/NyxoraSigner.js +181 -0
  75. package/dist/packages/signer/src/index.js +17 -0
  76. package/dist/packages/signer/src/server.js +25 -161
  77. package/launcher.ts +38 -9
  78. package/package.json +8 -3
  79. package/packages/core/package.json +21 -10
  80. package/packages/core/src/agent/bridgeWatcher.ts +3 -2
  81. package/packages/core/src/agent/cronManager.ts +2 -2
  82. package/packages/core/src/agent/llmProvider.ts +221 -0
  83. package/packages/core/src/agent/nyxDaemon.ts +104 -0
  84. package/packages/core/src/agent/osAgent.ts +381 -32
  85. package/packages/core/src/agent/reasoning.ts +376 -64
  86. package/packages/core/src/agent/reasoningScratchpad.ts +45 -0
  87. package/packages/core/src/agent/transactionManager.ts +36 -28
  88. package/packages/core/src/agent/web3Agent.ts +291 -40
  89. package/packages/core/src/cognitive/cognitiveManager.ts +65 -10
  90. package/packages/core/src/cognitive/prompts/web3/market-analysis.md +24 -0
  91. package/packages/core/src/cognitive/prompts/web3/portfolio-review.md +29 -0
  92. package/packages/core/src/cognitive/prompts/web3/risk-assessment.md +28 -0
  93. package/packages/core/src/cognitive/prompts/web3/trade-planning.md +30 -0
  94. package/packages/core/src/config/parser.ts +15 -4
  95. package/packages/core/src/gateway/chat.ts +57 -15
  96. package/packages/core/src/gateway/cli.ts +4 -0
  97. package/packages/core/src/gateway/discordAdapter.ts +87 -0
  98. package/packages/core/src/gateway/googleAuthModule.ts +2 -0
  99. package/packages/core/src/gateway/server.ts +66 -10
  100. package/packages/core/src/gateway/setup-ml.ts +68 -0
  101. package/packages/core/src/gateway/setup.ts +41 -3
  102. package/packages/core/src/gateway/telegram.ts +141 -30
  103. package/packages/core/src/memory/episodic.ts +76 -3
  104. package/packages/core/src/memory/logger.ts +142 -2
  105. package/packages/core/src/memory/promotionEngine.ts +19 -5
  106. package/packages/core/src/system/agentskills.ts +10 -0
  107. package/packages/core/src/system/plugins/GoogleWorkspacePlugin.ts +15 -3
  108. package/packages/core/src/system/plugins/SystemCorePlugin.ts +1 -1
  109. package/packages/core/src/system/plugins/SystemExternalPlugin.ts +1 -1
  110. package/packages/core/src/system/plugins/SystemPluginInstallerPlugin.ts +1 -1
  111. package/packages/core/src/system/plugins/SystemSocialPlugin.ts +1 -1
  112. package/packages/core/src/system/plugins/SystemWebPlugin.ts +1 -1
  113. package/packages/core/src/system/plugins/SystemWorkspacePlugin.ts +3 -3
  114. package/packages/core/src/system/plugins/createSkill.ts +1 -1
  115. package/packages/core/src/system/skillExtractor.ts +16 -5
  116. package/packages/core/src/system/skills/executeShell.ts +38 -7
  117. package/packages/core/src/system/skills/forgetMemory.ts +7 -4
  118. package/packages/core/src/system/skills/googleWorkspace.ts +109 -0
  119. package/packages/core/src/system/skills/scheduleTask.ts +7 -2
  120. package/packages/core/src/system/skills/searchWeb.ts +12 -6
  121. package/packages/core/src/utils/contextSummarizer.ts +100 -0
  122. package/packages/core/src/utils/skillManager.ts +1 -1
  123. package/packages/core/src/utils/streamSimulator.ts +88 -0
  124. package/packages/core/src/web3/aggregator/providers/ArbitrumBridgeProvider.ts +30 -11
  125. package/packages/core/src/web3/aggregator/providers/OpBridgeProvider.ts +43 -29
  126. package/packages/core/src/web3/aggregator/routeSelector.ts +6 -1
  127. package/packages/core/src/web3/plugins/Web3DefiPlugin.ts +1 -1
  128. package/packages/core/src/web3/plugins/Web3MarketPlugin.ts +6 -125
  129. package/packages/core/src/web3/plugins/Web3SecurityPlugin.ts +1 -1
  130. package/packages/core/src/web3/plugins/Web3WalletPlugin.ts +1 -1
  131. package/packages/core/src/web3/skills/bridgeToken.ts +21 -7
  132. package/packages/core/src/web3/skills/checkAddress.ts +2 -0
  133. package/packages/core/src/web3/skills/checkPortfolio.ts +23 -2
  134. package/packages/core/src/web3/skills/checkSecurity.ts +2 -0
  135. package/packages/core/src/web3/skills/confirmPendingTx.ts +1 -1
  136. package/packages/core/src/web3/skills/createLimitOrder.ts +17 -2
  137. package/packages/core/src/web3/skills/customTx.ts +3 -0
  138. package/packages/core/src/web3/skills/defiLending.ts +2 -0
  139. package/packages/core/src/web3/skills/getBalance.ts +2 -0
  140. package/packages/core/src/web3/skills/getPrice.ts +134 -30
  141. package/packages/core/src/web3/skills/getTxHistory.ts +2 -0
  142. package/packages/core/src/web3/skills/marketAnalysis.ts +45 -188
  143. package/packages/core/src/web3/skills/mintNft.ts +3 -0
  144. package/packages/core/src/web3/skills/provideLiquidity.ts +16 -10
  145. package/packages/core/src/web3/skills/revokeApprovals.ts +2 -0
  146. package/packages/core/src/web3/skills/swapToken.ts +20 -3
  147. package/packages/core/src/web3/skills/transfer.ts +2 -0
  148. package/packages/core/src/web3/skills/yieldVault.ts +2 -0
  149. package/packages/core/src/web3/utils/chains.ts +12 -0
  150. package/packages/core/src/web3/utils/marketEngine.ts +27 -33
  151. package/packages/dashboard/dist/assets/index-Czxksiao.js +18 -0
  152. package/packages/dashboard/dist/assets/index-DK2sTU47.css +1 -0
  153. package/packages/dashboard/dist/index.html +2 -2
  154. package/packages/dashboard/package.json +10 -10
  155. package/packages/mcp-server/dist/server.js +5 -1
  156. package/packages/mcp-server/package.json +6 -6
  157. package/packages/mcp-server/src/server.ts +11 -7
  158. package/packages/ml-engine/__pycache__/config.cpython-313.pyc +0 -0
  159. package/packages/ml-engine/__pycache__/main.cpython-313.pyc +0 -0
  160. package/packages/ml-engine/config.py +59 -0
  161. package/packages/ml-engine/main.py +34 -0
  162. package/packages/ml-engine/requirements.txt +22 -0
  163. package/packages/ml-engine/routers/__init__.py +1 -0
  164. package/packages/ml-engine/routers/__pycache__/__init__.cpython-313.pyc +0 -0
  165. package/packages/ml-engine/routers/__pycache__/cognitive.cpython-313.pyc +0 -0
  166. package/packages/ml-engine/routers/__pycache__/critic.cpython-313.pyc +0 -0
  167. package/packages/ml-engine/routers/__pycache__/llm.cpython-313.pyc +0 -0
  168. package/packages/ml-engine/routers/__pycache__/market.cpython-313.pyc +0 -0
  169. package/packages/ml-engine/routers/__pycache__/memory.cpython-313.pyc +0 -0
  170. package/packages/ml-engine/routers/cognitive.py +98 -0
  171. package/packages/ml-engine/routers/critic.py +111 -0
  172. package/packages/ml-engine/routers/llm.py +38 -0
  173. package/packages/ml-engine/routers/market.py +332 -0
  174. package/packages/ml-engine/routers/memory.py +125 -0
  175. package/packages/policy/package.json +3 -3
  176. package/packages/signer/package.json +16 -6
  177. package/packages/signer/src/NyxoraSigner.ts +161 -0
  178. package/packages/signer/src/index.ts +1 -0
  179. package/packages/signer/src/server.ts +25 -135
  180. package/dist/packages/core/src/agent/honchoDaemon.js +0 -91
  181. package/dist/packages/core/src/cognitive/prompts/autonomous/binance-trading-integration.md +0 -54
  182. package/dist/packages/core/src/gateway/test.js +0 -15
  183. package/dist/packages/core/src/web3/Web3DefiPlugin.js +0 -28
  184. package/dist/packages/core/src/web3/aggregator/aggregatorMainnet.js +0 -260
  185. package/dist/packages/core/src/web3/aggregator/aggregatorTestnet.js +0 -119
  186. package/dist/packages/core/src/web3/skills/nativeOpBridge.js +0 -71
  187. package/packages/core/src/agent/honchoDaemon.ts +0 -96
  188. package/packages/core/src/cognitive/prompts/autonomous/binance-trading-integration.md +0 -41
  189. package/packages/core/src/plugin/registry.test.ts +0 -46
  190. package/packages/core/src/utils/formatter.test.ts +0 -41
  191. package/packages/dashboard/dist/assets/index-CSoNa5cx.css +0 -1
  192. package/packages/dashboard/dist/assets/index-DbRWEoSr.js +0 -16
@@ -24,8 +24,9 @@ class OpBridgeProvider {
24
24
  return true;
25
25
  }
26
26
  supports(request) {
27
- const isOpStack = request.toChain === 'optimism_sepolia' || request.toChain === 'base_sepolia';
28
- if (request.fromChain !== 'sepolia' || !isOpStack)
27
+ const isL1ToL2 = request.fromChain === 'sepolia' && (request.toChain === 'optimism_sepolia' || request.toChain === 'base_sepolia');
28
+ const isL2ToL1 = request.toChain === 'sepolia' && (request.fromChain === 'optimism_sepolia' || request.fromChain === 'base_sepolia');
29
+ if (!isL1ToL2 && !isL2ToL1)
29
30
  return false;
30
31
  const isNative = request.fromToken.toLowerCase() === 'eth' ||
31
32
  request.fromToken.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' ||
@@ -33,34 +34,47 @@ class OpBridgeProvider {
33
34
  return isNative;
34
35
  }
35
36
  async getQuote(request, context) {
36
- // Each OP Stack L2 has its OWN L1StandardBridgeProxy on Sepolia L1
37
- // Using the wrong address sends ETH to the wrong contract = loss of funds
38
- const BRIDGE_ADDRESSES = {
39
- optimism_sepolia: '0xFBb0621E0B23b5478B630BD55a5f21f67730B0F1', // Confirmed: OP Sepolia L1StandardBridgeProxy
40
- base_sepolia: '0xfd0Bf71F60660E2f608ed56e1659C450eB113120', // Confirmed: Base Sepolia L1StandardBridgeProxy
41
- };
42
- const bridgeAddress = BRIDGE_ADDRESSES[request.toChain];
43
- if (!bridgeAddress) {
44
- throw new Error(`[OpBridgeProvider] No bridge address configured for destination chain: ${request.toChain}`);
37
+ const isL1ToL2 = request.fromChain === 'sepolia';
38
+ let bridgeAddress;
39
+ let callData;
40
+ if (isL1ToL2) {
41
+ // L1 to L2
42
+ const BRIDGE_ADDRESSES = {
43
+ optimism_sepolia: '0xFBb0621E0B23b5478B630BD55a5f21f67730B0F1',
44
+ base_sepolia: '0xfd0Bf71F60660E2f608ed56e1659C450eB113120',
45
+ };
46
+ bridgeAddress = BRIDGE_ADDRESSES[request.toChain];
47
+ if (!bridgeAddress) {
48
+ throw new Error(`[OpBridgeProvider] No bridge address configured for destination chain: ${request.toChain}`);
49
+ }
50
+ const depositEthAbi = (0, viem_1.parseAbi)([
51
+ 'function depositETH(uint32 _minGasLimit, bytes _extraData) payable'
52
+ ]);
53
+ callData = (0, viem_1.encodeFunctionData)({
54
+ abi: depositEthAbi,
55
+ functionName: 'depositETH',
56
+ args: [200000, '0x']
57
+ });
58
+ }
59
+ else {
60
+ // L2 to L1
61
+ bridgeAddress = '0x4200000000000000000000000000000000000010'; // L2StandardBridge predeploy on OP Stack
62
+ const bridgeEthAbi = (0, viem_1.parseAbi)([
63
+ 'function bridgeETH(uint32 _minGasLimit, bytes _extraData) payable'
64
+ ]);
65
+ callData = (0, viem_1.encodeFunctionData)({
66
+ abi: bridgeEthAbi,
67
+ functionName: 'bridgeETH',
68
+ args: [200000, '0x']
69
+ });
45
70
  }
46
- // ABI for depositETH
47
- const depositEthAbi = (0, viem_1.parseAbi)([
48
- 'function depositETH(uint32 _minGasLimit, bytes _extraData) payable'
49
- ]);
50
- // OP Stack requires a minGasLimit. 200000 is a safe default for simple ETH transfers.
51
- const minGasLimit = 200000;
52
- const extraData = '0x';
53
- const callData = (0, viem_1.encodeFunctionData)({
54
- abi: depositEthAbi,
55
- functionName: 'depositETH',
56
- args: [minGasLimit, extraData]
57
- });
58
- const destChainId = request.toChain === 'optimism_sepolia' ? 11155420 : 84532;
71
+ const getChainId = (name) => name === 'sepolia' ? 11155111 : (name === 'optimism_sepolia' ? 11155420 : 84532);
72
+ const note = isL1ToL2 ? 'OP Stack Standard Bridge L1->L2' : 'OP Stack Standard Bridge L2->L1 (Requires 7-day challenge period to finalize)';
59
73
  return {
60
74
  provider: this.manifest.name,
61
75
  routeId: `op-bridge-${crypto_1.default.randomUUID()}`,
62
- fromChainId: 11155111,
63
- toChainId: destChainId,
76
+ fromChainId: getChainId(request.fromChain),
77
+ toChainId: getChainId(request.toChain),
64
78
  inputAmount: BigInt(request.amountInWei),
65
79
  outputAmount: BigInt(request.amountInWei), // 1:1 bridging
66
80
  executable: true,
@@ -70,7 +84,7 @@ class OpBridgeProvider {
70
84
  calldata: callData,
71
85
  value: BigInt(request.amountInWei)
72
86
  },
73
- raw: { note: 'OP Stack Standard Bridge L1->L2' }
87
+ raw: { note }
74
88
  };
75
89
  }
76
90
  async isHealthy() {
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TestnetSwapProvider = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ class TestnetSwapProvider {
9
+ manifest = {
10
+ id: 'testnet_mock_swap',
11
+ name: 'Testnet Simulated Swap',
12
+ version: '1.0.1',
13
+ networks: ['testnet'],
14
+ capabilities: ['swap'],
15
+ allowedDomains: [],
16
+ permissions: {
17
+ network: false,
18
+ walletAccess: 'none',
19
+ filesystem: 'none'
20
+ }
21
+ };
22
+ isCrossChainSupported() {
23
+ return false;
24
+ }
25
+ supports(request) {
26
+ if (request.fromChain !== request.toChain)
27
+ return false;
28
+ // Only support testnet chains
29
+ return request.fromChain.includes('sepolia');
30
+ }
31
+ async getQuote(request, context) {
32
+ const chainIds = {
33
+ sepolia: 11155111,
34
+ base_sepolia: 84532,
35
+ optimism_sepolia: 11155420,
36
+ arbitrum_sepolia: 421614
37
+ };
38
+ // Simulate 1:0.98 exchange rate for testing (or a fixed amount if amounts aren't known)
39
+ // To make it look realistic, we just output 98% of the input conceptually (not accurate for different decimals, but works for mock UX).
40
+ const outAmount = (BigInt(request.amountInWei) * 98n) / 100n;
41
+ return {
42
+ provider: this.manifest.name,
43
+ routeId: `testnet-swap-${crypto_1.default.randomUUID()}`,
44
+ fromChainId: chainIds[request.fromChain] || 11155111,
45
+ toChainId: chainIds[request.toChain] || 11155111,
46
+ inputAmount: BigInt(request.amountInWei),
47
+ outputAmount: outAmount,
48
+ estimatedGasUsd: 0.05,
49
+ executable: true,
50
+ expiresAt: Date.now() + 86400000,
51
+ execution: {
52
+ // Send a 0 value transaction to the user's own address to simulate contract interaction
53
+ // without actually losing testnet funds or failing.
54
+ target: request.userAddress,
55
+ calldata: '0x',
56
+ value: 0n
57
+ },
58
+ raw: { note: 'Simulated Testnet Swap. Generating a dummy zero-value transaction for UI verification.' }
59
+ };
60
+ }
61
+ async isHealthy() {
62
+ return { ok: true, checkedAt: Date.now() };
63
+ }
64
+ }
65
+ exports.TestnetSwapProvider = TestnetSwapProvider;
@@ -36,7 +36,13 @@ async function fetchBestRoute(request, preference = "best_output") {
36
36
  // 1. Resolve eligible providers
37
37
  let eligibleProviders = providerRegistry_1.aggregatorRegistry.resolveEligibleProviders(request);
38
38
  if (request.preferredProvider && request.preferredProvider !== "auto") {
39
- eligibleProviders = eligibleProviders.filter(p => p.manifest.id === request.preferredProvider);
39
+ const filteredProviders = eligibleProviders.filter(p => p.manifest.id === request.preferredProvider);
40
+ if (filteredProviders.length > 0) {
41
+ eligibleProviders = filteredProviders;
42
+ }
43
+ else {
44
+ console.warn(`[RouteSelector] LLM Hallucinated or requested an ineligible provider: '${request.preferredProvider}'. Falling back to automatic provider routing.`);
45
+ }
40
46
  }
41
47
  if (eligibleProviders.length === 0) {
42
48
  throw new Error('[RouteSelector] No eligible providers found for this route.');
@@ -16,7 +16,7 @@ const confirmPendingTx_1 = require("../skills/confirmPendingTx");
16
16
  class Web3DefiPlugin {
17
17
  name = 'Web3DefiPlugin';
18
18
  description = 'Core DeFi operations including balance checking, portfolio analysis, and token swapping.';
19
- version = '1.0.0';
19
+ version = '1.0.1';
20
20
  tools = [
21
21
  getBalance_1.getBalanceToolDefinition,
22
22
  checkPortfolio_1.checkPortfolioToolDefinition,
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Web3MarketPlugin = void 0;
4
4
  const httpClient_1 = require("../../utils/httpClient");
5
- const riskIntelligence_1 = require("../utils/riskIntelligence");
6
5
  const marketConfigManager_1 = require("../../config/marketConfigManager");
7
6
  async function fetchCexData(symbol) {
8
7
  try {
@@ -96,139 +95,20 @@ async function fetchCexMomentum(symbol, currentP) {
96
95
  }
97
96
  }
98
97
  }
98
+ const marketAnalysis_1 = require("../skills/marketAnalysis");
99
99
  class Web3MarketPlugin {
100
100
  name = 'MarketAnalysis';
101
- version = '1.0.0';
101
+ version = '1.0.1';
102
102
  description = 'Provides deep market intelligence and analysis for Web3 assets.';
103
103
  tools = [
104
- {
105
- type: 'function',
106
- function: {
107
- name: 'analyze_market',
108
- description: 'Analyzes the market health of a token (Price, FDV, TVL, Holders, Momentum) by fetching from CEX, DEX, CoinGecko, and DefiLlama. Returns a full intelligence report.',
109
- parameters: {
110
- type: 'object',
111
- properties: {
112
- tokenAddressOrSymbol: { type: 'string', description: 'The token symbol (e.g. BTC, ETH) or Contract Address.' },
113
- chainName: { type: 'string', description: 'Optional chain name (e.g. ethereum, solana) if searching by address.' }
114
- },
115
- required: ['tokenAddressOrSymbol']
116
- }
117
- }
118
- }
104
+ marketAnalysis_1.marketAnalysisToolDefinition
119
105
  ];
120
106
  handlers = {
121
107
  'analyze_market': async (args, context) => {
122
108
  try {
123
109
  const { chainName, tokenAddressOrSymbol } = args;
124
- if (!tokenAddressOrSymbol)
125
- throw new Error("Token symbol is invalid.");
126
- const cleanInput = String(tokenAddressOrSymbol || "").replace('$', '').toLowerCase();
127
- const isAddress = cleanInput.startsWith('0x') && cleanInput.length === 42;
128
- let officialSymbol = cleanInput.toUpperCase();
129
- let contractAddress = isAddress ? cleanInput : null;
130
- let network = chainName || "UNKNOWN";
131
- let currentPrice = 0;
132
- let mcapUsd = 0;
133
- let liquidityUsd = 0;
134
- let volume24h = 0;
135
- let priceChange24h = 0;
136
- let rsi = null;
137
- let ma50 = null;
138
- let isCexAsset = false;
139
- // PHASE 1
140
- if (isAddress) {
141
- const targetPair = await fetchDexData(cleanInput, true, chainName);
142
- if (targetPair) {
143
- officialSymbol = targetPair.baseToken.symbol;
144
- contractAddress = targetPair.baseToken.address;
145
- network = targetPair.chainId.toUpperCase();
146
- currentPrice = parseFloat(targetPair.priceUsd || "0");
147
- mcapUsd = targetPair.fdv || 0;
148
- liquidityUsd = targetPair.liquidity?.usd || 0;
149
- volume24h = targetPair.volume?.h24 || 0;
150
- priceChange24h = targetPair.priceChange?.h24 || 0;
151
- }
152
- else {
153
- return `[Market Intelligence] Failed to find data for Contract Address ${tokenAddressOrSymbol} on DEX.`;
154
- }
155
- const momentum = await fetchCexMomentum(officialSymbol, currentPrice);
156
- ma50 = momentum.ma50;
157
- rsi = momentum.rsi;
158
- }
159
- else {
160
- const cgData = await fetchCoinGeckoData(officialSymbol);
161
- const cex = await fetchCexData(officialSymbol);
162
- if (cgData || cex) {
163
- isCexAsset = true;
164
- network = `Global CEX/Market`;
165
- currentPrice = cex ? cex.price : (cgData?.price || 0);
166
- volume24h = cgData ? cgData.vol : (cex?.vol || 0);
167
- priceChange24h = cex ? cex.change : (cgData?.change || 0);
168
- mcapUsd = cgData ? cgData.fdv : (volume24h * 10);
169
- liquidityUsd = cgData ? cgData.fdv * 0.1 : (volume24h * 2);
170
- const momentum = await fetchCexMomentum(officialSymbol, currentPrice);
171
- ma50 = momentum.ma50;
172
- rsi = momentum.rsi;
173
- }
174
- else {
175
- const targetPair = await fetchDexData(cleanInput, false, chainName);
176
- if (targetPair) {
177
- officialSymbol = targetPair.baseToken.symbol;
178
- contractAddress = targetPair.baseToken.address;
179
- network = targetPair.chainId.toUpperCase();
180
- currentPrice = parseFloat(targetPair.priceUsd || "0");
181
- mcapUsd = targetPair.fdv || 0;
182
- liquidityUsd = targetPair.liquidity?.usd || 0;
183
- volume24h = targetPair.volume?.h24 || 0;
184
- priceChange24h = targetPair.priceChange?.h24 || 0;
185
- }
186
- else {
187
- return `[Market Intelligence] Failed to find market data for symbol ${officialSymbol} on both CEX and DEX.`;
188
- }
189
- }
190
- }
191
- // PHASE 2
192
- let tvlChange7d = null;
193
- try {
194
- const llamaData = await (0, httpClient_1.safeFetchJson)(`https://api.llama.fi/protocol/${officialSymbol.toLowerCase()}`);
195
- if (llamaData && llamaData.tvl) {
196
- const tvlList = llamaData.tvl;
197
- if (tvlList.length > 7) {
198
- const todayTvl = tvlList[tvlList.length - 1].totalLiquidityUSD;
199
- const weekAgoTvl = tvlList[tvlList.length - 8].totalLiquidityUSD;
200
- if (weekAgoTvl > 0)
201
- tvlChange7d = ((todayTvl - weekAgoTvl) / weekAgoTvl) * 100;
202
- }
203
- }
204
- }
205
- catch { }
206
- // PHASE 3
207
- let top10HoldersPercent = null;
208
- if (contractAddress || isCexAsset) {
209
- if (mcapUsd > 100000000)
210
- top10HoldersPercent = 15;
211
- else if (mcapUsd < 500000)
212
- top10HoldersPercent = 85;
213
- else
214
- top10HoldersPercent = 45;
215
- }
216
- // PHASE 4
217
- const healthResult = (0, riskIntelligence_1.generateMarketHealthReport)(liquidityUsd, mcapUsd, tvlChange7d, volume24h, priceChange24h, top10HoldersPercent, rsi, currentPrice, ma50);
218
- // PHASE 5
219
- let report = `📊 **Market Intelligence Report: ${officialSymbol}**\n`;
220
- report += `CA: \`${contractAddress || 'N/A'}\` | Network: ${network}\n\n`;
221
- report += `**⭐ Overall Market Health Score:** ${healthResult.overallScore} / 10\n\n`;
222
- report += `**1. Liquidity Risk:** ${healthResult.liquidityScore !== null ? healthResult.liquidityScore + '/10' : '[ N/A ]'}\n`;
223
- report += `- Liquidity: $${liquidityUsd.toLocaleString()} vs FDV: $${mcapUsd.toLocaleString()}\n`;
224
- report += `**2. Smart Money Flow:** ${healthResult.smartMoneyScore !== null ? healthResult.smartMoneyScore + '/10' : '[ N/A - Not in DefiLlama ]'}\n`;
225
- report += `- 24h Volume: $${volume24h.toLocaleString()} | TVL 7D Change: ${tvlChange7d !== null ? tvlChange7d.toFixed(2) + '%' : 'N/A'}\n`;
226
- report += `**3. Holder Concentration:** ${healthResult.concentrationScore !== null ? healthResult.concentrationScore + '/10' : '[ N/A - RPC Pending ]'}\n`;
227
- report += `- Top 10 Holders: ${top10HoldersPercent !== null ? top10HoldersPercent + '%' : 'N/A'}\n`;
228
- report += `**4. Momentum (CEX):** ${healthResult.momentumScore !== null ? healthResult.momentumScore + '/10' : '[ N/A - DEX Only Coin ]'}\n`;
229
- report += `- Price: $${currentPrice} | MA50: ${ma50 ? '$' + ma50.toFixed(4) : 'N/A'} | RSI: ${rsi || 'N/A'}\n\n`;
230
- report += `*System Note for LLM: Use this exact data to provide a "Market Summary" and "Suggested Autonomous Actions" in the user's native language. If CEX momentum is N/A, explicitly warn about high risk Degen/Memecoin status. IMPORTANT: Always include a clear disclaimer at the end (translated into the user's native language) stating that this analysis is NOT financial advice (NFA).*`;
231
- return report;
110
+ const { analyzeMarket } = require('../skills/marketAnalysis');
111
+ return await analyzeMarket(chainName, tokenAddressOrSymbol);
232
112
  }
233
113
  catch (error) {
234
114
  return `[Market Intelligence] Failed to aggregate data: ${error.message}`;
@@ -8,7 +8,7 @@ const checkRegistryStatus_1 = require("../skills/checkRegistryStatus");
8
8
  class Web3SecurityPlugin {
9
9
  name = 'Web3SecurityPlugin';
10
10
  description = 'Security, analysis, and safety registry operations.';
11
- version = '1.0.0';
11
+ version = '1.0.1';
12
12
  tools = [
13
13
  checkSecurity_1.checkSecurityToolDefinition,
14
14
  getTrendingTokens_1.getTrendingTokensToolDefinition,
@@ -11,7 +11,7 @@ const transfer_1 = require("../skills/transfer");
11
11
  class Web3WalletPlugin {
12
12
  name = 'Web3WalletPlugin';
13
13
  description = 'Core wallet and transaction operations including transfer, custom tx, and history.';
14
- version = '1.0.0';
14
+ version = '1.0.1';
15
15
  tools = [
16
16
  transfer_1.transferToolDefinition,
17
17
  mintNft_1.mintNftToolDefinition,
@@ -42,10 +42,12 @@ const vaultClient_1 = require("../utils/vaultClient");
42
42
  const transactionManager_1 = require("../../agent/transactionManager");
43
43
  const tokens_1 = require("../utils/tokens");
44
44
  const defiRouter_1 = require("../aggregator/defiRouter");
45
+ const logger_1 = require("../../memory/logger");
46
+ const parser_1 = require("../../config/parser");
45
47
  async function prepareBridgeToken(fromChain, toChain, tokenSymbol, amountStr, mode = "auto", providerName = "auto", slippagePercent) {
46
48
  try {
47
- fromChain = String(fromChain || "");
48
- toChain = String(toChain || "");
49
+ fromChain = (0, config_1.normalizeChainName)(fromChain);
50
+ toChain = (0, config_1.normalizeChainName)(toChain);
49
51
  if (!fromChain || !toChain)
50
52
  throw new Error("Source or destination chain not provided by AI.");
51
53
  if (!amountStr)
@@ -86,7 +88,20 @@ async function prepareBridgeToken(fromChain, toChain, tokenSymbol, amountStr, mo
86
88
  decimals = meta.decimals;
87
89
  }
88
90
  const amountWei = (0, viem_1.parseUnits)(amountStr, decimals).toString();
89
- const slippage = slippagePercent || "auto";
91
+ // Front-to-Back Slippage Architecture
92
+ const userProfile = logger_1.logger.getUserProfile();
93
+ const maxSlippage = userProfile?.max_slippage || 1.0;
94
+ const config = (0, parser_1.loadConfig)();
95
+ const cfgSlippage = config.agent?.default_slippage;
96
+ let finalSlippage = slippagePercent;
97
+ if (finalSlippage === undefined || finalSlippage === null || finalSlippage === "auto") {
98
+ finalSlippage = (cfgSlippage === "auto" || !cfgSlippage) ? 0.5 : parseFloat(cfgSlippage);
99
+ }
100
+ if (typeof finalSlippage !== 'number' || isNaN(finalSlippage))
101
+ finalSlippage = 0.5;
102
+ if (finalSlippage > maxSlippage)
103
+ finalSlippage = maxSlippage;
104
+ const slippage = finalSlippage;
90
105
  // --- Pre-flight Balance Check ---
91
106
  const { validateTransactionBalances } = await Promise.resolve().then(() => __importStar(require('../utils/balanceChecker')));
92
107
  const balanceCheck = await validateTransactionBalances(fromChain, userAddress, fromTokenAddress, amountWei);
@@ -130,7 +145,7 @@ exports.bridgeTokenToolDefinition = {
130
145
  tokenSymbol: { type: "string" },
131
146
  amountStr: { type: "string" },
132
147
  mode: { type: "string", enum: ["auto", "manual"], default: "auto" },
133
- providerName: { type: "string", enum: ["auto", "lifi", "relay"], default: "auto" },
148
+ providerName: { type: "string", enum: ["auto", "lifi", "relay", "op_bridge_testnet", "arbitrum_bridge_testnet"], default: "auto", description: "The preferred provider. Use 'op_bridge_testnet' (for OP/Base Sepolia), 'arbitrum_bridge_testnet' (for Arb Sepolia), or 'relay' (testnet fallback)." },
134
149
  slippagePercent: { type: "number" }
135
150
  },
136
151
  required: ["fromChain", "toChain", "tokenSymbol", "amountStr"],
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkAddressToolDefinition = void 0;
4
4
  exports.checkAddress = checkAddress;
5
+ const chains_1 = require("../utils/chains");
5
6
  const viem_1 = require("viem");
6
7
  const config_1 = require("../config");
7
8
  async function checkAddress(chainName, address) {
8
9
  try {
10
+ chainName = (0, chains_1.normalizeChainName)(chainName);
9
11
  if (!(0, viem_1.isAddress)(address)) {
10
12
  return `Address validation failed: '${address}' is not a valid Web3 address format.`;
11
13
  }
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.checkPortfolioToolDefinition = void 0;
37
37
  exports.checkPortfolio = checkPortfolio;
38
+ const chains_1 = require("../utils/chains");
38
39
  const viem_1 = require("viem");
39
40
  const config_1 = require("../config");
40
41
  const tokens_1 = require("../utils/tokens");
@@ -43,6 +44,7 @@ const portfolioCache = {};
43
44
  const CACHE_TTL = 5000; // 5 seconds TTL
44
45
  async function checkPortfolio(chainName, address) {
45
46
  try {
47
+ chainName = (0, chains_1.normalizeChainName)(chainName);
46
48
  const client = (0, config_1.getPublicClient)(chainName);
47
49
  let targetAddress = address;
48
50
  if (!targetAddress) {
@@ -155,9 +157,27 @@ async function checkPortfolio(chainName, address) {
155
157
  try {
156
158
  const data = await (0, httpClient_1.safeFetchJson)(url);
157
159
  if (data.pairs) {
160
+ data.pairs.sort((a, b) => (b.liquidity?.usd || 0) - (a.liquidity?.usd || 0));
161
+ const chainMatched = new Set();
158
162
  data.pairs.forEach((p) => {
159
- if (!priceMap[String(p.baseToken.address).toLowerCase()]) {
160
- priceMap[String(p.baseToken.address).toLowerCase()] = parseFloat(p.priceUsd);
163
+ const baseAddr = String(p.baseToken?.address || "").toLowerCase();
164
+ const quoteAddr = String(p.quoteToken?.address || "").toLowerCase();
165
+ const priceUsd = parseFloat(p.priceUsd || "0");
166
+ const priceNative = parseFloat(p.priceNative || "0");
167
+ if (baseAddr && priceUsd > 0) {
168
+ if (!priceMap[baseAddr] || (!chainMatched.has(baseAddr) && p.chainId === chainName)) {
169
+ priceMap[baseAddr] = priceUsd;
170
+ if (p.chainId === chainName)
171
+ chainMatched.add(baseAddr);
172
+ }
173
+ }
174
+ if (quoteAddr && priceUsd > 0 && priceNative > 0) {
175
+ const quotePriceUsd = priceUsd / priceNative;
176
+ if (!priceMap[quoteAddr] || (!chainMatched.has(quoteAddr) && p.chainId === chainName)) {
177
+ priceMap[quoteAddr] = quotePriceUsd;
178
+ if (p.chainId === chainName)
179
+ chainMatched.add(quoteAddr);
180
+ }
161
181
  }
162
182
  });
163
183
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkSecurityToolDefinition = void 0;
4
4
  exports.checkTokenSecurity = checkTokenSecurity;
5
+ const chains_1 = require("../utils/chains");
5
6
  const config_1 = require("../config");
6
7
  const httpClient_1 = require("../../utils/httpClient");
7
8
  const CHAIN_IDS = {
@@ -18,6 +19,7 @@ const CHAIN_IDS = {
18
19
  };
19
20
  async function checkTokenSecurity(chainName, contractAddress) {
20
21
  try {
22
+ chainName = (0, chains_1.normalizeChainName)(chainName);
21
23
  const chainId = CHAIN_IDS[chainName];
22
24
  if (chainName === 'sepolia') {
23
25
  return `Security check API (GoPlus) does not support Sepolia testnet. Try a mainnet token.`;
@@ -118,7 +118,7 @@ exports.confirmPendingTxToolDefinition = {
118
118
  type: "function",
119
119
  function: {
120
120
  name: "confirm_pending_tx",
121
- description: "Approve or reject a pending transaction. Use this tool when a transaction has been queued and the user replies with a confirmation (like 'Yes' or 'Ya') or a rejection (like 'No' or 'Tidak').",
121
+ description: "Approve or reject a pending transaction. Use this tool when a transaction has been queued and the user replies with a confirmation (like 'Yes' or 'Ya') or a rejection (like 'No' or 'Tidak'). CRITICAL RULE: DO NOT call any other tool (like write_local_file) simultaneously with this one. Output ONLY this tool.",
122
122
  parameters: {
123
123
  type: "object",
124
124
  properties: {
@@ -4,8 +4,22 @@ exports.createLimitOrderToolDefinition = void 0;
4
4
  exports.createLimitOrder = createLimitOrder;
5
5
  const logger_1 = require("../../memory/logger");
6
6
  const transactionManager_1 = require("../../agent/transactionManager");
7
+ const parser_1 = require("../../config/parser");
7
8
  async function createLimitOrder(tokenSymbol, tokenAddress, triggerCondition, triggerPriceUsd, action, amountUsd, slippageTolerance) {
8
9
  try {
10
+ // Front-to-Back Slippage Architecture
11
+ const userProfile = logger_1.logger.getUserProfile();
12
+ const maxSlippage = userProfile?.max_slippage || 1.0;
13
+ const config = (0, parser_1.loadConfig)();
14
+ const cfgSlippage = config.agent?.default_slippage;
15
+ let finalSlippage = slippageTolerance;
16
+ if (finalSlippage === undefined || finalSlippage === null) {
17
+ finalSlippage = (cfgSlippage === "auto" || !cfgSlippage) ? 0.5 : parseFloat(cfgSlippage);
18
+ }
19
+ if (typeof finalSlippage !== 'number' || isNaN(finalSlippage))
20
+ finalSlippage = 0.5;
21
+ if (finalSlippage > maxSlippage)
22
+ finalSlippage = maxSlippage;
9
23
  const orderData = {
10
24
  token_symbol: tokenSymbol,
11
25
  token_address: tokenAddress,
@@ -13,7 +27,7 @@ async function createLimitOrder(tokenSymbol, tokenAddress, triggerCondition, tri
13
27
  trigger_price_usd: triggerPriceUsd,
14
28
  action,
15
29
  amount_usd: amountUsd,
16
- slippage_tolerance: slippageTolerance || 5.0
30
+ slippage_tolerance: finalSlippage
17
31
  };
18
32
  const orderId = logger_1.logger.createLimitOrder(orderData);
19
33
  const tx = transactionManager_1.txManager.createPendingTransaction('limit_order', 'any', {
@@ -36,11 +36,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.customTxToolDefinition = void 0;
37
37
  exports.prepareCustomTx = prepareCustomTx;
38
38
  exports.executeCustomTx = executeCustomTx;
39
+ const chains_1 = require("../utils/chains");
39
40
  const config_1 = require("../config");
40
41
  const transactionManager_1 = require("../../agent/transactionManager");
41
42
  const vaultClient_1 = require("../utils/vaultClient");
42
43
  async function prepareCustomTx(chainName, toAddress, data, valueWei = "0", description = "Custom transaction") {
43
44
  try {
45
+ chainName = (0, chains_1.normalizeChainName)(chainName);
44
46
  if (!chainName || !toAddress || !data)
45
47
  throw new Error("Missing required parameters for custom transaction.");
46
48
  const { getAddress } = await Promise.resolve().then(() => __importStar(require('../utils/vaultClient')));
@@ -84,6 +86,7 @@ exports.customTxToolDefinition = {
84
86
  },
85
87
  };
86
88
  async function executeCustomTx(chainName, details, autoApprove = false) {
89
+ chainName = (0, chains_1.normalizeChainName)(chainName);
87
90
  // Fix HMAC mismatch by guaranteeing amountWei exists to match valueWei
88
91
  const processedDetails = {
89
92
  ...details,
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.aaveSupplyToolDefinition = void 0;
37
37
  exports.prepareAaveSupply = prepareAaveSupply;
38
+ const chains_1 = require("../utils/chains");
38
39
  const viem_1 = require("viem");
39
40
  const config_1 = require("../config");
40
41
  const transactionManager_1 = require("../../agent/transactionManager");
@@ -65,6 +66,7 @@ const AAVE_V3_POOLS = {
65
66
  };
66
67
  async function prepareAaveSupply(chainName, tokenAddressOrSymbol, amountStr) {
67
68
  try {
69
+ chainName = (0, chains_1.normalizeChainName)(chainName);
68
70
  if (!chainName || !tokenAddressOrSymbol || !amountStr)
69
71
  throw new Error("Missing protocol/chain/token parameters for DeFi operation.");
70
72
  const publicClient = (0, config_1.getPublicClient)(chainName);
@@ -35,12 +35,14 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.getBalanceToolDefinition = void 0;
37
37
  exports.getBalance = getBalance;
38
+ const chains_1 = require("../utils/chains");
38
39
  const viem_1 = require("viem");
39
40
  const config_1 = require("../config");
40
41
  const tokens_1 = require("../utils/tokens");
41
42
  const userWhitelistManager_1 = require("../../utils/userWhitelistManager");
42
43
  async function getBalance(chainName, address, token) {
43
44
  try {
45
+ chainName = (0, chains_1.normalizeChainName)(chainName);
44
46
  const client = (0, config_1.getPublicClient)(chainName);
45
47
  let targetAddress = address;
46
48
  if (!targetAddress) {