Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/shaw/trust'
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoMandar committed Nov 9, 2024
2 parents 462c56f + 321dde6 commit 8c46f2c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/client-telegram/src/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ export class MessageManager {

// Decide whether to respond
const shouldRespond = await this._shouldRespond(message, state);
if (!shouldRespond) return;

if (shouldRespond) {
// Generate response
const context = composeContext({
state,
Expand Down Expand Up @@ -463,7 +462,6 @@ export class MessageManager {

// Update state after response
state = await this.runtime.updateRecentMessageState(state);
await this.runtime.evaluate(memory, state);

// Handle any resulting actions
await this.runtime.processActions(
Expand All @@ -472,6 +470,9 @@ export class MessageManager {
state,
callback
);
}

await this.runtime.evaluate(memory, state, shouldRespond);
} catch (error) {
console.error("❌ Error handling message:", error);
console.error("Error sending message:", error);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const models: Models = {
},
endpoint: "https://api.anthropic.com/v1",
model: {
[ModelClass.SMALL]: "claude-3-5-sonnet-20241022",
[ModelClass.SMALL]: "claude-3-5-haiku",
[ModelClass.MEDIUM]: "claude-3-5-sonnet-20241022",
[ModelClass.LARGE]: "claude-3-opus-20240229",
},
Expand Down
79 changes: 77 additions & 2 deletions packages/plugin-solana/src/evaluators/trust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
Evaluator,
} from "@ai16z/eliza/src/types.ts";
import { stringToUuid } from "@ai16z/eliza/src/uuid.ts";
import { TrustScoreManager } from "../providers/trustScoreProvider.ts";
import { TokenProvider } from "../providers/token.ts";
import { TrustScoreDatabase } from "../adapters/trustScoreDatabase.ts";

const shouldProcessTemplate =
`# Task: Decide if the recent messages should be processed for token recommendations.
Expand Down Expand Up @@ -135,21 +138,93 @@ async function handler(runtime: IAgentRuntime, message: Memory) {
!rec.alreadyKnown &&
(rec.ticker || rec.contractAddress) &&
rec.recommender &&
rec.conviction &&
rec.recommender.trim() !== ""
);
})

for (const rec of filteredRecommendations) {
console.log("Recommendation: ", rec);

// TODO: Check to make sure the contract address is valid, it's the right one, etc

if(!rec.contractAddress) {
console.warn("Not implemented: try to resolve CA from ticker")
continue;
}

// create the token provider and trust score manager
const tokenProvider = new TokenProvider(rec.contractAddress);
const trustScoreDb = new TrustScoreDatabase(runtime.databaseAdapter.db);
const trustScoreManager = new TrustScoreManager(tokenProvider, trustScoreDb);

// get actors from the database
const participants = await runtime.databaseAdapter.getParticipantsForRoom(message.roomId)

// find the first user Id from a user with the username that we extracted
const user = participants.find(async (actor) => {
const user = await runtime.databaseAdapter.getAccountById(actor);
return user.name.toLowerCase().trim() === rec.recommender.toLowerCase().trim();
});

if(!user) {
console.warn("Could not find user: ", rec.recommender)
continue;
}

const account = await runtime.databaseAdapter.getAccountById(user);
const userId = account.id;

const recMemory = {
userId: stringToUuid(rec.recommender),
userId,
agentId,
content: { text: JSON.stringify(rec) },
roomId,
createdAt: Date.now(),
};

await recommendationsManager.createMemory(recMemory, true);

// buy, dont buy, sell, dont sell

const buyAmounts = {
none: 0,
low: 10,
medium: 40,
high: 100
}

let buyAmount = buyAmounts[rec.conviction.toLowerCase().trim()]
if(!buyAmount) {
// handle annoying cases
// for now just put in 10 sol
buyAmount = 10;
}

// TODO: scale this with market cap probably?


// TODO: is this is a buy, sell, dont buy, or dont sell?

switch(rec.type) {
case "buy":
// for now, lets just assume buy only, but we should implement
await trustScoreManager.createTradePerformance(
runtime,
rec.contractAddress,
userId,
{
buy_amount: rec.buyAmount,
is_simulation: true,
}
);
break;
case "sell":
case "dont_sell":
case "dont_buy":
console.warn("Not implemented")
break;
}

}

return filteredRecommendations;
Expand Down

0 comments on commit 8c46f2c

Please sign in to comment.