Skip to content

Commit

Permalink
Fixed all the issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AIFlowML committed Jan 30, 2025
1 parent aac331d commit 0bcd6d9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 13 deletions.
41 changes: 41 additions & 0 deletions packages/plugin-dexscreener/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedVariables": "error"
},
"suspicious": {
"noExplicitAny": "error"
},
"style": {
"useConst": "error",
"useImportType": "off"
}
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 4,
"lineWidth": 100
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingCommas": "es5"
}
},
"files": {
"ignore": [
"dist/**/*",
"extra/**/*",
"node_modules/**/*"
]
}
}
10 changes: 9 additions & 1 deletion packages/plugin-dexscreener/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch"
"dev": "tsup --format esm --dts --watch",
"clean": "rm -rf dist",
"lint": "biome lint .",
"lint:fix": "biome check --apply .",
"format": "biome format .",
"format:fix": "biome format --write ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
},
"devDependencies": {
"@biomejs/biome": "1.9.4"
}
}
2 changes: 1 addition & 1 deletion packages/plugin-dexscreener/src/actions/tokenAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class TokenPriceAction implements Action {
suppressInitialMessage = true;
template = priceTemplate;

async validate(runtime: IAgentRuntime, message: Memory): Promise<boolean> {
async validate(_runtime: IAgentRuntime, message: Memory): Promise<boolean> {
const content = typeof message.content === 'string'
? message.content
: message.content?.text;
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin-dexscreener/src/actions/trendsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class LatestTokensAction implements Action {
suppressInitialMessage = true;
template = latestTokensTemplate;

async validate(runtime: IAgentRuntime, message: Memory): Promise<boolean> {
async validate(_runtime: IAgentRuntime, message: Memory): Promise<boolean> {
const content =
typeof message.content === "string"
? message.content
Expand All @@ -68,7 +68,7 @@ export class LatestTokensAction implements Action {
async handler(
runtime: IAgentRuntime,
message: Memory,
state?: State,
_state?: State,
_options: { [key: string]: unknown } = {},
callback?: HandlerCallback
): Promise<boolean> {
Expand Down Expand Up @@ -166,7 +166,7 @@ export class LatestBoostedTokensAction implements Action {
suppressInitialMessage = true;
template = latestBoostedTemplate;

async validate(runtime: IAgentRuntime, message: Memory): Promise<boolean> {
async validate(_runtime: IAgentRuntime, message: Memory): Promise<boolean> {
const content =
typeof message.content === "string"
? message.content
Expand All @@ -186,7 +186,7 @@ export class LatestBoostedTokensAction implements Action {
async handler(
runtime: IAgentRuntime,
message: Memory,
state?: State,
_state?: State,
_options: { [key: string]: unknown } = {},
callback?: HandlerCallback
): Promise<boolean> {
Expand Down Expand Up @@ -284,7 +284,7 @@ export class TopBoostedTokensAction implements Action {
suppressInitialMessage = true;
template = topBoostedTemplate;

async validate(runtime: IAgentRuntime, message: Memory): Promise<boolean> {
async validate(_runtime: IAgentRuntime, message: Memory): Promise<boolean> {
const content =
typeof message.content === "string"
? message.content
Expand All @@ -304,7 +304,7 @@ export class TopBoostedTokensAction implements Action {
async handler(
runtime: IAgentRuntime,
message: Memory,
state?: State,
_state?: State,
_options: { [key: string]: unknown } = {},
callback?: HandlerCallback
): Promise<boolean> {
Expand Down
25 changes: 20 additions & 5 deletions packages/plugin-dexscreener/src/providers/tokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@ interface TokenPriceData {
}
*/

interface DexScreenerPair {
baseToken: {
name: string;
symbol: string;
address: string;
decimals: number;
};
priceUsd: string;
liquidity?: {
usd: string;
};
volume?: {
h24: number;
};
}

export class TokenPriceProvider implements Provider {
async get(
runtime: IAgentRuntime,
_lengthruntime: IAgentRuntime,
message: Memory,
_state?: State
): Promise<string> {
Expand Down Expand Up @@ -93,21 +109,20 @@ export class TokenPriceProvider implements Provider {
return null;
}

private getBestPair(pairs: any[]): any {
private getBestPair(pairs: DexScreenerPair[]): DexScreenerPair {
return pairs.reduce((best, current) => {
const bestLiquidity = Number.parseFloat(best.liquidity?.usd || "0");
const currentLiquidity = Number.parseFloat(current.liquidity?.usd || "0");
return currentLiquidity > bestLiquidity ? current : best;
}, pairs[0]);
}

private formatPriceData(pair: any): string {
private formatPriceData(pair: DexScreenerPair): string {
const price = Number.parseFloat(pair.priceUsd).toFixed(6);
//const change24h = pair.priceChange?.h24?.toFixed(2) || "0.00";
const liquidity = Number.parseFloat(
pair.liquidity?.usd || "0"
).toLocaleString();
const volume = Number.parseFloat(pair.volume?.h24 || "0").toLocaleString();
const volume = (pair.volume?.h24 || 0).toLocaleString();

return `
The price of ${pair.baseToken.symbol} is $${price} USD, with liquidity of $${liquidity} and 24h volume of $${volume}.`;
Expand Down

0 comments on commit 0bcd6d9

Please sign in to comment.