From 319ff9ae21671cf2be586ff751476905ab675d7b Mon Sep 17 00:00:00 2001 From: michaelessiet Date: Fri, 14 Feb 2025 12:39:53 +0100 Subject: [PATCH 1/2] feat: support coingecko demo api key --- src/tools/coingecko/get_token_price_data.ts | 30 +- src/tools/coingecko/get_trending_tokens.ts | 22 +- src/types/index.ts | 697 ++++++++++---------- 3 files changed, 375 insertions(+), 374 deletions(-) diff --git a/src/tools/coingecko/get_token_price_data.ts b/src/tools/coingecko/get_token_price_data.ts index 409b418f..99e5c201 100644 --- a/src/tools/coingecko/get_token_price_data.ts +++ b/src/tools/coingecko/get_token_price_data.ts @@ -1,22 +1,22 @@ import { SolanaAgentKit } from "../../agent"; export async function getTokenPriceData( - agent: SolanaAgentKit, - tokenAddresses: string[], + agent: SolanaAgentKit, + tokenAddresses: string[], ) { - try { - const url = agent.config.COINGECKO_PRO_API_KEY - ? `https://pro-api.coingecko.com/api/v3/simple/token_price/solana?contract_addresses=${tokenAddresses.join(",")}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true&x_cg_pro_api_key=${agent.config.COINGECKO_PRO_API_KEY}` - : `https://api.coingecko.com/api/v3/simple/token_price/solana?contract_addresses=${tokenAddresses.join(",")}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true`; + try { + const url = agent.config.COINGECKO_PRO_API_KEY + ? `https://pro-api.coingecko.com/api/v3/simple/token_price/solana?contract_addresses=${tokenAddresses.join(",")}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true&x_cg_pro_api_key=${agent.config.COINGECKO_PRO_API_KEY}` + : `https://api.coingecko.com/api/v3/simple/token_price/solana?contract_addresses=${tokenAddresses.join(",")}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true${agent.config.COINGECKO_DEMO_API_KEY && `&x_cg_demo_api_key=${agent.config.COINGECKO_DEMO_API_KEY}`}`; - const res = await fetch(url); - const data = await res.json(); + const res = await fetch(url); + const data = await res.json(); - return data; - } catch (e) { - throw new Error( - // @ts-expect-error - error is an object - `Error fetching token price data from CoinGecko: ${e.message}`, - ); - } + return data; + } catch (e) { + throw new Error( + // @ts-expect-error - error is an object + `Error fetching token price data from CoinGecko: ${e.message}`, + ); + } } diff --git a/src/tools/coingecko/get_trending_tokens.ts b/src/tools/coingecko/get_trending_tokens.ts index c499452f..c4c43831 100644 --- a/src/tools/coingecko/get_trending_tokens.ts +++ b/src/tools/coingecko/get_trending_tokens.ts @@ -1,16 +1,16 @@ import { SolanaAgentKit } from "../../agent"; export async function getTrendingTokens(agent: SolanaAgentKit) { - try { - const url = agent.config.COINGECKO_PRO_API_KEY - ? `https://pro-api.coingecko.com/api/v3/search/trending?x_cg_pro_api_key=${agent.config.COINGECKO_PRO_API_KEY}` - : `https://api.coingecko.com/api/v3/search/trending`; - const res = await fetch(url); - const data = await res.json(); + try { + const url = agent.config.COINGECKO_PRO_API_KEY + ? `https://pro-api.coingecko.com/api/v3/search/trending?x_cg_pro_api_key=${agent.config.COINGECKO_PRO_API_KEY}` + : `https://api.coingecko.com/api/v3/search/trending${agent.config.COINGECKO_DEMO_API_KEY && `?x_cg_demo_api_key=${agent.config.COINGECKO_DEMO_API_KEY}`}`; + const res = await fetch(url); + const data = await res.json(); - return data; - } catch (e) { - // @ts-expect-error - e is an Error object - throw new Error(`Couldn't get trending tokens: ${e.message}`); - } + return data; + } catch (e) { + // @ts-expect-error - e is an Error object + throw new Error(`Couldn't get trending tokens: ${e.message}`); + } } diff --git a/src/types/index.ts b/src/types/index.ts index 99339fcd..195d0631 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -4,131 +4,132 @@ import { z } from "zod"; import { AlloraInference, AlloraTopic } from "@alloralabs/allora-sdk"; export interface Config { - OPENAI_API_KEY?: string; - PERPLEXITY_API_KEY?: string; - JUPITER_REFERRAL_ACCOUNT?: string; - JUPITER_FEE_BPS?: number; - FLASH_PRIVILEGE?: string; - FLEXLEND_API_KEY?: string; - HELIUS_API_KEY?: string; - PRIORITY_LEVEL?: "medium" | "high" | "veryHigh"; // medium, high, or veryHigh - SOLUTIOFI_API_KEY?: string; - ETHEREUM_PRIVATE_KEY?: string; - ALLORA_API_KEY?: string; - ALLORA_API_URL?: string; - ALLORA_NETWORK?: string; - ELFA_AI_API_KEY?: string; - COINGECKO_PRO_API_KEY?: string; + OPENAI_API_KEY?: string; + PERPLEXITY_API_KEY?: string; + JUPITER_REFERRAL_ACCOUNT?: string; + JUPITER_FEE_BPS?: number; + FLASH_PRIVILEGE?: string; + FLEXLEND_API_KEY?: string; + HELIUS_API_KEY?: string; + PRIORITY_LEVEL?: "medium" | "high" | "veryHigh"; // medium, high, or veryHigh + SOLUTIOFI_API_KEY?: string; + ETHEREUM_PRIVATE_KEY?: string; + ALLORA_API_KEY?: string; + ALLORA_API_URL?: string; + ALLORA_NETWORK?: string; + ELFA_AI_API_KEY?: string; + COINGECKO_PRO_API_KEY?: string; + COINGECKO_DEMO_API_KEY?: string; } export interface Creator { - address: string; - percentage: number; + address: string; + percentage: number; } export interface CollectionOptions { - name: string; - uri: string; - royaltyBasisPoints?: number; - creators?: Creator[]; + name: string; + uri: string; + royaltyBasisPoints?: number; + creators?: Creator[]; } // Add return type interface export interface CollectionDeployment { - collectionAddress: PublicKey; - signature: Uint8Array; + collectionAddress: PublicKey; + signature: Uint8Array; } export interface MintCollectionNFTResponse { - mint: PublicKey; - metadata: PublicKey; + mint: PublicKey; + metadata: PublicKey; } export interface PumpFunTokenOptions { - twitter?: string; - telegram?: string; - website?: string; - initialLiquiditySOL?: number; - slippageBps?: number; - priorityFee?: number; + twitter?: string; + telegram?: string; + website?: string; + initialLiquiditySOL?: number; + slippageBps?: number; + priorityFee?: number; } export interface PumpfunLaunchResponse { - signature: string; - mint: string; - metadataUri?: string; - error?: string; + signature: string; + mint: string; + metadataUri?: string; + error?: string; } /** * Lulo Account Details response format */ export interface LuloAccountDetailsResponse { - totalValue: number; - interestEarned: number; - realtimeApy: number; - settings: { - owner: string; - allowedProtocols: string | null; - homebase: string | null; - minimumRate: string; - }; + totalValue: number; + interestEarned: number; + realtimeApy: number; + settings: { + owner: string; + allowedProtocols: string | null; + homebase: string | null; + minimumRate: string; + }; } export interface JupiterTokenData { - address: string; - name: string; - symbol: string; - decimals: number; - tags: string[]; - logoURI: string; - daily_volume: number; - freeze_authority: string | null; - mint_authority: string | null; - permanent_delegate: string | null; - extensions: { - coingeckoId?: string; - }; + address: string; + name: string; + symbol: string; + decimals: number; + tags: string[]; + logoURI: string; + daily_volume: number; + freeze_authority: string | null; + mint_authority: string | null; + permanent_delegate: string | null; + extensions: { + coingeckoId?: string; + }; } export interface FetchPriceResponse { - status: "success" | "error"; - tokenId?: string; - priceInUSDC?: string; - message?: string; - code?: string; + status: "success" | "error"; + tokenId?: string; + priceInUSDC?: string; + message?: string; + code?: string; } export interface PythFetchPriceResponse { - status: "success" | "error"; - tokenSymbol: string; - priceFeedID?: string; - price?: string; - message?: string; - code?: string; + status: "success" | "error"; + tokenSymbol: string; + priceFeedID?: string; + price?: string; + message?: string; + code?: string; } export interface GibworkCreateTaskReponse { - status: "success" | "error"; - taskId?: string | undefined; - signature?: string | undefined; + status: "success" | "error"; + taskId?: string | undefined; + signature?: string | undefined; } /** * Example of an action with input and output */ export interface ActionExample { - input: Record; - output: Record; - explanation: string; + input: Record; + output: Record; + explanation: string; } /** * Handler function type for executing the action */ export type Handler = ( - agent: SolanaAgentKit, - input: Record, + agent: SolanaAgentKit, + input: Record, ) => Promise>; /** @@ -136,301 +137,301 @@ export type Handler = ( * This interface makes it easier to implement actions across different frameworks */ export interface Action { - /** - * Unique name of the action - */ - name: string; - - /** - * Alternative names/phrases that can trigger this action - */ - similes: string[]; - - /** - * Detailed description of what the action does - */ - description: string; - - /** - * Array of example inputs and outputs for the action - * Each inner array represents a group of related examples - */ - examples: ActionExample[][]; - - /** - * Zod schema for input validation - */ - schema: z.ZodType; - - /** - * Function that executes the action - */ - handler: Handler; + /** + * Unique name of the action + */ + name: string; + + /** + * Alternative names/phrases that can trigger this action + */ + similes: string[]; + + /** + * Detailed description of what the action does + */ + description: string; + + /** + * Array of example inputs and outputs for the action + * Each inner array represents a group of related examples + */ + examples: ActionExample[][]; + + /** + * Zod schema for input validation + */ + schema: z.ZodType; + + /** + * Function that executes the action + */ + handler: Handler; } export interface TokenCheck { - tokenProgram: string; - tokenType: string; - risks: Array<{ - name: string; - level: string; - description: string; - score: number; - }>; - score: number; + tokenProgram: string; + tokenType: string; + risks: Array<{ + name: string; + level: string; + description: string; + score: number; + }>; + score: number; } export interface PythPriceFeedIDItem { - id: string; - attributes: { - asset_type: string; - base: string; - }; + id: string; + attributes: { + asset_type: string; + base: string; + }; } export interface PythPriceItem { - binary: { - data: string[]; - encoding: string; - }; - parsed: [ - Array<{ - id: string; - price: { - price: string; - conf: string; - expo: number; - publish_time: number; - }; - ema_price: { - price: string; - conf: string; - expo: number; - publish_time: number; - }; - metadata: { - slot: number; - proof_available_time: number; - prev_publish_time: number; - }; - }>, - ]; + binary: { + data: string[]; + encoding: string; + }; + parsed: [ + Array<{ + id: string; + price: { + price: string; + conf: string; + expo: number; + publish_time: number; + }; + ema_price: { + price: string; + conf: string; + expo: number; + publish_time: number; + }; + metadata: { + slot: number; + proof_available_time: number; + prev_publish_time: number; + }; + }>, + ]; } export interface OrderParams { - quantity: number; - side: string; - price: number; + quantity: number; + side: string; + price: number; } export interface BatchOrderPattern { - side: string; - totalQuantity?: number; - priceRange?: { - min?: number; - max?: number; - }; - spacing?: { - type: "percentage" | "fixed"; - value: number; - }; - numberOfOrders?: number; - individualQuantity?: number; + side: string; + totalQuantity?: number; + priceRange?: { + min?: number; + max?: number; + }; + spacing?: { + type: "percentage" | "fixed"; + value: number; + }; + numberOfOrders?: number; + individualQuantity?: number; } export interface FlashTradeParams { - token: string; - side: "long" | "short"; - collateralUsd: number; - leverage: number; + token: string; + side: "long" | "short"; + collateralUsd: number; + leverage: number; } export interface FlashCloseTradeParams { - token: string; - side: "long" | "short"; + token: string; + side: "long" | "short"; } export interface HeliusWebhookResponse { - webhookURL: string; - webhookID: string; + webhookURL: string; + webhookID: string; } export interface HeliusWebhookIdResponse { - wallet: string; - webhookURL: string; - transactionTypes: string[]; - accountAddresses: string[]; - webhookType: string; + wallet: string; + webhookURL: string; + transactionTypes: string[]; + accountAddresses: string[]; + webhookType: string; } export interface PriorityFeeResponse { - jsonrpc: string; - id: string; - method: string; - params: Array<{ - transaction: string; - options: { priorityLevel: string }; - }>; + jsonrpc: string; + id: string; + method: string; + params: Array<{ + transaction: string; + options: { priorityLevel: string }; + }>; } export interface AlloraPriceInferenceResponse { - status: "success" | "error"; - tokenSymbol?: string; - timeframe?: string; - priceInference?: string; - message?: string; - code?: string; + status: "success" | "error"; + tokenSymbol?: string; + timeframe?: string; + priceInference?: string; + message?: string; + code?: string; } export interface AlloraGetAllTopicsResponse { - status: "success" | "error"; - topics?: AlloraTopic[]; - message?: string; - code?: string; + status: "success" | "error"; + topics?: AlloraTopic[]; + message?: string; + code?: string; } export interface AlloraGetInferenceByTopicIdResponse { - status: "success" | "error"; - topicId?: number; - inference?: AlloraInference; - message?: string; - code?: string; + status: "success" | "error"; + topicId?: number; + inference?: AlloraInference; + message?: string; + code?: string; } export interface SwitchboardSimulateFeedResponse { - status: "success" | "error"; - feed?: string; - value?: number; - message?: string; - code?: string; + status: "success" | "error"; + feed?: string; + value?: number; + message?: string; + code?: string; } // DeBridge Types ref: https://dln.debridge.finance/v1.0/ export interface deBridgeChainInfo { - chainId: string; - originalChainId: string; - chainName: string; + chainId: string; + originalChainId: string; + chainName: string; } export interface deBridgeSupportedChainsResponse { - chains: deBridgeChainInfo[]; + chains: deBridgeChainInfo[]; } export interface deBridgeTokenInfo { - name: string; - symbol: string; - address: string; - decimals: number; - chainId?: string; + name: string; + symbol: string; + address: string; + decimals: number; + chainId?: string; } export interface deBridgeTokensInfoResponse { - tokens: Record; + tokens: Record; } export interface deBridgeQuoteInput { - srcChainId: string; - srcChainTokenIn: string; - srcChainTokenInAmount: string; - dstChainId: string; - dstChainTokenOut: string; - dstChainTokenOutAmount?: string; - slippage?: number; - senderAddress?: string; + srcChainId: string; + srcChainTokenIn: string; + srcChainTokenInAmount: string; + dstChainId: string; + dstChainTokenOut: string; + dstChainTokenOutAmount?: string; + slippage?: number; + senderAddress?: string; } export interface deBridgeQuoteResponse { - estimation: { - srcChainTokenIn: { - amount: string; - tokenAddress: string; - decimals: number; - symbol: string; - }; - dstChainTokenOut: { - amount: string; - tokenAddress: string; - decimals: number; - symbol: string; - }; - fees: { - srcChainTokenIn: string; - dstChainTokenOut: string; - }; - }; + estimation: { + srcChainTokenIn: { + amount: string; + tokenAddress: string; + decimals: number; + symbol: string; + }; + dstChainTokenOut: { + amount: string; + tokenAddress: string; + decimals: number; + symbol: string; + }; + fees: { + srcChainTokenIn: string; + dstChainTokenOut: string; + }; + }; } export interface deBridgeOrderInput { - srcChainId: string; - srcChainTokenIn: string; - srcChainTokenInAmount: string; - dstChainId: string; - dstChainTokenOut: string; - dstChainTokenOutRecipient: string; - account: string; - dstChainTokenOutAmount?: string; - slippage?: number; - additionalTakerRewardBps?: number; - srcIntermediaryTokenAddress?: string; - dstIntermediaryTokenAddress?: string; - dstIntermediaryTokenSpenderAddress?: string; - intermediaryTokenUSDPrice?: number; - srcAllowedCancelBeneficiary?: string; - referralCode?: number; - affiliateFeePercent?: number; - srcChainOrderAuthorityAddress?: string; - srcChainRefundAddress?: string; - dstChainOrderAuthorityAddress?: string; - prependOperatingExpenses?: boolean; - deBridgeApp?: string; + srcChainId: string; + srcChainTokenIn: string; + srcChainTokenInAmount: string; + dstChainId: string; + dstChainTokenOut: string; + dstChainTokenOutRecipient: string; + account: string; + dstChainTokenOutAmount?: string; + slippage?: number; + additionalTakerRewardBps?: number; + srcIntermediaryTokenAddress?: string; + dstIntermediaryTokenAddress?: string; + dstIntermediaryTokenSpenderAddress?: string; + intermediaryTokenUSDPrice?: number; + srcAllowedCancelBeneficiary?: string; + referralCode?: number; + affiliateFeePercent?: number; + srcChainOrderAuthorityAddress?: string; + srcChainRefundAddress?: string; + dstChainOrderAuthorityAddress?: string; + prependOperatingExpenses?: boolean; + deBridgeApp?: string; } export interface deBridgeOrderResponse { - tx: { - data: string; - to: string; - value: string; - }; - estimation: { - srcChainTokenIn: { - amount: string; - tokenAddress: string; - decimals: number; - symbol: string; - }; - dstChainTokenOut: { - amount: string; - tokenAddress: string; - decimals: number; - symbol: string; - }; - fees: { - srcChainTokenIn: string; - dstChainTokenOut: string; - }; - }; + tx: { + data: string; + to: string; + value: string; + }; + estimation: { + srcChainTokenIn: { + amount: string; + tokenAddress: string; + decimals: number; + symbol: string; + }; + dstChainTokenOut: { + amount: string; + tokenAddress: string; + decimals: number; + symbol: string; + }; + fees: { + srcChainTokenIn: string; + dstChainTokenOut: string; + }; + }; } export interface deBridgeOrderIdsResponse { - orderIds: string[]; - errorCode?: number; - errorMessage?: string; + orderIds: string[]; + errorCode?: number; + errorMessage?: string; } export interface deBridgeOrderStatusResponse { - orderId: string; - status: - | "None" - | "Created" - | "Fulfilled" - | "SentUnlock" - | "OrderCancelled" - | "SentOrderCancel" - | "ClaimedUnlock" - | "ClaimedOrderCancel"; - srcChainTxHash?: string; - dstChainTxHash?: string; - orderLink?: string; - error?: string; + orderId: string; + status: + | "None" + | "Created" + | "Fulfilled" + | "SentUnlock" + | "OrderCancelled" + | "SentOrderCancel" + | "ClaimedUnlock" + | "ClaimedOrderCancel"; + srcChainTxHash?: string; + dstChainTxHash?: string; + orderLink?: string; + error?: string; } // Regular expressions for validating addresses @@ -439,69 +440,69 @@ export const EVM_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/; // Chain ID validation schema export const chainIdSchema = z.string().refine( - (val) => { - const num = Number.parseInt(val, 10); - // Regular chain IDs (1-99999) - if (num > 0 && num < 100000) { - return true; - } - // Special chain IDs (100000000+) - if (num >= 100000000) { - return true; - } - // Solana chain ID (7565164) - if (num === 7565164) { - return true; - } - return false; - }, - { - message: "Chain ID must be either 1-99999, 7565164 (Solana), or 100000000+", - }, + (val) => { + const num = Number.parseInt(val, 10); + // Regular chain IDs (1-99999) + if (num > 0 && num < 100000) { + return true; + } + // Special chain IDs (100000000+) + if (num >= 100000000) { + return true; + } + // Solana chain ID (7565164) + if (num === 7565164) { + return true; + } + return false; + }, + { + message: "Chain ID must be either 1-99999, 7565164 (Solana), or 100000000+", + }, ); // Token info parameters schema export const getDebridgeTokensInfoSchema = z.object({ - /** Chain ID to query tokens for */ - chainId: chainIdSchema.describe( - "Chain ID to get token information for. Examples: '1' (Ethereum), '56' (BNB Chain), '7565164' (Solana)", - ), - - /** Optional token address to filter results */ - tokenAddress: z - .string() - .optional() - .describe( - "Token address to query information for. For EVM chains: use 0x-prefixed address. For Solana: use base58 token address", - ), - - /** Optional search term to filter tokens by name or symbol */ - search: z - .string() - .optional() - .describe( - "Search term to filter tokens by name or symbol (e.g., 'USDC', 'Ethereum')", - ), + /** Chain ID to query tokens for */ + chainId: chainIdSchema.describe( + "Chain ID to get token information for. Examples: '1' (Ethereum), '56' (BNB Chain), '7565164' (Solana)", + ), + + /** Optional token address to filter results */ + tokenAddress: z + .string() + .optional() + .describe( + "Token address to query information for. For EVM chains: use 0x-prefixed address. For Solana: use base58 token address", + ), + + /** Optional search term to filter tokens by name or symbol */ + search: z + .string() + .optional() + .describe( + "Search term to filter tokens by name or symbol (e.g., 'USDC', 'Ethereum')", + ), }); export type GetDebridgeTokensInfoParams = z.infer< - typeof getDebridgeTokensInfoSchema + typeof getDebridgeTokensInfoSchema >; export interface FluxbeamServerResponse { - signature: string; + signature: string; } export interface Quote { - amountIn: number; - inputMint: string; - minimumOut: number; - outAmount: number; - outputMint: string; - pool: string; - program: string; + amountIn: number; + inputMint: string; + minimumOut: number; + outAmount: number; + outputMint: string; + pool: string; + program: string; } export interface TransformedResponse { - quote: Quote; + quote: Quote; } From db408ed4d09a258e3665b4d223642c48b413d8a8 Mon Sep 17 00:00:00 2001 From: michaelessiet Date: Fri, 14 Feb 2025 12:42:01 +0100 Subject: [PATCH 2/2] lint --- src/actions/elfa_ai/elfa_ai_actions.ts | 5 +- src/tools/coingecko/get_token_price_data.ts | 30 +- src/tools/coingecko/get_trending_tokens.ts | 22 +- src/types/index.ts | 698 ++++++++++---------- 4 files changed, 379 insertions(+), 376 deletions(-) diff --git a/src/actions/elfa_ai/elfa_ai_actions.ts b/src/actions/elfa_ai/elfa_ai_actions.ts index 68a154a4..fd2b70a3 100644 --- a/src/actions/elfa_ai/elfa_ai_actions.ts +++ b/src/actions/elfa_ai/elfa_ai_actions.ts @@ -270,7 +270,10 @@ export const elfaGetTopMentionsByTickerAction: Action = { ], ], schema: z.object({ - ticker: z.string().min(1).describe("Ticker symbol to retrieve mentions for"), + ticker: z + .string() + .min(1) + .describe("Ticker symbol to retrieve mentions for"), timeWindow: z .string() .min(1) diff --git a/src/tools/coingecko/get_token_price_data.ts b/src/tools/coingecko/get_token_price_data.ts index 99e5c201..73c127e8 100644 --- a/src/tools/coingecko/get_token_price_data.ts +++ b/src/tools/coingecko/get_token_price_data.ts @@ -1,22 +1,22 @@ import { SolanaAgentKit } from "../../agent"; export async function getTokenPriceData( - agent: SolanaAgentKit, - tokenAddresses: string[], + agent: SolanaAgentKit, + tokenAddresses: string[], ) { - try { - const url = agent.config.COINGECKO_PRO_API_KEY - ? `https://pro-api.coingecko.com/api/v3/simple/token_price/solana?contract_addresses=${tokenAddresses.join(",")}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true&x_cg_pro_api_key=${agent.config.COINGECKO_PRO_API_KEY}` - : `https://api.coingecko.com/api/v3/simple/token_price/solana?contract_addresses=${tokenAddresses.join(",")}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true${agent.config.COINGECKO_DEMO_API_KEY && `&x_cg_demo_api_key=${agent.config.COINGECKO_DEMO_API_KEY}`}`; + try { + const url = agent.config.COINGECKO_PRO_API_KEY + ? `https://pro-api.coingecko.com/api/v3/simple/token_price/solana?contract_addresses=${tokenAddresses.join(",")}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true&x_cg_pro_api_key=${agent.config.COINGECKO_PRO_API_KEY}` + : `https://api.coingecko.com/api/v3/simple/token_price/solana?contract_addresses=${tokenAddresses.join(",")}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true${agent.config.COINGECKO_DEMO_API_KEY && `&x_cg_demo_api_key=${agent.config.COINGECKO_DEMO_API_KEY}`}`; - const res = await fetch(url); - const data = await res.json(); + const res = await fetch(url); + const data = await res.json(); - return data; - } catch (e) { - throw new Error( - // @ts-expect-error - error is an object - `Error fetching token price data from CoinGecko: ${e.message}`, - ); - } + return data; + } catch (e) { + throw new Error( + // @ts-expect-error - error is an object + `Error fetching token price data from CoinGecko: ${e.message}`, + ); + } } diff --git a/src/tools/coingecko/get_trending_tokens.ts b/src/tools/coingecko/get_trending_tokens.ts index c4c43831..1a138847 100644 --- a/src/tools/coingecko/get_trending_tokens.ts +++ b/src/tools/coingecko/get_trending_tokens.ts @@ -1,16 +1,16 @@ import { SolanaAgentKit } from "../../agent"; export async function getTrendingTokens(agent: SolanaAgentKit) { - try { - const url = agent.config.COINGECKO_PRO_API_KEY - ? `https://pro-api.coingecko.com/api/v3/search/trending?x_cg_pro_api_key=${agent.config.COINGECKO_PRO_API_KEY}` - : `https://api.coingecko.com/api/v3/search/trending${agent.config.COINGECKO_DEMO_API_KEY && `?x_cg_demo_api_key=${agent.config.COINGECKO_DEMO_API_KEY}`}`; - const res = await fetch(url); - const data = await res.json(); + try { + const url = agent.config.COINGECKO_PRO_API_KEY + ? `https://pro-api.coingecko.com/api/v3/search/trending?x_cg_pro_api_key=${agent.config.COINGECKO_PRO_API_KEY}` + : `https://api.coingecko.com/api/v3/search/trending${agent.config.COINGECKO_DEMO_API_KEY && `?x_cg_demo_api_key=${agent.config.COINGECKO_DEMO_API_KEY}`}`; + const res = await fetch(url); + const data = await res.json(); - return data; - } catch (e) { - // @ts-expect-error - e is an Error object - throw new Error(`Couldn't get trending tokens: ${e.message}`); - } + return data; + } catch (e) { + // @ts-expect-error - e is an Error object + throw new Error(`Couldn't get trending tokens: ${e.message}`); + } } diff --git a/src/types/index.ts b/src/types/index.ts index 195d0631..9a93d1e6 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -4,132 +4,132 @@ import { z } from "zod"; import { AlloraInference, AlloraTopic } from "@alloralabs/allora-sdk"; export interface Config { - OPENAI_API_KEY?: string; - PERPLEXITY_API_KEY?: string; - JUPITER_REFERRAL_ACCOUNT?: string; - JUPITER_FEE_BPS?: number; - FLASH_PRIVILEGE?: string; - FLEXLEND_API_KEY?: string; - HELIUS_API_KEY?: string; - PRIORITY_LEVEL?: "medium" | "high" | "veryHigh"; // medium, high, or veryHigh - SOLUTIOFI_API_KEY?: string; - ETHEREUM_PRIVATE_KEY?: string; - ALLORA_API_KEY?: string; - ALLORA_API_URL?: string; - ALLORA_NETWORK?: string; - ELFA_AI_API_KEY?: string; - COINGECKO_PRO_API_KEY?: string; - COINGECKO_DEMO_API_KEY?: string; + OPENAI_API_KEY?: string; + PERPLEXITY_API_KEY?: string; + JUPITER_REFERRAL_ACCOUNT?: string; + JUPITER_FEE_BPS?: number; + FLASH_PRIVILEGE?: string; + FLEXLEND_API_KEY?: string; + HELIUS_API_KEY?: string; + PRIORITY_LEVEL?: "medium" | "high" | "veryHigh"; // medium, high, or veryHigh + SOLUTIOFI_API_KEY?: string; + ETHEREUM_PRIVATE_KEY?: string; + ALLORA_API_KEY?: string; + ALLORA_API_URL?: string; + ALLORA_NETWORK?: string; + ELFA_AI_API_KEY?: string; + COINGECKO_PRO_API_KEY?: string; + COINGECKO_DEMO_API_KEY?: string; } export interface Creator { - address: string; - percentage: number; + address: string; + percentage: number; } export interface CollectionOptions { - name: string; - uri: string; - royaltyBasisPoints?: number; - creators?: Creator[]; + name: string; + uri: string; + royaltyBasisPoints?: number; + creators?: Creator[]; } // Add return type interface export interface CollectionDeployment { - collectionAddress: PublicKey; - signature: Uint8Array; + collectionAddress: PublicKey; + signature: Uint8Array; } export interface MintCollectionNFTResponse { - mint: PublicKey; - metadata: PublicKey; + mint: PublicKey; + metadata: PublicKey; } export interface PumpFunTokenOptions { - twitter?: string; - telegram?: string; - website?: string; - initialLiquiditySOL?: number; - slippageBps?: number; - priorityFee?: number; + twitter?: string; + telegram?: string; + website?: string; + initialLiquiditySOL?: number; + slippageBps?: number; + priorityFee?: number; } export interface PumpfunLaunchResponse { - signature: string; - mint: string; - metadataUri?: string; - error?: string; + signature: string; + mint: string; + metadataUri?: string; + error?: string; } /** * Lulo Account Details response format */ export interface LuloAccountDetailsResponse { - totalValue: number; - interestEarned: number; - realtimeApy: number; - settings: { - owner: string; - allowedProtocols: string | null; - homebase: string | null; - minimumRate: string; - }; + totalValue: number; + interestEarned: number; + realtimeApy: number; + settings: { + owner: string; + allowedProtocols: string | null; + homebase: string | null; + minimumRate: string; + }; } export interface JupiterTokenData { - address: string; - name: string; - symbol: string; - decimals: number; - tags: string[]; - logoURI: string; - daily_volume: number; - freeze_authority: string | null; - mint_authority: string | null; - permanent_delegate: string | null; - extensions: { - coingeckoId?: string; - }; + address: string; + name: string; + symbol: string; + decimals: number; + tags: string[]; + logoURI: string; + daily_volume: number; + freeze_authority: string | null; + mint_authority: string | null; + permanent_delegate: string | null; + extensions: { + coingeckoId?: string; + }; } export interface FetchPriceResponse { - status: "success" | "error"; - tokenId?: string; - priceInUSDC?: string; - message?: string; - code?: string; + status: "success" | "error"; + tokenId?: string; + priceInUSDC?: string; + message?: string; + code?: string; } export interface PythFetchPriceResponse { - status: "success" | "error"; - tokenSymbol: string; - priceFeedID?: string; - price?: string; - message?: string; - code?: string; + status: "success" | "error"; + tokenSymbol: string; + priceFeedID?: string; + price?: string; + message?: string; + code?: string; } export interface GibworkCreateTaskReponse { - status: "success" | "error"; - taskId?: string | undefined; - signature?: string | undefined; + status: "success" | "error"; + taskId?: string | undefined; + signature?: string | undefined; } /** * Example of an action with input and output */ export interface ActionExample { - input: Record; - output: Record; - explanation: string; + input: Record; + output: Record; + explanation: string; } /** * Handler function type for executing the action */ export type Handler = ( - agent: SolanaAgentKit, - input: Record, + agent: SolanaAgentKit, + input: Record, ) => Promise>; /** @@ -137,301 +137,301 @@ export type Handler = ( * This interface makes it easier to implement actions across different frameworks */ export interface Action { - /** - * Unique name of the action - */ - name: string; - - /** - * Alternative names/phrases that can trigger this action - */ - similes: string[]; - - /** - * Detailed description of what the action does - */ - description: string; - - /** - * Array of example inputs and outputs for the action - * Each inner array represents a group of related examples - */ - examples: ActionExample[][]; - - /** - * Zod schema for input validation - */ - schema: z.ZodType; - - /** - * Function that executes the action - */ - handler: Handler; + /** + * Unique name of the action + */ + name: string; + + /** + * Alternative names/phrases that can trigger this action + */ + similes: string[]; + + /** + * Detailed description of what the action does + */ + description: string; + + /** + * Array of example inputs and outputs for the action + * Each inner array represents a group of related examples + */ + examples: ActionExample[][]; + + /** + * Zod schema for input validation + */ + schema: z.ZodType; + + /** + * Function that executes the action + */ + handler: Handler; } export interface TokenCheck { - tokenProgram: string; - tokenType: string; - risks: Array<{ - name: string; - level: string; - description: string; - score: number; - }>; - score: number; + tokenProgram: string; + tokenType: string; + risks: Array<{ + name: string; + level: string; + description: string; + score: number; + }>; + score: number; } export interface PythPriceFeedIDItem { - id: string; - attributes: { - asset_type: string; - base: string; - }; + id: string; + attributes: { + asset_type: string; + base: string; + }; } export interface PythPriceItem { - binary: { - data: string[]; - encoding: string; - }; - parsed: [ - Array<{ - id: string; - price: { - price: string; - conf: string; - expo: number; - publish_time: number; - }; - ema_price: { - price: string; - conf: string; - expo: number; - publish_time: number; - }; - metadata: { - slot: number; - proof_available_time: number; - prev_publish_time: number; - }; - }>, - ]; + binary: { + data: string[]; + encoding: string; + }; + parsed: [ + Array<{ + id: string; + price: { + price: string; + conf: string; + expo: number; + publish_time: number; + }; + ema_price: { + price: string; + conf: string; + expo: number; + publish_time: number; + }; + metadata: { + slot: number; + proof_available_time: number; + prev_publish_time: number; + }; + }>, + ]; } export interface OrderParams { - quantity: number; - side: string; - price: number; + quantity: number; + side: string; + price: number; } export interface BatchOrderPattern { - side: string; - totalQuantity?: number; - priceRange?: { - min?: number; - max?: number; - }; - spacing?: { - type: "percentage" | "fixed"; - value: number; - }; - numberOfOrders?: number; - individualQuantity?: number; + side: string; + totalQuantity?: number; + priceRange?: { + min?: number; + max?: number; + }; + spacing?: { + type: "percentage" | "fixed"; + value: number; + }; + numberOfOrders?: number; + individualQuantity?: number; } export interface FlashTradeParams { - token: string; - side: "long" | "short"; - collateralUsd: number; - leverage: number; + token: string; + side: "long" | "short"; + collateralUsd: number; + leverage: number; } export interface FlashCloseTradeParams { - token: string; - side: "long" | "short"; + token: string; + side: "long" | "short"; } export interface HeliusWebhookResponse { - webhookURL: string; - webhookID: string; + webhookURL: string; + webhookID: string; } export interface HeliusWebhookIdResponse { - wallet: string; - webhookURL: string; - transactionTypes: string[]; - accountAddresses: string[]; - webhookType: string; + wallet: string; + webhookURL: string; + transactionTypes: string[]; + accountAddresses: string[]; + webhookType: string; } export interface PriorityFeeResponse { - jsonrpc: string; - id: string; - method: string; - params: Array<{ - transaction: string; - options: { priorityLevel: string }; - }>; + jsonrpc: string; + id: string; + method: string; + params: Array<{ + transaction: string; + options: { priorityLevel: string }; + }>; } export interface AlloraPriceInferenceResponse { - status: "success" | "error"; - tokenSymbol?: string; - timeframe?: string; - priceInference?: string; - message?: string; - code?: string; + status: "success" | "error"; + tokenSymbol?: string; + timeframe?: string; + priceInference?: string; + message?: string; + code?: string; } export interface AlloraGetAllTopicsResponse { - status: "success" | "error"; - topics?: AlloraTopic[]; - message?: string; - code?: string; + status: "success" | "error"; + topics?: AlloraTopic[]; + message?: string; + code?: string; } export interface AlloraGetInferenceByTopicIdResponse { - status: "success" | "error"; - topicId?: number; - inference?: AlloraInference; - message?: string; - code?: string; + status: "success" | "error"; + topicId?: number; + inference?: AlloraInference; + message?: string; + code?: string; } export interface SwitchboardSimulateFeedResponse { - status: "success" | "error"; - feed?: string; - value?: number; - message?: string; - code?: string; + status: "success" | "error"; + feed?: string; + value?: number; + message?: string; + code?: string; } // DeBridge Types ref: https://dln.debridge.finance/v1.0/ export interface deBridgeChainInfo { - chainId: string; - originalChainId: string; - chainName: string; + chainId: string; + originalChainId: string; + chainName: string; } export interface deBridgeSupportedChainsResponse { - chains: deBridgeChainInfo[]; + chains: deBridgeChainInfo[]; } export interface deBridgeTokenInfo { - name: string; - symbol: string; - address: string; - decimals: number; - chainId?: string; + name: string; + symbol: string; + address: string; + decimals: number; + chainId?: string; } export interface deBridgeTokensInfoResponse { - tokens: Record; + tokens: Record; } export interface deBridgeQuoteInput { - srcChainId: string; - srcChainTokenIn: string; - srcChainTokenInAmount: string; - dstChainId: string; - dstChainTokenOut: string; - dstChainTokenOutAmount?: string; - slippage?: number; - senderAddress?: string; + srcChainId: string; + srcChainTokenIn: string; + srcChainTokenInAmount: string; + dstChainId: string; + dstChainTokenOut: string; + dstChainTokenOutAmount?: string; + slippage?: number; + senderAddress?: string; } export interface deBridgeQuoteResponse { - estimation: { - srcChainTokenIn: { - amount: string; - tokenAddress: string; - decimals: number; - symbol: string; - }; - dstChainTokenOut: { - amount: string; - tokenAddress: string; - decimals: number; - symbol: string; - }; - fees: { - srcChainTokenIn: string; - dstChainTokenOut: string; - }; - }; + estimation: { + srcChainTokenIn: { + amount: string; + tokenAddress: string; + decimals: number; + symbol: string; + }; + dstChainTokenOut: { + amount: string; + tokenAddress: string; + decimals: number; + symbol: string; + }; + fees: { + srcChainTokenIn: string; + dstChainTokenOut: string; + }; + }; } export interface deBridgeOrderInput { - srcChainId: string; - srcChainTokenIn: string; - srcChainTokenInAmount: string; - dstChainId: string; - dstChainTokenOut: string; - dstChainTokenOutRecipient: string; - account: string; - dstChainTokenOutAmount?: string; - slippage?: number; - additionalTakerRewardBps?: number; - srcIntermediaryTokenAddress?: string; - dstIntermediaryTokenAddress?: string; - dstIntermediaryTokenSpenderAddress?: string; - intermediaryTokenUSDPrice?: number; - srcAllowedCancelBeneficiary?: string; - referralCode?: number; - affiliateFeePercent?: number; - srcChainOrderAuthorityAddress?: string; - srcChainRefundAddress?: string; - dstChainOrderAuthorityAddress?: string; - prependOperatingExpenses?: boolean; - deBridgeApp?: string; + srcChainId: string; + srcChainTokenIn: string; + srcChainTokenInAmount: string; + dstChainId: string; + dstChainTokenOut: string; + dstChainTokenOutRecipient: string; + account: string; + dstChainTokenOutAmount?: string; + slippage?: number; + additionalTakerRewardBps?: number; + srcIntermediaryTokenAddress?: string; + dstIntermediaryTokenAddress?: string; + dstIntermediaryTokenSpenderAddress?: string; + intermediaryTokenUSDPrice?: number; + srcAllowedCancelBeneficiary?: string; + referralCode?: number; + affiliateFeePercent?: number; + srcChainOrderAuthorityAddress?: string; + srcChainRefundAddress?: string; + dstChainOrderAuthorityAddress?: string; + prependOperatingExpenses?: boolean; + deBridgeApp?: string; } export interface deBridgeOrderResponse { - tx: { - data: string; - to: string; - value: string; - }; - estimation: { - srcChainTokenIn: { - amount: string; - tokenAddress: string; - decimals: number; - symbol: string; - }; - dstChainTokenOut: { - amount: string; - tokenAddress: string; - decimals: number; - symbol: string; - }; - fees: { - srcChainTokenIn: string; - dstChainTokenOut: string; - }; - }; + tx: { + data: string; + to: string; + value: string; + }; + estimation: { + srcChainTokenIn: { + amount: string; + tokenAddress: string; + decimals: number; + symbol: string; + }; + dstChainTokenOut: { + amount: string; + tokenAddress: string; + decimals: number; + symbol: string; + }; + fees: { + srcChainTokenIn: string; + dstChainTokenOut: string; + }; + }; } export interface deBridgeOrderIdsResponse { - orderIds: string[]; - errorCode?: number; - errorMessage?: string; + orderIds: string[]; + errorCode?: number; + errorMessage?: string; } export interface deBridgeOrderStatusResponse { - orderId: string; - status: - | "None" - | "Created" - | "Fulfilled" - | "SentUnlock" - | "OrderCancelled" - | "SentOrderCancel" - | "ClaimedUnlock" - | "ClaimedOrderCancel"; - srcChainTxHash?: string; - dstChainTxHash?: string; - orderLink?: string; - error?: string; + orderId: string; + status: + | "None" + | "Created" + | "Fulfilled" + | "SentUnlock" + | "OrderCancelled" + | "SentOrderCancel" + | "ClaimedUnlock" + | "ClaimedOrderCancel"; + srcChainTxHash?: string; + dstChainTxHash?: string; + orderLink?: string; + error?: string; } // Regular expressions for validating addresses @@ -440,69 +440,69 @@ export const EVM_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/; // Chain ID validation schema export const chainIdSchema = z.string().refine( - (val) => { - const num = Number.parseInt(val, 10); - // Regular chain IDs (1-99999) - if (num > 0 && num < 100000) { - return true; - } - // Special chain IDs (100000000+) - if (num >= 100000000) { - return true; - } - // Solana chain ID (7565164) - if (num === 7565164) { - return true; - } - return false; - }, - { - message: "Chain ID must be either 1-99999, 7565164 (Solana), or 100000000+", - }, + (val) => { + const num = Number.parseInt(val, 10); + // Regular chain IDs (1-99999) + if (num > 0 && num < 100000) { + return true; + } + // Special chain IDs (100000000+) + if (num >= 100000000) { + return true; + } + // Solana chain ID (7565164) + if (num === 7565164) { + return true; + } + return false; + }, + { + message: "Chain ID must be either 1-99999, 7565164 (Solana), or 100000000+", + }, ); // Token info parameters schema export const getDebridgeTokensInfoSchema = z.object({ - /** Chain ID to query tokens for */ - chainId: chainIdSchema.describe( - "Chain ID to get token information for. Examples: '1' (Ethereum), '56' (BNB Chain), '7565164' (Solana)", - ), - - /** Optional token address to filter results */ - tokenAddress: z - .string() - .optional() - .describe( - "Token address to query information for. For EVM chains: use 0x-prefixed address. For Solana: use base58 token address", - ), - - /** Optional search term to filter tokens by name or symbol */ - search: z - .string() - .optional() - .describe( - "Search term to filter tokens by name or symbol (e.g., 'USDC', 'Ethereum')", - ), + /** Chain ID to query tokens for */ + chainId: chainIdSchema.describe( + "Chain ID to get token information for. Examples: '1' (Ethereum), '56' (BNB Chain), '7565164' (Solana)", + ), + + /** Optional token address to filter results */ + tokenAddress: z + .string() + .optional() + .describe( + "Token address to query information for. For EVM chains: use 0x-prefixed address. For Solana: use base58 token address", + ), + + /** Optional search term to filter tokens by name or symbol */ + search: z + .string() + .optional() + .describe( + "Search term to filter tokens by name or symbol (e.g., 'USDC', 'Ethereum')", + ), }); export type GetDebridgeTokensInfoParams = z.infer< - typeof getDebridgeTokensInfoSchema + typeof getDebridgeTokensInfoSchema >; export interface FluxbeamServerResponse { - signature: string; + signature: string; } export interface Quote { - amountIn: number; - inputMint: string; - minimumOut: number; - outAmount: number; - outputMint: string; - pool: string; - program: string; + amountIn: number; + inputMint: string; + minimumOut: number; + outAmount: number; + outputMint: string; + pool: string; + program: string; } export interface TransformedResponse { - quote: Quote; + quote: Quote; }