@ai.ntellect/core 0.3.1 → 0.3.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/dist/test.js CHANGED
@@ -1,373 +1,504 @@
1
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.getRssNews = exports.getChainsTVL = exports.fetchMarkPrice = exports.prepareEvmTransaction = exports.getNetworkProvider = exports.networkConfigs = exports.checkHoneypot = void 0;
7
- const ccxt_1 = __importDefault(require("ccxt"));
8
- const ethers_1 = require("ethers");
9
- const rss_parser_1 = __importDefault(require("rss-parser"));
10
- const zod_1 = require("zod");
11
- const agent_1 = require("./agent");
12
- const interpreter_1 = require("./llm/interpreter");
13
- const context_1 = require("./llm/interpreter/context");
14
- const orchestrator_1 = require("./llm/orchestrator");
15
- const cache_1 = require("./memory/cache");
16
- const persistent_1 = require("./memory/persistent");
17
- // Mapping des noms de chaînes vers leurs IDs
18
- const CHAIN_IDS = {
19
- ethereum: "1",
20
- bsc: "56",
21
- polygon: "137",
22
- matic: "137",
23
- avalanche: "43114",
24
- avax: "43114",
25
- fantom: "250",
26
- ftm: "250",
27
- arbitrum: "42161",
28
- arb: "42161",
29
- optimism: "10",
30
- base: "8453",
31
- zksync: "324",
32
- solana: "solana",
33
- sol: "solana",
34
- };
35
- exports.checkHoneypot = {
36
- name: "check-honeypot",
37
- description: `Analyze a token to detect if it is a honeypot. RESPECT THIS FORMAT FOR CHAIN NAME: ${CHAIN_IDS.toString()}`,
38
- parameters: zod_1.z.object({
39
- address: zod_1.z.string().describe("Address of the token"),
40
- chainName: zod_1.z.string().describe("Chain name (default: eth)"),
41
- }),
42
- execute: async ({ address, chainName, }) => {
43
- try {
44
- const API_URL = "https://api.honeypot.is/v2/IsHoneypot";
45
- const chainId = getChainId(chainName);
46
- console.log("💰 Checking honeypot for token", {
47
- address,
48
- chainId,
49
- });
50
- if (chainId === "solana") {
51
- return {
52
- status: "error",
53
- message: "L'analyse des tokens Solana n'est pas encore supportée. Cette fonctionnalité sera disponible prochainement.",
54
- chain: {
55
- name: "Solana",
56
- id: "solana",
57
- },
58
- };
59
- }
60
- const queryParams = new URLSearchParams({
61
- address: address,
62
- ...(chainId && { chainId }),
63
- ...{ simulateLiquidity: "true" },
64
- });
65
- const response = await fetch(`${API_URL}?${queryParams}`);
66
- if (!response.ok) {
67
- throw new Error(`Erreur API: ${response.status} ${response.statusText}`);
68
- }
69
- const data = await response.json();
70
- const result = {
71
- status: "success",
72
- token: {
73
- name: data.token.name,
74
- symbol: data.token.symbol,
75
- address: data.token.address,
76
- holders: data.token.totalHolders,
77
- },
78
- risk: {
79
- level: data.summary.risk,
80
- score: data.summary.riskLevel,
81
- flags: data.summary.flags || [],
82
- },
83
- analysis: {
84
- isHoneypot: data.honeypotResult?.isHoneypot || false,
85
- reason: data.honeypotResult?.honeypotReason || null,
86
- buyTax: data.simulationResult?.buyTax || 0,
87
- sellTax: data.simulationResult?.sellTax || 0,
88
- holders: {
89
- total: data.holderAnalysis?.holders || 0,
90
- successful: data.holderAnalysis?.successful || 0,
91
- failed: data.holderAnalysis?.failed || 0,
92
- siphoned: data.holderAnalysis?.siphoned || 0,
93
- },
94
- },
95
- chain: {
96
- name: data.chain.name,
97
- id: data.chain.id,
98
- },
99
- };
100
- return result;
101
- }
102
- catch (error) {
103
- throw error;
104
- }
105
- },
106
- };
107
- function getChainId(chainName) {
108
- if (!chainName)
109
- return undefined;
110
- const normalizedChainName = chainName.toLowerCase();
111
- return CHAIN_IDS[normalizedChainName];
112
- }
113
- exports.networkConfigs = {
114
- ethereum: {
115
- name: "Ethereum Mainnet",
116
- id: 1,
117
- rpc: "https://eth.llamarpc.com",
118
- explorerUrl: "https://etherscan.io",
119
- nativeToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
120
- },
121
- polygon: {
122
- name: "Polygon Mainnet",
123
- id: 137,
124
- rpc: "https://polygon.llamarpc.com",
125
- explorerUrl: "https://polygonscan.com",
126
- nativeToken: "0x0000000000000000000000000000000000001010",
127
- },
128
- arbitrum: {
129
- name: "Arbitrum Mainnet",
130
- id: 42161,
131
- rpc: "https://arbitrum.llamarpc.com",
132
- explorerUrl: "https://arbiscan.io",
133
- nativeToken: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
134
- },
135
- base: {
136
- name: "Base Mainnet",
137
- id: 8453,
138
- rpc: "https://base.llamarpc.com",
139
- explorerUrl: "https://basescan.org",
140
- nativeToken: "0x4200000000000000000000000000000000000006",
141
- },
142
- solana: {
143
- name: "Solana Mainnet",
144
- rpc: "https://api.mainnet-beta.solana.com",
145
- explorerUrl: "https://solscan.io",
146
- nativeToken: "So11111111111111111111111111111111111111112",
147
- },
148
- sepolia: {
149
- name: "Sepolia Testnet",
150
- id: 11155111,
151
- rpc: "https://sepolia.llamarpc.com",
152
- explorerUrl: "https://sepolia.etherscan.io",
153
- nativeToken: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
154
- },
155
- baseSepolia: {
156
- name: "Base Sepolia Testnet",
157
- id: 84532,
158
- rpc: "https://base-sepolia-rpc.publicnode.com",
159
- explorerUrl: "https://sepolia.basescan.org",
160
- nativeToken: "0x4200000000000000000000000000000000000006",
161
- },
162
- };
163
- const getNetworkProvider = (networkName) => {
164
- const config = exports.networkConfigs[networkName.toLowerCase()];
165
- if (!config) {
166
- throw new Error(`Network ${networkName} not supported`);
167
- }
168
- return { config };
169
- };
170
- exports.getNetworkProvider = getNetworkProvider;
171
- exports.prepareEvmTransaction = {
172
- name: "prepare-evm-transaction",
173
- description: "Prepare a transaction for the user to sign.",
174
- parameters: zod_1.z.object({
175
- walletAddress: zod_1.z.string(),
176
- amount: zod_1.z
177
- .string()
178
- .describe("Ask the user for the amount to send, if not specified"),
179
- network: zod_1.z
180
- .string()
181
- .describe("Examples networks: ethereum, arbitrum, base. IMPORTANT: You must respect the network name."),
182
- }),
183
- execute: async ({ walletAddress, amount, network, }) => {
184
- try {
185
- console.log("💰 Preparing transaction", {
186
- to: walletAddress,
187
- amount,
188
- network,
189
- });
190
- const networkConfig = exports.networkConfigs[network.toLowerCase()];
191
- if (!networkConfig) {
192
- throw new Error(`Network ${network} not found`);
193
- }
194
- return {
195
- to: walletAddress,
196
- value: (0, ethers_1.parseEther)(amount).toString(),
197
- chain: {
198
- id: networkConfig.id || 0,
199
- rpc: networkConfig.rpc,
200
- },
201
- type: "transfer",
202
- };
203
- }
204
- catch (error) {
205
- console.error("💰 Error sending transaction:", error);
206
- throw new Error("An error occurred while sending the transaction");
207
- }
208
- },
209
- };
210
- exports.fetchMarkPrice = {
211
- name: "fetch-mark-price",
212
- description: "Fetches mark price for the market",
213
- parameters: zod_1.z.object({
214
- symbol: zod_1.z
215
- .string()
216
- .describe("Unified symbol of the market to fetch the ticker for (default: BTC/USDT)"),
217
- params: zod_1.z.object({
218
- subType: zod_1.z
219
- .string()
220
- .describe("Type of funding rate: 'linear' or 'inverse'"),
221
- }),
222
- }),
223
- execute: async ({ symbol, params }) => {
224
- try {
225
- const binance = new ccxt_1.default.binance({});
226
- // Fetch mark price from the Binance API
227
- const markPrice = await binance.fetchMarkPrice(symbol, params);
228
- console.log("Mark price fetched:", markPrice);
229
- return markPrice;
230
- }
231
- catch (error) {
232
- console.error("Error fetching mark price:", error);
233
- throw error;
234
- }
235
- },
236
- };
237
- exports.getChainsTVL = {
238
- name: "get_chains_tvl",
239
- description: "Get current TVL (Total Value Locked) of all chains from DeFiLlama",
240
- parameters: zod_1.z.object({
241
- limit: zod_1.z
242
- .number()
243
- .optional()
244
- .default(10)
245
- .describe("Number of top chains to return (default: 10)"),
246
- }),
247
- execute: async ({ limit }) => {
248
- try {
249
- const response = await fetch("https://api.llama.fi/v2/chains", {
250
- headers: { accept: "*/*" },
251
- });
252
- if (!response.ok) {
253
- throw new Error(`HTTP error! status: ${response.status}`);
254
- }
255
- const chains = (await response.json());
256
- // Sort chains by TVL in descending order and take top N
257
- const topChains = chains
258
- .sort((a, b) => b.tvl - a.tvl)
259
- .slice(0, limit)
260
- .map((chain) => ({
261
- name: chain.name,
262
- tvl: chain.tvl,
263
- tokenSymbol: chain.tokenSymbol,
264
- }));
265
- const totalTVL = chains.reduce((sum, chain) => sum + chain.tvl, 0);
266
- return {
267
- summary: {
268
- totalTVL,
269
- numberOfChains: chains.length,
270
- },
271
- topChains,
272
- };
273
- }
274
- catch (error) {
275
- console.error("Error retrieving chains TVL data:", error);
276
- throw new Error(`Failed to fetch chains TVL data: ${error.message}`);
277
- }
278
- },
279
- };
280
- const RSS_FEEDS = [
281
- "https://www.investing.com/rss/news_301.rss",
282
- "https://cointelegraph.com/rss/category/analysis",
283
- "https://cointelegraph.com/rss/category/top-10-cryptocurrencies",
284
- ];
285
- const parser = new rss_parser_1.default();
286
- function stripHtmlTags(content) {
287
- if (!content)
288
- return "";
289
- return content
290
- .replace(/<[^>]*>/g, "")
291
- .replace(/\n/g, "")
292
- .replace(" ", "");
293
- }
294
- exports.getRssNews = {
295
- name: "get-news-rss",
296
- description: "Get latest news about on website",
297
- parameters: zod_1.z.object({}),
298
- execute: async () => {
299
- const itemsPerSource = 5;
300
- try {
301
- const feedPromises = RSS_FEEDS.map((url) => parser.parseURL(url));
302
- const results = await Promise.allSettled(feedPromises);
303
- const successfulFeeds = results
304
- .filter((result) => {
305
- return (result.status === "fulfilled" && result.value?.items?.length > 0);
306
- })
307
- .map((result) => result.value);
308
- const allItems = successfulFeeds
309
- .flatMap((feed) => feed.items.slice(0, itemsPerSource))
310
- .sort((a, b) => {
311
- const dateA = a.pubDate ? new Date(a.pubDate).getTime() : 0;
312
- const dateB = b.pubDate ? new Date(b.pubDate).getTime() : 0;
313
- return dateB - dateA;
314
- })
315
- .slice(0, 5)
316
- .map((item) => ({
317
- title: item.title,
318
- content: stripHtmlTags(item.content),
319
- link: item.link,
320
- date: item.pubDate,
321
- source: item.creator || new URL(item.link).hostname,
322
- }));
323
- const result = {
324
- status: "success",
325
- items: allItems,
326
- };
327
- return result;
328
- }
329
- catch (error) {
330
- throw error;
331
- }
332
- },
333
- };
334
- (async () => {
335
- const cacheMemory = new cache_1.CacheMemory();
336
- const memory = new persistent_1.PersistentMemory({
337
- host: "http://localhost:7700",
338
- apiKey: "aSampleMasterKey",
339
- });
340
- const orchestrator = new orchestrator_1.Orchestrator({
341
- id: "1",
342
- tools: [],
343
- memory: {
344
- persistent: memory,
345
- cache: cacheMemory,
346
- },
347
- });
348
- const securityInterpreter = new interpreter_1.Interpreter("security", context_1.securityInterpreterContext);
349
- const marketInterpreter = new interpreter_1.Interpreter("market", context_1.marketInterpreterContext);
350
- const generalInterpreter = new interpreter_1.Interpreter("general", context_1.generalInterpreterContext);
351
- // const ccacheMemory = await cacheMemory.findSimilarActions(
352
- // "le top 3 des chaines par TVL en DeFi",
353
- // {
354
- // similarityThreshold: 50,
355
- // maxResults: 5,
356
- // userId: "1",
357
- // scope: MemoryScope.GLOBAL,
358
- // }
359
- // );
360
- // console.log("✅ RECENT_ACTIONS: ", ccacheMemory);
361
- const agent = new agent_1.Agent({
362
- interpreters: [securityInterpreter, marketInterpreter, generalInterpreter],
363
- orchestrator,
364
- memory: {
365
- persistent: memory,
366
- cache: cacheMemory,
367
- },
368
- stream: false,
369
- maxEvaluatorIteration: 1,
370
- });
371
- const prompt = "c quoi le top 3 des chaines par TVL en DeFi";
372
- const result = await agent.process(prompt, {});
373
- })();
2
+ // import ccxt from "ccxt";
3
+ // import { parseEther } from "ethers";
4
+ // import Parser from "rss-parser";
5
+ // import { z } from "zod";
6
+ // import { Agent } from "./agent";
7
+ // import { Interpreter } from "./llm/interpreter";
8
+ // import {
9
+ // generalInterpreterContext,
10
+ // marketInterpreterContext,
11
+ // securityInterpreterContext,
12
+ // } from "./llm/interpreter/context";
13
+ // import { Orchestrator } from "./llm/orchestrator";
14
+ // import { CacheMemory } from "./memory/cache";
15
+ // import { PersistentMemory } from "./memory/persistent";
16
+ // import { ActionQueueManager } from "./services/queue";
17
+ // import { ActionScheduler } from "./services/scheduler";
18
+ // import { ScheduledAction } from "./types";
19
+ // interface HoneypotParams {
20
+ // address: string;
21
+ // chainName?: string;
22
+ // simulateLiquidity?: boolean;
23
+ // }
24
+ // // Mapping des noms de chaînes vers leurs IDs
25
+ // const CHAIN_IDS: { [key: string]: string } = {
26
+ // ethereum: "1",
27
+ // bsc: "56",
28
+ // polygon: "137",
29
+ // matic: "137",
30
+ // avalanche: "43114",
31
+ // avax: "43114",
32
+ // fantom: "250",
33
+ // ftm: "250",
34
+ // arbitrum: "42161",
35
+ // arb: "42161",
36
+ // optimism: "10",
37
+ // base: "8453",
38
+ // zksync: "324",
39
+ // solana: "solana",
40
+ // sol: "solana",
41
+ // };
42
+ // export const checkHoneypot = {
43
+ // name: "check-honeypot",
44
+ // description: `Analyze a token to detect if it is a honeypot. RESPECT THIS FORMAT FOR CHAIN NAME: ${CHAIN_IDS.toString()}`,
45
+ // parameters: z.object({
46
+ // address: z.string().describe("Address of the token"),
47
+ // chainName: z.string().describe("Chain name (default: eth)"),
48
+ // }),
49
+ // execute: async ({
50
+ // address,
51
+ // chainName,
52
+ // }: {
53
+ // address: string;
54
+ // chainName?: string;
55
+ // }) => {
56
+ // try {
57
+ // const API_URL = "https://api.honeypot.is/v2/IsHoneypot";
58
+ // const chainId = getChainId(chainName);
59
+ // console.log("💰 Checking honeypot for token", {
60
+ // address,
61
+ // chainId,
62
+ // });
63
+ // if (chainId === "solana") {
64
+ // return {
65
+ // status: "error",
66
+ // message:
67
+ // "L'analyse des tokens Solana n'est pas encore supportée. Cette fonctionnalité sera disponible prochainement.",
68
+ // chain: {
69
+ // name: "Solana",
70
+ // id: "solana",
71
+ // },
72
+ // };
73
+ // }
74
+ // const queryParams = new URLSearchParams({
75
+ // address: address,
76
+ // ...(chainId && { chainId }),
77
+ // ...{ simulateLiquidity: "true" },
78
+ // });
79
+ // const response = await fetch(`${API_URL}?${queryParams}`);
80
+ // if (!response.ok) {
81
+ // throw new Error(
82
+ // `Erreur API: ${response.status} ${response.statusText}`
83
+ // );
84
+ // }
85
+ // const data: any = await response.json();
86
+ // const result = {
87
+ // status: "success",
88
+ // token: {
89
+ // name: data.token.name,
90
+ // symbol: data.token.symbol,
91
+ // address: data.token.address,
92
+ // holders: data.token.totalHolders,
93
+ // },
94
+ // risk: {
95
+ // level: data.summary.risk,
96
+ // score: data.summary.riskLevel,
97
+ // flags: data.summary.flags || [],
98
+ // },
99
+ // analysis: {
100
+ // isHoneypot: data.honeypotResult?.isHoneypot || false,
101
+ // reason: data.honeypotResult?.honeypotReason || null,
102
+ // buyTax: data.simulationResult?.buyTax || 0,
103
+ // sellTax: data.simulationResult?.sellTax || 0,
104
+ // holders: {
105
+ // total: data.holderAnalysis?.holders || 0,
106
+ // successful: data.holderAnalysis?.successful || 0,
107
+ // failed: data.holderAnalysis?.failed || 0,
108
+ // siphoned: data.holderAnalysis?.siphoned || 0,
109
+ // },
110
+ // },
111
+ // chain: {
112
+ // name: data.chain.name,
113
+ // id: data.chain.id,
114
+ // },
115
+ // };
116
+ // return result;
117
+ // } catch (error: any) {
118
+ // throw error;
119
+ // }
120
+ // },
121
+ // };
122
+ // function getChainId(chainName?: string): string | undefined {
123
+ // if (!chainName) return undefined;
124
+ // const normalizedChainName = chainName.toLowerCase();
125
+ // return CHAIN_IDS[normalizedChainName];
126
+ // }
127
+ // export interface NetworkConfig {
128
+ // name: string;
129
+ // id?: number;
130
+ // rpc: string;
131
+ // explorerUrl: string;
132
+ // nativeToken: string; // WETH
133
+ // }
134
+ // export const networkConfigs: Record<string, NetworkConfig> = {
135
+ // ethereum: {
136
+ // name: "Ethereum Mainnet",
137
+ // id: 1,
138
+ // rpc: "https://eth.llamarpc.com",
139
+ // explorerUrl: "https://etherscan.io",
140
+ // nativeToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
141
+ // },
142
+ // polygon: {
143
+ // name: "Polygon Mainnet",
144
+ // id: 137,
145
+ // rpc: "https://polygon.llamarpc.com",
146
+ // explorerUrl: "https://polygonscan.com",
147
+ // nativeToken: "0x0000000000000000000000000000000000001010",
148
+ // },
149
+ // arbitrum: {
150
+ // name: "Arbitrum Mainnet",
151
+ // id: 42161,
152
+ // rpc: "https://arbitrum.llamarpc.com",
153
+ // explorerUrl: "https://arbiscan.io",
154
+ // nativeToken: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
155
+ // },
156
+ // base: {
157
+ // name: "Base Mainnet",
158
+ // id: 8453,
159
+ // rpc: "https://base.llamarpc.com",
160
+ // explorerUrl: "https://basescan.org",
161
+ // nativeToken: "0x4200000000000000000000000000000000000006",
162
+ // },
163
+ // solana: {
164
+ // name: "Solana Mainnet",
165
+ // rpc: "https://api.mainnet-beta.solana.com",
166
+ // explorerUrl: "https://solscan.io",
167
+ // nativeToken: "So11111111111111111111111111111111111111112",
168
+ // },
169
+ // sepolia: {
170
+ // name: "Sepolia Testnet",
171
+ // id: 11155111,
172
+ // rpc: "https://sepolia.llamarpc.com",
173
+ // explorerUrl: "https://sepolia.etherscan.io",
174
+ // nativeToken: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
175
+ // },
176
+ // baseSepolia: {
177
+ // name: "Base Sepolia Testnet",
178
+ // id: 84532,
179
+ // rpc: "https://base-sepolia-rpc.publicnode.com",
180
+ // explorerUrl: "https://sepolia.basescan.org",
181
+ // nativeToken: "0x4200000000000000000000000000000000000006",
182
+ // },
183
+ // };
184
+ // export const getNetworkProvider = (networkName: string) => {
185
+ // const config = networkConfigs[networkName.toLowerCase()];
186
+ // if (!config) {
187
+ // throw new Error(`Network ${networkName} not supported`);
188
+ // }
189
+ // return { config };
190
+ // };
191
+ // export type TransactionPrepared = {
192
+ // to: string;
193
+ // value: string;
194
+ // data?: string;
195
+ // chain: {
196
+ // id: number;
197
+ // rpc: string;
198
+ // };
199
+ // type: "transfer" | "approve" | "swap";
200
+ // method?: string;
201
+ // params?: any[];
202
+ // };
203
+ // export const prepareEvmTransaction = {
204
+ // name: "prepare-evm-transaction",
205
+ // description: "Prepare a transaction for the user to sign.",
206
+ // parameters: z.object({
207
+ // walletAddress: z.string(),
208
+ // amount: z
209
+ // .string()
210
+ // .describe("Ask the user for the amount to send, if not specified"),
211
+ // network: z
212
+ // .string()
213
+ // .describe(
214
+ // "Examples networks: ethereum, arbitrum, base. IMPORTANT: You must respect the network name."
215
+ // ),
216
+ // }),
217
+ // execute: async ({
218
+ // walletAddress,
219
+ // amount,
220
+ // network,
221
+ // }: {
222
+ // walletAddress: string;
223
+ // amount: string;
224
+ // network: string;
225
+ // }): Promise<TransactionPrepared> => {
226
+ // try {
227
+ // console.log("💰 Preparing transaction", {
228
+ // to: walletAddress,
229
+ // amount,
230
+ // network,
231
+ // });
232
+ // const networkConfig = networkConfigs[network.toLowerCase()];
233
+ // if (!networkConfig) {
234
+ // throw new Error(`Network ${network} not found`);
235
+ // }
236
+ // return {
237
+ // to: walletAddress,
238
+ // value: parseEther(amount).toString(),
239
+ // chain: {
240
+ // id: networkConfig.id || 0,
241
+ // rpc: networkConfig.rpc,
242
+ // },
243
+ // type: "transfer",
244
+ // };
245
+ // } catch (error) {
246
+ // console.error("💰 Error sending transaction:", error);
247
+ // throw new Error("An error occurred while sending the transaction");
248
+ // }
249
+ // },
250
+ // };
251
+ // export const fetchMarkPrice = {
252
+ // name: "fetch-mark-price",
253
+ // description: "Fetches mark price for the market",
254
+ // parameters: z.object({
255
+ // symbol: z
256
+ // .string()
257
+ // .describe(
258
+ // "Unified symbol of the market to fetch the ticker for (default: BTC/USDT)"
259
+ // ),
260
+ // params: z.object({
261
+ // subType: z
262
+ // .string()
263
+ // .describe("Type of funding rate: 'linear' or 'inverse'"),
264
+ // }),
265
+ // }),
266
+ // execute: async ({ symbol, params }: { symbol: string; params: any }) => {
267
+ // try {
268
+ // const binance = new ccxt.binance({});
269
+ // // Fetch mark price from the Binance API
270
+ // const markPrice = await binance.fetchMarkPrice(symbol, params);
271
+ // console.log("Mark price fetched:", markPrice);
272
+ // return markPrice;
273
+ // } catch (error: any) {
274
+ // console.error("Error fetching mark price:", error);
275
+ // throw error;
276
+ // }
277
+ // },
278
+ // };
279
+ // interface ChainTVL {
280
+ // name: string;
281
+ // tvl: number;
282
+ // tokenSymbol: string | null;
283
+ // chainId: number | string | null;
284
+ // gecko_id: string | null;
285
+ // cmcId: string | null;
286
+ // }
287
+ // export const getChainsTVL = {
288
+ // name: "get_chains_tvl",
289
+ // description:
290
+ // "Get current TVL (Total Value Locked) of all chains from DeFiLlama",
291
+ // parameters: z.object({
292
+ // limit: z
293
+ // .number()
294
+ // .optional()
295
+ // .default(10)
296
+ // .describe("Number of top chains to return (default: 10)"),
297
+ // }),
298
+ // execute: async ({ limit }: { limit: number }) => {
299
+ // try {
300
+ // const response = await fetch("https://api.llama.fi/v2/chains", {
301
+ // headers: { accept: "*/*" },
302
+ // });
303
+ // if (!response.ok) {
304
+ // throw new Error(`HTTP error! status: ${response.status}`);
305
+ // }
306
+ // const chains = (await response.json()) as ChainTVL[];
307
+ // // Sort chains by TVL in descending order and take top N
308
+ // const topChains = chains
309
+ // .sort((a, b) => b.tvl - a.tvl)
310
+ // .slice(0, limit)
311
+ // .map((chain) => ({
312
+ // name: chain.name,
313
+ // tvl: chain.tvl,
314
+ // tokenSymbol: chain.tokenSymbol,
315
+ // }));
316
+ // const totalTVL = chains.reduce((sum, chain) => sum + chain.tvl, 0);
317
+ // return {
318
+ // summary: {
319
+ // totalTVL,
320
+ // numberOfChains: chains.length,
321
+ // },
322
+ // topChains,
323
+ // };
324
+ // } catch (error) {
325
+ // console.error("Error retrieving chains TVL data:", error);
326
+ // throw new Error(
327
+ // `Failed to fetch chains TVL data: ${(error as Error).message}`
328
+ // );
329
+ // }
330
+ // },
331
+ // };
332
+ // const RSS_FEEDS = [
333
+ // "https://www.investing.com/rss/news_301.rss",
334
+ // "https://cointelegraph.com/rss/category/analysis",
335
+ // "https://cointelegraph.com/rss/category/top-10-cryptocurrencies",
336
+ // ];
337
+ // const parser = new Parser();
338
+ // function stripHtmlTags(content: string): string {
339
+ // if (!content) return "";
340
+ // return content
341
+ // .replace(/<[^>]*>/g, "")
342
+ // .replace(/\n/g, "")
343
+ // .replace(" ", "");
344
+ // }
345
+ // export const getRssNews = {
346
+ // name: "get-news-rss",
347
+ // description: "Get latest news about on website",
348
+ // parameters: z.object({}),
349
+ // execute: async () => {
350
+ // const itemsPerSource = 5;
351
+ // try {
352
+ // const feedPromises = RSS_FEEDS.map((url) => parser.parseURL(url));
353
+ // const results = await Promise.allSettled(feedPromises);
354
+ // const successfulFeeds = results
355
+ // .filter(
356
+ // (result): result is PromiseFulfilledResult<Parser.Output<any>> => {
357
+ // return (
358
+ // result.status === "fulfilled" && result.value?.items?.length > 0
359
+ // );
360
+ // }
361
+ // )
362
+ // .map((result) => result.value);
363
+ // const allItems = successfulFeeds
364
+ // .flatMap((feed) => feed.items.slice(0, itemsPerSource))
365
+ // .sort((a, b) => {
366
+ // const dateA = a.pubDate ? new Date(a.pubDate).getTime() : 0;
367
+ // const dateB = b.pubDate ? new Date(b.pubDate).getTime() : 0;
368
+ // return dateB - dateA;
369
+ // })
370
+ // .slice(0, 5)
371
+ // .map((item) => ({
372
+ // title: item.title,
373
+ // content: stripHtmlTags(item.content),
374
+ // link: item.link,
375
+ // date: item.pubDate,
376
+ // source: item.creator || new URL(item.link).hostname,
377
+ // }));
378
+ // const result = {
379
+ // status: "success",
380
+ // items: allItems,
381
+ // };
382
+ // return result;
383
+ // } catch (error: any) {
384
+ // throw error;
385
+ // }
386
+ // },
387
+ // };
388
+ // (async () => {
389
+ // const cacheMemory = new CacheMemory();
390
+ // const memory = new PersistentMemory({
391
+ // host: "http://localhost:7700",
392
+ // apiKey: "aSampleMasterKey",
393
+ // });
394
+ // const orchestrator = new Orchestrator({
395
+ // id: "1",
396
+ // tools: [
397
+ // prepareEvmTransaction,
398
+ // checkHoneypot,
399
+ // getChainsTVL,
400
+ // getRssNews,
401
+ // {
402
+ // name: "hello",
403
+ // description: "hello",
404
+ // parameters: z.object({
405
+ // name: z.string(),
406
+ // }),
407
+ // execute: async () => {
408
+ // console.log("hello");
409
+ // },
410
+ // },
411
+ // ],
412
+ // memory: {
413
+ // persistent: memory,
414
+ // cache: cacheMemory,
415
+ // },
416
+ // });
417
+ // const securityInterpreter = new Interpreter(
418
+ // "security",
419
+ // securityInterpreterContext
420
+ // );
421
+ // const marketInterpreter = new Interpreter("market", marketInterpreterContext);
422
+ // const generalInterpreter = new Interpreter(
423
+ // "general",
424
+ // generalInterpreterContext
425
+ // );
426
+ // // const ccacheMemory = await cacheMemory.findSimilarActions(
427
+ // // "le top 3 des chaines par TVL en DeFi",
428
+ // // {
429
+ // // similarityThreshold: 50,
430
+ // // maxResults: 5,
431
+ // // userId: "1",
432
+ // // scope: MemoryScope.GLOBAL,
433
+ // // }
434
+ // // );
435
+ // // console.log("✅ RECENT_ACTIONS: ", ccacheMemory);
436
+ // const agent = new Agent({
437
+ // interpreters: [securityInterpreter, marketInterpreter, generalInterpreter],
438
+ // orchestrator,
439
+ // memory: {
440
+ // persistent: memory,
441
+ // cache: cacheMemory,
442
+ // },
443
+ // stream: false,
444
+ // maxEvaluatorIteration: 1,
445
+ // });
446
+ // const prompt = "tu pourrais analyser le bnb/usdt";
447
+ // // const result = await agent.process(prompt, {});
448
+ // const scheduler = new ActionScheduler(
449
+ // new ActionQueueManager(orchestrator.tools),
450
+ // orchestrator,
451
+ // {
452
+ // onActionScheduled: (action: ScheduledAction) => {
453
+ // console.log("🗓️ Action programmée:", {
454
+ // id: action.id,
455
+ // name: action.action.name,
456
+ // scheduledTime: action.scheduledTime,
457
+ // });
458
+ // },
459
+ // onActionStart: (action: ScheduledAction) => {
460
+ // console.log("▶️ Action démarrée:", action.id);
461
+ // },
462
+ // onActionComplete: (action: ScheduledAction, result: any) => {
463
+ // console.log("✅ Action terminée:", {
464
+ // id: action.id,
465
+ // result,
466
+ // });
467
+ // },
468
+ // onActionFailed: (action: ScheduledAction, error: any) => {
469
+ // console.error("❌ Action échouée:", {
470
+ // id: action.id,
471
+ // error: error.message,
472
+ // });
473
+ // },
474
+ // onActionCancelled: (actionId: string) => {
475
+ // console.log("🚫 Action annulée:", actionId);
476
+ // },
477
+ // }
478
+ // );
479
+ // // Test du scheduler
480
+ // console.log("🕒 Testing scheduler...");
481
+ // const scheduledTime = new Date(Date.now() + 10000);
482
+ // const actionId = await scheduler.scheduleAction(
483
+ // {
484
+ // name: "hello",
485
+ // description: "hello",
486
+ // parameters: z.object({
487
+ // name: z.string(),
488
+ // }),
489
+ // execute: async () => {
490
+ // console.log("hello");
491
+ // return "Hello executed!";
492
+ // },
493
+ // },
494
+ // scheduledTime,
495
+ // "user123",
496
+ // {
497
+ // type: "daily",
498
+ // interval: 1,
499
+ // }
500
+ // );
501
+ // // Attendre 15 secondes
502
+ // await new Promise((resolve) => setTimeout(resolve, 15000));
503
+ // console.log("✅ Test terminé");
504
+ // })();