Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin-dexscreener lint #3069

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
odilitime marked this conversation as resolved.
Show resolved Hide resolved
odilitime marked this conversation as resolved.
Show resolved Hide resolved
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
Loading