Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Freytes authored Dec 15, 2024
1 parent 5476e42 commit 414183e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/plugin-goat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
import { Connection, PublicKey } from "@solana/web3.js";
import type { Chain, WalletClient, Signature, Balance } from "@goat-sdk/core";
import { getTokenBalance } from "@ai16z/plugin-solana/src/providers/tokenUtils";
import * as fs from 'fs';
import * as path from 'path';

// Validation schema for Twitter-related settings
const TwitterConfigSchema = z.object({
Expand Down Expand Up @@ -119,8 +121,7 @@ interface SolanaPluginExtended extends Plugin {
const REQUIRED_SETTINGS = {
WALLET_PUBLIC_KEY: "Solana wallet public key",
DEXSCREENER_WATCHLIST_ID: "DexScreener watchlist ID",
COINGECKO_API_KEY: "CoinGecko API key",
DEXSCREENER_WATCHLIST_URL: "DexScreener watchlist URL"
COINGECKO_API_KEY: "CoinGecko API key"
} as const;

// Add near the top imports
Expand Down Expand Up @@ -150,6 +151,20 @@ const validateSolanaAddress = (address: string | undefined): boolean => {
}
};

// Add function to load token addresses
function loadTokenAddresses(): string[] {
try {
const filePath = path.resolve(process.cwd(), '../characters/tokens/tokenaddresses.json');
const data = fs.readFileSync(filePath, 'utf8');
const addresses = JSON.parse(data);
elizaLogger.log("Loaded token addresses:", addresses);
return addresses;
} catch (error) {
elizaLogger.error("Failed to load token addresses:", error);
throw new Error("Token addresses file not found or invalid");
}
}

async function createGoatPlugin(
getSetting: (key: string) => string | undefined,
runtime?: IAgentRuntime
Expand Down Expand Up @@ -292,8 +307,7 @@ async function createGoatPlugin(
coingecko({ apiKey: getSetting("COINGECKO_API_KEY") })
],
dexscreener: {
watchlistUrl: getSetting("DEXSCREENER_WATCHLIST_URL") ||
`https://api.dexscreener.com/latest/dex/watchlists/${getSetting("DEXSCREENER_WATCHLIST_ID")}`,
watchlistUrl: `https://api.dexscreener.com/latest/dex/tokens/${loadTokenAddresses().join(',')}`,
chain: "solana",
updateInterval: parseInt(getSetting("UPDATE_INTERVAL") || "300")
},
Expand Down

0 comments on commit 414183e

Please sign in to comment.