forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
90 lines (77 loc) · 3.19 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Client, IAgentRuntime } from "@ai16z/eliza/src/types.ts";
import { TrustScoreManager } from "@ai16z/plugin-solana/src/providers/trustScoreProvider.ts";
import { TokenProvider } from "@ai16z/plugin-solana/src/providers/token.ts";
import { WalletProvider } from "@ai16z/plugin-solana/src/providers/wallet.ts";
import { TrustScoreDatabase } from "@ai16z/plugin-solana/src/adapters/trustScoreDatabase.ts";
import { Connection, PublicKey } from "@solana/web3.js";
export class AutoClient {
interval: NodeJS.Timeout;
runtime: IAgentRuntime;
trustScoreProvider: TrustScoreManager;
walletProvider: WalletProvider;
constructor(runtime: IAgentRuntime) {
this.runtime = runtime;
const trustScoreDb = new TrustScoreDatabase(runtime.databaseAdapter.db);
this.trustScoreProvider = new TrustScoreManager(null, trustScoreDb);
this.walletProvider = new WalletProvider(
new Connection(runtime.getSetting("RPC_URL")),
new PublicKey(runtime.getSetting("WALLET_PUBLIC_KEY"))
);
// start a loop that runs every x seconds
this.interval = setInterval(
async () => {
await this.makeTrades();
},
60 * 60 * 1000
); // 1 hour in milliseconds
}
async makeTrades() {
console.log("Running auto loop");
// malibu todos
const startDate = new Date(new Date().getTime() - 60 * 60 * 1000);
const endDate = new Date();
// get recommendations from the last hour (or whatever time period we want) in order desc by trust score
const recommendations =
await this.trustScoreProvider.getRecommendations(
startDate,
endDate
);
// get high trust recommendations
const highTrustRecommendations = recommendations.filter(
(r) => r.averageTrustScore > 0.7
);
// get information for all tokens which were recommended
const tokenInfos = highTrustRecommendations.map(
async (highTrustRecommendation) => {
const tokenProvider = new TokenProvider(
highTrustRecommendation.tokenAddress,
this.walletProvider
);
const tokenInfo = await tokenProvider.getProcessedTokenData();
const shouldTrade = await tokenProvider.shouldTradeToken();
return { tokenInfo, shouldTrade };
}
);
// get any additional information we might need
// make sure we're looking at the right tokens and data
// shaw -- TODOs
// compose thesis context
// write a thesis which trades and why
// compose trade context
// geratate trades with LLM
// parse trades from LLM
// post thesis to twitter
// malibu todos
// execute trades
}
}
export const AutoClientInterface: Client = {
start: async (runtime: IAgentRuntime) => {
const client = new AutoClient(runtime);
return client;
},
stop: async (runtime: IAgentRuntime) => {
console.warn("Direct client does not support stopping yet");
},
};
export default AutoClientInterface;