Skip to content

Commit f058c0a

Browse files
committed
refactor: update .gitignore, clean up imports, and enhance error handling in Rabbi Trader plugin
1 parent 8f4738e commit f058c0a

File tree

12 files changed

+1806
-1722
lines changed

12 files changed

+1806
-1722
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,7 @@ eliza.manifest.sgx
6363
eliza.sig
6464
.cursorrules
6565
notes/
66-
scripts/twitter-scraper/*
66+
scripts/twitter-scraper/*
67+
68+
.specstory
69+
core*

agent/src/index.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ import { binancePlugin } from "@elizaos/plugin-binance";
5555
// tradePlugin,
5656
// webhookPlugin,
5757
// } from "@elizaos/plugin-coinbase";
58-
import { coingeckoPlugin } from "@elizaos/plugin-coingecko";
59-
import { coinmarketcapPlugin } from "@elizaos/plugin-coinmarketcap";
58+
// import { coingeckoPlugin } from "@elizaos/plugin-coingecko";
59+
// import { coinmarketcapPlugin } from "@elizaos/plugin-coinmarketcap";
6060
// import { confluxPlugin } from "@elizaos/plugin-conflux";
6161
// import { createCosmosPlugin } from "@elizaos/plugin-cosmos";
6262
// import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
@@ -84,26 +84,26 @@ import { teeMarlinPlugin } from "@elizaos/plugin-tee-marlin";
8484
import { webSearchPlugin } from "@elizaos/plugin-web-search";
8585

8686
import { giphyPlugin } from "@elizaos/plugin-giphy";
87-
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
88-
import { letzAIPlugin } from "@elizaos/plugin-letzai";
87+
// import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
88+
// import { letzAIPlugin } from "@elizaos/plugin-letzai";
8989
import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";
9090
// import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
9191

9292
// import { akashPlugin } from "@elizaos/plugin-akash";
9393
import { OpacityAdapter } from "@elizaos/plugin-opacity";
9494
import { openWeatherPlugin } from "@elizaos/plugin-open-weather";
95-
import { quaiPlugin } from "@elizaos/plugin-quai";
95+
// import { quaiPlugin } from "@elizaos/plugin-quai";
9696
import createRabbiTraderPlugin from "@elizaos/plugin-rabbi-trader";
97-
import { stargazePlugin } from "@elizaos/plugin-stargaze";
97+
// import { stargazePlugin } from "@elizaos/plugin-stargaze";
9898
import Database from "better-sqlite3";
9999
import fs from "fs";
100100
import net from "net";
101101
import path from "path";
102102
import { fileURLToPath } from "url";
103103
import yargs from "yargs";
104104

105-
import { whaleDataEvaluator } from "./whaleDataEvaluator.js";
106-
import { whaleDataProvider } from "./whaleDataProvider.js";
105+
// import { whaleDataEvaluator } from "./whaleDataEvaluator.js";
106+
// import { whaleDataProvider } from "./whaleDataProvider.js";
107107

108108
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
109109
const __dirname = path.dirname(__filename); // get the name of the directory
@@ -753,7 +753,7 @@ export async function createAgent(
753753
databaseAdapter: db,
754754
token,
755755
modelProvider: character.modelProvider,
756-
evaluators: [whaleDataEvaluator],
756+
evaluators: [],
757757
character,
758758
// character.plugins are handled when clients are added
759759
plugins: [
@@ -796,9 +796,9 @@ export async function createAgent(
796796
? nftGenerationPlugin
797797
: null,
798798
// getSecret(character, "ZEROG_PRIVATE_KEY") ? zgPlugin : null,
799-
getSecret(character, "COINMARKETCAP_API_KEY")
800-
? coinmarketcapPlugin
801-
: null,
799+
// getSecret(character, "COINMARKETCAP_API_KEY")
800+
// ? coinmarketcapPlugin
801+
// : null,
802802
// getSecret(character, "COINBASE_COMMERCE_KEY")
803803
// ? coinbaseCommercePlugin
804804
// : null,
@@ -834,10 +834,10 @@ export async function createAgent(
834834
// : null,
835835
goatPlugin,
836836
rabbiPlugin,
837-
getSecret(character, "COINGECKO_API_KEY") ||
838-
getSecret(character, "COINGECKO_PRO_API_KEY")
839-
? coingeckoPlugin
840-
: null,
837+
// getSecret(character, "COINGECKO_API_KEY") ||
838+
// getSecret(character, "COINGECKO_PRO_API_KEY")
839+
// ? coingeckoPlugin
840+
// : null,
841841
getSecret(character, "EVM_PROVIDER_URL") ? goatPlugin : null,
842842
// getSecret(character, "ABSTRACT_PRIVATE_KEY")
843843
// ? abstractPlugin
@@ -873,8 +873,8 @@ export async function createAgent(
873873
getSecret(character, "ECHOCHAMBERS_API_KEY")
874874
? echoChambersPlugin
875875
: null,
876-
getSecret(character, "LETZAI_API_KEY") ? letzAIPlugin : null,
877-
getSecret(character, "STARGAZE_ENDPOINT") ? stargazePlugin : null,
876+
// getSecret(character, "LETZAI_API_KEY") ? letzAIPlugin : null,
877+
// getSecret(character, "STARGAZE_ENDPOINT") ? stargazePlugin : null,
878878
getSecret(character, "GIPHY_API_KEY") ? giphyPlugin : null,
879879
getSecret(character, "GENLAYER_PRIVATE_KEY")
880880
? genLayerPlugin
@@ -891,19 +891,19 @@ export async function createAgent(
891891
// ? artheraPlugin
892892
// : null,
893893
// getSecret(character, "ALLORA_API_KEY") ? alloraPlugin : null,
894-
getSecret(character, "HYPERLIQUID_PRIVATE_KEY")
895-
? hyperliquidPlugin
896-
: null,
897-
getSecret(character, "HYPERLIQUID_TESTNET")
898-
? hyperliquidPlugin
899-
: null,
894+
// getSecret(character, "HYPERLIQUID_PRIVATE_KEY")
895+
// ? hyperliquidPlugin
896+
// : null,
897+
// getSecret(character, "HYPERLIQUID_TESTNET")
898+
// ? hyperliquidPlugin
899+
// : null,
900900
// getSecret(character, "AKASH_MNEMONIC") &&
901901
// getSecret(character, "AKASH_WALLET_ADDRESS")
902902
// ? akashPlugin
903903
// : null,
904-
getSecret(character, "QUAI_PRIVATE_KEY") ? quaiPlugin : null,
904+
// getSecret(character, "QUAI_PRIVATE_KEY") ? quaiPlugin : null,
905905
].filter(Boolean),
906-
providers: [whaleDataProvider],
906+
providers: [],
907907
actions: [],
908908
services: [],
909909
managers: [],

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"build": "turbo run build --filter=!eliza-docs",
66
"build-docker": "turbo run build",
77
"cleanstart": "if [ -f agent/data/db.sqlite ]; then rm agent/data/db.sqlite; fi && pnpm --filter \"@elizaos/agent\" start --isRoot",
8-
"cleanstart:debug": "if [ -f agent/data/db.sqlite ]; then rm agent/data/db.sqlite; fi && cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@elizaos/agent\" start --isRoot --characters=\"vergen.character.json\"",
8+
"cleanstart:debug": "if [ -f agent/data/db.sqlite ]; then rm agent/data/db.sqlite; fi && cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@elizaos/agent\" start --isRoot --characters=\"vergen.json\"",
99
"start": "pnpm --filter \"@elizaos/agent\" start --isRoot",
10-
"start:vergen": "pnpm --filter \"@elizaos/agent\" start --isRoot --characters=\"vergen.character.json\"",
10+
"start:vergen": "pnpm --filter \"@elizaos/agent\" start --isRoot --characters=\"vergen.json\"",
1111
"start:client": "pnpm --dir client dev",
12-
"start:debug": "cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@elizaos/agent\" start --isRoot",
12+
"start:debug": "cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@elizaos/agent\" start --isRoot --characters=\"vergen.json\"",
1313
"dev": "bash ./scripts/dev.sh",
14-
"dev:vergen": "bash ./scripts/dev.sh --isRoot --characters=\"vergen.character.json\"",
14+
"dev:vergen": "bash ./scripts/dev.sh --isRoot --characters=\"vergen.json\"",
1515
"lint": "bash ./scripts/lint.sh",
1616
"prettier-check": "npx prettier --check --cache .",
1717
"prettier": "npx prettier --write --cache .",

packages/client-auto/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dependencies": {
2222
"@elizaos/core": "workspace:*",
2323
"@elizaos/plugin-rabbi-trader": "workspace:*",
24+
"@elizaos/plugin-solana": "workspace:*",
2425
"@types/body-parser": "1.19.5",
2526
"@types/cors": "2.8.17",
2627
"@types/express": "5.0.0",

packages/client-auto/src/index.ts

+100-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Client, IAgentRuntime, elizaLogger } from "@elizaos/core";
22
import createRabbiTraderPlugin from "@elizaos/plugin-rabbi-trader";
3+
import { solanaPlugin } from "@elizaos/plugin-solana";
34

45
export class AutoClient {
56
private interval: NodeJS.Timeout | null = null;
@@ -16,60 +17,127 @@ export class AutoClient {
1617
private async initialize() {
1718
try {
1819
elizaLogger.log("AutoClient initialization started");
19-
await this.initializePlugin();
20-
elizaLogger.log("AutoClient initialization completed");
21-
} catch (error) {
22-
elizaLogger.error("AutoClient initialization failed:", error);
23-
throw error;
24-
}
25-
}
2620

27-
private async initializePlugin() {
28-
try {
29-
elizaLogger.log(
30-
"Initializing Rabbi Trader plugin in AutoClient..."
31-
);
21+
// Initialize the Rabbi Trader plugin
22+
elizaLogger.log("Initializing Rabbi Trader plugin...");
3223

33-
this.plugin = await createRabbiTraderPlugin(
34-
(key: string) => this.runtime.getSetting(key),
35-
this.runtime
24+
// Validate required settings first
25+
const requiredSettings = [
26+
"WALLET_PUBLIC_KEY",
27+
"DEXSCREENER_WATCHLIST_ID",
28+
"COINGECKO_API_KEY",
29+
"SOLANA_RPC_URL",
30+
];
31+
32+
const missingSettings = requiredSettings.filter(
33+
(key) => !this.runtime.getSetting(key)
3634
);
35+
if (missingSettings.length > 0) {
36+
elizaLogger.warn(
37+
`Missing required settings: ${missingSettings.join(", ")}`
38+
);
39+
this.startBasicInterval();
40+
return;
41+
}
42+
43+
// Initialize Solana plugin first
44+
if (solanaPlugin) {
45+
elizaLogger.log("Initializing Solana plugin...");
46+
// Register the plugin with runtime instead of calling initialize
47+
this.runtime.plugins.push(solanaPlugin);
48+
}
3749

38-
elizaLogger.log("Plugin created, initializing...");
39-
await this.plugin.initialize(this.runtime);
50+
// Override getSetting to force enable trading and provide additional required settings
51+
const getSettingWithTrading = (key: string) => {
52+
if (key === "ENABLE_TRADING") return "true";
53+
if (key === "TWITTER_ENABLED") return "true";
54+
if (key === "TWITTER_USERNAME") return "VerticalDegen";
55+
const value = this.runtime.getSetting(key);
56+
if (!value) {
57+
elizaLogger.debug(`Setting ${key} not found: ${key}`);
58+
}
59+
return value;
60+
};
61+
62+
elizaLogger.log("Creating Rabbi Trader plugin...");
63+
try {
64+
this.plugin = await createRabbiTraderPlugin(
65+
getSettingWithTrading,
66+
this.runtime
67+
);
68+
if (!this.plugin) {
69+
throw new Error("Plugin creation returned undefined");
70+
}
71+
} catch (error) {
72+
elizaLogger.error("Error creating Rabbi Trader plugin:", {
73+
error,
74+
errorMessage:
75+
error instanceof Error ? error.message : String(error),
76+
stack: error instanceof Error ? error.stack : undefined,
77+
});
78+
this.startBasicInterval();
79+
return;
80+
}
4081

41-
elizaLogger.log("Plugin initialized, starting...");
42-
await this.plugin.start();
82+
// Initialize the plugin if it has an initialize method
83+
if (this.plugin.initialize) {
84+
await this.plugin.initialize(this.runtime);
85+
}
4386

44-
if (this.plugin.onStart) {
45-
elizaLogger.log("Triggering plugin onStart...");
46-
await this.plugin.onStart();
87+
// Start the plugin if it has a start method
88+
if (this.plugin.start) {
89+
await this.plugin.start();
4790
}
4891

92+
elizaLogger.log("Rabbi Trader plugin initialized successfully");
4993
elizaLogger.log(
50-
"Rabbi Trader plugin fully initialized and started in AutoClient"
94+
"Trading is enabled, monitoring will start automatically"
5195
);
96+
97+
elizaLogger.log("AutoClient initialization completed");
5298
} catch (error) {
53-
elizaLogger.error(
54-
"Failed to initialize Rabbi Trader plugin in AutoClient:",
55-
{
56-
error,
57-
phase: "initialization",
58-
pluginState: this.plugin ? "created" : "null",
59-
}
60-
);
61-
throw error;
99+
elizaLogger.error("AutoClient initialization failed:", {
100+
error,
101+
errorMessage:
102+
error instanceof Error ? error.message : String(error),
103+
stack: error instanceof Error ? error.stack : undefined,
104+
});
105+
// Start basic interval even if plugin fails
106+
this.startBasicInterval();
62107
}
63108
}
64109

110+
private startBasicInterval() {
111+
elizaLogger.log("Starting basic monitoring interval");
112+
// Clear any existing interval
113+
if (this.interval) {
114+
clearInterval(this.interval);
115+
}
116+
117+
// Start a loop that runs every hour
118+
this.interval = setInterval(
119+
async () => {
120+
elizaLogger.log("Running basic auto client check...");
121+
},
122+
60 * 60 * 1000 // 1 hour in milliseconds
123+
);
124+
}
125+
65126
public async stop() {
66127
elizaLogger.log("Stopping AutoClient...");
67128
try {
129+
// Clear the basic interval if it exists
68130
if (this.interval) {
69131
clearInterval(this.interval);
70132
this.interval = null;
71133
}
72134

135+
// Stop the plugin if it has a stop method
136+
if (this.plugin?.stop) {
137+
await this.plugin.stop();
138+
}
139+
140+
// Cleanup plugin if it exists and has a cleanup method
73141
if (this.plugin?.cleanup) {
74142
await this.plugin.cleanup();
75143
}

0 commit comments

Comments
 (0)