Skip to content

Commit

Permalink
Merge branch 'feat/simulation-sell-types' of http://github.com/ai16z/…
Browse files Browse the repository at this point in the history
…eliza into HEAD
  • Loading branch information
lalalune committed Nov 28, 2024
2 parents 49be4ea + 2d72901 commit c9468d3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-solana/src/actions/swapDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const executeSwapForDAO: Action = {

try {
const connection = new Connection(
"https://api.mainnet-beta.solana.com" // better if we use a better rpc
runtime.getSetting("RPC_URL") as string
);
const authority = Keypair.fromSecretKey(
Uint8Array.from(
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-solana/src/evaluators/trust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ async function handler(runtime: IAgentRuntime, message: Memory) {
for (const rec of filteredRecommendations) {
// create the wallet provider and token provider
const walletProvider = new WalletProvider(
new Connection("https://api.mainnet-beta.solana.com"),
new Connection(
runtime.getSetting("RPC_URL") ||
"https://api.mainnet-beta.solana.com"
),
new PublicKey(
runtime.getSetting("SOLANA_PUBLIC_KEY") ??
runtime.getSetting("WALLET_PUBLIC_KEY")
Expand Down
28 changes: 19 additions & 9 deletions packages/plugin-solana/src/providers/simulationSellingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {
TrustScoreDatabase,
TokenPerformance,
// TradePerformance,
// TokenRecommendation,
ProcessedTokenData,
TokenRecommendation,
} from "@ai16z/plugin-trustdb";
import { Connection, PublicKey } from "@solana/web3.js";
// Assuming TokenProvider and IAgentRuntime are available
Expand All @@ -12,6 +11,7 @@ import { TokenProvider } from "./token.ts";
import { IAgentRuntime } from "@ai16z/eliza";
import { WalletProvider } from "./wallet.ts";
import * as amqp from "amqplib";
import { ProcessedTokenData } from "../types/token.ts";

interface SellDetails {
sell_amount: number;
Expand Down Expand Up @@ -133,7 +133,7 @@ export class SimulationSellingService {

try {
console.log(
`Executing sell for token ${tokenPerformance.tokenSymbol}: ${amountToSell}`
`Executing sell for token ${tokenPerformance.symbol}: ${amountToSell}`
);

// Update the sell details
Expand All @@ -151,7 +151,7 @@ export class SimulationSellingService {
// Update sell details in the database
const sellDetailsData = await this.updateSellDetails(
tokenAddress,
tokenPerformance.recommenderId,
sell_recommender_id,
sellTimeStamp,
sellDetails,
true, // isSimulation
Expand Down Expand Up @@ -209,15 +209,21 @@ export class SimulationSellingService {
);
// const shouldTrade = await tokenProvider.shouldTradeToken();
// if (shouldTrade) {
const tokenRecommendations: TokenRecommendation[] =
this.trustScoreDb.getRecommendationsByToken(
tokenPerformance.tokenAddress
);
const tokenRecommendation: TokenRecommendation =
tokenRecommendations[0];
const balance = tokenPerformance.balance;
const sell_recommender_id = tokenPerformance.recommenderId;
const sell_recommender_id = tokenRecommendation.recommenderId;
const tokenAddress = tokenPerformance.tokenAddress;
const process = await this.startProcessInTheSonarBackend(
tokenAddress,
balance,
true,
sell_recommender_id,
tokenPerformance.initial_mc
tokenPerformance.initialMarketCap
);
if (process) {
this.runningProcesses.add(tokenAddress);
Expand All @@ -226,7 +232,10 @@ export class SimulationSellingService {
});
}

public processTokenPerformance(tokenAddress: string) {
public processTokenPerformance(
tokenAddress: string,
recommenderId: string
) {
try {
const runningProcesses = this.runningProcesses;
// check if token is already being processed
Expand All @@ -236,20 +245,21 @@ export class SimulationSellingService {
}
const tokenPerformance =
this.trustScoreDb.getTokenPerformance(tokenAddress);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const tokenProvider = new TokenProvider(
tokenPerformance.tokenAddress,
this.walletProvider,
this.runtime.cacheManager
);
const balance = tokenPerformance.balance;
const sell_recommender_id = tokenPerformance.recommenderId;
const sell_recommender_id = recommenderId;
const process = this.startProcessInTheSonarBackend(
tokenAddress,
balance,
true,
sell_recommender_id,
tokenPerformance.initial_mc
tokenPerformance.initialMarketCap
);
if (process) {
this.runningProcesses.add(tokenAddress);
Expand Down
8 changes: 6 additions & 2 deletions packages/plugin-solana/src/providers/trustScoreProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ export class TrustScoreManager {

this.trustScoreDb.upsertTokenPerformance({
tokenAddress: tokenAddress,
symbol: processedData.tokenCodex.symbol,
priceChange24h: processedData.tradeData.price_change_24h_percent,
volumeChange24h: processedData.tradeData.volume_24h,
trade_24h_change: processedData.tradeData.trade_24h_change_percent,
Expand Down Expand Up @@ -453,7 +454,10 @@ export class TrustScoreManager {
};
this.trustScoreDb.addTransaction(transaction);
}
this.simulationSellingService.processTokenPerformance(tokenAddress);
this.simulationSellingService.processTokenPerformance(
tokenAddress,
recommenderId
);
// api call to update trade performance
this.createTradeInBe(tokenAddress, recommenderId, username, data);
return creationData;
Expand Down Expand Up @@ -531,7 +535,7 @@ export class TrustScoreManager {
const processedData: ProcessedTokenData =
await this.tokenProvider.getProcessedTokenData();
const wallet = new WalletProvider(
new Connection("https://api.mainnet-beta.solana.com"),
this.connection,
new PublicKey(Wallet!)
);
const prices = await wallet.fetchPrices(runtime);
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-trustdb/src/adapters/trustScoreDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface RecommenderMetrics {

export interface TokenPerformance {
tokenAddress: string;
symbol: string;
priceChange24h: number;
volumeChange24h: number;
trade_24h_change: number;
Expand Down Expand Up @@ -109,6 +110,7 @@ interface RecommenderMetricsRow {

interface TokenPerformanceRow {
token_address: string;
symbol: string;
price_change_24h: number;
volume_change_24h: number;
trade_24h_change: number;
Expand Down Expand Up @@ -193,6 +195,7 @@ export class TrustScoreDatabase {
this.db.exec(`
CREATE TABLE IF NOT EXISTS token_performance (
token_address TEXT PRIMARY KEY,
symbol TEXT,
price_change_24h REAL,
volume_change_24h REAL,
trade_24h_change REAL,
Expand Down Expand Up @@ -818,6 +821,7 @@ export class TrustScoreDatabase {

return {
tokenAddress: row.token_address,
symbol: row.symbol,
priceChange24h: row.price_change_24h,
volumeChange24h: row.volume_change_24h,
trade_24h_change: row.trade_24h_change,
Expand Down Expand Up @@ -852,6 +856,7 @@ export class TrustScoreDatabase {

return rows.map((row) => ({
tokenAddress: row.token_address,
symbol: row.symbol,
priceChange24h: row.price_change_24h,
volumeChange24h: row.volume_change_24h,
trade_24h_change: row.trade_24h_change,
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c9468d3

Please sign in to comment.