diff --git a/packages/plugin-akash/src/actions/closeDeployment.ts b/packages/plugin-akash/src/actions/closeDeployment.ts index f245c689044..ee50e0067da 100644 --- a/packages/plugin-akash/src/actions/closeDeployment.ts +++ b/packages/plugin-akash/src/actions/closeDeployment.ts @@ -7,8 +7,8 @@ import { MsgCloseDeployment } from "@akashnetwork/akash-api/akash/deployment/v1b import { validateAkashConfig } from "../environment"; import { fetchDeployments } from "./getDeploymentApi"; import { AkashError, AkashErrorCode } from "../error/error"; -import { getCertificatePath } from "../utils/paths"; -import { inspectRuntime, isPluginLoaded } from "../runtime_inspect"; +// import { getCertificatePath } from "../utils/paths"; +import { isPluginLoaded } from "../runtime_inspect"; interface CloseDeploymentContent extends Content { dseq?: string; @@ -16,7 +16,7 @@ interface CloseDeploymentContent extends Content { } // Certificate file path -const CERTIFICATE_PATH = getCertificatePath(import.meta.url); +// const CERTIFICATE_PATH = getCertificatePath(import.meta.url); // Initialize wallet and client async function initializeClient(runtime: IAgentRuntime) { @@ -312,7 +312,7 @@ export const closeDeploymentAction: Action = { runtime: IAgentRuntime, message: Memory, state: State | undefined, - options: { [key: string]: unknown } = {}, + _options: { [key: string]: unknown } = {}, callback?: HandlerCallback ): Promise => { const actionId = Date.now().toString(); diff --git a/packages/plugin-akash/src/actions/createDeployment.ts b/packages/plugin-akash/src/actions/createDeployment.ts index f8adfed0e19..d64c5a6ebca 100644 --- a/packages/plugin-akash/src/actions/createDeployment.ts +++ b/packages/plugin-akash/src/actions/createDeployment.ts @@ -16,7 +16,7 @@ import { AkashError, AkashErrorCode, withRetry } from "../error/error"; import * as fs from 'fs'; import * as path from 'path'; import { getCertificatePath, getDefaultSDLPath } from "../utils/paths"; -import { fileURLToPath } from 'url'; +// import { fileURLToPath } from 'url'; import { inspectRuntime, isPluginLoaded } from "../runtime_inspect"; import https from 'node:https'; import axios from 'axios'; @@ -162,7 +162,8 @@ const loadSDLFromFile = (filePath: string): string => { } }; -const formatErrorMessage = (error: unknown): string => { +// Preserved for future use +/* const formatErrorMessage = (error: unknown): string => { if (error instanceof AkashError) { if (error.code === AkashErrorCode.WALLET_NOT_INITIALIZED) { return "Akash wallet not initialized"; @@ -196,7 +197,7 @@ const formatErrorMessage = (error: unknown): string => { return "Failed to parse SDL: Invalid format"; } return message; -}; +}; */ async function initializeWallet(mnemonic: string) { elizaLogger.debug("=== Initializing Wallet ===", { @@ -619,7 +620,7 @@ async function queryLeaseStatus(lease: any, providerUri: string, certificate: Ce 'Content-Type': 'application/json', 'Accept': 'application/json' }, - // @ts-ignore - Node's fetch has agent support + // @ts-expect-error - TypeScript's fetch types don't include Node's agent support, but it exists at runtime agent, signal: AbortSignal.timeout(10000) }); @@ -1138,7 +1139,7 @@ export const createDeploymentAction: Action = { runtime: IAgentRuntime, message: Memory, state: State | undefined, - options: { [key: string]: unknown; } = {}, + _options: { [key: string]: unknown; } = {}, callback?: HandlerCallback ): Promise => { const actionId = Date.now().toString(); diff --git a/packages/plugin-akash/src/actions/getDeploymentApi.ts b/packages/plugin-akash/src/actions/getDeploymentApi.ts index a279dff3b96..417a9fc508a 100644 --- a/packages/plugin-akash/src/actions/getDeploymentApi.ts +++ b/packages/plugin-akash/src/actions/getDeploymentApi.ts @@ -5,7 +5,7 @@ import { validateAkashConfig } from "../environment"; import { AkashError, AkashErrorCode } from "../error/error"; import * as fs from 'fs'; import * as path from 'path'; -import { getCertificatePath, getDeploymentsPath } from "../utils/paths"; +import { getDeploymentsPath } from "../utils/paths"; export interface DeploymentInfo { owner: string; @@ -278,7 +278,6 @@ export async function loadDeploymentInfo(filePath: string): Promise => { const actionId = Date.now().toString(); elizaLogger.info("Starting deployment API request", { actionId }); try { - const config = await validateAkashConfig(runtime); + // const config = await validateAkashConfig(runtime); const params = message.content as Partial; // Fetch deployments diff --git a/packages/plugin-akash/src/actions/getDeploymentStatus.ts b/packages/plugin-akash/src/actions/getDeploymentStatus.ts index 48413f7b4d8..98a90dccf99 100644 --- a/packages/plugin-akash/src/actions/getDeploymentStatus.ts +++ b/packages/plugin-akash/src/actions/getDeploymentStatus.ts @@ -144,7 +144,7 @@ export const getDeploymentStatusAction: Action = { runtime: IAgentRuntime, message: Memory, state: State | undefined, - options: { [key: string]: unknown } = {}, + _options: { [key: string]: unknown } = {}, callback?: HandlerCallback ): Promise => { const actionId = Date.now().toString(); diff --git a/packages/plugin-akash/src/actions/getGPUPricing.ts b/packages/plugin-akash/src/actions/getGPUPricing.ts index 562c0871984..35e407f00f1 100644 --- a/packages/plugin-akash/src/actions/getGPUPricing.ts +++ b/packages/plugin-akash/src/actions/getGPUPricing.ts @@ -94,7 +94,7 @@ export const getGPUPricingAction: Action = { runtime: IAgentRuntime, message: Memory, state: State | undefined, - options: { [key: string]: unknown; } = {}, + _options: { [key: string]: unknown; } = {}, callback?: HandlerCallback ): Promise => { const actionId = Date.now().toString(); diff --git a/packages/plugin-akash/src/actions/getManifest.ts b/packages/plugin-akash/src/actions/getManifest.ts index 981cf9c65e0..5d6e116f9e9 100644 --- a/packages/plugin-akash/src/actions/getManifest.ts +++ b/packages/plugin-akash/src/actions/getManifest.ts @@ -6,8 +6,8 @@ import { AkashError, AkashErrorCode } from "../error/error"; import * as fs from 'fs'; import * as path from 'path'; import yaml from 'js-yaml'; -import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate"; -import { getCertificatePath, getDefaultSDLPath } from "../utils/paths"; +// import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate"; +import { getDefaultSDLPath } from "../utils/paths"; interface GetManifestContent extends Content { sdl?: string; @@ -121,10 +121,10 @@ const validateSDL = (sdlContent: string, validationLevel: string = "strict"): bo // }); return true; } catch (error) { - // elizaLogger.error("SDL validation failed", { - // error: error instanceof Error ? error.message : String(error), - // validationLevel - // }); + elizaLogger.error("SDL validation failed", { + error: error instanceof Error ? error.message : String(error), + validationLevel + }); return false; } }; @@ -186,7 +186,7 @@ export const getManifestAction: Action = { runtime: IAgentRuntime, message: Memory, state: State | undefined, - options: { [key: string]: unknown; } = {}, + _options: { [key: string]: unknown; } = {}, callback?: HandlerCallback ): Promise => { const actionId = Date.now().toString(); diff --git a/packages/plugin-akash/src/actions/getProvidersList.ts b/packages/plugin-akash/src/actions/getProvidersList.ts index 3944e9c507d..52e3c0fe911 100644 --- a/packages/plugin-akash/src/actions/getProvidersList.ts +++ b/packages/plugin-akash/src/actions/getProvidersList.ts @@ -211,7 +211,7 @@ export const getProvidersListAction: Action = { runtime: IAgentRuntime, message: Memory, state: State | undefined, - options: { [key: string]: unknown; } = {}, + _options: { [key: string]: unknown; } = {}, callback?: HandlerCallback ): Promise => { const actionId = Date.now().toString(); diff --git a/packages/plugin-akash/src/error/error.ts b/packages/plugin-akash/src/error/error.ts index 3211d8f8283..fb6d56416b3 100644 --- a/packages/plugin-akash/src/error/error.ts +++ b/packages/plugin-akash/src/error/error.ts @@ -1,4 +1,3 @@ -import { elizaLogger } from "@elizaos/core"; export enum AkashErrorCategory { WALLET = 'WALLET', diff --git a/packages/plugin-akash/src/index.ts b/packages/plugin-akash/src/index.ts index e8c8955204c..ffa07f75f6b 100644 --- a/packages/plugin-akash/src/index.ts +++ b/packages/plugin-akash/src/index.ts @@ -1,4 +1,4 @@ -import { Plugin, elizaLogger } from "@elizaos/core"; +import { Plugin} from "@elizaos/core"; import { createDeploymentAction } from "./actions/createDeployment"; import { closeDeploymentAction } from "./actions/closeDeployment"; import { getProviderInfoAction } from "./actions/getProviderInfo"; diff --git a/packages/plugin-akash/src/providers/wallet.ts b/packages/plugin-akash/src/providers/wallet.ts index 100b8f6bdca..397c37ba5a0 100644 --- a/packages/plugin-akash/src/providers/wallet.ts +++ b/packages/plugin-akash/src/providers/wallet.ts @@ -1,7 +1,7 @@ import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import { SigningStargateClient } from "@cosmjs/stargate"; -import { elizaLogger } from "@elizaos/core"; -import { IAgentRuntime, Memory } from "@elizaos/core/src/types"; +import { elizaLogger, IAgentRuntime, Memory } from "@elizaos/core"; +// import { IAgentRuntime, Memory } from "@elizaos/core/src/types"; import { validateAkashConfig } from "../environment"; import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate"; import { @@ -9,7 +9,6 @@ import { AkashWalletState, AkashError, AKASH_ERROR_CODES, - AkashRegistryTypes } from "../types"; // Use a proper UUID for the wallet room diff --git a/packages/plugin-akash/src/types.ts b/packages/plugin-akash/src/types.ts index 8d5c94a9880..b784290b499 100644 --- a/packages/plugin-akash/src/types.ts +++ b/packages/plugin-akash/src/types.ts @@ -1,10 +1,10 @@ -import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing"; +import { DirectSecp256k1HdWallet} from "@cosmjs/proto-signing"; import { SigningStargateClient } from "@cosmjs/stargate"; -import { Provider } from "@elizaos/core"; +// import { Provider } from "@elizaos/core"; import { IAgentRuntime, Memory } from "@elizaos/core"; import { SDL } from "@akashnetwork/akashjs/build/sdl"; import { MsgCreateDeployment } from "@akashnetwork/akash-api/akash/deployment/v1beta3"; -import { QueryBidsRequest, MsgCreateLease, BidID } from "@akashnetwork/akash-api/akash/market/v1beta4"; +import { MsgCreateLease} from "@akashnetwork/akash-api/akash/market/v1beta4"; // Core wallet state type export interface AkashWalletState { diff --git a/packages/plugin-akash/src/utils/paths.ts b/packages/plugin-akash/src/utils/paths.ts index 3cbb1cd1e07..c74151b2f7a 100644 --- a/packages/plugin-akash/src/utils/paths.ts +++ b/packages/plugin-akash/src/utils/paths.ts @@ -2,7 +2,6 @@ import * as path from 'path'; import { fileURLToPath } from 'url'; import { elizaLogger } from "@elizaos/core"; import { existsSync } from 'fs'; -import fs from 'fs'; import { getConfig } from '../environment'; export const getPluginRoot = (importMetaUrl: string) => { @@ -81,7 +80,7 @@ export const getDefaultSDLPath = (importMetaUrl: string) => { const config = getConfig(process.env.AKASH_ENV); const sdlFileName = config.AKASH_SDL; const sdlPath = path.join(srcPath, 'sdl', sdlFileName); - const sdlDir = path.dirname(sdlPath); + // const sdlDir = path.dirname(sdlPath); // Only log if file doesn't exist as a warning if (!existsSync(sdlPath)) { diff --git a/packages/plugin-starknet/package.json b/packages/plugin-starknet/package.json index adb327aa083..190a31a118c 100644 --- a/packages/plugin-starknet/package.json +++ b/packages/plugin-starknet/package.json @@ -20,6 +20,7 @@ ], "dependencies": { "@elizaos/core": "workspace:*", + "@elizaos/plugin-trustdb": "workspace:*", "@avnu/avnu-sdk": "2.1.1", "@uniswap/sdk-core": "6.0.0", "unruggable-sdk": "1.4.0", diff --git a/packages/plugin-starknet/src/providers/portfolioProvider.ts b/packages/plugin-starknet/src/providers/portfolioProvider.ts index 94fc3bb0f7b..95ed4b524f1 100644 --- a/packages/plugin-starknet/src/providers/portfolioProvider.ts +++ b/packages/plugin-starknet/src/providers/portfolioProvider.ts @@ -119,4 +119,4 @@ const walletProvider: Provider = { }, }; -export { walletProvider }; +export { walletProvider, TokenBalances }; diff --git a/packages/plugin-starknet/src/providers/token.ts b/packages/plugin-starknet/src/providers/token.ts index ec6aaaf3c57..96ac18ac5e0 100644 --- a/packages/plugin-starknet/src/providers/token.ts +++ b/packages/plugin-starknet/src/providers/token.ts @@ -12,7 +12,7 @@ import { CalculatedBuyAmounts, Prices, } from "../types/trustDB.ts"; -import { WalletProvider, Item } from "./walletProvider.ts"; +import { WalletProvider, TokenBalances } from "./portfolioProvider.ts"; import { num } from "starknet"; import { analyzeHighSupplyHolders, @@ -129,22 +129,35 @@ export class TokenProvider { } // TODO: Update to Starknet - async getTokensInWallet(runtime: IAgentRuntime): Promise { - const walletInfo = - await this.walletProvider.fetchPortfolioValue(runtime); - const items = walletInfo.items; - return items; + async getTokensInWallet(): Promise { + const tokenBalances = + await this.walletProvider.getWalletPortfolio(); + return tokenBalances; } // check if the token symbol is in the wallet - async getTokenFromWallet(runtime: IAgentRuntime, tokenSymbol: string) { + async getTokenFromWallet(tokenSymbol: string) { try { - const items = await this.getTokensInWallet(runtime); - const token = items.find((item) => item.symbol === tokenSymbol); + // Find the token in the PORTFOLIO_TOKENS using the provided tokenSymbol + const portfolioToken = Object.values(PORTFOLIO_TOKENS).find( + (token) => token.coingeckoId === tokenSymbol + ); + + if (!portfolioToken) { + console.warn(`Token with symbol ${tokenSymbol} not found in PORTFOLIO_TOKENS`); + return null; + } + + const tokenAddress = portfolioToken.address; + + // Get the list of tokens in the wallet + const items = await this.getTokensInWallet(); - if (token) { - return token.address; + // Check if the tokenAddress exists in the TokenBalances + if (items[tokenAddress]) { + return tokenAddress; } else { + console.warn(`Token with address ${tokenAddress} not found in wallet`); return null; } } catch (error) { diff --git a/packages/plugin-starknet/src/providers/trustScoreProvider.ts b/packages/plugin-starknet/src/providers/trustScoreProvider.ts index 74334acaa9b..d44a990868a 100644 --- a/packages/plugin-starknet/src/providers/trustScoreProvider.ts +++ b/packages/plugin-starknet/src/providers/trustScoreProvider.ts @@ -19,7 +19,7 @@ import { } from "@elizaos/plugin-trustdb"; import { getTokenBalance } from "../utils/index.ts"; import { TokenProvider } from "./token.ts"; -import { WalletProvider } from "./walletProvider.ts"; +import { WalletProvider } from "./portfolioProvider.ts"; const _Wallet = settings.MAIN_WALLET_ADDRESS; interface TradeData { @@ -136,16 +136,19 @@ export class TrustScoreManager { tokenAddress: processedData.dexScreenerData.pairs[0]?.baseToken.address || "", + symbol: processedData.dexScreenerData.pairs[0]?.baseToken.symbol || "", + balance: 0, // TODO: Implement balance check + initialMarketCap: processedData.dexScreenerData.pairs[0]?.marketCap || 0, priceChange24h: - processedData.tradeData.price_change_24h_percent, - volumeChange24h: processedData.tradeData.volume_24h, + processedData.tradeData.market.priceChangePercentage24h, + volumeChange24h: processedData.tradeData.market.starknetVolume24h, trade_24h_change: - processedData.tradeData.trade_24h_change_percent, + processedData.tradeData.market.starknetTradingVolume24h, liquidity: processedData.dexScreenerData.pairs[0]?.liquidity.usd || 0, liquidityChange24h: 0, holderChange24h: - processedData.tradeData.unique_wallet_24h_change_percent, + processedData.tradeData.market.starknetTradingVolume24h, rugPull: false, // TODO: Implement rug pull detection isScam: false, // TODO: Implement scam detection marketCapChange24h: 0, // TODO: Implement market cap change @@ -289,8 +292,8 @@ export class TrustScoreManager { async suspiciousVolume(tokenAddress: string): Promise { const processedData: ProcessedTokenData = await this.tokenProvider.getProcessedTokenData(); - const unique_wallet_24h = processedData.tradeData.unique_wallet_24h; - const volume_24h = processedData.tradeData.volume_24h; + const unique_wallet_24h = processedData.tradeData.market.starknetTradingVolume24h; + const volume_24h = processedData.tradeData.market.starknetVolume24h; const suspiciousVolume = unique_wallet_24h / volume_24h > 0.5; elizaLogger.log( `Fetched processed token data for token: ${tokenAddress}` @@ -305,7 +308,13 @@ export class TrustScoreManager { `Fetched processed token data for token: ${tokenAddress}` ); - return processedData.tradeData.volume_24h_change_percent > 50; + // Use starknetTradingVolume24h as a proxy for volume growth + const currentVolume = processedData.tradeData.market.starknetTradingVolume24h; + + // Define a growth threshold (e.g., $1M volume as sustained growth) + const growthThreshold = 1_000_000; + + return currentVolume > growthThreshold; } async isRapidDump(tokenAddress: string): Promise { @@ -315,7 +324,11 @@ export class TrustScoreManager { `Fetched processed token data for token: ${tokenAddress}` ); - return processedData.tradeData.trade_24h_change_percent < -50; + // Use priceChangePercentage24h as a proxy for rapid dump + const priceChange24h = processedData.tradeData.market.priceChangePercentage24h; + + // Consider a rapid dump if the price drops more than 50% in 24 hours + return priceChange24h < -50; } async checkTrustScore(tokenAddress: string): Promise { @@ -358,15 +371,18 @@ export class TrustScoreManager { // TODO: change to starknet const wallet = new WalletProvider(runtime); - const prices = await wallet.fetchPrices(runtime); - const solPrice = prices.solana.usd; - const buySol = data.buy_amount / parseFloat(solPrice); - const buy_value_usd = data.buy_amount * processedData.tradeData.price; + const prices = await wallet.getTokenUsdValues(); + const solPrice = prices.solana?.usd; + if (!solPrice) { + throw new Error("Unable to fetch Solana price (cryptoName: 'solana')."); + } + const buySol = data.buy_amount / solPrice; + const buy_value_usd = data.buy_amount * processedData.tradeData.market.currentPrice; const creationData = { token_address: tokenAddress, recommender_id: recommender.id, - buy_price: processedData.tradeData.price, + buy_price: processedData.tradeData.market.currentPrice, sell_price: 0, buy_timeStamp: new Date().toISOString(), sell_timeStamp: "", @@ -469,11 +485,14 @@ export class TrustScoreManager { // TODO: const wallet = new WalletProvider(this.runtime); - const prices = await wallet.fetchPrices(runtime); - const solPrice = prices.solana.usd; - const sellSol = sellDetails.sell_amount / parseFloat(solPrice); + const prices = await wallet.getTokenUsdValues(); + const solPrice = prices.solana?.usd; + if (!solPrice) { + throw new Error("Unable to fetch Solana price (cryptoName: 'solana')."); + } + const sellSol = sellDetails.sell_amount / solPrice; const sell_value_usd = - sellDetails.sell_amount * processedData.tradeData.price; + sellDetails.sell_amount * processedData.tradeData.market.currentPrice; const trade = await this.trustScoreDb.getLatestTradePerformance( tokenAddress, recommender.id, @@ -484,7 +503,7 @@ export class TrustScoreManager { processedData.dexScreenerData.pairs[0]?.marketCap || 0; const liquidity = processedData.dexScreenerData.pairs[0]?.liquidity.usd || 0; - const sell_price = processedData.tradeData.price; + const sell_price = processedData.tradeData.market.currentPrice; const profit_usd = sell_value_usd - trade.buy_value_usd; const profit_percent = (profit_usd / trade.buy_value_usd) * 100; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5e2baa0332f..d44ab31209d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1587,6 +1587,18 @@ importers: specifier: 7.1.0 version: 7.1.0 + packages/plugin-defillama: + dependencies: + '@elizaos/core': + specifier: workspace:* + version: link:../core + axios: + specifier: ^1.6.0 + version: 1.7.9(debug@4.4.0) + tsup: + specifier: ^8.3.5 + version: 8.3.5(@swc/core@1.10.6(@swc/helpers@0.5.15))(jiti@2.4.2)(postcss@8.4.49)(tsx@4.19.2)(typescript@5.7.2)(yaml@2.7.0) + packages/plugin-depin: dependencies: '@elizaos/core':