@@ -11,6 +11,9 @@ import {
11
11
Evaluator ,
12
12
} from "@ai16z/eliza/src/types.ts" ;
13
13
import { stringToUuid } from "@ai16z/eliza/src/uuid.ts" ;
14
+ import { TrustScoreManager } from "../providers/trustScoreProvider.ts" ;
15
+ import { TokenProvider } from "../providers/token.ts" ;
16
+ import { TrustScoreDatabase } from "../adapters/trustScoreDatabase.ts" ;
14
17
15
18
const shouldProcessTemplate =
16
19
`# Task: Decide if the recent messages should be processed for token recommendations.
@@ -135,21 +138,93 @@ async function handler(runtime: IAgentRuntime, message: Memory) {
135
138
! rec . alreadyKnown &&
136
139
( rec . ticker || rec . contractAddress ) &&
137
140
rec . recommender &&
141
+ rec . conviction &&
138
142
rec . recommender . trim ( ) !== ""
139
143
) ;
140
144
} )
141
145
142
146
for ( const rec of filteredRecommendations ) {
143
- console . log ( "Recommendation: " , rec ) ;
147
+
148
+ // TODO: Check to make sure the contract address is valid, it's the right one, etc
149
+
150
+ if ( ! rec . contractAddress ) {
151
+ console . warn ( "Not implemented: try to resolve CA from ticker" )
152
+ continue ;
153
+ }
154
+
155
+ // create the token provider and trust score manager
156
+ const tokenProvider = new TokenProvider ( rec . contractAddress ) ;
157
+ const trustScoreDb = new TrustScoreDatabase ( runtime . databaseAdapter . db ) ;
158
+ const trustScoreManager = new TrustScoreManager ( tokenProvider , trustScoreDb ) ;
159
+
160
+ // get actors from the database
161
+ const participants = await runtime . databaseAdapter . getParticipantsForRoom ( message . roomId )
162
+
163
+ // find the first user Id from a user with the username that we extracted
164
+ const user = participants . find ( async ( actor ) => {
165
+ const user = await runtime . databaseAdapter . getAccountById ( actor ) ;
166
+ return user . name . toLowerCase ( ) . trim ( ) === rec . recommender . toLowerCase ( ) . trim ( ) ;
167
+ } ) ;
168
+
169
+ if ( ! user ) {
170
+ console . warn ( "Could not find user: " , rec . recommender )
171
+ continue ;
172
+ }
173
+
174
+ const account = await runtime . databaseAdapter . getAccountById ( user ) ;
175
+ const userId = account . id ;
176
+
144
177
const recMemory = {
145
- userId : stringToUuid ( rec . recommender ) ,
178
+ userId,
146
179
agentId,
147
180
content : { text : JSON . stringify ( rec ) } ,
148
181
roomId,
149
182
createdAt : Date . now ( ) ,
150
183
} ;
151
184
152
185
await recommendationsManager . createMemory ( recMemory , true ) ;
186
+
187
+ // buy, dont buy, sell, dont sell
188
+
189
+ const buyAmounts = {
190
+ none : 0 ,
191
+ low : 10 ,
192
+ medium : 40 ,
193
+ high : 100
194
+ }
195
+
196
+ let buyAmount = buyAmounts [ rec . conviction . toLowerCase ( ) . trim ( ) ]
197
+ if ( ! buyAmount ) {
198
+ // handle annoying cases
199
+ // for now just put in 10 sol
200
+ buyAmount = 10 ;
201
+ }
202
+
203
+ // TODO: scale this with market cap probably?
204
+
205
+
206
+ // TODO: is this is a buy, sell, dont buy, or dont sell?
207
+
208
+ switch ( rec . type ) {
209
+ case "buy" :
210
+ // for now, lets just assume buy only, but we should implement
211
+ await trustScoreManager . createTradePerformance (
212
+ runtime ,
213
+ rec . contractAddress ,
214
+ userId ,
215
+ {
216
+ buy_amount : rec . buyAmount ,
217
+ is_simulation : true ,
218
+ }
219
+ ) ;
220
+ break ;
221
+ case "sell" :
222
+ case "dont_sell" :
223
+ case "dont_buy" :
224
+ console . warn ( "Not implemented" )
225
+ break ;
226
+ }
227
+
153
228
}
154
229
155
230
return filteredRecommendations ;
0 commit comments