nyxora 1.0.0
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/.env.example +17 -0
- package/IDENTITY.md +8 -0
- package/README.md +61 -0
- package/SECURITY.md +19 -0
- package/config.yaml +10 -0
- package/dashboard/README.md +73 -0
- package/dashboard/eslint.config.js +22 -0
- package/dashboard/index.html +13 -0
- package/dashboard/package-lock.json +2737 -0
- package/dashboard/package.json +31 -0
- package/dashboard/public/favicon.svg +1 -0
- package/dashboard/public/icons.svg +24 -0
- package/dashboard/src/App.css +184 -0
- package/dashboard/src/App.tsx +485 -0
- package/dashboard/src/BalanceWidget.tsx +65 -0
- package/dashboard/src/MarketWidget.tsx +73 -0
- package/dashboard/src/Memory.tsx +109 -0
- package/dashboard/src/Overview.tsx +156 -0
- package/dashboard/src/Settings.tsx +213 -0
- package/dashboard/src/Skills.tsx +97 -0
- package/dashboard/src/SwapWidget.tsx +130 -0
- package/dashboard/src/TransactionWidget.tsx +86 -0
- package/dashboard/src/assets/hero.png +0 -0
- package/dashboard/src/assets/react.svg +1 -0
- package/dashboard/src/assets/vite.svg +1 -0
- package/dashboard/src/index.css +508 -0
- package/dashboard/src/main.tsx +10 -0
- package/dashboard/src/overview.css +304 -0
- package/dashboard/tsconfig.app.json +25 -0
- package/dashboard/tsconfig.json +7 -0
- package/dashboard/tsconfig.node.json +24 -0
- package/dashboard/vite.config.ts +7 -0
- package/dist/agent/reasoning.js +254 -0
- package/dist/config/parser.js +36 -0
- package/dist/config/paths.js +35 -0
- package/dist/gateway/cli.js +86 -0
- package/dist/gateway/server.js +154 -0
- package/dist/gateway/telegram.js +45 -0
- package/dist/gateway/test.js +50 -0
- package/dist/gateway/tracker.js +49 -0
- package/dist/memory/logger.js +50 -0
- package/dist/src/agent/reasoning.js +96 -0
- package/dist/src/config/parser.js +25 -0
- package/dist/src/gateway/cli.js +79 -0
- package/dist/src/memory/logger.js +50 -0
- package/dist/src/web3/config.js +80 -0
- package/dist/src/web3/skills/getBalance.js +43 -0
- package/dist/web3/config.js +83 -0
- package/dist/web3/skills/getBalance.js +80 -0
- package/dist/web3/skills/getPrice.js +44 -0
- package/dist/web3/skills/swapToken.js +71 -0
- package/dist/web3/skills/transfer.js +48 -0
- package/package.json +38 -0
- package/src/agent/reasoning.d.ts +2 -0
- package/src/agent/reasoning.d.ts.map +1 -0
- package/src/agent/reasoning.js +97 -0
- package/src/agent/reasoning.js.map +1 -0
- package/src/agent/reasoning.ts +232 -0
- package/src/config/parser.d.ts +17 -0
- package/src/config/parser.d.ts.map +1 -0
- package/src/config/parser.js +26 -0
- package/src/config/parser.js.map +1 -0
- package/src/config/parser.ts +47 -0
- package/src/config/paths.ts +33 -0
- package/src/gateway/cli.d.ts +3 -0
- package/src/gateway/cli.d.ts.map +1 -0
- package/src/gateway/cli.js +80 -0
- package/src/gateway/cli.js.map +1 -0
- package/src/gateway/cli.ts +58 -0
- package/src/gateway/server.ts +131 -0
- package/src/gateway/telegram.ts +47 -0
- package/src/gateway/test.ts +16 -0
- package/src/gateway/tracker.ts +70 -0
- package/src/memory/logger.d.ts +18 -0
- package/src/memory/logger.d.ts.map +1 -0
- package/src/memory/logger.js +51 -0
- package/src/memory/logger.js.map +1 -0
- package/src/memory/logger.ts +57 -0
- package/src/web3/config.d.ts +793 -0
- package/src/web3/config.d.ts.map +1 -0
- package/src/web3/config.js +81 -0
- package/src/web3/config.js.map +1 -0
- package/src/web3/config.ts +51 -0
- package/src/web3/skills/getBalance.d.ts +25 -0
- package/src/web3/skills/getBalance.d.ts.map +1 -0
- package/src/web3/skills/getBalance.js +46 -0
- package/src/web3/skills/getBalance.js.map +1 -0
- package/src/web3/skills/getBalance.ts +48 -0
- package/src/web3/skills/getPrice.ts +43 -0
- package/src/web3/skills/swapToken.ts +69 -0
- package/src/web3/skills/transfer.ts +47 -0
- package/tsconfig.json +13 -0
- package/user.md +10 -0
|
@@ -0,0 +1,50 @@
|
|
|
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.Logger = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const parser_1 = require("../config/parser");
|
|
10
|
+
class Logger {
|
|
11
|
+
logFilePath;
|
|
12
|
+
memory = [];
|
|
13
|
+
constructor() {
|
|
14
|
+
const config = (0, parser_1.loadConfig)();
|
|
15
|
+
this.logFilePath = path_1.default.resolve(process.cwd(), config.memory.path || 'memory.json');
|
|
16
|
+
this.loadMemory();
|
|
17
|
+
}
|
|
18
|
+
loadMemory() {
|
|
19
|
+
if (fs_1.default.existsSync(this.logFilePath)) {
|
|
20
|
+
try {
|
|
21
|
+
const data = fs_1.default.readFileSync(this.logFilePath, 'utf-8');
|
|
22
|
+
this.memory = JSON.parse(data);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error('Failed to read memory file. Starting fresh.');
|
|
26
|
+
this.memory = [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
saveMemory() {
|
|
31
|
+
try {
|
|
32
|
+
fs_1.default.writeFileSync(this.logFilePath, JSON.stringify(this.memory, null, 2));
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error('Failed to write memory file.');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
getHistory() {
|
|
39
|
+
return [...this.memory];
|
|
40
|
+
}
|
|
41
|
+
addEntry(entry) {
|
|
42
|
+
this.memory.push(entry);
|
|
43
|
+
this.saveMemory();
|
|
44
|
+
}
|
|
45
|
+
clear() {
|
|
46
|
+
this.memory = [];
|
|
47
|
+
this.saveMemory();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
exports.supportedChains = void 0;
|
|
37
|
+
exports.getPublicClient = getPublicClient;
|
|
38
|
+
exports.getWalletClient = getWalletClient;
|
|
39
|
+
exports.getAddress = getAddress;
|
|
40
|
+
const viem_1 = require("viem");
|
|
41
|
+
const accounts_1 = require("viem/accounts");
|
|
42
|
+
const chains_1 = require("viem/chains");
|
|
43
|
+
const dotenv = __importStar(require("dotenv"));
|
|
44
|
+
dotenv.config();
|
|
45
|
+
exports.supportedChains = {
|
|
46
|
+
ethereum: chains_1.mainnet,
|
|
47
|
+
base: chains_1.base,
|
|
48
|
+
bsc: chains_1.bsc,
|
|
49
|
+
arbitrum: chains_1.arbitrum,
|
|
50
|
+
optimism: chains_1.optimism,
|
|
51
|
+
};
|
|
52
|
+
function getPublicClient(chainName) {
|
|
53
|
+
const chain = exports.supportedChains[chainName];
|
|
54
|
+
if (!chain)
|
|
55
|
+
throw new Error(`Unsupported chain: ${chainName}`);
|
|
56
|
+
return (0, viem_1.createPublicClient)({
|
|
57
|
+
chain,
|
|
58
|
+
transport: (0, viem_1.http)(), // Falls back to public RPC, can be customized with process.env
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function getWalletClient(chainName) {
|
|
62
|
+
const chain = exports.supportedChains[chainName];
|
|
63
|
+
if (!chain)
|
|
64
|
+
throw new Error(`Unsupported chain: ${chainName}`);
|
|
65
|
+
const privateKey = process.env.PRIVATE_KEY;
|
|
66
|
+
if (!privateKey)
|
|
67
|
+
throw new Error('PRIVATE_KEY is not set in .env');
|
|
68
|
+
const account = (0, accounts_1.privateKeyToAccount)(privateKey);
|
|
69
|
+
return (0, viem_1.createWalletClient)({
|
|
70
|
+
account,
|
|
71
|
+
chain,
|
|
72
|
+
transport: (0, viem_1.http)(),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function getAddress() {
|
|
76
|
+
const privateKey = process.env.PRIVATE_KEY;
|
|
77
|
+
if (!privateKey)
|
|
78
|
+
throw new Error('PRIVATE_KEY is not set in .env');
|
|
79
|
+
return (0, accounts_1.privateKeyToAccount)(privateKey).address;
|
|
80
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBalanceToolDefinition = void 0;
|
|
4
|
+
exports.getBalance = getBalance;
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const config_1 = require("../config");
|
|
7
|
+
async function getBalance(chainName, address) {
|
|
8
|
+
try {
|
|
9
|
+
const client = (0, config_1.getPublicClient)(chainName);
|
|
10
|
+
let targetAddress = address;
|
|
11
|
+
if (!targetAddress) {
|
|
12
|
+
throw new Error('Address is required but could not be resolved.');
|
|
13
|
+
}
|
|
14
|
+
const balanceWei = await client.getBalance({ address: targetAddress });
|
|
15
|
+
const balanceEth = (0, viem_1.formatEther)(balanceWei);
|
|
16
|
+
return `${balanceEth} on ${chainName}`;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
return `Failed to get balance: ${error.message}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.getBalanceToolDefinition = {
|
|
23
|
+
type: "function",
|
|
24
|
+
function: {
|
|
25
|
+
name: "get_balance",
|
|
26
|
+
description: "Get the native token balance (ETH, BNB, etc) of a wallet address on a specific chain. If address is omitted, it returns the balance of the agent's own wallet.",
|
|
27
|
+
parameters: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
chainName: {
|
|
31
|
+
type: "string",
|
|
32
|
+
enum: ["ethereum", "base", "bsc", "arbitrum", "optimism"],
|
|
33
|
+
description: "The name of the blockchain to check."
|
|
34
|
+
},
|
|
35
|
+
address: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Optional. The 0x... address of the wallet. If not provided, it uses the agent's wallet."
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
required: ["chainName"]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
exports.supportedChains = void 0;
|
|
37
|
+
exports.getPublicClient = getPublicClient;
|
|
38
|
+
exports.getWalletClient = getWalletClient;
|
|
39
|
+
exports.getAddress = getAddress;
|
|
40
|
+
const viem_1 = require("viem");
|
|
41
|
+
const accounts_1 = require("viem/accounts");
|
|
42
|
+
const chains_1 = require("viem/chains");
|
|
43
|
+
const dotenv = __importStar(require("dotenv"));
|
|
44
|
+
dotenv.config();
|
|
45
|
+
exports.supportedChains = {
|
|
46
|
+
ethereum: chains_1.mainnet,
|
|
47
|
+
base: chains_1.base,
|
|
48
|
+
bsc: chains_1.bsc,
|
|
49
|
+
arbitrum: chains_1.arbitrum,
|
|
50
|
+
optimism: chains_1.optimism,
|
|
51
|
+
sepolia: chains_1.sepolia,
|
|
52
|
+
};
|
|
53
|
+
function getPublicClient(chainName) {
|
|
54
|
+
const chain = exports.supportedChains[chainName];
|
|
55
|
+
if (!chain)
|
|
56
|
+
throw new Error(`Unsupported chain: ${chainName}`);
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
return (0, viem_1.createPublicClient)({
|
|
59
|
+
chain,
|
|
60
|
+
transport: (0, viem_1.http)(), // Falls back to public RPC, can be customized with process.env
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function getWalletClient(chainName) {
|
|
64
|
+
const chain = exports.supportedChains[chainName];
|
|
65
|
+
if (!chain)
|
|
66
|
+
throw new Error(`Unsupported chain: ${chainName}`);
|
|
67
|
+
const privateKey = process.env.PRIVATE_KEY;
|
|
68
|
+
if (!privateKey)
|
|
69
|
+
throw new Error('PRIVATE_KEY is not set in .env');
|
|
70
|
+
const account = (0, accounts_1.privateKeyToAccount)(privateKey);
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
return (0, viem_1.createWalletClient)({
|
|
73
|
+
account,
|
|
74
|
+
chain,
|
|
75
|
+
transport: (0, viem_1.http)(),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function getAddress() {
|
|
79
|
+
const privateKey = process.env.PRIVATE_KEY;
|
|
80
|
+
if (!privateKey)
|
|
81
|
+
throw new Error('PRIVATE_KEY is not set in .env');
|
|
82
|
+
return (0, accounts_1.privateKeyToAccount)(privateKey).address;
|
|
83
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
exports.getBalanceToolDefinition = void 0;
|
|
37
|
+
exports.getBalance = getBalance;
|
|
38
|
+
const viem_1 = require("viem");
|
|
39
|
+
const config_1 = require("../config");
|
|
40
|
+
async function getBalance(chainName, address) {
|
|
41
|
+
try {
|
|
42
|
+
const client = (0, config_1.getPublicClient)(chainName);
|
|
43
|
+
let targetAddress = address;
|
|
44
|
+
if (!targetAddress) {
|
|
45
|
+
const { getAddress } = await Promise.resolve().then(() => __importStar(require('../config')));
|
|
46
|
+
targetAddress = getAddress();
|
|
47
|
+
}
|
|
48
|
+
if (!targetAddress) {
|
|
49
|
+
throw new Error('Address is required but could not be resolved from private key.');
|
|
50
|
+
}
|
|
51
|
+
const balanceWei = await client.getBalance({ address: targetAddress });
|
|
52
|
+
const balanceEth = (0, viem_1.formatEther)(balanceWei);
|
|
53
|
+
return `${balanceEth} on ${chainName}`;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
return `Failed to get balance: ${error.message}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.getBalanceToolDefinition = {
|
|
60
|
+
type: "function",
|
|
61
|
+
function: {
|
|
62
|
+
name: "get_balance",
|
|
63
|
+
description: "Get the native token balance (ETH, BNB, etc) of a wallet address on a specific chain. If address is omitted, it returns the balance of the agent's own wallet.",
|
|
64
|
+
parameters: {
|
|
65
|
+
type: "object",
|
|
66
|
+
properties: {
|
|
67
|
+
chainName: {
|
|
68
|
+
type: "string",
|
|
69
|
+
enum: ["ethereum", "base", "bsc", "arbitrum", "optimism", "sepolia"],
|
|
70
|
+
description: "The name of the blockchain to check."
|
|
71
|
+
},
|
|
72
|
+
address: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "Optional. The 0x... address of the wallet. If not provided, it uses the agent's wallet."
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
required: ["chainName"]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPriceToolDefinition = void 0;
|
|
4
|
+
exports.getPrice = getPrice;
|
|
5
|
+
exports.getPriceToolDefinition = {
|
|
6
|
+
type: "function",
|
|
7
|
+
function: {
|
|
8
|
+
name: "get_price",
|
|
9
|
+
description: "Fetches the current price of a cryptocurrency in USD along with its 24h change percentage.",
|
|
10
|
+
parameters: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
coinId: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "The CoinGecko ID of the coin (e.g., 'ethereum', 'bitcoin', 'solana')."
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
required: ["coinId"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
async function getPrice(coinId) {
|
|
23
|
+
try {
|
|
24
|
+
const url = `https://api.coingecko.com/api/v3/simple/price?ids=${coinId}&vs_currencies=usd&include_24hr_change=true`;
|
|
25
|
+
const response = await fetch(url);
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
28
|
+
}
|
|
29
|
+
const data = await response.json();
|
|
30
|
+
if (!data[coinId]) {
|
|
31
|
+
return JSON.stringify({ error: `Could not find price data for ${coinId}` });
|
|
32
|
+
}
|
|
33
|
+
const price = data[coinId].usd;
|
|
34
|
+
const change24h = data[coinId].usd_24h_change;
|
|
35
|
+
return JSON.stringify({
|
|
36
|
+
coin: coinId,
|
|
37
|
+
priceUsd: price,
|
|
38
|
+
change24h: change24h
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return JSON.stringify({ error: `Failed to fetch price: ${error.message}` });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.swapTokenToolDefinition = void 0;
|
|
4
|
+
exports.swapToken = swapToken;
|
|
5
|
+
exports.swapTokenToolDefinition = {
|
|
6
|
+
type: "function",
|
|
7
|
+
function: {
|
|
8
|
+
name: "swap_token",
|
|
9
|
+
description: "Executes a decentralized token swap (DEX) to exchange one cryptocurrency for another.",
|
|
10
|
+
parameters: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
chainName: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "The blockchain network (e.g., 'ethereum', 'base', 'arbitrum', 'sepolia')",
|
|
16
|
+
},
|
|
17
|
+
fromToken: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "The token symbol to sell/swap from (e.g., 'ETH', 'USDC')",
|
|
20
|
+
},
|
|
21
|
+
toToken: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "The token symbol to buy/swap to (e.g., 'USDC', 'UNI')",
|
|
24
|
+
},
|
|
25
|
+
amount: {
|
|
26
|
+
type: "number",
|
|
27
|
+
description: "The amount of fromToken to swap",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ["chainName", "fromToken", "toToken", "amount"],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
async function swapToken(chainName, fromToken, toToken, amount) {
|
|
35
|
+
try {
|
|
36
|
+
// Generate simulated exchange rate for testnet/demo purposes
|
|
37
|
+
let rate = 1.0;
|
|
38
|
+
// Simple mock rates based on common pairs
|
|
39
|
+
if (fromToken.toUpperCase() === 'ETH' && toToken.toUpperCase() === 'USDC')
|
|
40
|
+
rate = 3200;
|
|
41
|
+
if (fromToken.toUpperCase() === 'USDC' && toToken.toUpperCase() === 'ETH')
|
|
42
|
+
rate = 1 / 3200;
|
|
43
|
+
if (fromToken.toUpperCase() === 'ETH' && toToken.toUpperCase() === 'LINK')
|
|
44
|
+
rate = 200;
|
|
45
|
+
if (fromToken.toUpperCase() === 'SOL' && toToken.toUpperCase() === 'USDC')
|
|
46
|
+
rate = 150;
|
|
47
|
+
// Add a slight random variance (±1%) to simulate live market slippage
|
|
48
|
+
const variance = 1 + (Math.random() * 0.02 - 0.01);
|
|
49
|
+
const finalRate = rate * variance;
|
|
50
|
+
const toAmount = amount * finalRate;
|
|
51
|
+
// Simulate transaction execution delay
|
|
52
|
+
await new Promise(resolve => setTimeout(resolve, 2500));
|
|
53
|
+
// Generate mock transaction hash
|
|
54
|
+
const txHash = '0x' + Array.from({ length: 64 }, () => Math.floor(Math.random() * 16).toString(16)).join('');
|
|
55
|
+
const swapResult = {
|
|
56
|
+
chain: chainName,
|
|
57
|
+
fromToken: fromToken.toUpperCase(),
|
|
58
|
+
toToken: toToken.toUpperCase(),
|
|
59
|
+
fromAmount: amount.toFixed(4),
|
|
60
|
+
toAmount: toAmount.toFixed(4),
|
|
61
|
+
exchangeRate: finalRate.toFixed(6),
|
|
62
|
+
gasFee: (Math.random() * 0.005).toFixed(4) + ' ETH',
|
|
63
|
+
txHash: txHash,
|
|
64
|
+
status: 'SUCCESS'
|
|
65
|
+
};
|
|
66
|
+
return JSON.stringify(swapResult);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return JSON.stringify({ error: `Failed to execute swap: ${error.message}` });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transferToolDefinition = void 0;
|
|
4
|
+
exports.transferNative = transferNative;
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const config_1 = require("../config");
|
|
7
|
+
async function transferNative(chainName, toAddress, amountEth) {
|
|
8
|
+
try {
|
|
9
|
+
const client = (0, config_1.getWalletClient)(chainName);
|
|
10
|
+
// Attempt to send the transaction
|
|
11
|
+
const hash = await client.sendTransaction({
|
|
12
|
+
account: client.account,
|
|
13
|
+
chain: client.chain,
|
|
14
|
+
to: toAddress,
|
|
15
|
+
value: (0, viem_1.parseEther)(amountEth),
|
|
16
|
+
});
|
|
17
|
+
return `Successfully transferred ${amountEth} native token on ${chainName}. Transaction hash: ${hash}`;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return `Failed to transfer: ${error.message}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.transferToolDefinition = {
|
|
24
|
+
type: "function",
|
|
25
|
+
function: {
|
|
26
|
+
name: "transfer_native",
|
|
27
|
+
description: "Transfer native tokens (ETH, BNB, etc.) from the agent's wallet to a destination address.",
|
|
28
|
+
parameters: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
chainName: {
|
|
32
|
+
type: "string",
|
|
33
|
+
enum: ["ethereum", "base", "bsc", "arbitrum", "optimism", "sepolia"],
|
|
34
|
+
description: "The name of the blockchain to execute the transfer on."
|
|
35
|
+
},
|
|
36
|
+
toAddress: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "The destination 0x... wallet address."
|
|
39
|
+
},
|
|
40
|
+
amountEth: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "The amount of tokens to send in ETH units (e.g. '0.01')."
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
required: ["chainName", "toAddress", "amountEth"]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nyxora",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/gateway/cli.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"nyxora": "./dist/gateway/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "npm run build --prefix dashboard && tsc",
|
|
11
|
+
"start": "node dist/gateway/cli.js",
|
|
12
|
+
"dashboard": "npm run build && node dist/gateway/cli.js",
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"type": "commonjs",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"concurrently": "^9.2.1",
|
|
21
|
+
"cors": "^2.8.6",
|
|
22
|
+
"dotenv": "^17.4.2",
|
|
23
|
+
"express": "^5.2.1",
|
|
24
|
+
"node-telegram-bot-api": "^0.67.0",
|
|
25
|
+
"open": "^11.0.0",
|
|
26
|
+
"openai": "^6.39.0",
|
|
27
|
+
"viem": "^2.51.0",
|
|
28
|
+
"yaml": "^2.9.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/cors": "^2.8.19",
|
|
32
|
+
"@types/express": "^5.0.6",
|
|
33
|
+
"@types/node": "^25.9.1",
|
|
34
|
+
"@types/node-telegram-bot-api": "^0.64.14",
|
|
35
|
+
"ts-node": "^10.9.2",
|
|
36
|
+
"typescript": "^6.0.3"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasoning.d.ts","sourceRoot":"","sources":["reasoning.ts"],"names":[],"mappings":"AAkBA,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmFrE"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processUserInput = processUserInput;
|
|
4
|
+
const openai_1 = require("openai");
|
|
5
|
+
const parser_1 = require("../config/parser");
|
|
6
|
+
const logger_1 = require("../memory/logger");
|
|
7
|
+
const getBalance_1 = require("../web3/skills/getBalance");
|
|
8
|
+
const config = (0, parser_1.loadConfig)();
|
|
9
|
+
const logger = new logger_1.Logger();
|
|
10
|
+
// Initialize OpenAI client
|
|
11
|
+
const openai = new openai_1.OpenAI({
|
|
12
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
13
|
+
});
|
|
14
|
+
const systemPrompt = `You are an autonomous Web3 agent operating on EVM chains.
|
|
15
|
+
Your wallet address is available via the tools.
|
|
16
|
+
Always use the tools to interact with the blockchain.
|
|
17
|
+
If the user doesn't specify a chain, default to: ${config.agent.default_chain}.`;
|
|
18
|
+
async function processUserInput(input) {
|
|
19
|
+
// Add user input to memory
|
|
20
|
+
logger.addEntry({ role: 'user', content: input });
|
|
21
|
+
const history = logger.getHistory();
|
|
22
|
+
// Format messages for OpenAI
|
|
23
|
+
const messages = [
|
|
24
|
+
{ role: 'system', content: systemPrompt },
|
|
25
|
+
...history.map(m => {
|
|
26
|
+
const msg = { role: m.role, content: m.content || "" };
|
|
27
|
+
if (m.name)
|
|
28
|
+
msg.name = m.name;
|
|
29
|
+
if (m.tool_call_id)
|
|
30
|
+
msg.tool_call_id = m.tool_call_id;
|
|
31
|
+
if (m.tool_calls)
|
|
32
|
+
msg.tool_calls = m.tool_calls;
|
|
33
|
+
return msg;
|
|
34
|
+
})
|
|
35
|
+
];
|
|
36
|
+
try {
|
|
37
|
+
if (config.llm.provider !== 'openai') {
|
|
38
|
+
return `Provider ${config.llm.provider} is configured, but currently only OpenAI adapter is fully implemented in this demo.`;
|
|
39
|
+
}
|
|
40
|
+
const response = await openai.chat.completions.create({
|
|
41
|
+
model: config.llm.model,
|
|
42
|
+
temperature: config.llm.temperature,
|
|
43
|
+
messages: messages,
|
|
44
|
+
tools: [getBalance_1.getBalanceToolDefinition],
|
|
45
|
+
tool_choice: "auto",
|
|
46
|
+
});
|
|
47
|
+
const responseMessage = response.choices[0].message;
|
|
48
|
+
// Log assistant response
|
|
49
|
+
logger.addEntry({
|
|
50
|
+
role: 'assistant',
|
|
51
|
+
content: responseMessage.content || "",
|
|
52
|
+
tool_calls: responseMessage.tool_calls,
|
|
53
|
+
});
|
|
54
|
+
// Check if the model wants to call a tool
|
|
55
|
+
if (responseMessage.tool_calls && responseMessage.tool_calls.length > 0) {
|
|
56
|
+
for (const toolCall of responseMessage.tool_calls) {
|
|
57
|
+
if (toolCall.function.name === 'get_balance') {
|
|
58
|
+
const args = JSON.parse(toolCall.function.arguments);
|
|
59
|
+
const balanceResult = await (0, getBalance_1.getBalance)(args.chainName, args.address);
|
|
60
|
+
logger.addEntry({
|
|
61
|
+
role: 'tool',
|
|
62
|
+
tool_call_id: toolCall.id,
|
|
63
|
+
name: toolCall.function.name,
|
|
64
|
+
content: balanceResult,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Second call to get the final answer after tool execution
|
|
69
|
+
const secondMessages = [
|
|
70
|
+
{ role: 'system', content: systemPrompt },
|
|
71
|
+
...logger.getHistory().map(m => {
|
|
72
|
+
const msg = { role: m.role, content: m.content || "" };
|
|
73
|
+
if (m.name)
|
|
74
|
+
msg.name = m.name;
|
|
75
|
+
if (m.tool_call_id)
|
|
76
|
+
msg.tool_call_id = m.tool_call_id;
|
|
77
|
+
if (m.tool_calls)
|
|
78
|
+
msg.tool_calls = m.tool_calls;
|
|
79
|
+
return msg;
|
|
80
|
+
})
|
|
81
|
+
];
|
|
82
|
+
const secondResponse = await openai.chat.completions.create({
|
|
83
|
+
model: config.llm.model,
|
|
84
|
+
messages: secondMessages,
|
|
85
|
+
});
|
|
86
|
+
const finalContent = secondResponse.choices[0].message.content || "";
|
|
87
|
+
logger.addEntry({ role: 'assistant', content: finalContent });
|
|
88
|
+
return finalContent;
|
|
89
|
+
}
|
|
90
|
+
return responseMessage.content || "No response generated.";
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error("LLM Error:", error);
|
|
94
|
+
return `Error connecting to AI Provider: ${error.message}`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=reasoning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasoning.js","sourceRoot":"","sources":["reasoning.ts"],"names":[],"mappings":";;AAkBA,4CAmFC;AArGD,mCAAgC;AAChC,6CAA8C;AAC9C,6CAA0C;AAC1C,0DAAiF;AAEjF,MA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