nyxora 26.6.20 → 26.6.21

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 (80) hide show
  1. package/README.md +18 -1
  2. package/bin/nyxora.mjs +32 -0
  3. package/dist/packages/core/src/agent/reasoning.js +10 -0
  4. package/dist/packages/core/src/config/parser.js +121 -7
  5. package/dist/packages/core/src/gateway/chat.js +82 -0
  6. package/dist/packages/core/src/gateway/cli.js +63 -0
  7. package/dist/packages/core/src/gateway/server.js +100 -56
  8. package/dist/packages/core/src/gateway/setup.js +39 -22
  9. package/dist/packages/core/src/utils/formatter.test.js +40 -0
  10. package/dist/packages/core/src/utils/skillManager.js +91 -0
  11. package/dist/packages/core/src/utils/userWhitelistManager.js +41 -36
  12. package/dist/packages/core/src/web3/aggregator/aggregatorMainnet.js +2 -2
  13. package/dist/packages/core/src/web3/aggregator/defiRouter.js +3 -0
  14. package/dist/packages/core/src/web3/skills/bridgeToken.js +4 -0
  15. package/dist/packages/core/src/web3/skills/checkRegistryStatus.js +13 -0
  16. package/dist/packages/core/src/web3/skills/customTx.js +2 -0
  17. package/dist/packages/core/src/web3/skills/defiLending.js +2 -0
  18. package/dist/packages/core/src/web3/skills/manageCustomTokens.js +18 -32
  19. package/dist/packages/core/src/web3/skills/marketAnalysis.js +3 -1
  20. package/dist/packages/core/src/web3/skills/mintNft.js +2 -0
  21. package/dist/packages/core/src/web3/skills/provideLiquidity.js +2 -0
  22. package/dist/packages/core/src/web3/skills/revokeApprovals.js +2 -0
  23. package/dist/packages/core/src/web3/skills/swapToken.js +4 -2
  24. package/dist/packages/core/src/web3/skills/transfer.js +2 -0
  25. package/dist/packages/core/src/web3/skills/yieldVault.js +2 -0
  26. package/dist/packages/core/src/web3/utils/tokens.js +9 -1
  27. package/package.json +2 -1
  28. package/packages/core/package.json +1 -1
  29. package/packages/core/src/agent/reasoning.ts +11 -0
  30. package/packages/core/src/config/parser.ts +119 -9
  31. package/packages/core/src/gateway/chat.ts +85 -0
  32. package/packages/core/src/gateway/cli.ts +63 -0
  33. package/packages/core/src/gateway/server.ts +115 -60
  34. package/packages/core/src/gateway/setup.ts +39 -27
  35. package/packages/core/src/utils/formatter.test.ts +41 -0
  36. package/packages/core/src/utils/skillManager.ts +98 -0
  37. package/packages/core/src/utils/userWhitelistManager.ts +48 -39
  38. package/packages/core/src/web3/aggregator/aggregatorMainnet.ts +2 -2
  39. package/packages/core/src/web3/aggregator/defiRouter.ts +4 -0
  40. package/packages/core/src/web3/skills/bridgeToken.ts +3 -0
  41. package/packages/core/src/web3/skills/checkRegistryStatus.ts +13 -0
  42. package/packages/core/src/web3/skills/customTx.ts +1 -0
  43. package/packages/core/src/web3/skills/defiLending.ts +1 -0
  44. package/packages/core/src/web3/skills/manageCustomTokens.ts +18 -29
  45. package/packages/core/src/web3/skills/marketAnalysis.ts +2 -1
  46. package/packages/core/src/web3/skills/mintNft.ts +1 -0
  47. package/packages/core/src/web3/skills/provideLiquidity.ts +1 -0
  48. package/packages/core/src/web3/skills/revokeApprovals.ts +1 -0
  49. package/packages/core/src/web3/skills/swapToken.ts +3 -2
  50. package/packages/core/src/web3/skills/transfer.ts +1 -0
  51. package/packages/core/src/web3/skills/yieldVault.ts +1 -0
  52. package/packages/core/src/web3/utils/tokens.ts +9 -1
  53. package/packages/dashboard/dist/assets/index-Di9x08yk.js +16 -0
  54. package/packages/dashboard/dist/index.html +1 -1
  55. package/packages/dashboard/package.json +1 -1
  56. package/packages/mcp-server/package.json +1 -1
  57. package/packages/policy/package.json +1 -1
  58. package/packages/signer/package.json +1 -1
  59. package/dist/packages/core/src/agent/limitOrderManager.js +0 -124
  60. package/dist/packages/core/src/system/pluginManager.js +0 -91
  61. package/dist/packages/core/src/system/skills/installSkill.js +0 -52
  62. package/dist/packages/core/src/test-all-routers.js +0 -81
  63. package/dist/packages/core/src/test-router.js +0 -38
  64. package/dist/packages/core/src/web3/skills/autonomousDefi.js +0 -191
  65. package/dist/packages/core/src/web3/skills/createWallet.js +0 -34
  66. package/dist/packages/core/src/web3/skills/limitOrder.js +0 -106
  67. package/dist/packages/core/src/web3/utils/protocolRegistry.js +0 -46
  68. package/dist/tsconfig.tsbuildinfo +0 -1
  69. package/packages/core/src/__tests__/reasoning.test.ts +0 -81
  70. package/packages/core/src/__tests__/tokens.test.ts +0 -55
  71. package/packages/core/src/__tests__/web3.test.ts +0 -50
  72. package/packages/core/src/agent/reasoning.d.ts.map +0 -1
  73. package/packages/core/src/config/parser.d.ts.map +0 -1
  74. package/packages/core/src/gateway/cli.d.ts.map +0 -1
  75. package/packages/core/src/memory/logger.d.ts.map +0 -1
  76. package/packages/core/src/test-all-routers.ts +0 -59
  77. package/packages/core/src/test-router.ts +0 -49
  78. package/packages/core/src/web3/config.d.ts.map +0 -1
  79. package/packages/core/src/web3/skills/getBalance.d.ts.map +0 -1
  80. package/packages/dashboard/dist/assets/index-O2m42q4p.js +0 -16
@@ -74,8 +74,8 @@ export async function fetchMainnetBestRoute(
74
74
  promises.push(fetchOpenOcean(fromChain, toChain, fromToken, toToken, amountInWei, userAddress, slippageTolerance, keys.openocean_key));
75
75
  }
76
76
 
77
- // Provider 6: KyberSwap (Cross-chain & Same-chain)
78
- if (isProviderHealthy('kyberswap')) {
77
+ // Provider 6: KyberSwap (Same-chain ONLY)
78
+ if (!isCrossChain && isProviderHealthy('kyberswap')) {
79
79
  promises.push(fetchKyberSwap(fromChain, fromToken, toToken, amountInWei, userAddress, slippageTolerance));
80
80
  }
81
81
 
@@ -12,6 +12,10 @@ export async function routeTransaction(
12
12
  slippageTolerance: number | "auto" = "auto"
13
13
  ): Promise<RouteQuote> {
14
14
 
15
+ if (!fromChain || !toChain) {
16
+ throw new Error("Missing source or destination chain in routing.");
17
+ }
18
+
15
19
  // Auto-correct: If one is testnet and the other is mainnet, assume they meant testnet
16
20
  if (fromChain.includes('sepolia') && !toChain.includes('sepolia')) {
17
21
  if (toChain === 'base') toChain = 'base_sepolia';
@@ -15,6 +15,9 @@ export async function prepareBridgeToken(
15
15
  slippagePercent?: number | "auto"
16
16
  ): Promise<string> {
17
17
  try {
18
+ if (!fromChain || !toChain) throw new Error("Source or destination chain not provided by AI.");
19
+ if (!amountStr) throw new Error("Bridge amount not provided by AI.");
20
+
18
21
  const userAddress = await getAddress();
19
22
 
20
23
  // Auto-correct: If one is testnet and the other is mainnet, assume they meant testnet
@@ -83,3 +83,16 @@ export async function checkRegistryStatus(): Promise<{ isActive: boolean; reason
83
83
  return { isActive: true, reason: 'Registry check skipped due to network error.' };
84
84
  }
85
85
  }
86
+
87
+ export const checkRegistryStatusToolDefinition = {
88
+ type: "function",
89
+ function: {
90
+ name: "check_registry_status",
91
+ description: "Internal Security Middleware: Checks the On-Chain Kill Switch Registry before executing any transaction. If the agent is deactivated, the transaction will be strictly blocked for safety.",
92
+ parameters: {
93
+ type: "object",
94
+ properties: {},
95
+ required: []
96
+ }
97
+ }
98
+ };
@@ -10,6 +10,7 @@ export async function prepareCustomTx(
10
10
  description: string = "Custom transaction"
11
11
  ): Promise<string> {
12
12
  try {
13
+ if (!chainName || !toAddress || !data) throw new Error("Missing required parameters for custom transaction.");
13
14
  const tx = txManager.createPendingTransaction('custom', chainName, {
14
15
  toAddress,
15
16
  data,
@@ -31,6 +31,7 @@ const AAVE_V3_POOLS: Record<string, `0x${string}`> = {
31
31
 
32
32
  export async function prepareAaveSupply(chainName: ChainName, tokenAddressOrSymbol: string, amountStr: string): Promise<string> {
33
33
  try {
34
+ if (!chainName || !tokenAddressOrSymbol || !amountStr) throw new Error("Missing protocol/chain/token parameters for DeFi operation.");
34
35
  const publicClient = getPublicClient(chainName);
35
36
  const userAddress = await getAddress();
36
37
  const account = userAddress as `0x${string}`;
@@ -1,13 +1,12 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { getPath } from '../../config/paths';
4
1
  import { SUPPORTED_CHAIN_NAMES, ChainName } from '../config';
2
+ import { saveTokenToWhitelist, removeTokenFromWhitelist } from '../../utils/userWhitelistManager';
3
+ import { getAddress } from '../utils/vaultClient';
5
4
 
6
5
  export const manageCustomTokensDefinition = {
7
6
  type: 'function',
8
7
  function: {
9
8
  name: 'manage_custom_tokens',
10
- description: 'Add or remove a custom ERC-20 token (like a memecoin or specific token) from the user\'s local portfolio watcher.',
9
+ description: 'Add or remove a custom ERC-20 token (like a memecoin or specific token) from the user\'s local portfolio watcher and swap whitelist.',
11
10
  parameters: {
12
11
  type: 'object',
13
12
  properties: {
@@ -27,10 +26,10 @@ export const manageCustomTokensDefinition = {
27
26
  },
28
27
  contract_address: {
29
28
  type: 'string',
30
- description: 'The smart contract address of the token. Only required for "add" action.'
29
+ description: 'The smart contract address of the token. Required for "add" action or "remove" action.'
31
30
  }
32
31
  },
33
- required: ['action', 'chain_name', 'symbol']
32
+ required: ['action', 'chain_name', 'symbol', 'contract_address']
34
33
  }
35
34
  }
36
35
  };
@@ -38,43 +37,33 @@ export const manageCustomTokensDefinition = {
38
37
  export async function executeManageCustomTokens(args: any): Promise<string> {
39
38
  const { action, chain_name, symbol, contract_address } = args;
40
39
 
41
- if (!SUPPORTED_CHAIN_NAMES.includes(chain_name)) {
42
- return `Error: Unsupported chain ${chain_name}.`;
40
+ if (!chain_name) {
41
+ throw new Error("Chain name is required.");
43
42
  }
44
43
 
45
- const customTokensPath = getPath('custom_tokens.json');
46
- let customTokens: Record<string, Record<string, string>> = {};
47
-
48
- if (fs.existsSync(customTokensPath)) {
49
- try {
50
- const data = fs.readFileSync(customTokensPath, 'utf8');
51
- customTokens = JSON.parse(data);
52
- } catch (e) {
53
- console.error('Error parsing custom_tokens.json', e);
54
- }
44
+ if (!symbol) {
45
+ throw new Error("Token symbol is required.");
55
46
  }
56
47
 
57
- if (!customTokens[chain_name]) {
58
- customTokens[chain_name] = {};
48
+ if (!SUPPORTED_CHAIN_NAMES.includes(chain_name as ChainName)) {
49
+ return `Error: Unsupported chain ${chain_name}.`;
59
50
  }
60
51
 
61
52
  const upperSymbol = symbol.toUpperCase();
53
+ const userAddress = await getAddress();
62
54
 
63
55
  if (action === 'add') {
64
56
  if (!contract_address || !contract_address.startsWith('0x')) {
65
57
  return `Error: Invalid or missing contract_address.`;
66
58
  }
67
- customTokens[chain_name][upperSymbol] = contract_address;
68
- fs.writeFileSync(customTokensPath, JSON.stringify(customTokens, null, 2));
69
- return `Successfully added custom token ${upperSymbol} to the ${chain_name} portfolio tracker.`;
59
+ await saveTokenToWhitelist(userAddress, chain_name as ChainName, contract_address, 'manual', upperSymbol);
60
+ return `Successfully added custom token ${upperSymbol} to the ${chain_name} portfolio tracker and swap whitelist.`;
70
61
  } else if (action === 'remove') {
71
- if (customTokens[chain_name][upperSymbol]) {
72
- delete customTokens[chain_name][upperSymbol];
73
- fs.writeFileSync(customTokensPath, JSON.stringify(customTokens, null, 2));
74
- return `Successfully removed custom token ${upperSymbol} from the ${chain_name} portfolio tracker.`;
75
- } else {
76
- return `Warning: Token ${upperSymbol} was not found in the custom portfolio tracker for ${chain_name}.`;
62
+ if (!contract_address || !contract_address.startsWith('0x')) {
63
+ return `Error: Invalid or missing contract_address for removal.`;
77
64
  }
65
+ removeTokenFromWhitelist(userAddress, chain_name, contract_address);
66
+ return `Successfully removed custom token ${upperSymbol} from the ${chain_name} whitelist.`;
78
67
  }
79
68
 
80
69
  return `Error: Invalid action.`;
@@ -47,7 +47,7 @@ async function fetchDexData(query: string, isCa: boolean, chainName?: ChainName)
47
47
  if (data && data.pairs && data.pairs.length > 0) {
48
48
  let pairs = data.pairs;
49
49
  if (chainName) {
50
- pairs = pairs.filter((p: any) => p.chainId.toLowerCase() === chainName.toLowerCase());
50
+ pairs = pairs.filter((p: any) => p.chainId?.toLowerCase() === chainName?.toLowerCase());
51
51
  if (pairs.length === 0) pairs = data.pairs;
52
52
  }
53
53
  return pairs.sort((a: any, b: any) => (b.volume?.h24 || 0) - (a.volume?.h24 || 0))[0];
@@ -82,6 +82,7 @@ async function fetchCexMomentum(symbol: string, currentP: number) {
82
82
 
83
83
  export async function analyzeMarket(chainName: ChainName, tokenAddressOrSymbol: string): Promise<string> {
84
84
  try {
85
+ if (!tokenAddressOrSymbol) throw new Error("Token symbol is invalid.");
85
86
  const cleanInput = tokenAddressOrSymbol.replace('$', '').toLowerCase();
86
87
  const isAddress = cleanInput.startsWith('0x') && cleanInput.length === 42;
87
88
 
@@ -10,6 +10,7 @@ export async function prepareMintNft(
10
10
  valueEth: string = "0"
11
11
  ): Promise<string> {
12
12
  try {
13
+ if (!chainName || !contractAddress || !functionSignature) throw new Error("Missing required parameters to mint NFT.");
13
14
  const publicClient = getPublicClient(chainName);
14
15
  const userAddress = await getAddress();
15
16
  const account = userAddress as `0x${string}`;
@@ -62,6 +62,7 @@ export async function prepareProvideLiquidity(
62
62
  slippagePercent?: number | "auto"
63
63
  ): Promise<string> {
64
64
  try {
65
+ if (!chainName || !token0AddressOrSymbol || !token1AddressOrSymbol || !amount0Str || !amount1Str) throw new Error("Missing protocol/chain/token parameters for DeFi operation.");
65
66
  let actualSlippage = slippagePercent;
66
67
  if (actualSlippage === undefined || actualSlippage === null || actualSlippage === "auto") {
67
68
  try {
@@ -7,6 +7,7 @@ import { resolveToken, ERC20_ABI, getTokenMetadata } from '../utils/tokens';
7
7
 
8
8
  export async function prepareRevokeApproval(chainName: ChainName, tokenAddressOrSymbol: string, spenderAddress: `0x${string}`): Promise<string> {
9
9
  try {
10
+ if (!chainName || !tokenAddressOrSymbol || !spenderAddress) throw new Error("Missing required parameters for revoking approval.");
10
11
  const publicClient = getPublicClient(chainName);
11
12
  const userAddress = await getAddress();
12
13
  const account = userAddress as `0x${string}`;
@@ -16,6 +16,7 @@ export async function prepareSwapToken(
16
16
  slippagePercent?: number | "auto"
17
17
  ): Promise<string> {
18
18
  try {
19
+ if (!chainName || !fromToken || !toToken || !amountStr) throw new Error("Missing required parameters for swap (chain, tokens, or amount).");
19
20
  const userAddress = await getAddress();
20
21
 
21
22
  const fromTokenAddress = resolveToken(fromToken, chainName);
@@ -23,9 +24,9 @@ export async function prepareSwapToken(
23
24
  const isNativeIn = fromTokenAddress === "0x0000000000000000000000000000000000000000";
24
25
 
25
26
  // Auto-save to Degen Whitelist
26
- if (!isNativeIn) saveTokenToWhitelist(userAddress, chainName, fromTokenAddress, 'swap');
27
+ if (!isNativeIn) await saveTokenToWhitelist(userAddress, chainName, fromTokenAddress, 'swap');
27
28
  if (toTokenAddress !== "0x0000000000000000000000000000000000000000") {
28
- saveTokenToWhitelist(userAddress, chainName, toTokenAddress, 'swap');
29
+ await saveTokenToWhitelist(userAddress, chainName, toTokenAddress, 'swap');
29
30
  }
30
31
 
31
32
  // Default to 18 decimals for formatting input, though Aggregator handles this if we pass raw
@@ -6,6 +6,7 @@ import { submitTransaction } from '../utils/vaultClient';
6
6
 
7
7
  export async function prepareTransfer(chainName: ChainName, toAddress: `0x${string}`, amountStr: string, token?: string): Promise<string> {
8
8
  try {
9
+ if (!chainName || !toAddress || !amountStr) throw new Error("Missing required parameters for transfer (chain, recipient, or amount).");
9
10
  const publicClient = getPublicClient(chainName);
10
11
  const userAddress = await getAddress();
11
12
  const account = userAddress as `0x${string}`;
@@ -23,6 +23,7 @@ const VAULT_ABI = [
23
23
 
24
24
  export async function prepareVaultDeposit(chainName: ChainName, protocol: string, vaultAddress: `0x${string}`, tokenAddressOrSymbol: string, amountStr: string): Promise<string> {
25
25
  try {
26
+ if (!chainName || !vaultAddress || !tokenAddressOrSymbol || !amountStr) throw new Error("Missing protocol/chain/token parameters for DeFi operation.");
26
27
  const publicClient = getPublicClient(chainName);
27
28
  const userAddress = await getAddress();
28
29
  const account = userAddress as `0x${string}`;
@@ -1,4 +1,5 @@
1
1
  import { ChainName } from '../config';
2
+ import { getUserWhitelist } from '../../utils/userWhitelistManager';
2
3
 
3
4
  export const ERC20_ABI = [
4
5
  {
@@ -72,7 +73,7 @@ export const TOKEN_MAP: Record<ChainName, Record<string, `0x${string}`>> = {
72
73
  ETH: "0x0000000000000000000000000000000000000000",
73
74
  WETH: "0x4200000000000000000000000000000000000006",
74
75
  USDC: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
75
- USDT: "0xf55BEC9cbd4732f1F4143f647652e924540d9d64"
76
+ USDT: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2"
76
77
  },
77
78
  optimism: {
78
79
  ETH: "0x0000000000000000000000000000000000000000",
@@ -127,6 +128,13 @@ export function resolveToken(tokenSymbolOrAddress: string, chainName: ChainName)
127
128
  return chainTokens[symbolUpper];
128
129
  }
129
130
 
131
+ const whitelistData = getUserWhitelist();
132
+ for (const addr in whitelistData) {
133
+ const tokens = whitelistData[addr];
134
+ const match = tokens.find(t => t.chainName === chainName && t.symbol === symbolUpper);
135
+ if (match) return match.address as `0x${string}`;
136
+ }
137
+
130
138
  throw new Error(`Token "${tokenSymbolOrAddress}" pada chain ${chainName} tidak ditemukan. Silakan gunakan alamat kontrak langsung (0x...).`);
131
139
  }
132
140