nyxora 26.7.2 → 26.7.3
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/CHANGELOG.md +95 -47
- package/README.md +23 -19
- package/bin/nyxora.mjs +4 -6
- package/dist/launcher.js +44 -8
- package/dist/packages/core/src/agent/bridgeWatcher.js +3 -2
- package/dist/packages/core/src/agent/cronManager.js +2 -2
- package/dist/packages/core/src/agent/llmProvider.js +242 -0
- package/dist/packages/core/src/agent/nyxDaemon.js +97 -0
- package/dist/packages/core/src/agent/osAgent.js +203 -29
- package/dist/packages/core/src/agent/reasoning.js +353 -60
- package/dist/packages/core/src/agent/reasoningScratchpad.js +47 -0
- package/dist/packages/core/src/agent/transactionManager.js +36 -31
- package/dist/packages/core/src/agent/web3Agent.js +263 -37
- package/dist/packages/core/src/cognitive/cognitiveManager.js +63 -10
- package/dist/packages/core/src/config/parser.js +10 -4
- package/dist/packages/core/src/gateway/chat.js +56 -13
- package/dist/packages/core/src/gateway/cli.js +3 -0
- package/dist/packages/core/src/gateway/discordAdapter.js +81 -0
- package/dist/packages/core/src/gateway/server.js +58 -9
- package/dist/packages/core/src/gateway/setup-ml.js +64 -0
- package/dist/packages/core/src/gateway/setup.js +39 -3
- package/dist/packages/core/src/gateway/telegram.js +120 -24
- package/dist/packages/core/src/memory/episodic.js +47 -3
- package/dist/packages/core/src/memory/logger.js +120 -2
- package/dist/packages/core/src/memory/promotionEngine.js +18 -5
- package/dist/packages/core/src/system/agentskills.js +10 -0
- package/dist/packages/core/src/system/plugins/GoogleWorkspacePlugin.js +1 -1
- package/dist/packages/core/src/system/plugins/SystemCorePlugin.js +1 -1
- package/dist/packages/core/src/system/plugins/SystemExternalPlugin.js +1 -1
- package/dist/packages/core/src/system/plugins/SystemPluginInstallerPlugin.js +1 -1
- package/dist/packages/core/src/system/plugins/SystemSocialPlugin.js +1 -1
- package/dist/packages/core/src/system/plugins/SystemWebPlugin.js +1 -1
- package/dist/packages/core/src/system/plugins/SystemWorkspacePlugin.js +3 -3
- package/dist/packages/core/src/system/plugins/createSkill.js +1 -1
- package/dist/packages/core/src/system/skillExtractor.js +16 -5
- package/dist/packages/core/src/system/skills/forgetMemory.js +6 -4
- package/dist/packages/core/src/system/skills/scheduleTask.js +7 -2
- package/dist/packages/core/src/test_mainnet.js +45 -0
- package/dist/packages/core/src/utils/contextSummarizer.js +82 -0
- package/dist/packages/core/src/utils/skillManager.js +1 -1
- package/dist/packages/core/src/utils/streamSimulator.js +85 -0
- package/dist/packages/core/src/web3/aggregator/providers/ArbitrumBridgeProvider.js +28 -11
- package/dist/packages/core/src/web3/aggregator/providers/OpBridgeProvider.js +41 -27
- package/dist/packages/core/src/web3/aggregator/providers/TestnetSwapProvider.js +65 -0
- package/dist/packages/core/src/web3/aggregator/routeSelector.js +7 -1
- package/dist/packages/core/src/web3/plugins/Web3DefiPlugin.js +1 -1
- package/dist/packages/core/src/web3/plugins/Web3MarketPlugin.js +5 -125
- package/dist/packages/core/src/web3/plugins/Web3SecurityPlugin.js +1 -1
- package/dist/packages/core/src/web3/plugins/Web3WalletPlugin.js +1 -1
- package/dist/packages/core/src/web3/skills/bridgeToken.js +19 -4
- package/dist/packages/core/src/web3/skills/checkAddress.js +2 -0
- package/dist/packages/core/src/web3/skills/checkPortfolio.js +22 -2
- package/dist/packages/core/src/web3/skills/checkSecurity.js +2 -0
- package/dist/packages/core/src/web3/skills/confirmPendingTx.js +1 -1
- package/dist/packages/core/src/web3/skills/createLimitOrder.js +15 -1
- package/dist/packages/core/src/web3/skills/customTx.js +3 -0
- package/dist/packages/core/src/web3/skills/defiLending.js +2 -0
- package/dist/packages/core/src/web3/skills/getBalance.js +2 -0
- package/dist/packages/core/src/web3/skills/getPrice.js +134 -27
- package/dist/packages/core/src/web3/skills/getTxHistory.js +2 -0
- package/dist/packages/core/src/web3/skills/marketAnalysis.js +28 -191
- package/dist/packages/core/src/web3/skills/mintNft.js +3 -0
- package/dist/packages/core/src/web3/skills/provideLiquidity.js +16 -12
- package/dist/packages/core/src/web3/skills/revokeApprovals.js +2 -0
- package/dist/packages/core/src/web3/skills/swapToken.js +20 -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/chains.js +19 -0
- package/dist/packages/core/src/web3/utils/marketEngine.js +26 -33
- package/dist/packages/signer/src/NyxoraSigner.js +181 -0
- package/dist/packages/signer/src/index.js +17 -0
- package/dist/packages/signer/src/server.js +25 -161
- package/launcher.ts +38 -9
- package/package.json +6 -2
- package/packages/core/package.json +21 -10
- package/packages/core/src/agent/bridgeWatcher.ts +3 -2
- package/packages/core/src/agent/cronManager.ts +2 -2
- package/packages/core/src/agent/llmProvider.ts +219 -0
- package/packages/core/src/agent/nyxDaemon.ts +104 -0
- package/packages/core/src/agent/osAgent.ts +230 -32
- package/packages/core/src/agent/reasoning.ts +376 -64
- package/packages/core/src/agent/reasoningScratchpad.ts +45 -0
- package/packages/core/src/agent/transactionManager.ts +36 -28
- package/packages/core/src/agent/web3Agent.ts +291 -40
- package/packages/core/src/cognitive/cognitiveManager.ts +65 -10
- package/packages/core/src/cognitive/prompts/web3/market-analysis.md +24 -0
- package/packages/core/src/cognitive/prompts/web3/portfolio-review.md +29 -0
- package/packages/core/src/cognitive/prompts/web3/risk-assessment.md +28 -0
- package/packages/core/src/cognitive/prompts/web3/trade-planning.md +30 -0
- package/packages/core/src/config/parser.ts +15 -4
- package/packages/core/src/gateway/chat.ts +57 -15
- package/packages/core/src/gateway/cli.ts +4 -0
- package/packages/core/src/gateway/discordAdapter.ts +87 -0
- package/packages/core/src/gateway/server.ts +66 -10
- package/packages/core/src/gateway/setup-ml.ts +68 -0
- package/packages/core/src/gateway/setup.ts +41 -3
- package/packages/core/src/gateway/telegram.ts +138 -27
- package/packages/core/src/memory/episodic.ts +64 -3
- package/packages/core/src/memory/logger.ts +142 -2
- package/packages/core/src/memory/promotionEngine.ts +19 -5
- package/packages/core/src/system/agentskills.ts +10 -0
- package/packages/core/src/system/plugins/GoogleWorkspacePlugin.ts +1 -1
- package/packages/core/src/system/plugins/SystemCorePlugin.ts +1 -1
- package/packages/core/src/system/plugins/SystemExternalPlugin.ts +1 -1
- package/packages/core/src/system/plugins/SystemPluginInstallerPlugin.ts +1 -1
- package/packages/core/src/system/plugins/SystemSocialPlugin.ts +1 -1
- package/packages/core/src/system/plugins/SystemWebPlugin.ts +1 -1
- package/packages/core/src/system/plugins/SystemWorkspacePlugin.ts +3 -3
- package/packages/core/src/system/plugins/createSkill.ts +1 -1
- package/packages/core/src/system/skillExtractor.ts +16 -5
- package/packages/core/src/system/skills/forgetMemory.ts +7 -4
- package/packages/core/src/system/skills/scheduleTask.ts +7 -2
- package/packages/core/src/utils/contextSummarizer.ts +100 -0
- package/packages/core/src/utils/skillManager.ts +1 -1
- package/packages/core/src/utils/streamSimulator.ts +88 -0
- package/packages/core/src/web3/aggregator/providers/ArbitrumBridgeProvider.ts +30 -11
- package/packages/core/src/web3/aggregator/providers/OpBridgeProvider.ts +43 -29
- package/packages/core/src/web3/aggregator/routeSelector.ts +6 -1
- package/packages/core/src/web3/plugins/Web3DefiPlugin.ts +1 -1
- package/packages/core/src/web3/plugins/Web3MarketPlugin.ts +6 -125
- package/packages/core/src/web3/plugins/Web3SecurityPlugin.ts +1 -1
- package/packages/core/src/web3/plugins/Web3WalletPlugin.ts +1 -1
- package/packages/core/src/web3/skills/bridgeToken.ts +21 -7
- package/packages/core/src/web3/skills/checkAddress.ts +2 -0
- package/packages/core/src/web3/skills/checkPortfolio.ts +23 -2
- package/packages/core/src/web3/skills/checkSecurity.ts +2 -0
- package/packages/core/src/web3/skills/confirmPendingTx.ts +1 -1
- package/packages/core/src/web3/skills/createLimitOrder.ts +17 -2
- package/packages/core/src/web3/skills/customTx.ts +3 -0
- package/packages/core/src/web3/skills/defiLending.ts +2 -0
- package/packages/core/src/web3/skills/getBalance.ts +2 -0
- package/packages/core/src/web3/skills/getPrice.ts +134 -30
- package/packages/core/src/web3/skills/getTxHistory.ts +2 -0
- package/packages/core/src/web3/skills/marketAnalysis.ts +45 -188
- package/packages/core/src/web3/skills/mintNft.ts +3 -0
- package/packages/core/src/web3/skills/provideLiquidity.ts +16 -10
- package/packages/core/src/web3/skills/revokeApprovals.ts +2 -0
- package/packages/core/src/web3/skills/swapToken.ts +20 -3
- package/packages/core/src/web3/skills/transfer.ts +2 -0
- package/packages/core/src/web3/skills/yieldVault.ts +2 -0
- package/packages/core/src/web3/utils/chains.ts +12 -0
- package/packages/core/src/web3/utils/marketEngine.ts +27 -33
- package/packages/dashboard/dist/assets/index-BTfp141V.js +18 -0
- package/packages/dashboard/dist/assets/index-DK2sTU47.css +1 -0
- package/packages/dashboard/dist/index.html +2 -2
- package/packages/dashboard/package.json +10 -10
- package/packages/mcp-server/dist/server.js +5 -1
- package/packages/mcp-server/package.json +6 -6
- package/packages/mcp-server/src/server.ts +11 -7
- package/packages/policy/package.json +3 -3
- package/packages/signer/package.json +16 -6
- package/packages/signer/src/NyxoraSigner.ts +161 -0
- package/packages/signer/src/index.ts +1 -0
- package/packages/signer/src/server.ts +25 -135
- package/dist/packages/core/src/agent/honchoDaemon.js +0 -91
- package/dist/packages/core/src/cognitive/prompts/autonomous/binance-trading-integration.md +0 -54
- package/dist/packages/core/src/gateway/test.js +0 -15
- package/dist/packages/core/src/web3/Web3DefiPlugin.js +0 -28
- package/dist/packages/core/src/web3/aggregator/aggregatorMainnet.js +0 -260
- package/dist/packages/core/src/web3/aggregator/aggregatorTestnet.js +0 -119
- package/dist/packages/core/src/web3/skills/nativeOpBridge.js +0 -71
- package/packages/core/src/agent/honchoDaemon.ts +0 -96
- package/packages/core/src/cognitive/prompts/autonomous/binance-trading-integration.md +0 -41
- package/packages/core/src/plugin/registry.test.ts +0 -46
- package/packages/core/src/utils/formatter.test.ts +0 -41
- package/packages/dashboard/dist/assets/index-CSoNa5cx.css +0 -1
- package/packages/dashboard/dist/assets/index-DbRWEoSr.js +0 -16
|
@@ -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.
|
|
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.
|
|
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 =
|
|
48
|
-
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
|
-
|
|
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
|
-
|
|
160
|
-
|
|
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:
|
|
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) {
|
|
@@ -4,50 +4,157 @@ exports.getPriceToolDefinition = void 0;
|
|
|
4
4
|
exports.getPrice = getPrice;
|
|
5
5
|
const httpClient_1 = require("../../utils/httpClient");
|
|
6
6
|
const marketConfigManager_1 = require("../../config/marketConfigManager");
|
|
7
|
+
const parser_1 = require("../../config/parser");
|
|
7
8
|
exports.getPriceToolDefinition = {
|
|
8
9
|
type: "function",
|
|
9
10
|
function: {
|
|
10
|
-
name: "
|
|
11
|
-
description: "Fetches the current price of a cryptocurrency.",
|
|
11
|
+
name: "get_price_and_fiat_value",
|
|
12
|
+
description: "Fetches the current price of a cryptocurrency and performs perfect fiat/amount conversion.",
|
|
12
13
|
parameters: {
|
|
13
14
|
type: "object",
|
|
14
15
|
properties: {
|
|
15
16
|
coinId: {
|
|
16
17
|
type: "string",
|
|
17
|
-
description: "The CoinGecko ID of the coin (e.g., 'ethereum', 'bitcoin', '
|
|
18
|
+
description: "The CoinGecko ID of the coin, its symbol, or its exact Contract Address (e.g., 'ethereum', 'bitcoin', 'jrny', '0x123...'). For low-cap/DEX tokens, ALWAYS use the Contract Address if available."
|
|
18
19
|
},
|
|
19
20
|
currency: {
|
|
20
21
|
type: "string",
|
|
21
|
-
description: "The fiat currency to convert to (e.g., 'usd', 'idr', 'eur', 'jpy').
|
|
22
|
+
description: "The fiat currency to convert to (e.g., 'usd', 'idr', 'eur', 'jpy'). If omitted, it automatically defaults to the user's configured base fiat."
|
|
23
|
+
},
|
|
24
|
+
amount: {
|
|
25
|
+
type: "number",
|
|
26
|
+
description: "Optional. The number of tokens. If provided, the tool calculates the total fiat value exactly."
|
|
22
27
|
}
|
|
23
28
|
},
|
|
24
29
|
required: ["coinId"]
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
};
|
|
28
|
-
async function getPrice(coinId, currency
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
async function getPrice(coinId, currency, amount) {
|
|
34
|
+
const config = (0, parser_1.loadConfig)();
|
|
35
|
+
const defaultFiat = config.agent?.base_fiat || 'usd';
|
|
36
|
+
const cur = String(currency || defaultFiat).toLowerCase();
|
|
37
|
+
const curUpper = cur.toUpperCase();
|
|
38
|
+
const keys = (0, marketConfigManager_1.loadMarketKeys)();
|
|
39
|
+
// Helper to fetch USDT -> Target Fiat rate
|
|
40
|
+
async function getUsdtToFiatRate() {
|
|
41
|
+
if (cur === 'usd' || cur === 'usdt')
|
|
42
|
+
return 1;
|
|
43
|
+
// Tier 1 for Fiat: CoinGecko
|
|
44
|
+
try {
|
|
45
|
+
const isPro = !!keys.coingecko_key;
|
|
46
|
+
const baseUrl = isPro ? 'https://pro-api.coingecko.com/api/v3' : 'https://api.coingecko.com/api/v3';
|
|
47
|
+
const headers = isPro ? { 'x-cg-pro-api-key': keys.coingecko_key } : undefined;
|
|
48
|
+
const data = await (0, httpClient_1.safeFetchJson)(`${baseUrl}/simple/price?ids=tether&vs_currencies=${cur}`, { headers });
|
|
49
|
+
if (data && data.tether && data.tether[cur])
|
|
50
|
+
return data.tether[cur];
|
|
51
|
+
}
|
|
52
|
+
catch (e) { }
|
|
53
|
+
// Tier 2 for Fiat: CoinMarketCap
|
|
54
|
+
if (keys.cmc_key) {
|
|
55
|
+
try {
|
|
56
|
+
const data = await (0, httpClient_1.safeFetchJson)(`https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?slug=tether&convert=${curUpper}`, {
|
|
57
|
+
headers: { 'X-CMC_PRO_API_KEY': keys.cmc_key }
|
|
58
|
+
});
|
|
59
|
+
const coinList = Object.values(data?.data || {});
|
|
60
|
+
if (coinList[0] && coinList[0].quote[curUpper])
|
|
61
|
+
return coinList[0].quote[curUpper].price;
|
|
62
|
+
}
|
|
63
|
+
catch (e) { }
|
|
64
|
+
}
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
const fiatRate = await getUsdtToFiatRate();
|
|
68
|
+
if (fiatRate === 0 && cur !== 'usd') {
|
|
69
|
+
return `❌ **Failed to fetch fiat exchange rate** for **USDT -> ${curUpper}**.`;
|
|
70
|
+
}
|
|
71
|
+
let tokenUsdPrice = 0;
|
|
72
|
+
let change24h = 0;
|
|
73
|
+
let source = '';
|
|
74
|
+
let tokenName = coinId.toUpperCase();
|
|
75
|
+
// TIER 1: CoinMarketCap (Token -> USD)
|
|
76
|
+
if (keys.cmc_key && tokenUsdPrice === 0) {
|
|
77
|
+
try {
|
|
78
|
+
const url = `https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?slug=${coinId.toLowerCase()}&convert=USD`;
|
|
79
|
+
const data = await (0, httpClient_1.safeFetchJson)(url, { headers: { 'X-CMC_PRO_API_KEY': keys.cmc_key } });
|
|
80
|
+
const coin = Object.values(data?.data || {})[0];
|
|
81
|
+
if (coin && coin.quote && coin.quote.USD) {
|
|
82
|
+
tokenUsdPrice = coin.quote.USD.price;
|
|
83
|
+
change24h = coin.quote.USD.percent_change_24h;
|
|
84
|
+
tokenName = coin.symbol;
|
|
85
|
+
source = 'CoinMarketCap Pro';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) { }
|
|
89
|
+
}
|
|
90
|
+
// TIER 2: CoinGecko (Token -> USD)
|
|
91
|
+
if (tokenUsdPrice === 0) {
|
|
92
|
+
try {
|
|
93
|
+
const isPro = !!keys.coingecko_key;
|
|
94
|
+
const baseUrl = isPro ? 'https://pro-api.coingecko.com/api/v3' : 'https://api.coingecko.com/api/v3';
|
|
95
|
+
const headers = isPro ? { 'x-cg-pro-api-key': keys.coingecko_key } : undefined;
|
|
96
|
+
const url = `${baseUrl}/simple/price?ids=${coinId}&vs_currencies=usd&include_24hr_change=true`;
|
|
97
|
+
const data = await (0, httpClient_1.safeFetchJson)(url, { headers });
|
|
98
|
+
if (data && data[coinId]) {
|
|
99
|
+
tokenUsdPrice = data[coinId].usd;
|
|
100
|
+
change24h = data[coinId].usd_24h_change || 0;
|
|
101
|
+
source = `CoinGecko ${isPro ? 'Pro' : 'Public'}`;
|
|
102
|
+
}
|
|
39
103
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
104
|
+
catch (e) { }
|
|
105
|
+
}
|
|
106
|
+
// TIER 3: Nyxora Python ML Engine (For obscure/low-cap DEX tokens)
|
|
107
|
+
if (tokenUsdPrice === 0) {
|
|
108
|
+
try {
|
|
109
|
+
const mlData = await (0, httpClient_1.safeFetchJson)(`http://localhost:8000/web3/analyze?query=${coinId}&chain=ethereum`);
|
|
110
|
+
if (mlData && mlData.currentPrice) {
|
|
111
|
+
tokenUsdPrice = mlData.currentPrice;
|
|
112
|
+
change24h = mlData.priceChange24h || 0;
|
|
113
|
+
tokenName = mlData.officialSymbol || coinId.toUpperCase();
|
|
114
|
+
source = 'ML Engine (On-Chain/DEX Routing)';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (e) { }
|
|
118
|
+
}
|
|
119
|
+
// TIER 4: DexScreener (Direct CA or Symbol Search)
|
|
120
|
+
if (tokenUsdPrice === 0) {
|
|
121
|
+
try {
|
|
122
|
+
const data = await (0, httpClient_1.safeFetchJson)(`https://api.dexscreener.com/latest/dex/search?q=${coinId}`);
|
|
123
|
+
if (data.pairs && data.pairs.length > 0) {
|
|
124
|
+
const pair = data.pairs[0];
|
|
125
|
+
tokenUsdPrice = Number(pair.priceUsd);
|
|
126
|
+
change24h = pair.priceChange?.h24 || 0;
|
|
127
|
+
tokenName = pair.baseToken.symbol;
|
|
128
|
+
source = 'DexScreener';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (e) { }
|
|
132
|
+
}
|
|
133
|
+
if (tokenUsdPrice === 0) {
|
|
134
|
+
return `❌ **Failed to fetch price:** Could not find price data for **${coinId.toUpperCase()}** on CMC, CoinGecko, or DexScreener.`;
|
|
135
|
+
}
|
|
136
|
+
// Final Math: Amount * Token(USD) * USDT(Fiat Rate)
|
|
137
|
+
const finalPricePerUnit = tokenUsdPrice * fiatRate;
|
|
138
|
+
const isPositive = change24h >= 0;
|
|
139
|
+
const arrow = isPositive ? '📈 🟩 +' : '📉 🟥 ';
|
|
140
|
+
const formatter = new Intl.NumberFormat(cur === 'idr' ? 'id-ID' : 'en-US', { style: 'currency', currency: curUpper });
|
|
141
|
+
const priceFormatted = formatter.format(finalPricePerUnit);
|
|
142
|
+
const changeFormatted = change24h ? change24h.toFixed(2) : '0.00';
|
|
143
|
+
let report = `💰 **Price Update for ${tokenName}**\n\n`;
|
|
144
|
+
if (amount !== undefined && amount !== null) {
|
|
145
|
+
const totalVal = amount * finalPricePerUnit;
|
|
146
|
+
const totalFormatted = formatter.format(totalVal);
|
|
147
|
+
report += `- **Amount**: ${amount} ${tokenName}\n`;
|
|
148
|
+
report += `- **Price per Unit (${curUpper})**: \`${priceFormatted}\`\n`;
|
|
149
|
+
report += `- **Total Value**: \`${totalFormatted}\`\n`;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
report += `- **Price (${curUpper})**: \`${priceFormatted}\`\n`;
|
|
153
|
+
}
|
|
154
|
+
report += `- **24h Change**: ${arrow}${changeFormatted}%\n`;
|
|
155
|
+
if (cur !== 'usd' && cur !== 'usdt') {
|
|
156
|
+
report += `- **USDT Rate**: \`${formatter.format(fiatRate)}\` / USDT\n`;
|
|
52
157
|
}
|
|
158
|
+
report += `_Source: ${source} (Token) | Live Fiat Oracle (USDT Rate)_`;
|
|
159
|
+
return report;
|
|
53
160
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTxHistoryToolDefinition = void 0;
|
|
4
4
|
exports.getTxHistory = getTxHistory;
|
|
5
|
+
const chains_1 = require("../utils/chains");
|
|
5
6
|
const parser_1 = require("../../config/parser");
|
|
6
7
|
const config_1 = require("../config");
|
|
7
8
|
const viem_1 = require("viem");
|
|
@@ -20,6 +21,7 @@ const CHAIN_IDS = {
|
|
|
20
21
|
};
|
|
21
22
|
async function getTxHistory(chainName, address, days = 30) {
|
|
22
23
|
try {
|
|
24
|
+
chainName = (0, chains_1.normalizeChainName)(chainName);
|
|
23
25
|
const targetAddress = address || await (0, config_1.getAddress)();
|
|
24
26
|
const chainId = CHAIN_IDS[chainName];
|
|
25
27
|
if (!chainId) {
|