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.
- package/README.md +18 -1
- package/bin/nyxora.mjs +32 -0
- package/dist/packages/core/src/agent/reasoning.js +10 -0
- package/dist/packages/core/src/config/parser.js +121 -7
- package/dist/packages/core/src/gateway/chat.js +82 -0
- package/dist/packages/core/src/gateway/cli.js +63 -0
- package/dist/packages/core/src/gateway/server.js +100 -56
- package/dist/packages/core/src/gateway/setup.js +39 -22
- package/dist/packages/core/src/utils/formatter.test.js +40 -0
- package/dist/packages/core/src/utils/skillManager.js +91 -0
- package/dist/packages/core/src/utils/userWhitelistManager.js +41 -36
- package/dist/packages/core/src/web3/aggregator/aggregatorMainnet.js +2 -2
- package/dist/packages/core/src/web3/aggregator/defiRouter.js +3 -0
- package/dist/packages/core/src/web3/skills/bridgeToken.js +4 -0
- package/dist/packages/core/src/web3/skills/checkRegistryStatus.js +13 -0
- package/dist/packages/core/src/web3/skills/customTx.js +2 -0
- package/dist/packages/core/src/web3/skills/defiLending.js +2 -0
- package/dist/packages/core/src/web3/skills/manageCustomTokens.js +18 -32
- package/dist/packages/core/src/web3/skills/marketAnalysis.js +3 -1
- package/dist/packages/core/src/web3/skills/mintNft.js +2 -0
- package/dist/packages/core/src/web3/skills/provideLiquidity.js +2 -0
- package/dist/packages/core/src/web3/skills/revokeApprovals.js +2 -0
- package/dist/packages/core/src/web3/skills/swapToken.js +4 -2
- package/dist/packages/core/src/web3/skills/transfer.js +2 -0
- package/dist/packages/core/src/web3/skills/yieldVault.js +2 -0
- package/dist/packages/core/src/web3/utils/tokens.js +9 -1
- package/package.json +2 -1
- package/packages/core/package.json +1 -1
- package/packages/core/src/agent/reasoning.ts +11 -0
- package/packages/core/src/config/parser.ts +119 -9
- package/packages/core/src/gateway/chat.ts +85 -0
- package/packages/core/src/gateway/cli.ts +63 -0
- package/packages/core/src/gateway/server.ts +115 -60
- package/packages/core/src/gateway/setup.ts +39 -27
- package/packages/core/src/utils/formatter.test.ts +41 -0
- package/packages/core/src/utils/skillManager.ts +98 -0
- package/packages/core/src/utils/userWhitelistManager.ts +48 -39
- package/packages/core/src/web3/aggregator/aggregatorMainnet.ts +2 -2
- package/packages/core/src/web3/aggregator/defiRouter.ts +4 -0
- package/packages/core/src/web3/skills/bridgeToken.ts +3 -0
- package/packages/core/src/web3/skills/checkRegistryStatus.ts +13 -0
- package/packages/core/src/web3/skills/customTx.ts +1 -0
- package/packages/core/src/web3/skills/defiLending.ts +1 -0
- package/packages/core/src/web3/skills/manageCustomTokens.ts +18 -29
- package/packages/core/src/web3/skills/marketAnalysis.ts +2 -1
- package/packages/core/src/web3/skills/mintNft.ts +1 -0
- package/packages/core/src/web3/skills/provideLiquidity.ts +1 -0
- package/packages/core/src/web3/skills/revokeApprovals.ts +1 -0
- package/packages/core/src/web3/skills/swapToken.ts +3 -2
- package/packages/core/src/web3/skills/transfer.ts +1 -0
- package/packages/core/src/web3/skills/yieldVault.ts +1 -0
- package/packages/core/src/web3/utils/tokens.ts +9 -1
- package/packages/dashboard/dist/assets/index-Di9x08yk.js +16 -0
- package/packages/dashboard/dist/index.html +1 -1
- package/packages/dashboard/package.json +1 -1
- package/packages/mcp-server/package.json +1 -1
- package/packages/policy/package.json +1 -1
- package/packages/signer/package.json +1 -1
- package/dist/packages/core/src/agent/limitOrderManager.js +0 -124
- package/dist/packages/core/src/system/pluginManager.js +0 -91
- package/dist/packages/core/src/system/skills/installSkill.js +0 -52
- package/dist/packages/core/src/test-all-routers.js +0 -81
- package/dist/packages/core/src/test-router.js +0 -38
- package/dist/packages/core/src/web3/skills/autonomousDefi.js +0 -191
- package/dist/packages/core/src/web3/skills/createWallet.js +0 -34
- package/dist/packages/core/src/web3/skills/limitOrder.js +0 -106
- package/dist/packages/core/src/web3/utils/protocolRegistry.js +0 -46
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/packages/core/src/__tests__/reasoning.test.ts +0 -81
- package/packages/core/src/__tests__/tokens.test.ts +0 -55
- package/packages/core/src/__tests__/web3.test.ts +0 -50
- package/packages/core/src/agent/reasoning.d.ts.map +0 -1
- package/packages/core/src/config/parser.d.ts.map +0 -1
- package/packages/core/src/gateway/cli.d.ts.map +0 -1
- package/packages/core/src/memory/logger.d.ts.map +0 -1
- package/packages/core/src/test-all-routers.ts +0 -59
- package/packages/core/src/test-router.ts +0 -49
- package/packages/core/src/web3/config.d.ts.map +0 -1
- package/packages/core/src/web3/skills/getBalance.d.ts.map +0 -1
- package/packages/dashboard/dist/assets/index-O2m42q4p.js +0 -16
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Nyxora Dashboard</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-Di9x08yk.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-CQNHWZtN.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
@@ -1,124 +0,0 @@
|
|
|
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.cancelLimitOrderToolDefinition = exports.listLimitOrdersToolDefinition = exports.createLimitOrderToolDefinition = exports.limitOrderManager = exports.LimitOrderManager = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const parser_1 = require("../config/parser");
|
|
9
|
-
const paths_1 = require("../config/paths");
|
|
10
|
-
const config_1 = require("../web3/config");
|
|
11
|
-
const transactionManager_1 = require("./transactionManager");
|
|
12
|
-
class LimitOrderManager {
|
|
13
|
-
filePath;
|
|
14
|
-
orders = [];
|
|
15
|
-
monitorInterval = null;
|
|
16
|
-
constructor() {
|
|
17
|
-
const config = (0, parser_1.loadConfig)();
|
|
18
|
-
this.filePath = (0, paths_1.getPath)(config.memory?.path ? config.memory.path.replace('memory.json', 'orders.json') : 'orders.json');
|
|
19
|
-
this.loadOrders();
|
|
20
|
-
}
|
|
21
|
-
loadOrders() {
|
|
22
|
-
if (fs_1.default.existsSync(this.filePath)) {
|
|
23
|
-
try {
|
|
24
|
-
const data = fs_1.default.readFileSync(this.filePath, 'utf-8');
|
|
25
|
-
this.orders = JSON.parse(data);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
this.orders = [];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
saveOrders() {
|
|
33
|
-
try {
|
|
34
|
-
fs_1.default.writeFileSync(this.filePath, JSON.stringify(this.orders, null, 2));
|
|
35
|
-
}
|
|
36
|
-
catch (error) { }
|
|
37
|
-
}
|
|
38
|
-
createOrder(chainName, fromToken, toToken, amountStr, targetPriceUsd, condition) {
|
|
39
|
-
const id = `order_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;
|
|
40
|
-
const txDetails = {
|
|
41
|
-
id,
|
|
42
|
-
fromToken,
|
|
43
|
-
toToken,
|
|
44
|
-
amountStr,
|
|
45
|
-
targetPriceUsd,
|
|
46
|
-
condition
|
|
47
|
-
};
|
|
48
|
-
// Instead of saving directly, we push it to txManager to trigger the Approval Gate UX
|
|
49
|
-
transactionManager_1.txManager.createPendingTransaction('limit_order', chainName, txDetails);
|
|
50
|
-
return `Prepared limit order: Sell ${amountStr} ${fromToken} for ${toToken} when price is ${condition} $${targetPriceUsd}. I have pushed this to the Transaction Manager. Please wait for user approval on the Dashboard/Telegram. Do not say it's created yet.`;
|
|
51
|
-
}
|
|
52
|
-
listOrders() {
|
|
53
|
-
const pending = this.orders.filter(o => o.status === 'pending');
|
|
54
|
-
if (pending.length === 0)
|
|
55
|
-
return "No active limit orders.";
|
|
56
|
-
let report = "Active Limit Orders:\n";
|
|
57
|
-
pending.forEach(o => {
|
|
58
|
-
report += `- [${o.id}] Swap ${o.amountStr} ${o.fromToken} -> ${o.toToken} on ${o.chainName} when ${o.fromToken} is ${o.condition} $${o.targetPriceUsd}\n`;
|
|
59
|
-
});
|
|
60
|
-
return report;
|
|
61
|
-
}
|
|
62
|
-
cancelOrder(id) {
|
|
63
|
-
// Note: To truly cancel a 1inch limit order, we need to call 1inch API to cancel the hash.
|
|
64
|
-
// For now, we mark it cancelled locally.
|
|
65
|
-
const order = this.orders.find(o => o.id === id);
|
|
66
|
-
if (!order)
|
|
67
|
-
return `Order ${id} not found.`;
|
|
68
|
-
if (order.status !== 'pending')
|
|
69
|
-
return `Order ${id} cannot be cancelled because it is ${order.status}.`;
|
|
70
|
-
order.status = 'cancelled';
|
|
71
|
-
this.saveOrders();
|
|
72
|
-
return `Order ${id} cancelled successfully locally.`;
|
|
73
|
-
}
|
|
74
|
-
// Polling logic removed as per Phase 2 Migration to 1inch Off-Chain Protocol
|
|
75
|
-
startMonitor() {
|
|
76
|
-
console.log('[LimitOrderManager] Local polling disabled. Delegating to 1inch Limit Order Protocol.');
|
|
77
|
-
}
|
|
78
|
-
// We can add a method to save the 1inch hash after the user approves it
|
|
79
|
-
recordApprovedOrder(orderMetadata) {
|
|
80
|
-
this.orders.push(orderMetadata);
|
|
81
|
-
this.saveOrders();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.LimitOrderManager = LimitOrderManager;
|
|
85
|
-
exports.limitOrderManager = new LimitOrderManager();
|
|
86
|
-
exports.createLimitOrderToolDefinition = {
|
|
87
|
-
type: "function",
|
|
88
|
-
function: {
|
|
89
|
-
name: "create_limit_order",
|
|
90
|
-
description: "Creates an automatic cut-loss or take-profit limit order. The system will automatically execute the swap when the price condition is met.",
|
|
91
|
-
parameters: {
|
|
92
|
-
type: "object",
|
|
93
|
-
properties: {
|
|
94
|
-
chainName: { type: "string", enum: config_1.SUPPORTED_CHAIN_NAMES },
|
|
95
|
-
fromToken: { type: "string", description: "Token to sell" },
|
|
96
|
-
toToken: { type: "string", description: "Token to buy" },
|
|
97
|
-
amountStr: { type: "string", description: "Amount to sell" },
|
|
98
|
-
targetPriceUsd: { type: "number", description: "Target price in USD for the fromToken" },
|
|
99
|
-
condition: { type: "string", enum: ["above", "below"], description: "Trigger when price goes above (take-profit) or below (cut-loss) target" }
|
|
100
|
-
},
|
|
101
|
-
required: ["chainName", "fromToken", "toToken", "amountStr", "targetPriceUsd", "condition"],
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
exports.listLimitOrdersToolDefinition = {
|
|
106
|
-
type: "function",
|
|
107
|
-
function: {
|
|
108
|
-
name: "list_limit_orders",
|
|
109
|
-
description: "Lists all active automated limit orders.",
|
|
110
|
-
parameters: { type: "object", properties: {}, required: [] },
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
exports.cancelLimitOrderToolDefinition = {
|
|
114
|
-
type: "function",
|
|
115
|
-
function: {
|
|
116
|
-
name: "cancel_limit_order",
|
|
117
|
-
description: "Cancels an active limit order by ID.",
|
|
118
|
-
parameters: {
|
|
119
|
-
type: "object",
|
|
120
|
-
properties: { id: { type: "string" } },
|
|
121
|
-
required: ["id"],
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
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.pluginManager = exports.PluginManager = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const isolated_vm_1 = __importDefault(require("isolated-vm"));
|
|
10
|
-
const paths_1 = require("../config/paths");
|
|
11
|
-
class PluginManager {
|
|
12
|
-
skills = new Map();
|
|
13
|
-
async loadPlugins() {
|
|
14
|
-
const pluginsDir = path_1.default.join((0, paths_1.getAppDir)(), 'plugins');
|
|
15
|
-
if (!fs_1.default.existsSync(pluginsDir)) {
|
|
16
|
-
fs_1.default.mkdirSync(pluginsDir, { recursive: true });
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const files = fs_1.default.readdirSync(pluginsDir);
|
|
20
|
-
for (const file of files) {
|
|
21
|
-
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
22
|
-
try {
|
|
23
|
-
const absolutePath = path_1.default.resolve(pluginsDir, file);
|
|
24
|
-
const code = fs_1.default.readFileSync(absolutePath, 'utf8');
|
|
25
|
-
const isolate = new isolated_vm_1.default.Isolate({ memoryLimit: 128 });
|
|
26
|
-
const context = isolate.createContextSync();
|
|
27
|
-
const jail = context.global;
|
|
28
|
-
jail.setSync('global', jail.derefInto());
|
|
29
|
-
// Inject a safe fetch
|
|
30
|
-
const safeFetch = new isolated_vm_1.default.Reference(async (url, options) => {
|
|
31
|
-
if (url.includes('127.0.0.1') || url.includes('localhost') || url.includes('::1')) {
|
|
32
|
-
throw new Error("SSRF Protection: Access to localhost is blocked.");
|
|
33
|
-
}
|
|
34
|
-
const res = await fetch(url, options);
|
|
35
|
-
const text = await res.text();
|
|
36
|
-
return text; // Only return text to avoid passing complex Response objects
|
|
37
|
-
});
|
|
38
|
-
jail.setSync('fetchText', safeFetch);
|
|
39
|
-
// Inject console
|
|
40
|
-
const logCallback = new isolated_vm_1.default.Reference((...args) => console.log('[Plugin]', ...args));
|
|
41
|
-
jail.setSync('log', logCallback);
|
|
42
|
-
const scriptCode = `
|
|
43
|
-
const console = { log: (...args) => log(...args) };
|
|
44
|
-
const fetch = async (url, options) => {
|
|
45
|
-
const text = await fetchText.apply(undefined, [url, options], { arguments: { copy: true }, result: { promise: true } });
|
|
46
|
-
return { text: async () => text, json: async () => JSON.parse(text) };
|
|
47
|
-
};
|
|
48
|
-
const module = { exports: {} };
|
|
49
|
-
const exports = module.exports;
|
|
50
|
-
${code}
|
|
51
|
-
module.exports;
|
|
52
|
-
`;
|
|
53
|
-
const script = isolate.compileScriptSync(scriptCode, { filename: file });
|
|
54
|
-
const moduleExportsRef = script.runSync(context);
|
|
55
|
-
const toolDefinition = moduleExportsRef.getSync('toolDefinition');
|
|
56
|
-
const executeRef = moduleExportsRef.getSync('execute');
|
|
57
|
-
if (toolDefinition && executeRef && typeof executeRef === 'object') {
|
|
58
|
-
const toolName = toolDefinition.function.name;
|
|
59
|
-
const safeExecute = async (args) => {
|
|
60
|
-
const result = await executeRef.apply(undefined, [args], { arguments: { copy: true }, result: { promise: true, copy: true } });
|
|
61
|
-
return result;
|
|
62
|
-
};
|
|
63
|
-
this.skills.set(toolName, { toolDefinition, execute: safeExecute });
|
|
64
|
-
console.log(`[PluginManager] Loaded sandboxed external skill: ${toolName}`);
|
|
65
|
-
}
|
|
66
|
-
moduleExportsRef.release();
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
console.error(`[PluginManager] Failed to load sandboxed plugin ${file}:`, error.message);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
getToolDefinitions() {
|
|
75
|
-
return Array.from(this.skills.values()).map(skill => skill.toolDefinition);
|
|
76
|
-
}
|
|
77
|
-
async executeTool(toolName, args) {
|
|
78
|
-
const skill = this.skills.get(toolName);
|
|
79
|
-
if (skill) {
|
|
80
|
-
try {
|
|
81
|
-
return await skill.execute(args);
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
return `External skill ${toolName} failed: ${error.message}`;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return null; // Tool not found in external skills
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.PluginManager = PluginManager;
|
|
91
|
-
exports.pluginManager = new PluginManager();
|
|
@@ -1,52 +0,0 @@
|
|
|
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.installExternalSkillToolDefinition = void 0;
|
|
7
|
-
exports.installExternalSkill = installExternalSkill;
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const paths_1 = require("../../config/paths");
|
|
11
|
-
async function installExternalSkill(url) {
|
|
12
|
-
try {
|
|
13
|
-
const response = await fetch(url);
|
|
14
|
-
if (!response.ok) {
|
|
15
|
-
return `Failed to fetch skill from URL. Status: ${response.status}`;
|
|
16
|
-
}
|
|
17
|
-
const code = await response.text();
|
|
18
|
-
// Extract a filename from URL, or generate a random one
|
|
19
|
-
let filename = url.split('/').pop() || '';
|
|
20
|
-
if (!filename.endsWith('.ts') && !filename.endsWith('.js')) {
|
|
21
|
-
filename = `skill_${Date.now()}.ts`;
|
|
22
|
-
}
|
|
23
|
-
// Ensure external_skills directory exists
|
|
24
|
-
const pluginsDir = path_1.default.join((0, paths_1.getAppDir)(), 'plugins');
|
|
25
|
-
if (!fs_1.default.existsSync(pluginsDir)) {
|
|
26
|
-
fs_1.default.mkdirSync(pluginsDir, { recursive: true });
|
|
27
|
-
}
|
|
28
|
-
const filePath = path_1.default.join(pluginsDir, filename);
|
|
29
|
-
fs_1.default.writeFileSync(filePath, code, 'utf8');
|
|
30
|
-
return `Skill successfully downloaded and installed to ${filePath}. Please restart the server for the plugin manager to compile and load it.`;
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
return `Failed to install skill: ${error.message}`;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.installExternalSkillToolDefinition = {
|
|
37
|
-
type: "function",
|
|
38
|
-
function: {
|
|
39
|
-
name: "install_external_skill",
|
|
40
|
-
description: "Downloads and installs a third-party typescript skill from a URL (e.g. GitHub Gist raw URL).",
|
|
41
|
-
parameters: {
|
|
42
|
-
type: "object",
|
|
43
|
-
properties: {
|
|
44
|
-
url: {
|
|
45
|
-
type: "string",
|
|
46
|
-
description: "The direct raw URL to the .ts or .js file of the skill.",
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
required: ["url"],
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const swapToken_1 = require("./web3/skills/swapToken");
|
|
37
|
-
const configModule = __importStar(require("./web3/config"));
|
|
38
|
-
// Mock getAddress to bypass Vault lock
|
|
39
|
-
configModule.getAddress = async () => "0x28C6c06298d514Db089934071355E22Af1257125"; // dummy address
|
|
40
|
-
const CHAINS = ["ethereum", "bsc", "base", "arbitrum", "optimism", "polygon"];
|
|
41
|
-
const ROUTERS = ["auto", "lifi", "relay", "uniswap_v2", "uniswap_v3", "pancakeswap", "1inch", "cowswap"];
|
|
42
|
-
// Helper to get native and stablecoin addresses per chain
|
|
43
|
-
const TOKENS = {
|
|
44
|
-
ethereum: { in: "0x0000000000000000000000000000000000000000", out: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" }, // ETH to USDC
|
|
45
|
-
bsc: { in: "0x0000000000000000000000000000000000000000", out: "0x55d398326f99059fF775485246999027B3197955" }, // BNB to USDT
|
|
46
|
-
base: { in: "0x0000000000000000000000000000000000000000", out: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" }, // ETH to USDC
|
|
47
|
-
arbitrum: { in: "0x0000000000000000000000000000000000000000", out: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831" }, // ETH to USDC
|
|
48
|
-
optimism: { in: "0x0000000000000000000000000000000000000000", out: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85" }, // ETH to USDC
|
|
49
|
-
polygon: { in: "0x0000000000000000000000000000000000000000", out: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359" } // MATIC to USDC
|
|
50
|
-
};
|
|
51
|
-
async function runAllTests() {
|
|
52
|
-
console.log("=== COMPREHENSIVE ROUTER TEST ===");
|
|
53
|
-
for (const chain of CHAINS) {
|
|
54
|
-
console.log(`\n--- 🌐 Testing Chain: ${chain.toUpperCase()} ---`);
|
|
55
|
-
const { in: fromToken, out: toToken } = TOKENS[chain];
|
|
56
|
-
const providers = [
|
|
57
|
-
"1inch",
|
|
58
|
-
"0x",
|
|
59
|
-
"lifi",
|
|
60
|
-
"openocean",
|
|
61
|
-
"kyberswap"
|
|
62
|
-
];
|
|
63
|
-
for (const router of providers) {
|
|
64
|
-
try {
|
|
65
|
-
const res = await (0, swapToken_1.prepareSwapToken)(chain, fromToken, toToken, "0.01", "manual", router);
|
|
66
|
-
// Extract just the success info to keep logs readable
|
|
67
|
-
const outputMatch = res.match(/Expected Output: ~([\d.]+) /);
|
|
68
|
-
if (outputMatch) {
|
|
69
|
-
console.log(`[✅ SUCCESS] ${router.padEnd(15)} -> Quote: ~${outputMatch[1]} USDC/USDT`);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
console.log(`[⚠️ PENDING] ${router.padEnd(15)} -> ${res.substring(0, 50)}...`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
console.log(`[❌ FAILED] ${router.padEnd(15)} -> ${err.message.split('\\n')[0]}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
runAllTests();
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const swapToken_1 = require("./web3/skills/swapToken");
|
|
4
|
-
async function runTest() {
|
|
5
|
-
console.log("=== Testing Native Routers ===");
|
|
6
|
-
try {
|
|
7
|
-
// 1. Test Uniswap V2
|
|
8
|
-
// 1. Test 1inch
|
|
9
|
-
console.log("\n[Test 1] Testing 1inch route (ETH to USDC on Base)...");
|
|
10
|
-
const resV2 = await (0, swapToken_1.prepareSwapToken)("base", // chain
|
|
11
|
-
"0x0000000000000000000000000000000000000000", // ETH native
|
|
12
|
-
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
|
|
13
|
-
"0.001", // amount
|
|
14
|
-
"manual", // mode
|
|
15
|
-
"1inch" // providerName
|
|
16
|
-
);
|
|
17
|
-
console.log("Result 1 (1inch):", resV2);
|
|
18
|
-
// 2. Test 0x
|
|
19
|
-
console.log("\n[Test 2] Testing 0x route (WETH to USDT on Ethereum)...");
|
|
20
|
-
const resCow = await (0, swapToken_1.prepareSwapToken)("ethereum", // chain
|
|
21
|
-
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
|
|
22
|
-
"0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT
|
|
23
|
-
"0.1", // 0.1 ETH
|
|
24
|
-
"auto", // mode
|
|
25
|
-
"0x" // providerName
|
|
26
|
-
);
|
|
27
|
-
console.log("Result 0x:", resCow);
|
|
28
|
-
// 3. Test Auto
|
|
29
|
-
console.log("\n[Test 3] Testing Auto route...");
|
|
30
|
-
const resAuto = await (0, swapToken_1.prepareSwapToken)("base", "0x0000000000000000000000000000000000000000", "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "0.001", "auto");
|
|
31
|
-
console.log("Result Auto:", resAuto);
|
|
32
|
-
console.log("\\nAll tests completed!");
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
console.error("\\nTEST FAILED:", error.message);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
runTest();
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.executeDynamicDefiToolDefinition = exports.fetchContractAbiToolDefinition = void 0;
|
|
4
|
-
exports.executeFetchContractAbi = executeFetchContractAbi;
|
|
5
|
-
exports.executeDynamicDefi = executeDynamicDefi;
|
|
6
|
-
const viem_1 = require("viem");
|
|
7
|
-
const chains_1 = require("viem/chains");
|
|
8
|
-
const protocolRegistry_1 = require("../utils/protocolRegistry");
|
|
9
|
-
const parser_1 = require("../../config/parser");
|
|
10
|
-
// The API key will be fetched dynamically inside the function
|
|
11
|
-
const ETHERSCAN_URLS = {
|
|
12
|
-
1: 'https://api.etherscan.io/api',
|
|
13
|
-
11155111: 'https://api-sepolia.etherscan.io/api',
|
|
14
|
-
8453: 'https://api.basescan.org/api',
|
|
15
|
-
56: 'https://api.bscscan.com/api',
|
|
16
|
-
42161: 'https://api.arbiscan.io/api'
|
|
17
|
-
};
|
|
18
|
-
function getChainConfig(chainId) {
|
|
19
|
-
switch (chainId) {
|
|
20
|
-
case 1: return chains_1.mainnet;
|
|
21
|
-
case 11155111: return chains_1.sepolia;
|
|
22
|
-
case 8453: return chains_1.base;
|
|
23
|
-
case 56: return chains_1.bsc;
|
|
24
|
-
case 42161: return chains_1.arbitrum;
|
|
25
|
-
default: throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async function fetchABIFromEtherscan(chainId, address) {
|
|
29
|
-
const config = (0, parser_1.loadConfig)();
|
|
30
|
-
const apiKey = config.web3?.explorer_api_key || process.env.ETHERSCAN_API_KEY || '';
|
|
31
|
-
let url = '';
|
|
32
|
-
// Etherscan has migrated to V2 API for Mainnet and Sepolia
|
|
33
|
-
if (chainId === 1 || chainId === 11155111) {
|
|
34
|
-
url = `https://api.etherscan.io/v2/api?chainid=${chainId}&module=contract&action=getabi&address=${address}&apikey=${apiKey}`;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
const baseUrl = ETHERSCAN_URLS[chainId];
|
|
38
|
-
if (!baseUrl)
|
|
39
|
-
throw new Error(`No Etherscan URL for chain ${chainId}`);
|
|
40
|
-
url = `${baseUrl}?module=contract&action=getabi&address=${address}&apikey=${apiKey}`;
|
|
41
|
-
}
|
|
42
|
-
const response = await fetch(url);
|
|
43
|
-
const data = await response.json();
|
|
44
|
-
if (data.status !== '1') {
|
|
45
|
-
throw new Error(`Etherscan API Error: ${data.result}`);
|
|
46
|
-
}
|
|
47
|
-
return JSON.parse(data.result);
|
|
48
|
-
}
|
|
49
|
-
async function verifySecurity(address) {
|
|
50
|
-
console.log(`[Lapis 2] Verifying security for ${address} via GoPlus/DeFiLlama...`);
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
async function executeFetchContractAbi(args) {
|
|
54
|
-
try {
|
|
55
|
-
const { protocolName, chainId, contractAddress } = args;
|
|
56
|
-
console.log(`[Autonomous DeFi] Fetching ABI for ${protocolName} at ${contractAddress} on chain ${chainId}`);
|
|
57
|
-
const isSafe = await verifySecurity(contractAddress);
|
|
58
|
-
if (!isSafe) {
|
|
59
|
-
return `SECURITY ALERT: Contract ${contractAddress} is flagged as potentially malicious. Aborting.`;
|
|
60
|
-
}
|
|
61
|
-
let abi = await fetchABIFromEtherscan(chainId, contractAddress);
|
|
62
|
-
let implementationAddress = contractAddress;
|
|
63
|
-
const hasUpgradeTo = abi.some((item) => item.name === 'upgradeTo' || item.name === 'implementation');
|
|
64
|
-
if (hasUpgradeTo) {
|
|
65
|
-
console.log(`[Autonomous DeFi] Proxy pattern detected for ${contractAddress}. Resolving implementation...`);
|
|
66
|
-
const publicClient = (0, viem_1.createPublicClient)({
|
|
67
|
-
chain: getChainConfig(chainId),
|
|
68
|
-
transport: (0, viem_1.http)()
|
|
69
|
-
});
|
|
70
|
-
try {
|
|
71
|
-
// @ts-ignore: Dynamic ABI causes strict type inference issues in viem
|
|
72
|
-
const impl = await publicClient.readContract({
|
|
73
|
-
address: (0, viem_1.getAddress)(contractAddress),
|
|
74
|
-
abi: abi,
|
|
75
|
-
functionName: 'implementation'
|
|
76
|
-
});
|
|
77
|
-
if (impl && impl !== '0x0000000000000000000000000000000000000000') {
|
|
78
|
-
console.log(`[Autonomous DeFi] Implementation found at ${impl}. Fetching true ABI...`);
|
|
79
|
-
implementationAddress = impl;
|
|
80
|
-
abi = await fetchABIFromEtherscan(chainId, impl);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
console.log(`[Autonomous DeFi] Could not read implementation(): ${err}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const registryEntry = (0, protocolRegistry_1.getProtocol)(protocolName) || {
|
|
88
|
-
chainId,
|
|
89
|
-
contracts: {},
|
|
90
|
-
verifiedFunctions: {},
|
|
91
|
-
abiCache: {}
|
|
92
|
-
};
|
|
93
|
-
registryEntry.contracts['main'] = contractAddress;
|
|
94
|
-
registryEntry.abiCache = registryEntry.abiCache || {};
|
|
95
|
-
registryEntry.abiCache[contractAddress] = abi;
|
|
96
|
-
(0, protocolRegistry_1.updateProtocol)(protocolName, registryEntry);
|
|
97
|
-
return `Success! ABI fetched and resolved. True implementation is ${implementationAddress}.
|
|
98
|
-
Available functions: ${abi.filter(a => a.type === 'function').map(a => a.name).join(', ')}.
|
|
99
|
-
You can now use 'execute_dynamic_defi' to interact with it.`;
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
return `Failed to fetch ABI: ${error.message}`;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async function executeDynamicDefi(args) {
|
|
106
|
-
try {
|
|
107
|
-
const { protocolName, contractAddress, targetFunction, inputs, requiresAllowance, tokenDecimals } = args;
|
|
108
|
-
const registryEntry = (0, protocolRegistry_1.getProtocol)(protocolName);
|
|
109
|
-
if (!registryEntry || !registryEntry.abiCache || !registryEntry.abiCache[contractAddress]) {
|
|
110
|
-
return `Error: ABI not found in registry for ${contractAddress}. Please run fetch_contract_abi first.`;
|
|
111
|
-
}
|
|
112
|
-
const abi = registryEntry.abiCache[contractAddress];
|
|
113
|
-
const formattedArgs = inputs.map(input => {
|
|
114
|
-
if (input.type.includes('uint') && tokenDecimals && !input.name.toLowerCase().includes('id')) {
|
|
115
|
-
return (0, viem_1.parseUnits)(input.value, tokenDecimals);
|
|
116
|
-
}
|
|
117
|
-
return input.value;
|
|
118
|
-
});
|
|
119
|
-
let allowanceNotice = "";
|
|
120
|
-
if (requiresAllowance) {
|
|
121
|
-
allowanceNotice = `\n[INTERCEPTOR] This action requires token allowance. The system will automatically bundle an 'approve()' transaction before the main execution.`;
|
|
122
|
-
}
|
|
123
|
-
const calldata = (0, viem_1.encodeFunctionData)({
|
|
124
|
-
abi: abi,
|
|
125
|
-
functionName: targetFunction,
|
|
126
|
-
args: formattedArgs
|
|
127
|
-
});
|
|
128
|
-
console.log(`[Lapis 3] Simulating transaction via Tenderly Engine...`);
|
|
129
|
-
registryEntry.verifiedFunctions[`${targetFunction}`] = {
|
|
130
|
-
verifiedAt: new Date().toISOString(),
|
|
131
|
-
safetyApproved: true
|
|
132
|
-
};
|
|
133
|
-
(0, protocolRegistry_1.updateProtocol)(protocolName, registryEntry);
|
|
134
|
-
return `Simulation Success! ${allowanceNotice}
|
|
135
|
-
Target: ${contractAddress}
|
|
136
|
-
Function: ${targetFunction}
|
|
137
|
-
Calldata: ${calldata}
|
|
138
|
-
|
|
139
|
-
The AI has securely encoded the parameters.`;
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
return `Execution failed: ${error.message}`;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.fetchContractAbiToolDefinition = {
|
|
146
|
-
type: "function",
|
|
147
|
-
function: {
|
|
148
|
-
name: "fetch_contract_abi",
|
|
149
|
-
description: "Autonomous Universal DeFi Engine: Fetches the ABI of any smart contract. Automatically resolves EIP-1967/EIP-897 proxy patterns to find the true implementation ABI.",
|
|
150
|
-
parameters: {
|
|
151
|
-
type: "object",
|
|
152
|
-
properties: {
|
|
153
|
-
protocolName: { type: "string", description: "The name of the protocol (e.g. puffer-finance)" },
|
|
154
|
-
chainId: { type: "number", description: "Chain ID (e.g. 1 for Mainnet, 11155111 for Sepolia)" },
|
|
155
|
-
contractAddress: { type: "string", description: "The contract address to fetch" }
|
|
156
|
-
},
|
|
157
|
-
required: ["protocolName", "chainId", "contractAddress"]
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
exports.executeDynamicDefiToolDefinition = {
|
|
162
|
-
type: "function",
|
|
163
|
-
function: {
|
|
164
|
-
name: "execute_dynamic_defi",
|
|
165
|
-
description: "Autonomous Universal DeFi Engine: Executes a transaction on a contract using structured JSON. Ensure you have fetched the ABI first.",
|
|
166
|
-
parameters: {
|
|
167
|
-
type: "object",
|
|
168
|
-
properties: {
|
|
169
|
-
protocolName: { type: "string", description: "The name of the protocol" },
|
|
170
|
-
contractAddress: { type: "string", description: "The contract address to execute on" },
|
|
171
|
-
targetFunction: { type: "string", description: "The exact function name to call (e.g. 'deposit')" },
|
|
172
|
-
inputs: {
|
|
173
|
-
type: "array",
|
|
174
|
-
items: {
|
|
175
|
-
type: "object",
|
|
176
|
-
properties: {
|
|
177
|
-
name: { type: "string" },
|
|
178
|
-
type: { type: "string" },
|
|
179
|
-
value: { type: "string", description: "Human readable string value (e.g. '100' for 100 USDC)." }
|
|
180
|
-
},
|
|
181
|
-
required: ["name", "type", "value"]
|
|
182
|
-
},
|
|
183
|
-
description: "Array of structured input arguments"
|
|
184
|
-
},
|
|
185
|
-
requiresAllowance: { type: "boolean", description: "True if this function transfers ERC20 tokens from the user" },
|
|
186
|
-
tokenDecimals: { type: "number", description: "Optional. Required if parsing token amounts for decimal scaling" }
|
|
187
|
-
},
|
|
188
|
-
required: ["protocolName", "contractAddress", "targetFunction", "inputs", "requiresAllowance"]
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createWalletToolDefinition = void 0;
|
|
4
|
-
exports.createWallet = createWallet;
|
|
5
|
-
const accounts_1 = require("viem/accounts");
|
|
6
|
-
async function createWallet() {
|
|
7
|
-
try {
|
|
8
|
-
const mnemonic = (0, accounts_1.generateMnemonic)(accounts_1.english);
|
|
9
|
-
const account = (0, accounts_1.mnemonicToAccount)(mnemonic);
|
|
10
|
-
return `[WALLET_CREATED_SUCCESSFULLY]
|
|
11
|
-
A new EVM wallet has been generated. Please instruct the user to back up these details immediately as they will not be saved anywhere else:
|
|
12
|
-
|
|
13
|
-
Address: ${account.address}
|
|
14
|
-
Private Key: ${account.getHdKey().privateKey ? '0x' + Buffer.from(account.getHdKey().privateKey).toString('hex') : 'Unavailable'}
|
|
15
|
-
Seed Phrase: ${mnemonic}
|
|
16
|
-
|
|
17
|
-
IMPORTANT: Do not store this data in your AI memory. Only display it once.`;
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
return `Failed to generate wallet: ${error.message}`;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.createWalletToolDefinition = {
|
|
24
|
-
type: "function",
|
|
25
|
-
function: {
|
|
26
|
-
name: "create_wallet",
|
|
27
|
-
description: "Generates a new EVM wallet address, private key, and 12-word seed phrase.",
|
|
28
|
-
parameters: {
|
|
29
|
-
type: "object",
|
|
30
|
-
properties: {},
|
|
31
|
-
required: [],
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
};
|