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-quick-intel #2890

Merged
merged 3 commits into from
Jan 28, 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
35 changes: 27 additions & 8 deletions packages/plugin-quick-intel/src/actions/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,31 @@ import {
import { auditTemplate } from "../templates";
import { extractTokenInfo } from "../utils/chain-detection";

interface AuditResponse {
tokenDetails?: {
tokenName: string;
[key: string]: unknown;
};
[key: string]: unknown;
}

interface DexPair {
chainId: string;
[key: string]: unknown;
}

interface DexResponse {
pairs?: DexPair[];
otherChains?: string[];
}
class TokenAuditAction {
private apiKey: string;

constructor(apiKey: string) {
this.apiKey = apiKey;
}

async audit(chain: string, tokenAddress: string): Promise<any> {
async audit(chain: string, tokenAddress: string): Promise<AuditResponse> {
elizaLogger.log("Auditing token:", { chain, tokenAddress });
const myHeaders = new Headers();
myHeaders.append("X-QKNTL-KEY", this.apiKey);
Expand All @@ -41,7 +58,7 @@ class TokenAuditAction {
return await response.json();
}

async fetchDexData(tokenAddress: string, chain: string): Promise<any> {
async fetchDexData(tokenAddress: string, chain: string): Promise<DexResponse | null> {
elizaLogger.log("Fetching DEX data:", { tokenAddress, chain });
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
Expand All @@ -62,13 +79,13 @@ class TokenAuditAction {
}

// Filter pairs for the target chain
const chainPairs = data.pairs.filter((pair: any) =>
const chainPairs = data.pairs.filter((pair: DexPair) =>
pair.chainId.toLowerCase() === chain.toLowerCase() || pair.chainId.toLowerCase().includes(chain.toLowerCase())
);

const otherChains = data.pairs
.filter((pair: any) => pair.chainId.toLowerCase() !== chain.toLowerCase())
.map((pair: any) => pair.chainId);
.filter((pair: DexPair) => pair.chainId.toLowerCase() !== chain.toLowerCase())
.map((pair: DexPair) => pair.chainId) as string[];

return {
pairs: chainPairs,
Expand Down Expand Up @@ -116,14 +133,16 @@ export const auditAction: Action = {
action.fetchDexData(tokenAddress, chain)
]);

state = await runtime.composeState(message, {
const newState = await runtime.composeState(message, {
...state,
auditData: JSON.stringify(auditData, null, 2),
marketData: auditData?.tokenDetails?.tokenName ? JSON.stringify(dexData, null, 2) : null,
});


// Generate analysis using audit data
const context = composeContext({
state,
state: newState,
template: auditTemplate
});

Expand Down Expand Up @@ -159,7 +178,7 @@ export const auditAction: Action = {

if (callback) {
await callback({
text: `An error occurred while performing the token audit. Please try again later, and ensure the address is correct, and chain is supported.`,
text: "An error occurred while performing the token audit. Please try again later, and ensure the address is correct, and chain is supported.",
content: { error: "Internal server error" },
inReplyTo: message.id
});
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-quick-intel/src/utils/chain-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function normalizeChainName(chain: string): string | null {
}

export function extractTokenInfo(message: string): TokenInfo {
let result: TokenInfo = {
const result: TokenInfo = {
chain: null,
tokenAddress: null
};
Expand Down
Loading