@@ -27,6 +27,7 @@ interface TokenPair {
27
27
name : string ;
28
28
symbol : string ;
29
29
} ;
30
+ marketCap : number ;
30
31
priceNative : string ;
31
32
priceUsd : string ;
32
33
txns : {
@@ -147,10 +148,10 @@ export const searchCashTags = async (
147
148
} ;
148
149
149
150
export const cashtags : Action = {
150
- name : "FIND_BEST_MATCH " ,
151
+ name : "FIND_BEST_CASHTAG_MATCH " ,
151
152
similes : [ "FIND_TOKEN" , "SEARCH_TOKEN" , "GET_TOKEN" , "FIND_PAIR" ] ,
152
153
description :
153
- "Searches for the best matching token pair based on age, liquidity, volume, and transaction count" ,
154
+ "Searches for the best matching token pair (ca) or $cashtag ($SOL) based on age, liquidity, volume, and transaction count" ,
154
155
validate : async ( runtime : IAgentRuntime , message : Memory , state : State ) => {
155
156
return true
156
157
} ,
@@ -163,50 +164,62 @@ export const cashtags: Action = {
163
164
) => {
164
165
const userId = runtime . agentId ;
165
166
const { roomId } = message ;
166
- const datestr = new Date ( ) . toUTCString ( ) . replace ( / : / g, "-" ) ;
167
167
168
+
168
169
// Extract cashtag from message
169
170
const cashtag = message . content . text
170
171
. match ( / \$ [ A - Z a - z ] + / ) ?. [ 0 ]
171
172
?. replace ( "$" , "" ) ;
172
173
173
- if ( ! cashtag ) {
174
- callback ( {
175
- text : "No cashtag found in the message. Please include a cashtag (e.g. $PNUT)" ,
176
- action : "FIND_BEST_MATCH_RESPONSE" ,
177
- source : "DexScreener" ,
178
- } ) ;
179
- return ;
180
- }
181
-
182
174
const callbackData : Content = {
183
175
text : undefined ,
184
176
action : "FIND_BEST_MATCH_RESPONSE" ,
185
177
source : "DexScreener" ,
186
178
attachments : [ ] ,
187
179
} ;
188
180
181
+ if ( ! cashtag ) {
182
+ // callback({
183
+ // text: "No cashtag found in the message. Please include a cashtag (e.g. $PNUT)",
184
+ // action: "FIND_BEST_MATCH_RESPONSE",
185
+ // source: "DexScreener",
186
+ // });
187
+ callbackData . text = "No cashtag found in the message. Please include a cashtag (e.g. $PNUT)" ;
188
+
189
+ return ;
190
+ }
191
+
192
+ console . log ( `[${ roomId } ] Processing FIND_BEST_MATCH request... $` , cashtag ) ;
193
+
189
194
try {
190
195
const { data : bestMatch , error } = await searchCashTags ( cashtag ) ;
191
196
192
197
if ( error ) {
193
198
callbackData . text = error ;
194
- callback ( callbackData ) ;
199
+ // callback(callbackData);
195
200
return ;
196
201
}
202
+ console . log ( bestMatch ) ;
197
203
198
204
// Format response
199
- const responseText = `Best match for $${ cashtag } :
200
- Token: ${ bestMatch . baseToken . name } (${ bestMatch . baseToken . symbol } )
201
- Age: ${ Math . floor ( ( Date . now ( ) - bestMatch . pairCreatedAt ) / ( 1000 * 60 * 60 * 24 ) ) } days
202
- Liquidity: $${ bestMatch . liquidity . usd . toLocaleString ( ) }
203
- 24h Volume: $${ bestMatch . volume . h24 . toLocaleString ( ) }
204
- 24h Transactions: ${ ( bestMatch . txns . h24 . buys + bestMatch . txns . h24 . sells ) . toLocaleString ( ) }
205
- Price: $${ bestMatch . priceUsd }
206
- DEX: ${ bestMatch . dexId }
207
- Pair Address: ${ bestMatch . pairAddress } ` ;
208
-
209
- callbackData . text = responseText ;
205
+ const responseText = `
206
+ Best match for $${ cashtag } :
207
+ Token: ${ bestMatch . baseToken . name } (${ bestMatch . baseToken . symbol } )
208
+ MCAP: $${ ( bestMatch . marketCap ) . toFixed ( 2 ) } M
209
+ Age: ${ Math . floor ( ( Date . now ( ) - bestMatch . pairCreatedAt ) / ( 1000 * 60 * 60 * 24 ) ) } days
210
+ Liquidity: $${ bestMatch . liquidity . usd . toLocaleString ( ) }
211
+ 24h Volume: $${ bestMatch . volume . h24 . toLocaleString ( ) }
212
+ 24h Transactions: ${ ( bestMatch . txns . h24 . buys + bestMatch . txns . h24 . sells ) . toLocaleString ( ) }
213
+ Price: $${ bestMatch . priceUsd }
214
+ DEX: ${ bestMatch . dexId }
215
+ Pair Address: ${ bestMatch . pairAddress }
216
+
217
+ URL: ${ bestMatch . url } ` ;
218
+
219
+ callbackData . text = `Create a reply with the token information for $${ cashtag } .
220
+ Message from user - ${ message . content . text }
221
+ Token information - ${ responseText }
222
+ ` ;
210
223
211
224
// Store the full response as an attachment
212
225
const attachmentId =
@@ -219,10 +232,10 @@ Pair Address: ${bestMatch.pairAddress}`;
219
232
title : `Best Match for $${ cashtag } ` ,
220
233
source : "DexScreener" ,
221
234
description : `Token analysis for ${ bestMatch . baseToken . symbol } ` ,
222
- text : JSON . stringify ( bestMatch , null , 2 ) ,
223
- } ) ;
235
+ text : JSON . stringify ( bestMatch , null , 2 )
236
+ } )
224
237
225
- callback ( callbackData ) ;
238
+ // callback(callbackData);
226
239
227
240
// Log to database
228
241
runtime . databaseAdapter . log ( {
@@ -240,15 +253,21 @@ Pair Address: ${bestMatch.pairAddress}`;
240
253
roomId,
241
254
embedding : embeddingZeroVector ,
242
255
} ;
256
+
243
257
244
258
await runtime . messageManager . createMemory ( memory ) ;
245
- await runtime . evaluate ( message , state ) ;
259
+ const response = await runtime . evaluate ( message , state ) ;
260
+
261
+
246
262
} catch ( error ) {
247
263
console . error ( "Error in findBestMatch:" , error ) ;
248
264
callbackData . text = `Error processing request: ${ error . message } ` ;
249
265
callback ( callbackData ) ;
250
266
}
251
267
268
+ console . log ( callbackData ) ;
269
+ typeof callback === "function" && callback ( callbackData ) ;
270
+
252
271
return callbackData ;
253
272
} ,
254
273
examples : [
@@ -263,7 +282,7 @@ Pair Address: ${bestMatch.pairAddress}`;
263
282
user : "{{user2}}" ,
264
283
content : {
265
284
text : "Let me search for the best matching pair..." ,
266
- action : "FIND_BEST_MATCH " ,
285
+ action : "FIND_BEST_CASHTAG_MATCH " ,
267
286
} ,
268
287
} ,
269
288
] ,
@@ -278,7 +297,7 @@ Pair Address: ${bestMatch.pairAddress}`;
278
297
user : "{{user2}}" ,
279
298
content : {
280
299
text : "I'll look up the token information..." ,
281
- action : "FIND_BEST_MATCH " ,
300
+ action : "FIND_BEST_CASHTAG_MATCH " ,
282
301
} ,
283
302
} ,
284
303
] ,
@@ -293,7 +312,7 @@ Pair Address: ${bestMatch.pairAddress}`;
293
312
user : "{{user2}}" ,
294
313
content : {
295
314
text : "Searching for the best BTC pair..." ,
296
- action : "FIND_BEST_MATCH " ,
315
+ action : "FIND_BEST_CASHTAG_MATCH " ,
297
316
} ,
298
317
} ,
299
318
] ,
0 commit comments