Skip to content

Commit bf5b72d

Browse files
authored
Merge pull request #2029 from Jonatan-Chaverri/fix_starknet_plugin
Fix: fix starknet plugin by replacing walletProvider with portfolio provider
2 parents 570de1c + a9d5c27 commit bf5b72d

File tree

5 files changed

+76
-31
lines changed

5 files changed

+76
-31
lines changed

packages/plugin-starknet/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
],
2121
"dependencies": {
2222
"@elizaos/core": "workspace:*",
23+
"@elizaos/plugin-trustdb": "workspace:*",
2324
"@avnu/avnu-sdk": "2.1.1",
2425
"@uniswap/sdk-core": "6.0.0",
2526
"unruggable-sdk": "1.4.0",

packages/plugin-starknet/src/providers/portfolioProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ const walletProvider: Provider = {
119119
},
120120
};
121121

122-
export { walletProvider };
122+
export { walletProvider, TokenBalances };

packages/plugin-starknet/src/providers/token.ts

+24-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
CalculatedBuyAmounts,
1313
Prices,
1414
} from "../types/trustDB.ts";
15-
import { WalletProvider, Item } from "./walletProvider.ts";
15+
import { WalletProvider, TokenBalances } from "./portfolioProvider.ts";
1616
import { num } from "starknet";
1717
import {
1818
analyzeHighSupplyHolders,
@@ -129,22 +129,35 @@ export class TokenProvider {
129129
}
130130

131131
// TODO: Update to Starknet
132-
async getTokensInWallet(runtime: IAgentRuntime): Promise<Item[]> {
133-
const walletInfo =
134-
await this.walletProvider.fetchPortfolioValue(runtime);
135-
const items = walletInfo.items;
136-
return items;
132+
async getTokensInWallet(): Promise<TokenBalances> {
133+
const tokenBalances =
134+
await this.walletProvider.getWalletPortfolio();
135+
return tokenBalances;
137136
}
138137

139138
// check if the token symbol is in the wallet
140-
async getTokenFromWallet(runtime: IAgentRuntime, tokenSymbol: string) {
139+
async getTokenFromWallet(tokenSymbol: string) {
141140
try {
142-
const items = await this.getTokensInWallet(runtime);
143-
const token = items.find((item) => item.symbol === tokenSymbol);
141+
// Find the token in the PORTFOLIO_TOKENS using the provided tokenSymbol
142+
const portfolioToken = Object.values(PORTFOLIO_TOKENS).find(
143+
(token) => token.coingeckoId === tokenSymbol
144+
);
145+
146+
if (!portfolioToken) {
147+
console.warn(`Token with symbol ${tokenSymbol} not found in PORTFOLIO_TOKENS`);
148+
return null;
149+
}
150+
151+
const tokenAddress = portfolioToken.address;
152+
153+
// Get the list of tokens in the wallet
154+
const items = await this.getTokensInWallet();
144155

145-
if (token) {
146-
return token.address;
156+
// Check if the tokenAddress exists in the TokenBalances
157+
if (items[tokenAddress]) {
158+
return tokenAddress;
147159
} else {
160+
console.warn(`Token with address ${tokenAddress} not found in wallet`);
148161
return null;
149162
}
150163
} catch (error) {

packages/plugin-starknet/src/providers/trustScoreProvider.ts

+38-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from "@elizaos/plugin-trustdb";
2020
import { getTokenBalance } from "../utils/index.ts";
2121
import { TokenProvider } from "./token.ts";
22-
import { WalletProvider } from "./walletProvider.ts";
22+
import { WalletProvider } from "./portfolioProvider.ts";
2323

2424
const _Wallet = settings.MAIN_WALLET_ADDRESS;
2525
interface TradeData {
@@ -136,16 +136,19 @@ export class TrustScoreManager {
136136
tokenAddress:
137137
processedData.dexScreenerData.pairs[0]?.baseToken.address ||
138138
"",
139+
symbol: processedData.dexScreenerData.pairs[0]?.baseToken.symbol || "",
140+
balance: 0, // TODO: Implement balance check
141+
initialMarketCap: processedData.dexScreenerData.pairs[0]?.marketCap || 0,
139142
priceChange24h:
140-
processedData.tradeData.price_change_24h_percent,
141-
volumeChange24h: processedData.tradeData.volume_24h,
143+
processedData.tradeData.market.priceChangePercentage24h,
144+
volumeChange24h: processedData.tradeData.market.starknetVolume24h,
142145
trade_24h_change:
143-
processedData.tradeData.trade_24h_change_percent,
146+
processedData.tradeData.market.starknetTradingVolume24h,
144147
liquidity:
145148
processedData.dexScreenerData.pairs[0]?.liquidity.usd || 0,
146149
liquidityChange24h: 0,
147150
holderChange24h:
148-
processedData.tradeData.unique_wallet_24h_change_percent,
151+
processedData.tradeData.market.starknetTradingVolume24h,
149152
rugPull: false, // TODO: Implement rug pull detection
150153
isScam: false, // TODO: Implement scam detection
151154
marketCapChange24h: 0, // TODO: Implement market cap change
@@ -289,8 +292,8 @@ export class TrustScoreManager {
289292
async suspiciousVolume(tokenAddress: string): Promise<boolean> {
290293
const processedData: ProcessedTokenData =
291294
await this.tokenProvider.getProcessedTokenData();
292-
const unique_wallet_24h = processedData.tradeData.unique_wallet_24h;
293-
const volume_24h = processedData.tradeData.volume_24h;
295+
const unique_wallet_24h = processedData.tradeData.market.starknetTradingVolume24h;
296+
const volume_24h = processedData.tradeData.market.starknetVolume24h;
294297
const suspiciousVolume = unique_wallet_24h / volume_24h > 0.5;
295298
elizaLogger.log(
296299
`Fetched processed token data for token: ${tokenAddress}`
@@ -305,7 +308,13 @@ export class TrustScoreManager {
305308
`Fetched processed token data for token: ${tokenAddress}`
306309
);
307310

308-
return processedData.tradeData.volume_24h_change_percent > 50;
311+
// Use starknetTradingVolume24h as a proxy for volume growth
312+
const currentVolume = processedData.tradeData.market.starknetTradingVolume24h;
313+
314+
// Define a growth threshold (e.g., $1M volume as sustained growth)
315+
const growthThreshold = 1_000_000;
316+
317+
return currentVolume > growthThreshold;
309318
}
310319

311320
async isRapidDump(tokenAddress: string): Promise<boolean> {
@@ -315,7 +324,11 @@ export class TrustScoreManager {
315324
`Fetched processed token data for token: ${tokenAddress}`
316325
);
317326

318-
return processedData.tradeData.trade_24h_change_percent < -50;
327+
// Use priceChangePercentage24h as a proxy for rapid dump
328+
const priceChange24h = processedData.tradeData.market.priceChangePercentage24h;
329+
330+
// Consider a rapid dump if the price drops more than 50% in 24 hours
331+
return priceChange24h < -50;
319332
}
320333

321334
async checkTrustScore(tokenAddress: string): Promise<TokenSecurityData> {
@@ -358,15 +371,18 @@ export class TrustScoreManager {
358371
// TODO: change to starknet
359372
const wallet = new WalletProvider(runtime);
360373

361-
const prices = await wallet.fetchPrices(runtime);
362-
const solPrice = prices.solana.usd;
363-
const buySol = data.buy_amount / parseFloat(solPrice);
364-
const buy_value_usd = data.buy_amount * processedData.tradeData.price;
374+
const prices = await wallet.getTokenUsdValues();
375+
const solPrice = prices.solana?.usd;
376+
if (!solPrice) {
377+
throw new Error("Unable to fetch Solana price (cryptoName: 'solana').");
378+
}
379+
const buySol = data.buy_amount / solPrice;
380+
const buy_value_usd = data.buy_amount * processedData.tradeData.market.currentPrice;
365381

366382
const creationData = {
367383
token_address: tokenAddress,
368384
recommender_id: recommender.id,
369-
buy_price: processedData.tradeData.price,
385+
buy_price: processedData.tradeData.market.currentPrice,
370386
sell_price: 0,
371387
buy_timeStamp: new Date().toISOString(),
372388
sell_timeStamp: "",
@@ -469,11 +485,14 @@ export class TrustScoreManager {
469485
// TODO:
470486
const wallet = new WalletProvider(this.runtime);
471487

472-
const prices = await wallet.fetchPrices(runtime);
473-
const solPrice = prices.solana.usd;
474-
const sellSol = sellDetails.sell_amount / parseFloat(solPrice);
488+
const prices = await wallet.getTokenUsdValues();
489+
const solPrice = prices.solana?.usd;
490+
if (!solPrice) {
491+
throw new Error("Unable to fetch Solana price (cryptoName: 'solana').");
492+
}
493+
const sellSol = sellDetails.sell_amount / solPrice;
475494
const sell_value_usd =
476-
sellDetails.sell_amount * processedData.tradeData.price;
495+
sellDetails.sell_amount * processedData.tradeData.market.currentPrice;
477496
const trade = await this.trustScoreDb.getLatestTradePerformance(
478497
tokenAddress,
479498
recommender.id,
@@ -484,7 +503,7 @@ export class TrustScoreManager {
484503
processedData.dexScreenerData.pairs[0]?.marketCap || 0;
485504
const liquidity =
486505
processedData.dexScreenerData.pairs[0]?.liquidity.usd || 0;
487-
const sell_price = processedData.tradeData.price;
506+
const sell_price = processedData.tradeData.market.currentPrice;
488507
const profit_usd = sell_value_usd - trade.buy_value_usd;
489508
const profit_percent = (profit_usd / trade.buy_value_usd) * 100;
490509

pnpm-lock.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)