diff --git a/src/actions/balance.ts b/src/actions/balance.ts index 36d9304..107b709 100644 --- a/src/actions/balance.ts +++ b/src/actions/balance.ts @@ -11,7 +11,7 @@ const balanceAction: Action = { "get wallet balance", "view balance", "show balance", - "check token balance" + "check token balance", ], description: `Get the balance of a Solana wallet or token account. If you want to get the balance of your wallet, you don't need to provide the tokenAddress. @@ -23,37 +23,40 @@ const balanceAction: Action = { output: { status: "success", balance: "100", - token: "SOL" + token: "SOL", }, - explanation: "Get SOL balance of the wallet" - } + explanation: "Get SOL balance of the wallet", + }, ], [ { input: { - tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" + tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", }, output: { status: "success", balance: "1000", - token: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" + token: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", }, - explanation: "Get USDC token balance" - } - ] + explanation: "Get USDC token balance", + }, + ], ], schema: z.object({ - tokenAddress: z.string().optional() + tokenAddress: z.string().optional(), }), handler: async (agent: SolanaAgentKit, input: Record) => { - const balance = await get_balance(agent, input.tokenAddress && new PublicKey(input.tokenAddress)); + const balance = await get_balance( + agent, + input.tokenAddress && new PublicKey(input.tokenAddress), + ); return { status: "success", balance: balance, - token: input.tokenAddress || "SOL" + token: input.tokenAddress || "SOL", }; - } + }, }; -export default balanceAction; \ No newline at end of file +export default balanceAction; diff --git a/src/actions/createGibworkTask.ts b/src/actions/createGibworkTask.ts index 419b7b5..3ff8b12 100644 --- a/src/actions/createGibworkTask.ts +++ b/src/actions/createGibworkTask.ts @@ -1,7 +1,7 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { PublicKey, VersionedTransaction } from "@solana/web3.js"; +import { PublicKey } from "@solana/web3.js"; import { create_gibwork_task } from "../tools"; const createGibworkTaskAction: Action = { @@ -12,9 +12,10 @@ const createGibworkTaskAction: Action = { "create gig", "post task", "create work", - "new task on gibwork" + "new task on gibwork", ], - description: "Create a new task on the Gibwork platform with payment in SPL tokens", + description: + "Create a new task on the Gibwork platform with payment in SPL tokens", examples: [ [ { @@ -24,45 +25,38 @@ const createGibworkTaskAction: Action = { requirements: "Experience with Rust and React", tags: ["solana", "rust", "react"], tokenMintAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", - tokenAmount: 100 + tokenAmount: 100, }, output: { status: "success", taskId: "task_123", signature: "3YKpM1...", - message: "Successfully created task: Build a Solana dApp" + message: "Successfully created task: Build a Solana dApp", }, - explanation: "Create a new task on Gibwork with 100 USDC payment" - } - ] + explanation: "Create a new task on Gibwork with 100 USDC payment", + }, + ], ], schema: z.object({ - title: z.string() - .min(1) - .describe("Title of the task"), - content: z.string() - .min(1) - .describe("Description of the task"), - requirements: z.string() + title: z.string().min(1).describe("Title of the task"), + content: z.string().min(1).describe("Description of the task"), + requirements: z + .string() .min(1) .describe("Requirements to complete the task"), - tags: z.array(z.string()) + tags: z + .array(z.string()) .min(1) .describe("List of tags associated with the task"), - tokenMintAddress: z.string() - .describe("Token mint address for payment"), - tokenAmount: z.number() - .positive() - .describe("Payment amount for the task"), - payer: z.string() + tokenMintAddress: z.string().describe("Token mint address for payment"), + tokenAmount: z.number().positive().describe("Payment amount for the task"), + payer: z + .string() .optional() - .describe("Optional payer address (defaults to wallet address)") + .describe("Optional payer address (defaults to wallet address)"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { - const tokenMintAddress = new PublicKey(input.tokenMintAddress); - const payer = input.payer ? new PublicKey(input.payer) : undefined; - const responseData = await create_gibwork_task( agent, input.title, @@ -71,22 +65,22 @@ const createGibworkTaskAction: Action = { input.tags, new PublicKey(input.tokenMintAddress), input.tokenAmount, - input.payer ? new PublicKey(input.payer) : undefined + input.payer ? new PublicKey(input.payer) : undefined, ); return { status: "success", taskId: responseData.taskId, signature: responseData.signature, - message: `Successfully created task: ${input.title}` + message: `Successfully created task: ${input.title}`, }; } catch (error: any) { return { status: "error", - message: `Failed to create task: ${error.message}` + message: `Failed to create task: ${error.message}`, }; } - } + }, }; -export default createGibworkTaskAction; \ No newline at end of file +export default createGibworkTaskAction; diff --git a/src/actions/createImage.ts b/src/actions/createImage.ts index 722a683..8906844 100644 --- a/src/actions/createImage.ts +++ b/src/actions/createImage.ts @@ -1,8 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import OpenAI from "openai"; -import { create } from "domain"; import { create_image } from "../tools/create_image"; const createImageAction: Action = { @@ -13,9 +11,10 @@ const createImageAction: Action = { "make image", "generate artwork", "create picture", - "generate picture" + "generate picture", ], - description: "Create an AI-generated image based on a text prompt using OpenAI's DALL-E models", + description: + "Create an AI-generated image based on a text prompt using OpenAI's DALL-E models", examples: [ [ { @@ -24,56 +23,56 @@ const createImageAction: Action = { model: "dall-e-3", size: "1024x1024", quality: "standard", - style: "natural" + style: "natural", }, output: { status: "success", imageUrl: "https://example.com/image.png", - message: "Successfully generated image" + message: "Successfully generated image", }, - explanation: "Generate an image of a sunset landscape using DALL-E 3" - } - ] + explanation: "Generate an image of a sunset landscape using DALL-E 3", + }, + ], ], schema: z.object({ - prompt: z.string() + prompt: z + .string() .min(1) .max(1000) .describe("The text description of the image to generate"), - model: z.enum(["dall-e-3"]) + model: z + .enum(["dall-e-3"]) .default("dall-e-3") .describe("The AI model to use for generation"), - size: z.enum(["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"]) + size: z + .enum(["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"]) .default("1024x1024") .describe("The size of the generated image"), - quality: z.enum(["standard", "hd"]) + quality: z + .enum(["standard", "hd"]) .default("standard") .describe("The quality level of the generated image"), - style: z.enum(["natural", "vivid"]) + style: z + .enum(["natural", "vivid"]) .default("natural") - .describe("The style of the generated image") + .describe("The style of the generated image"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { if (!agent.openai_api_key) { return { status: "error", - message: "OpenAI API key not found in agent configuration" + message: "OpenAI API key not found in agent configuration", }; } const { prompt, model, size } = input; - - const openai = new OpenAI({ - apiKey: agent.openai_api_key - }); - const response = await create_image(agent, prompt, model, size); return { status: "success", imageUrl: response.images[0].url, - message: "Successfully generated image" + message: "Successfully generated image", }; } catch (error: any) { // Handle specific OpenAI error types @@ -82,21 +81,21 @@ const createImageAction: Action = { if (status === 429) { return { status: "error", - message: "Rate limit exceeded. Please try again later." + message: "Rate limit exceeded. Please try again later.", }; } return { status: "error", - message: `OpenAI API error: ${data.error?.message || error.message}` + message: `OpenAI API error: ${data.error?.message || error.message}`, }; } return { status: "error", - message: `Failed to generate image: ${error.message}` + message: `Failed to generate image: ${error.message}`, }; } - } + }, }; -export default createImageAction; \ No newline at end of file +export default createImageAction; diff --git a/src/actions/createOpenbookMarket.ts b/src/actions/createOpenbookMarket.ts index 0e923c0..dafb509 100644 --- a/src/actions/createOpenbookMarket.ts +++ b/src/actions/createOpenbookMarket.ts @@ -1,8 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { OPEN_BOOK_PROGRAM, Raydium, TxVersion } from "@raydium-io/raydium-sdk-v2"; -import { MintLayout, TOKEN_PROGRAM_ID } from "@solana/spl-token"; import { PublicKey } from "@solana/web3.js"; import { openbookCreateMarket } from "../tools"; @@ -14,42 +12,41 @@ const createOpenbookMarketAction: Action = { "new openbook market", "create trading pair", "setup dex market", - "new trading market" + "new trading market", ], description: "Create a new trading market on Openbook DEX", examples: [ [ { input: { - baseMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC - quoteMint: "So11111111111111111111111111111111111111112", // SOL + baseMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC + quoteMint: "So11111111111111111111111111111111111111112", // SOL lotSize: 1, - tickSize: 0.01 + tickSize: 0.01, }, output: { status: "success", signatures: ["2ZE7Rz...", "3YKpM1..."], - message: "Successfully created Openbook market" + message: "Successfully created Openbook market", }, - explanation: "Create a new USDC/SOL market on Openbook with default lot and tick sizes" - } - ] + explanation: + "Create a new USDC/SOL market on Openbook with default lot and tick sizes", + }, + ], ], schema: z.object({ - baseMint: z.string() - .min(1) - .describe("The base token's mint address"), - quoteMint: z.string() - .min(1) - .describe("The quote token's mint address"), - lotSize: z.number() + baseMint: z.string().min(1).describe("The base token's mint address"), + quoteMint: z.string().min(1).describe("The quote token's mint address"), + lotSize: z + .number() .positive() .default(1) .describe("The minimum order size (lot size)"), - tickSize: z.number() + tickSize: z + .number() .positive() .default(0.01) - .describe("The minimum price increment (tick size)") + .describe("The minimum price increment (tick size)"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -58,27 +55,26 @@ const createOpenbookMarketAction: Action = { const lotSize = input.lotSize || 1; const tickSize = input.tickSize || 0.01; - const signatures = await openbookCreateMarket( agent, baseMint, quoteMint, lotSize, - tickSize + tickSize, ); return { status: "success", signatures, - message: "Successfully created Openbook market" + message: "Successfully created Openbook market", }; } catch (error: any) { return { status: "error", - message: `Failed to create Openbook market: ${error.message}` + message: `Failed to create Openbook market: ${error.message}`, }; } - } + }, }; -export default createOpenbookMarketAction; \ No newline at end of file +export default createOpenbookMarketAction; diff --git a/src/actions/createOrcaSingleSidedWhirlpool.ts b/src/actions/createOrcaSingleSidedWhirlpool.ts index f23389d..dc82984 100644 --- a/src/actions/createOrcaSingleSidedWhirlpool.ts +++ b/src/actions/createOrcaSingleSidedWhirlpool.ts @@ -27,48 +27,58 @@ const createOrcaSingleSidedWhirlpoolAction: Action = { "initialize orca whirlpool", "create orca concentrated pool", "setup orca concentrated liquidity", - "create orca trading pair" + "create orca trading pair", ], - description: "Create a new single-sided whirlpool on Orca with concentrated liquidity", + description: + "Create a new single-sided whirlpool on Orca with concentrated liquidity", examples: [ [ { input: { depositTokenAmount: "1000000000000", // 1 million tokens with 6 decimals - depositTokenMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC - otherTokenMint: "So11111111111111111111111111111111111111112", // SOL + depositTokenMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC + otherTokenMint: "So11111111111111111111111111111111111111112", // SOL initialPrice: "0.001", maxPrice: "5.0", - feeTier: 0.3 + feeTier: 0.3, }, output: { status: "success", signature: "2ZE7Rz...", - message: "Successfully created Orca single-sided whirlpool" + message: "Successfully created Orca single-sided whirlpool", }, - explanation: "Create a USDC/SOL whirlpool with 1M USDC initial liquidity" - } - ] + explanation: + "Create a USDC/SOL whirlpool with 1M USDC initial liquidity", + }, + ], ], schema: z.object({ - depositTokenAmount: z.string() + depositTokenAmount: z + .string() .min(1) - .describe("The amount of deposit token to provide as liquidity (including decimals)"), - depositTokenMint: z.string() + .describe( + "The amount of deposit token to provide as liquidity (including decimals)", + ), + depositTokenMint: z + .string() .min(1) .describe("The mint address of the token being deposited"), - otherTokenMint: z.string() + otherTokenMint: z + .string() .min(1) .describe("The mint address of the other token in the pool"), - initialPrice: z.string() + initialPrice: z + .string() .min(1) .describe("Initial price of deposit token in terms of the other token"), - maxPrice: z.string() + maxPrice: z + .string() .min(1) .describe("Maximum price at which liquidity is added"), - feeTier: z.number() + feeTier: z + .number() .refine((val) => val in FEE_TIERS, "Invalid fee tier") - .describe("Fee tier percentage for the pool (e.g., 0.3 for 0.3%)") + .describe("Fee tier percentage for the pool (e.g., 0.3 for 0.3%)"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -87,21 +97,21 @@ const createOrcaSingleSidedWhirlpoolAction: Action = { otherTokenMint, initialPrice, maxPrice, - feeTier + feeTier, ); return { status: "success", signature, - message: "Successfully created Orca single-sided whirlpool" + message: "Successfully created Orca single-sided whirlpool", }; } catch (error: any) { return { status: "error", - message: `Failed to create whirlpool: ${error.message}` + message: `Failed to create whirlpool: ${error.message}`, }; } - } + }, }; -export default createOrcaSingleSidedWhirlpoolAction; \ No newline at end of file +export default createOrcaSingleSidedWhirlpoolAction; diff --git a/src/actions/deployCollection.ts b/src/actions/deployCollection.ts index 77efc10..0ac8e6c 100644 --- a/src/actions/deployCollection.ts +++ b/src/actions/deployCollection.ts @@ -1,4 +1,3 @@ -import { PublicKey } from "@solana/web3.js"; import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; @@ -17,7 +16,7 @@ const deployCollectionAction: Action = { "launch collection", "deploy nft collection", "create nft collection", - "mint collection" + "mint collection", ], description: `Deploy a new NFT collection on Solana blockchain.`, examples: [ @@ -26,43 +25,43 @@ const deployCollectionAction: Action = { input: { name: "My Collection", uri: "https://example.com/collection.json", - royaltyBasisPoints: 500 + royaltyBasisPoints: 500, }, output: { status: "success", message: "Collection deployed successfully", collectionAddress: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN", - name: "My Collection" + name: "My Collection", }, - explanation: "Deploy an NFT collection with 5% royalty" - } + explanation: "Deploy an NFT collection with 5% royalty", + }, ], [ { input: { name: "Basic Collection", - uri: "https://example.com/basic.json" + uri: "https://example.com/basic.json", }, output: { status: "success", message: "Collection deployed successfully", collectionAddress: "8nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkM", - name: "Basic Collection" + name: "Basic Collection", }, - explanation: "Deploy a basic NFT collection without royalties" - } - ] + explanation: "Deploy a basic NFT collection without royalties", + }, + ], ], schema: z.object({ name: z.string().min(1, "Name is required"), uri: z.string().url("URI must be a valid URL"), - royaltyBasisPoints: z.number().min(0).max(10000).optional() + royaltyBasisPoints: z.number().min(0).max(10000).optional(), }), handler: async (agent: SolanaAgentKit, input: Record) => { const options: CollectionOptions = { name: input.name, uri: input.uri, - royaltyBasisPoints: input.royaltyBasisPoints + royaltyBasisPoints: input.royaltyBasisPoints, }; const result = await deploy_collection(agent, options); @@ -71,9 +70,9 @@ const deployCollectionAction: Action = { status: "success", message: "Collection deployed successfully", collectionAddress: result.collectionAddress.toString(), - name: input.name + name: input.name, }; - } + }, }; -export default deployCollectionAction; \ No newline at end of file +export default deployCollectionAction; diff --git a/src/actions/deployToken.ts b/src/actions/deployToken.ts index 2a1793d..d365054 100644 --- a/src/actions/deployToken.ts +++ b/src/actions/deployToken.ts @@ -1,5 +1,4 @@ -import { PublicKey } from "@solana/web3.js"; -import { Action, ActionExample } from "../types/action"; +import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; import { deploy_token } from "../tools"; @@ -13,7 +12,8 @@ const deployTokenAction: Action = { "create new token", "mint token", ], - description: "Deploy a new SPL token on the Solana blockchain with specified parameters", + description: + "Deploy a new SPL token on the Solana blockchain with specified parameters", examples: [ [ { @@ -22,38 +22,38 @@ const deployTokenAction: Action = { uri: "https://example.com/token.json", symbol: "MTK", decimals: 9, - initialSupply: 1000000 + initialSupply: 1000000, }, output: { mint: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN", status: "success", - message: "Token deployed successfully" + message: "Token deployed successfully", }, - explanation: "Deploy a token with initial supply and metadata" - } + explanation: "Deploy a token with initial supply and metadata", + }, ], [ { input: { name: "Basic Token", uri: "https://example.com/basic.json", - symbol: "BASIC" + symbol: "BASIC", }, output: { mint: "8nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkM", status: "success", - message: "Token deployed successfully" + message: "Token deployed successfully", }, - explanation: "Deploy a basic token with minimal parameters" - } - ] + explanation: "Deploy a basic token with minimal parameters", + }, + ], ], schema: z.object({ name: z.string().min(1, "Name is required"), uri: z.string().url("URI must be a valid URL"), symbol: z.string().min(1, "Symbol is required"), decimals: z.number().optional(), - initialSupply: z.number().optional() + initialSupply: z.number().optional(), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -63,21 +63,21 @@ const deployTokenAction: Action = { input.uri, input.symbol, input.decimals, - input.initialSupply + input.initialSupply, ); return { mint: result.mint.toString(), status: "success", - message: "Token deployed successfully" + message: "Token deployed successfully", }; } catch (error: any) { return { status: "error", - message: `Token deployment failed: ${error.message}` + message: `Token deployment failed: ${error.message}`, }; } - } -} + }, +}; -export default deployTokenAction; \ No newline at end of file +export default deployTokenAction; diff --git a/src/actions/fetchPrice.ts b/src/actions/fetchPrice.ts index 9512e14..0c45391 100644 --- a/src/actions/fetchPrice.ts +++ b/src/actions/fetchPrice.ts @@ -11,26 +11,29 @@ const fetchPriceAction: Action = { "check price", "token value", "price check", - "get price in usd" + "get price in usd", ], - description: "Fetch the current price of a Solana token in USDC using Jupiter API", + description: + "Fetch the current price of a Solana token in USDC using Jupiter API", examples: [ [ { input: { - tokenAddress: "So11111111111111111111111111111111111111112" + tokenAddress: "So11111111111111111111111111111111111111112", }, output: { status: "success", price: "23.45", - message: "Current price: $23.45 USDC" + message: "Current price: $23.45 USDC", }, - explanation: "Get the current price of SOL token in USDC" - } - ] + explanation: "Get the current price of SOL token in USDC", + }, + ], ], schema: z.object({ - tokenAddress: z.string().describe("The mint address of the token to fetch the price for") + tokenAddress: z + .string() + .describe("The mint address of the token to fetch the price for"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -40,15 +43,15 @@ const fetchPriceAction: Action = { return { status: "success", price, - message: `Current price: $${price} USDC` + message: `Current price: $${price} USDC`, }; } catch (error: any) { return { status: "error", - message: `Failed to fetch price: ${error.message}` + message: `Failed to fetch price: ${error.message}`, }; } - } + }, }; -export default fetchPriceAction; \ No newline at end of file +export default fetchPriceAction; diff --git a/src/actions/getAllDomainsTLDs.ts b/src/actions/getAllDomainsTLDs.ts index 60c05d2..34dbd19 100644 --- a/src/actions/getAllDomainsTLDs.ts +++ b/src/actions/getAllDomainsTLDs.ts @@ -11,9 +11,10 @@ const getAllDomainsTLDsAction: Action = { "fetch domain tlds", "get top level domains", "list available tlds", - "get domain suffixes" + "get domain suffixes", ], - description: "Get a list of all available top-level domains (TLDs) for Solana domains", + description: + "Get a list of all available top-level domains (TLDs) for Solana domains", examples: [ [ { @@ -21,14 +22,15 @@ const getAllDomainsTLDsAction: Action = { output: { status: "success", tlds: [".sol", ".abc", ".backpack", ".bonk"], - message: "Successfully retrieved all domain TLDs" + message: "Successfully retrieved all domain TLDs", }, - explanation: "Get a list of all available TLDs that can be used for Solana domains" - } - ] + explanation: + "Get a list of all available TLDs that can be used for Solana domains", + }, + ], ], schema: z.object({}), - handler: async (agent: SolanaAgentKit, input: Record) => { + handler: async (agent: SolanaAgentKit) => { try { // Get all domain TLDs const tlds = await getAllDomainsTLDs(agent); @@ -36,15 +38,15 @@ const getAllDomainsTLDsAction: Action = { return { status: "success", tlds, - message: "Successfully retrieved all domain TLDs" + message: "Successfully retrieved all domain TLDs", }; } catch (error: any) { return { status: "error", - message: `Failed to get domain TLDs: ${error.message}` + message: `Failed to get domain TLDs: ${error.message}`, }; } - } + }, }; -export default getAllDomainsTLDsAction; \ No newline at end of file +export default getAllDomainsTLDsAction; diff --git a/src/actions/getAllRegisteredAllDomains.ts b/src/actions/getAllRegisteredAllDomains.ts index 96fe879..6ed9140 100644 --- a/src/actions/getAllRegisteredAllDomains.ts +++ b/src/actions/getAllRegisteredAllDomains.ts @@ -11,7 +11,7 @@ const getAllRegisteredAllDomainsAction: Action = { "fetch registered domains", "get domain list", "list active domains", - "get registered names" + "get registered names", ], description: "Get a list of all registered domains across all TLDs", examples: [ @@ -19,28 +19,30 @@ const getAllRegisteredAllDomainsAction: Action = { { input: { limit: 100, - offset: 0 + offset: 0, }, output: { status: "success", domains: ["solana.sol", "bonk.abc", "wallet.backpack"], total: 3, - message: "Successfully retrieved registered domains" + message: "Successfully retrieved registered domains", }, - explanation: "Get the first 100 registered domains across all TLDs" - } - ] + explanation: "Get the first 100 registered domains across all TLDs", + }, + ], ], schema: z.object({ - limit: z.number() + limit: z + .number() .positive() .max(1000) .default(100) .describe("Maximum number of domains to return"), - offset: z.number() + offset: z + .number() .nonnegative() .default(0) - .describe("Number of domains to skip") + .describe("Number of domains to skip"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -50,20 +52,19 @@ const getAllRegisteredAllDomainsAction: Action = { // Get all registered domains const domains = await getAllRegisteredAllDomains(agent); - return { status: "success", domains: domains.slice(offset, offset + limit), total: domains.length, - message: "Successfully retrieved registered domains" + message: "Successfully retrieved registered domains", }; } catch (error: any) { return { status: "error", - message: `Failed to get registered domains: ${error.message}` + message: `Failed to get registered domains: ${error.message}`, }; } - } + }, }; -export default getAllRegisteredAllDomainsAction; \ No newline at end of file +export default getAllRegisteredAllDomainsAction; diff --git a/src/actions/getMainAllDomainsDomain.ts b/src/actions/getMainAllDomainsDomain.ts index 4f301f9..ad57161 100644 --- a/src/actions/getMainAllDomainsDomain.ts +++ b/src/actions/getMainAllDomainsDomain.ts @@ -2,7 +2,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; import { PublicKey } from "@solana/web3.js"; -import { TldParser } from "@onsol/tldparser"; import { getMainAllDomainsDomain } from "../tools"; const getMainAllDomainsDomainAction: Action = { @@ -13,52 +12,56 @@ const getMainAllDomainsDomainAction: Action = { "get default domain", "get main address name", "get primary name", - "get main domain name" + "get main domain name", ], description: "Get the main domain associated with a wallet address", examples: [ [ { input: { - address: "7nxQB..." + address: "7nxQB...", }, output: { status: "success", domain: "solana.sol", - message: "Successfully retrieved main domain" + message: "Successfully retrieved main domain", }, - explanation: "Get the main domain name for a given wallet address" - } - ] + explanation: "Get the main domain name for a given wallet address", + }, + ], ], schema: z.object({ - address: z.string() + address: z + .string() .min(1) - .describe("The wallet address to get the main domain for") + .describe("The wallet address to get the main domain for"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { - const mainDomain = await getMainAllDomainsDomain(agent, new PublicKey(input.address)); + const mainDomain = await getMainAllDomainsDomain( + agent, + new PublicKey(input.address), + ); if (!mainDomain) { return { status: "error", - message: "No main domain found for this address" + message: "No main domain found for this address", }; } return { status: "success", domain: mainDomain, - message: "Successfully retrieved main domain" + message: "Successfully retrieved main domain", }; } catch (error: any) { return { status: "error", - message: `Failed to get main domain: ${error.message}` + message: `Failed to get main domain: ${error.message}`, }; } - } + }, }; -export default getMainAllDomainsDomainAction; \ No newline at end of file +export default getMainAllDomainsDomainAction; diff --git a/src/actions/getOwnedAllDomains.ts b/src/actions/getOwnedAllDomains.ts index 9cb279a..359bf38 100644 --- a/src/actions/getOwnedAllDomains.ts +++ b/src/actions/getOwnedAllDomains.ts @@ -12,29 +12,31 @@ const getOwnedAllDomainsAction: Action = { "fetch wallet domains", "get owned names", "list my domains", - "get address domains" + "get address domains", ], - description: "Get all domains owned by a specific wallet address across all TLDs", + description: + "Get all domains owned by a specific wallet address across all TLDs", examples: [ [ { input: { - address: "7nxQB..." + address: "7nxQB...", }, output: { status: "success", domains: ["solana.sol", "wallet.abc", "user.backpack"], total: 3, - message: "Successfully retrieved owned domains" + message: "Successfully retrieved owned domains", }, - explanation: "Get all domain names owned by a specific wallet address" - } - ] + explanation: "Get all domain names owned by a specific wallet address", + }, + ], ], schema: z.object({ - address: z.string() + address: z + .string() .min(1) - .describe("The wallet address to get owned domains for") + .describe("The wallet address to get owned domains for"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -47,15 +49,15 @@ const getOwnedAllDomainsAction: Action = { status: "success", domains, total: domains.length, - message: `Successfully retrieved ${domains.length} owned domain${domains.length === 1 ? '' : 's'}` + message: `Successfully retrieved ${domains.length} owned domain${domains.length === 1 ? "" : "s"}`, }; } catch (error: any) { return { status: "error", - message: `Failed to get owned domains: ${error.message}` + message: `Failed to get owned domains: ${error.message}`, }; } - } + }, }; -export default getOwnedAllDomainsAction; \ No newline at end of file +export default getOwnedAllDomainsAction; diff --git a/src/actions/getOwnedDomainsForTLD.ts b/src/actions/getOwnedDomainsForTLD.ts index 3b2a06e..b419e58 100644 --- a/src/actions/getOwnedDomainsForTLD.ts +++ b/src/actions/getOwnedDomainsForTLD.ts @@ -1,7 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { PublicKey } from "@solana/web3.js"; import { getOwnedDomainsForTLD } from "../tools"; const getOwnedDomainsForTLDAction: Action = { @@ -12,29 +11,32 @@ const getOwnedDomainsForTLDAction: Action = { "fetch wallet domains by tld", "get owned names by extension", "list my domains by tld", - "get address domains for tld" + "get address domains for tld", ], - description: "Get all domains owned by a specific wallet address for a given top-level domain (TLD)", + description: + "Get all domains owned by a specific wallet address for a given top-level domain (TLD)", examples: [ [ { input: { - tld: "sol" + tld: "sol", }, output: { status: "success", domains: ["solana.sol", "wallet.sol", "user.sol"], total: 3, - message: "Successfully retrieved owned domains for .sol" + message: "Successfully retrieved owned domains for .sol", }, - explanation: "Get all .sol domain names owned by a specific wallet address" - } - ] + explanation: + "Get all .sol domain names owned by a specific wallet address", + }, + ], ], schema: z.object({ - tld: z.string() + tld: z + .string() .min(1) - .describe("The top-level domain to filter by (e.g., 'sol', 'abc')") + .describe("The top-level domain to filter by (e.g., 'sol', 'abc')"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -47,15 +49,15 @@ const getOwnedDomainsForTLDAction: Action = { status: "success", domains, total: domains.length, - message: `Successfully retrieved ${domains.length} owned domain${domains.length === 1 ? '' : 's'} for .${tld}` + message: `Successfully retrieved ${domains.length} owned domain${domains.length === 1 ? "" : "s"} for .${tld}`, }; } catch (error: any) { return { status: "error", - message: `Failed to get owned domains: ${error.message}` + message: `Failed to get owned domains: ${error.message}`, }; } - } + }, }; -export default getOwnedDomainsForTLDAction; \ No newline at end of file +export default getOwnedDomainsForTLDAction; diff --git a/src/actions/getPrimaryDomain.ts b/src/actions/getPrimaryDomain.ts index f19b091..d903c04 100644 --- a/src/actions/getPrimaryDomain.ts +++ b/src/actions/getPrimaryDomain.ts @@ -1,7 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { getPrimaryDomain as _getPrimaryDomain } from "@bonfida/spl-name-service"; import { PublicKey } from "@solana/web3.js"; import { getPrimaryDomain } from "../tools"; @@ -13,51 +12,46 @@ const getPrimaryDomainAction: Action = { "check primary domain", "find primary domain", "get main domain", - "primary sol domain" + "primary sol domain", ], - description: "Get the primary .sol domain associated with a Solana wallet address", + description: + "Get the primary .sol domain associated with a Solana wallet address", examples: [ [ { input: { - account: "7nxQB..." + account: "7nxQB...", }, output: { status: "success", domain: "vitalik.sol", - message: "Primary domain: vitalik.sol" + message: "Primary domain: vitalik.sol", }, - explanation: "Get the primary .sol domain for a wallet address" - } - ] + explanation: "Get the primary .sol domain for a wallet address", + }, + ], ], schema: z.object({ - account: z.string() - .min(1) - .describe("The Solana wallet address to lookup") + account: z.string().min(1).describe("The Solana wallet address to lookup"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { const account = new PublicKey(input.account); - const response = await getPrimaryDomain( - agent, - account - ); - + const response = await getPrimaryDomain(agent, account); return { status: "success", domain: response, - message: `Primary domain: ${response}` + message: `Primary domain: ${response}`, }; } catch (error: any) { return { status: "error", - message: `Failed to get primary domain: ${error.message}` + message: `Failed to get primary domain: ${error.message}`, }; } - } + }, }; -export default getPrimaryDomainAction; \ No newline at end of file +export default getPrimaryDomainAction; diff --git a/src/actions/getTPS.ts b/src/actions/getTPS.ts index 546da65..b5c0979 100644 --- a/src/actions/getTPS.ts +++ b/src/actions/getTPS.ts @@ -10,9 +10,10 @@ const getTPSAction: Action = { "check network speed", "network performance", "transaction throughput", - "network tps" + "network tps", ], - description: "Get the current transactions per second (TPS) of the Solana network", + description: + "Get the current transactions per second (TPS) of the Solana network", examples: [ [ { @@ -20,11 +21,11 @@ const getTPSAction: Action = { output: { status: "success", tps: 3500, - message: "Current network TPS: 3500" + message: "Current network TPS: 3500", }, - explanation: "Get the current TPS of the Solana network" - } - ] + explanation: "Get the current TPS of the Solana network", + }, + ], ], schema: z.object({}), // No input parameters required handler: async (agent: SolanaAgentKit, _input: Record) => { @@ -33,15 +34,15 @@ const getTPSAction: Action = { return { status: "success", response, - message: `Current network TPS: ${response}` + message: `Current network TPS: ${response}`, }; } catch (error: any) { return { status: "error", - message: `Failed to get TPS: ${error.message}` + message: `Failed to get TPS: ${error.message}`, }; } - } + }, }; -export default getTPSAction; \ No newline at end of file +export default getTPSAction; diff --git a/src/actions/getTokenData.ts b/src/actions/getTokenData.ts index 8ac9721..57b288b 100644 --- a/src/actions/getTokenData.ts +++ b/src/actions/getTokenData.ts @@ -12,14 +12,14 @@ const getTokenDataAction: Action = { "token details", "lookup token", "find token", - "token data" + "token data", ], description: "Get token data from either a token address or ticker symbol", examples: [ [ { input: { - address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" + address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", }, output: { status: "success", @@ -27,16 +27,16 @@ const getTokenDataAction: Action = { name: "USD Coin", symbol: "USDC", address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", - decimals: 6 - } + decimals: 6, + }, }, - explanation: "Get token data using the token's address" - } + explanation: "Get token data using the token's address", + }, ], [ { input: { - ticker: "SOL" + ticker: "SOL", }, output: { status: "success", @@ -44,19 +44,21 @@ const getTokenDataAction: Action = { name: "Wrapped SOL", symbol: "SOL", address: "So11111111111111111111111111111111111111112", - decimals: 9 - } + decimals: 9, + }, }, - explanation: "Get token data using the token's ticker symbol" - } - ] + explanation: "Get token data using the token's ticker symbol", + }, + ], ], - schema: z.object({ - address: z.string().optional().describe("The token's mint address"), - ticker: z.string().optional().describe("The token's ticker symbol") - }).refine(data => data.address || data.ticker, { - message: "Either address or ticker must be provided" - }), + schema: z + .object({ + address: z.string().optional().describe("The token's mint address"), + ticker: z.string().optional().describe("The token's ticker symbol"), + }) + .refine((data) => data.address || data.ticker, { + message: "Either address or ticker must be provided", + }), handler: async (agent: SolanaAgentKit, input: Record) => { try { let tokenData: JupiterTokenData | undefined; @@ -71,7 +73,7 @@ const getTokenDataAction: Action = { if (!tokenData) { return { status: "error", - message: "Token not found or not verified" + message: "Token not found or not verified", }; } return { @@ -81,16 +83,16 @@ const getTokenDataAction: Action = { symbol: tokenData.symbol, address: tokenData.address, decimals: tokenData.decimals, - logoURI: tokenData.logoURI - } + logoURI: tokenData.logoURI, + }, }; } catch (error: any) { return { status: "error", - message: `Failed to get token data: ${error.message}` + message: `Failed to get token data: ${error.message}`, }; } - } + }, }; -export default getTokenDataAction; \ No newline at end of file +export default getTokenDataAction; diff --git a/src/actions/index.ts b/src/actions/index.ts index d3b1679..cb81ce1 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -58,4 +58,4 @@ export const actions = [ launchPumpfunTokenAction, ]; -export type { Action, ActionExample, Handler } from "../types/action"; \ No newline at end of file +export type { Action, ActionExample, Handler } from "../types/action"; diff --git a/src/actions/launchPumpfunToken.ts b/src/actions/launchPumpfunToken.ts index 00f0add..601bb47 100644 --- a/src/actions/launchPumpfunToken.ts +++ b/src/actions/launchPumpfunToken.ts @@ -1,7 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { VersionedTransaction, Keypair } from "@solana/web3.js"; import { launchPumpFunToken } from "../tools"; const launchPumpfunTokenAction: Action = { @@ -12,9 +11,10 @@ const launchPumpfunTokenAction: Action = { "deploy pumpfun token", "create meme token", "launch memecoin", - "create pump token" + "create pump token", ], - description: "Launch a new token on Pump.fun with customizable metadata and initial liquidity", + description: + "Launch a new token on Pump.fun with customizable metadata and initial liquidity", examples: [ [ { @@ -28,78 +28,79 @@ const launchPumpfunTokenAction: Action = { website: "https://sampletoken.com", initialLiquiditySOL: 0.1, slippageBps: 10, - priorityFee: 0.0001 + priorityFee: 0.0001, }, output: { status: "success", signature: "2ZE7Rz...", mint: "7nxQB...", metadataUri: "https://arweave.net/...", - message: "Successfully launched token on Pump.fun" + message: "Successfully launched token on Pump.fun", }, - explanation: "Launch a new token with custom metadata and 0.1 SOL initial liquidity" - } - ] + explanation: + "Launch a new token with custom metadata and 0.1 SOL initial liquidity", + }, + ], ], schema: z.object({ - tokenName: z.string() - .min(1) - .max(32) - .describe("Name of the token"), - tokenTicker: z.string() + tokenName: z.string().min(1).max(32).describe("Name of the token"), + tokenTicker: z + .string() .min(2) .max(10) .describe("Ticker symbol of the token"), - description: z.string() + description: z + .string() .min(1) .max(1000) .describe("Description of the token"), - imageUrl: z.string() - .url() - .describe("URL of the token image"), - twitter: z.string() - .optional() - .describe("Twitter handle (optional)"), - telegram: z.string() - .optional() - .describe("Telegram group link (optional)"), - website: z.string() - .url() - .optional() - .describe("Website URL (optional)"), - initialLiquiditySOL: z.number() + imageUrl: z.string().url().describe("URL of the token image"), + twitter: z.string().optional().describe("Twitter handle (optional)"), + telegram: z.string().optional().describe("Telegram group link (optional)"), + website: z.string().url().optional().describe("Website URL (optional)"), + initialLiquiditySOL: z + .number() .min(0.0001) .default(0.0001) .describe("Initial liquidity in SOL"), - slippageBps: z.number() + slippageBps: z + .number() .min(1) .max(1000) .default(5) .describe("Slippage tolerance in basis points"), - priorityFee: z.number() + priorityFee: z + .number() .min(0.00001) .default(0.00005) - .describe("Priority fee in SOL") + .describe("Priority fee in SOL"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { const { tokenName, tokenTicker, description, imageUrl } = input; - const result = await launchPumpFunToken(agent, tokenName, tokenTicker, description, imageUrl, input); + const result = await launchPumpFunToken( + agent, + tokenName, + tokenTicker, + description, + imageUrl, + input, + ); return { status: "success", signature: result.signature, mint: result.mint, metadataUri: result.metadataUri, - message: "Successfully launched token on Pump.fun" + message: "Successfully launched token on Pump.fun", }; } catch (error: any) { return { status: "error", - message: `Failed to launch token: ${error.message}` + message: `Failed to launch token: ${error.message}`, }; } - } + }, }; -export default launchPumpfunTokenAction; \ No newline at end of file +export default launchPumpfunTokenAction; diff --git a/src/actions/lendAsset.ts b/src/actions/lendAsset.ts index b4b0885..1072ace 100644 --- a/src/actions/lendAsset.ts +++ b/src/actions/lendAsset.ts @@ -1,7 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { VersionedTransaction } from "@solana/web3.js"; import { lendAsset } from "../tools"; const lendAssetAction: Action = { @@ -12,28 +11,26 @@ const lendAssetAction: Action = { "earn yield", "lend with lulo", "deposit usdc", - "lending" + "lending", ], description: "Lend USDC tokens to earn yield using Lulo protocol", examples: [ [ { input: { - amount: 100 + amount: 100, }, output: { status: "success", signature: "4xKpN2...", - message: "Successfully lent 100 USDC" + message: "Successfully lent 100 USDC", }, - explanation: "Lend 100 USDC to earn yield on Lulo" - } - ] + explanation: "Lend 100 USDC to earn yield on Lulo", + }, + ], ], schema: z.object({ - amount: z.number() - .positive() - .describe("Amount of USDC to lend") + amount: z.number().positive().describe("Amount of USDC to lend"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -44,15 +41,15 @@ const lendAssetAction: Action = { return { status: "success", signature: response, - message: `Successfully lent ${amount} USDC` + message: `Successfully lent ${amount} USDC`, }; } catch (error: any) { return { status: "error", - message: `Lending failed: ${error.message}` + message: `Lending failed: ${error.message}`, }; } - } + }, }; -export default lendAssetAction; \ No newline at end of file +export default lendAssetAction; diff --git a/src/actions/mintNFT.ts b/src/actions/mintNFT.ts index 949514c..5c3d691 100644 --- a/src/actions/mintNFT.ts +++ b/src/actions/mintNFT.ts @@ -11,7 +11,7 @@ const mintNFTAction: Action = { "create nft", "mint token", "create token", - "add nft to collection" + "add nft to collection", ], description: `Mint a new NFT in a collection on Solana blockchain.`, examples: [ @@ -20,7 +20,7 @@ const mintNFTAction: Action = { input: { collectionMint: "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w", name: "My NFT", - uri: "https://example.com/nft.json" + uri: "https://example.com/nft.json", }, output: { status: "success", @@ -28,12 +28,12 @@ const mintNFTAction: Action = { mintAddress: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN", metadata: { name: "My NFT", - uri: "https://example.com/nft.json" + uri: "https://example.com/nft.json", }, - recipient: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN" + recipient: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN", }, - explanation: "Mint an NFT to the default wallet" - } + explanation: "Mint an NFT to the default wallet", + }, ], [ { @@ -41,7 +41,7 @@ const mintNFTAction: Action = { collectionMint: "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w", name: "Gift NFT", uri: "https://example.com/gift.json", - recipient: "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u" + recipient: "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u", }, output: { status: "success", @@ -49,19 +49,19 @@ const mintNFTAction: Action = { mintAddress: "8nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkM", metadata: { name: "Gift NFT", - uri: "https://example.com/gift.json" + uri: "https://example.com/gift.json", }, - recipient: "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u" + recipient: "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u", }, - explanation: "Mint an NFT to a specific recipient" - } - ] + explanation: "Mint an NFT to a specific recipient", + }, + ], ], schema: z.object({ collectionMint: z.string().min(32, "Invalid collection mint address"), name: z.string().min(1, "Name is required"), uri: z.string().url("URI must be a valid URL"), - recipient: z.string().min(32, "Invalid recipient address") + recipient: z.string().min(32, "Invalid recipient address"), }), handler: async (agent: SolanaAgentKit, input: Record) => { const result = await mintCollectionNFT( @@ -69,9 +69,9 @@ const mintNFTAction: Action = { new PublicKey(input.collectionMint), { name: input.name, - uri: input.uri + uri: input.uri, }, - input.recipient ? new PublicKey(input.recipient) : undefined + input.recipient ? new PublicKey(input.recipient) : undefined, ); return { @@ -80,11 +80,11 @@ const mintNFTAction: Action = { mintAddress: result.mint.toString(), metadata: { name: input.name, - uri: input.uri + uri: input.uri, }, - recipient: input.recipient || result.mint.toString() + recipient: input.recipient || result.mint.toString(), }; - } + }, }; -export default mintNFTAction; \ No newline at end of file +export default mintNFTAction; diff --git a/src/actions/pythFetchPrice.ts b/src/actions/pythFetchPrice.ts index 1c1f9e0..02ff1d8 100644 --- a/src/actions/pythFetchPrice.ts +++ b/src/actions/pythFetchPrice.ts @@ -1,8 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { PriceServiceConnection } from "@pythnetwork/price-service-client"; -import BN from "bn.js"; import { pythFetchPrice } from "../tools"; const pythFetchPriceAction: Action = { @@ -13,28 +11,29 @@ const pythFetchPriceAction: Action = { "pyth oracle price", "fetch from pyth", "pyth price feed", - "oracle price" + "oracle price", ], description: "Fetch the current price from a Pyth oracle price feed", examples: [ [ { input: { - priceFeedId: "Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD" // SOL/USD price feed + priceFeedId: "Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD", // SOL/USD price feed }, output: { status: "success", price: "23.45", - message: "Current price: $23.45" + message: "Current price: $23.45", }, - explanation: "Get the current SOL/USD price from Pyth oracle" - } - ] + explanation: "Get the current SOL/USD price from Pyth oracle", + }, + ], ], schema: z.object({ - priceFeedId: z.string() + priceFeedId: z + .string() .min(1) - .describe("The Pyth price feed ID to fetch the price from") + .describe("The Pyth price feed ID to fetch the price from"), }), handler: async (_agent: SolanaAgentKit, input: Record) => { try { @@ -45,15 +44,15 @@ const pythFetchPriceAction: Action = { return { status: "success", price: priceStr, - message: `Current price: $${priceStr}` + message: `Current price: $${priceStr}`, }; } catch (error: any) { return { status: "error", - message: `Failed to fetch price from Pyth: ${error.message}` + message: `Failed to fetch price from Pyth: ${error.message}`, }; } - } + }, }; -export default pythFetchPriceAction; \ No newline at end of file +export default pythFetchPriceAction; diff --git a/src/actions/raydiumCreateAmmV4.ts b/src/actions/raydiumCreateAmmV4.ts index afda966..412ef18 100644 --- a/src/actions/raydiumCreateAmmV4.ts +++ b/src/actions/raydiumCreateAmmV4.ts @@ -1,15 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { - AMM_V4, - FEE_DESTINATION_ID, - MARKET_STATE_LAYOUT_V3, - OPEN_BOOK_PROGRAM, - Raydium, - TxVersion, -} from "@raydium-io/raydium-sdk-v2"; -import { MintLayout, TOKEN_PROGRAM_ID } from "@solana/spl-token"; import { PublicKey } from "@solana/web3.js"; import BN from "bn.js"; import { raydiumCreateAmmV4 } from "../tools"; @@ -22,49 +13,51 @@ const raydiumCreateAmmV4Action: Action = { "initialize raydium v4 amm", "create raydium v4 market maker", "setup raydium v4 pool", - "create raydium v4 trading pair" + "create raydium v4 trading pair", ], - description: "Create a new AMM V4 pool on Raydium with advanced features and improved efficiency", + description: + "Create a new AMM V4 pool on Raydium with advanced features and improved efficiency", examples: [ [ { input: { - baseMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC - quoteMint: "So11111111111111111111111111111111111111112", // SOL + baseMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC + quoteMint: "So11111111111111111111111111111111111111112", // SOL baseAmount: 1000, quoteAmount: 10, - startPrice: 100, // 1 SOL = 100 USDC - openTime: 1672531200 // Unix timestamp + startPrice: 100, // 1 SOL = 100 USDC + openTime: 1672531200, // Unix timestamp }, output: { status: "success", signature: "2ZE7Rz...", poolId: "7nxQB...", - message: "Successfully created Raydium AMM V4 pool" + message: "Successfully created Raydium AMM V4 pool", }, - explanation: "Create a USDC-SOL V4 pool with initial liquidity and price" - } - ] + explanation: + "Create a USDC-SOL V4 pool with initial liquidity and price", + }, + ], ], schema: z.object({ - baseMint: z.string() - .min(1) - .describe("The base token mint address"), - quoteMint: z.string() - .min(1) - .describe("The quote token mint address"), - baseAmount: z.number() + baseMint: z.string().min(1).describe("The base token mint address"), + quoteMint: z.string().min(1).describe("The quote token mint address"), + baseAmount: z + .number() .positive() .describe("Initial base token amount to provide as liquidity"), - quoteAmount: z.number() + quoteAmount: z + .number() .positive() .describe("Initial quote token amount to provide as liquidity"), - startPrice: z.number() + startPrice: z + .number() .positive() .describe("Initial price of quote token in base token units"), - openTime: z.number() + openTime: z + .number() .positive() - .describe("Unix timestamp when trading should start") + .describe("Unix timestamp when trading should start"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -73,20 +66,26 @@ const raydiumCreateAmmV4Action: Action = { const quoteAmount = new BN(input.quoteAmount); const startTime = new BN(input.startTime); - const txId = await raydiumCreateAmmV4(agent, marketId, baseAmount, quoteAmount, startTime); + const txId = await raydiumCreateAmmV4( + agent, + marketId, + baseAmount, + quoteAmount, + startTime, + ); return { status: "success", signature: txId, - message: "Successfully created Raydium AMM V4 pool" + message: "Successfully created Raydium AMM V4 pool", }; } catch (error: any) { return { status: "error", - message: `Failed to create AMM V4 pool: ${error.message}` + message: `Failed to create AMM V4 pool: ${error.message}`, }; } - } + }, }; -export default raydiumCreateAmmV4Action; \ No newline at end of file +export default raydiumCreateAmmV4Action; diff --git a/src/actions/raydiumCreateCpmm.ts b/src/actions/raydiumCreateCpmm.ts index 0e6795c..28fe82a 100644 --- a/src/actions/raydiumCreateCpmm.ts +++ b/src/actions/raydiumCreateCpmm.ts @@ -1,13 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { - CREATE_CPMM_POOL_FEE_ACC, - CREATE_CPMM_POOL_PROGRAM, - Raydium, - TxVersion, -} from "@raydium-io/raydium-sdk-v2"; -import { MintLayout } from "@solana/spl-token"; import { PublicKey } from "@solana/web3.js"; import BN from "bn.js"; import { raydiumCreateCpmm } from "../tools"; @@ -20,45 +13,46 @@ const raydiumCreateCpmmAction: Action = { "initialize raydium amm", "create constant product market maker", "setup raydium cpmm", - "create raydium trading pair" + "create raydium trading pair", ], - description: "Create a new Constant Product Market Maker (CPMM) pool on Raydium", + description: + "Create a new Constant Product Market Maker (CPMM) pool on Raydium", examples: [ [ { input: { - baseMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC - quoteMint: "So11111111111111111111111111111111111111112", // SOL + baseMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC + quoteMint: "So11111111111111111111111111111111111111112", // SOL baseAmount: 1000, quoteAmount: 10, - startTime: 1672531200 // Unix timestamp + startTime: 1672531200, // Unix timestamp }, output: { status: "success", signature: "2ZE7Rz...", poolId: "7nxQB...", - message: "Successfully created Raydium CPMM pool" + message: "Successfully created Raydium CPMM pool", }, - explanation: "Create a USDC-SOL pool with initial liquidity of 1000 USDC and 10 SOL" - } - ] + explanation: + "Create a USDC-SOL pool with initial liquidity of 1000 USDC and 10 SOL", + }, + ], ], schema: z.object({ - baseMint: z.string() - .min(1) - .describe("The base token mint address"), - quoteMint: z.string() - .min(1) - .describe("The quote token mint address"), - baseAmount: z.number() + baseMint: z.string().min(1).describe("The base token mint address"), + quoteMint: z.string().min(1).describe("The quote token mint address"), + baseAmount: z + .number() .positive() .describe("Initial base token amount to provide as liquidity"), - quoteAmount: z.number() + quoteAmount: z + .number() .positive() .describe("Initial quote token amount to provide as liquidity"), - startTime: z.number() + startTime: z + .number() .positive() - .describe("Unix timestamp when trading should start") + .describe("Unix timestamp when trading should start"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -69,20 +63,28 @@ const raydiumCreateCpmmAction: Action = { const mintBAmount = new BN(input.quoteAmount); const startTime = new BN(input.startTime); - const txId = await raydiumCreateCpmm(agent, mintA, mintB, configId, mintAAmount, mintBAmount, startTime); + const txId = await raydiumCreateCpmm( + agent, + mintA, + mintB, + configId, + mintAAmount, + mintBAmount, + startTime, + ); return { status: "success", signature: txId, - message: "Successfully created Raydium CPMM pool" + message: "Successfully created Raydium CPMM pool", }; } catch (error: any) { return { status: "error", - message: `Failed to create CPMM pool: ${error.message}` + message: `Failed to create CPMM pool: ${error.message}`, }; } - } + }, }; -export default raydiumCreateCpmmAction; \ No newline at end of file +export default raydiumCreateCpmmAction; diff --git a/src/actions/registerDomain.ts b/src/actions/registerDomain.ts index 50b398a..b4a6d8d 100644 --- a/src/actions/registerDomain.ts +++ b/src/actions/registerDomain.ts @@ -1,10 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { Transaction } from "@solana/web3.js"; -import { registerDomainNameV2 } from "@bonfida/spl-name-service"; -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; -import { TOKENS } from "../constants"; import { registerDomain } from "../tools"; const registerDomainAction: Action = { @@ -15,7 +11,7 @@ const registerDomainAction: Action = { "get domain name", "register .sol", "purchase domain", - "domain registration" + "domain registration", ], description: "Register a .sol domain name using Bonfida Name Service", examples: [ @@ -23,26 +19,25 @@ const registerDomainAction: Action = { { input: { name: "mydomain", - spaceKB: 1 + spaceKB: 1, }, output: { status: "success", signature: "2ZE7Rz...", - message: "Successfully registered mydomain.sol" + message: "Successfully registered mydomain.sol", }, - explanation: "Register a new .sol domain with 1KB storage space" - } - ] + explanation: "Register a new .sol domain with 1KB storage space", + }, + ], ], schema: z.object({ - name: z.string() - .min(1) - .describe("Domain name to register (without .sol)"), - spaceKB: z.number() + name: z.string().min(1).describe("Domain name to register (without .sol)"), + spaceKB: z + .number() .min(1) .max(10) .default(1) - .describe("Space allocation in KB (max 10KB)") + .describe("Space allocation in KB (max 10KB)"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -54,15 +49,15 @@ const registerDomainAction: Action = { return { status: "success", signature, - message: `Successfully registered ${name}.sol` + message: `Successfully registered ${name}.sol`, }; } catch (error: any) { return { status: "error", - message: `Domain registration failed: ${error.message}` + message: `Domain registration failed: ${error.message}`, }; } - } + }, }; -export default registerDomainAction; \ No newline at end of file +export default registerDomainAction; diff --git a/src/actions/requestFunds.ts b/src/actions/requestFunds.ts index 49e4c2b..116c15e 100644 --- a/src/actions/requestFunds.ts +++ b/src/actions/requestFunds.ts @@ -10,7 +10,7 @@ const requestFundsAction: Action = { "get test sol", "use faucet", "request test tokens", - "get devnet sol" + "get devnet sol", ], description: "Request SOL from Solana faucet (devnet/testnet only)", examples: [ @@ -20,11 +20,11 @@ const requestFundsAction: Action = { output: { status: "success", message: "Successfully requested faucet funds", - network: "devnet.solana.com" + network: "devnet.solana.com", }, - explanation: "Request SOL from the devnet faucet" - } - ] + explanation: "Request SOL from the devnet faucet", + }, + ], ], schema: z.object({}), // No input parameters required handler: async (agent: SolanaAgentKit, _input: Record) => { @@ -33,9 +33,9 @@ const requestFundsAction: Action = { return { status: "success", message: "Successfully requested faucet funds", - network: agent.connection.rpcEndpoint.split("/")[2] + network: agent.connection.rpcEndpoint.split("/")[2], }; - } + }, }; -export default requestFundsAction; \ No newline at end of file +export default requestFundsAction; diff --git a/src/actions/resolveDomain.ts b/src/actions/resolveDomain.ts index 1d6307a..aca514e 100644 --- a/src/actions/resolveDomain.ts +++ b/src/actions/resolveDomain.ts @@ -1,7 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { TldParser } from "@onsol/tldparser"; import { resolveAllDomains } from "../tools"; const resolveDomainAction: Action = { @@ -11,25 +10,25 @@ const resolveDomainAction: Action = { "lookup domain", "get domain owner", "check domain", - "find domain owner" + "find domain owner", ], description: "Resolve a Solana domain name to get its owner's public key", examples: [ [ { input: { - domain: "example.sol" + domain: "example.sol", }, output: { status: "success", - owner: "7nxQB..." + owner: "7nxQB...", }, - explanation: "Resolve a .sol domain name to get the owner's public key" - } - ] + explanation: "Resolve a .sol domain name to get the owner's public key", + }, + ], ], schema: z.object({ - domain: z.string().min(1).describe("The domain name to resolve") + domain: z.string().min(1).describe("The domain name to resolve"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { @@ -38,15 +37,15 @@ const resolveDomainAction: Action = { return { status: "success", owner: tld, - message: `Successfully resolved domain ${domain}` + message: `Successfully resolved domain ${domain}`, }; } catch (error: any) { return { status: "error", - message: `Failed to resolve domain: ${error.message}` + message: `Failed to resolve domain: ${error.message}`, }; } - } + }, }; -export default resolveDomainAction; \ No newline at end of file +export default resolveDomainAction; diff --git a/src/actions/resolveSolDomain.ts b/src/actions/resolveSolDomain.ts index ce13fe3..26ebae0 100644 --- a/src/actions/resolveSolDomain.ts +++ b/src/actions/resolveSolDomain.ts @@ -1,7 +1,6 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { resolve } from "@bonfida/spl-name-service"; import { resolveSolDomain } from "../tools"; const resolveSolDomainAction: Action = { @@ -12,47 +11,49 @@ const resolveSolDomainAction: Action = { "get sol domain owner", "check sol domain", "find sol domain owner", - "resolve .sol" + "resolve .sol", ], - description: "Resolve a .sol domain to its corresponding Solana wallet address using Bonfida Name Service", + description: + "Resolve a .sol domain to its corresponding Solana wallet address using Bonfida Name Service", examples: [ [ { input: { - domain: "vitalik.sol" + domain: "vitalik.sol", }, output: { status: "success", owner: "7nxQB...", - message: "Successfully resolved vitalik.sol" + message: "Successfully resolved vitalik.sol", }, - explanation: "Resolve a .sol domain to get the owner's wallet address" - } - ] + explanation: "Resolve a .sol domain to get the owner's wallet address", + }, + ], ], schema: z.object({ - domain: z.string() + domain: z + .string() .min(1) - .describe("The .sol domain to resolve (with or without .sol suffix)") + .describe("The .sol domain to resolve (with or without .sol suffix)"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { const domain = input.domain as string; - const res = await resolveSolDomain(agent,domain) + const res = await resolveSolDomain(agent, domain); return { status: "success", owner: res.toString(), - message: `Successfully resolved ${res}` + message: `Successfully resolved ${res}`, }; } catch (error: any) { return { status: "error", - message: `Failed to resolve domain: ${error.message}` + message: `Failed to resolve domain: ${error.message}`, }; } - } + }, }; -export default resolveSolDomainAction; \ No newline at end of file +export default resolveSolDomainAction; diff --git a/src/actions/stakeWithJup.ts b/src/actions/stakeWithJup.ts index 7110a72..630f024 100644 --- a/src/actions/stakeWithJup.ts +++ b/src/actions/stakeWithJup.ts @@ -1,8 +1,7 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { VersionedTransaction } from "@solana/web3.js"; -import { stakeWithJup, trade } from "../tools"; +import { stakeWithJup } from "../tools"; const stakeWithJupAction: Action = { name: "solana_stake_with_jup", @@ -12,46 +11,45 @@ const stakeWithJupAction: Action = { "jup staking", "stake with jup", "liquid staking", - "get jupsol" + "get jupsol", ], - description: "Stake SOL tokens with Jupiter's liquid staking protocol to receive jupSOL", + description: + "Stake SOL tokens with Jupiter's liquid staking protocol to receive jupSOL", examples: [ [ { input: { - amount: 1.5 + amount: 1.5, }, output: { status: "success", signature: "5KtPn3...", - message: "Successfully staked 1.5 SOL for jupSOL" + message: "Successfully staked 1.5 SOL for jupSOL", }, - explanation: "Stake 1.5 SOL to receive jupSOL tokens" - } - ] + explanation: "Stake 1.5 SOL to receive jupSOL tokens", + }, + ], ], schema: z.object({ - amount: z.number() - .positive() - .describe("Amount of SOL to stake") + amount: z.number().positive().describe("Amount of SOL to stake"), }), handler: async (agent: SolanaAgentKit, input: Record) => { try { const amount = input.amount as number; - - const res = await stakeWithJup(agent,amount) + + const res = await stakeWithJup(agent, amount); return { status: "success", res, - message: `Successfully staked ${amount} SOL for jupSOL` + message: `Successfully staked ${amount} SOL for jupSOL`, }; } catch (error: any) { return { status: "error", - message: `jupSOL staking failed: ${error.message}` + message: `jupSOL staking failed: ${error.message}`, }; } - } + }, }; -export default stakeWithJupAction; \ No newline at end of file +export default stakeWithJupAction; diff --git a/src/actions/trade.ts b/src/actions/trade.ts index bb27f79..397f0ca 100644 --- a/src/actions/trade.ts +++ b/src/actions/trade.ts @@ -11,7 +11,7 @@ const tradeAction: Action = { "exchange tokens", "trade tokens", "convert tokens", - "swap sol" + "swap sol", ], description: `This tool can be used to swap tokens to another token (It uses Jupiter Exchange).`, examples: [ @@ -19,18 +19,19 @@ const tradeAction: Action = { { input: { outputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", - inputAmount: 1 + inputAmount: 1, }, output: { status: "success", message: "Trade executed successfully", - transaction: "5UfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7", + transaction: + "5UfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7", inputAmount: 1, inputToken: "SOL", - outputToken: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" + outputToken: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", }, - explanation: "Swap 1 SOL for USDC" - } + explanation: "Swap 1 SOL for USDC", + }, ], [ { @@ -38,34 +39,36 @@ const tradeAction: Action = { outputMint: "So11111111111111111111111111111111111111112", inputAmount: 100, inputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", - slippageBps: 100 + slippageBps: 100, }, output: { status: "success", message: "Trade executed successfully", - transaction: "4VfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7", + transaction: + "4VfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7", inputAmount: 100, inputToken: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", - outputToken: "So11111111111111111111111111111111111111112" + outputToken: "So11111111111111111111111111111111111111112", }, - explanation: "Swap 100 USDC for SOL with 1% slippage" - } - ] + explanation: "Swap 100 USDC for SOL with 1% slippage", + }, + ], ], schema: z.object({ outputMint: z.string().min(32, "Invalid output mint address"), inputAmount: z.number().positive("Input amount must be positive"), inputMint: z.string().min(32, "Invalid input mint address").optional(), - slippageBps: z.number().min(0).max(10000).optional() + slippageBps: z.number().min(0).max(10000).optional(), }), handler: async (agent: SolanaAgentKit, input: Record) => { - const tx = await trade(agent, + const tx = await trade( + agent, new PublicKey(input.outputMint), input.inputAmount, input.inputMint ? new PublicKey(input.inputMint) : new PublicKey("So11111111111111111111111111111111111111112"), - input.slippageBps + input.slippageBps, ); return { @@ -74,9 +77,9 @@ const tradeAction: Action = { transaction: tx, inputAmount: input.inputAmount, inputToken: input.inputMint || "SOL", - outputToken: input.outputMint + outputToken: input.outputMint, }; - } + }, }; -export default tradeAction; \ No newline at end of file +export default tradeAction; diff --git a/src/actions/transfer.ts b/src/actions/transfer.ts index 3769481..cc8a648 100644 --- a/src/actions/transfer.ts +++ b/src/actions/transfer.ts @@ -11,7 +11,7 @@ const transferAction: Action = { "transfer funds", "send money", "send sol", - "transfer tokens" + "transfer tokens", ], description: `Transfer tokens or SOL to another address (also called as wallet address).`, examples: [ @@ -19,7 +19,7 @@ const transferAction: Action = { { input: { to: "8x2dR8Mpzuz2YqyZyZjUbYWKSWesBo5jMx2Q9Y86udVk", - amount: 1 + amount: 1, }, output: { status: "success", @@ -27,17 +27,18 @@ const transferAction: Action = { amount: 1, recipient: "8x2dR8Mpzuz2YqyZyZjUbYWKSWesBo5jMx2Q9Y86udVk", token: "SOL", - transaction: "5UfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7" + transaction: + "5UfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7", }, - explanation: "Transfer 1 SOL to the recipient address" - } + explanation: "Transfer 1 SOL to the recipient address", + }, ], [ { input: { to: "8x2dR8Mpzuz2YqyZyZjUbYWKSWesBo5jMx2Q9Y86udVk", amount: 100, - mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" + mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", }, output: { status: "success", @@ -45,22 +46,23 @@ const transferAction: Action = { amount: 100, recipient: "8x2dR8Mpzuz2YqyZyZjUbYWKSWesBo5jMx2Q9Y86udVk", token: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", - transaction: "4VfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7" + transaction: + "4VfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7", }, - explanation: "Transfer 100 USDC tokens to the recipient address" - } - ] + explanation: "Transfer 100 USDC tokens to the recipient address", + }, + ], ], schema: z.object({ to: z.string().min(32, "Invalid Solana address"), amount: z.number().positive("Amount must be positive"), - mint: z.string().optional() + mint: z.string().optional(), }), handler: async (agent: SolanaAgentKit, input: Record) => { const recipient = new PublicKey(input.to); const mintAddress = input.mint ? new PublicKey(input.mint) : undefined; - const tx = await transfer(agent,recipient, input.amount, mintAddress); + const tx = await transfer(agent, recipient, input.amount, mintAddress); return { status: "success", @@ -68,9 +70,9 @@ const transferAction: Action = { amount: input.amount, recipient: input.to, token: input.mint || "SOL", - transaction: tx + transaction: tx, }; - } + }, }; -export default transferAction; \ No newline at end of file +export default transferAction; diff --git a/src/langchain/index.ts b/src/langchain/index.ts index 4e64556..09df522 100644 --- a/src/langchain/index.ts +++ b/src/langchain/index.ts @@ -10,7 +10,6 @@ import { create_image } from "../tools/create_image"; import { BN } from "@coral-xyz/anchor"; import { FEE_TIERS } from "../tools"; import { toJSON } from "../utils/toJSON"; -import { wrapLangChainTool } from "../utils/langchainWrapper"; import deployTokenAction from "../actions/deployToken"; import balanceAction from "../actions/balance"; import transferAction from "../actions/transfer"; @@ -41,7 +40,7 @@ export class SolanaBalanceTool extends Tool { return JSON.stringify({ status: "error", message: error.message, - code: error.code || "UNKNOWN_ERROR" + code: error.code || "UNKNOWN_ERROR", }); } } @@ -69,7 +68,7 @@ export class SolanaTransferTool extends Tool { return JSON.stringify({ status: "error", message: error.message, - code: error.code || "UNKNOWN_ERROR" + code: error.code || "UNKNOWN_ERROR", }); } } @@ -97,7 +96,7 @@ export class SolanaDeployTokenTool extends Tool { return JSON.stringify({ status: "error", message: error.message, - code: error.code || "UNKNOWN_ERROR" + code: error.code || "UNKNOWN_ERROR", }); } } @@ -125,7 +124,7 @@ export class SolanaDeployCollectionTool extends Tool { return JSON.stringify({ status: "error", message: error.message, - code: error.code || "UNKNOWN_ERROR" + code: error.code || "UNKNOWN_ERROR", }); } } @@ -153,7 +152,7 @@ export class SolanaMintNFTTool extends Tool { return JSON.stringify({ status: "error", message: error.message, - code: error.code || "UNKNOWN_ERROR" + code: error.code || "UNKNOWN_ERROR", }); } } @@ -181,7 +180,7 @@ export class SolanaTradeTool extends Tool { return JSON.stringify({ status: "error", message: error.message, - code: error.code || "UNKNOWN_ERROR" + code: error.code || "UNKNOWN_ERROR", }); } } @@ -206,7 +205,7 @@ export class SolanaRequestFundsTool extends Tool { return JSON.stringify({ status: "error", message: error.message, - code: error.code || "UNKNOWN_ERROR" + code: error.code || "UNKNOWN_ERROR", }); } } diff --git a/src/types/action.ts b/src/types/action.ts index d715177..df4c0be 100644 --- a/src/types/action.ts +++ b/src/types/action.ts @@ -13,7 +13,10 @@ export interface ActionExample { /** * Handler function type for executing the action */ -export type Handler = (agent: SolanaAgentKit, input: Record) => Promise>; +export type Handler = ( + agent: SolanaAgentKit, + input: Record, +) => Promise>; /** * Main Action interface inspired by ELIZA @@ -50,4 +53,4 @@ export interface Action { * Function that executes the action */ handler: Handler; -} \ No newline at end of file +} diff --git a/src/utils/actionExecutor.ts b/src/utils/actionExecutor.ts index 0bb8f4b..e152ecb 100644 --- a/src/utils/actionExecutor.ts +++ b/src/utils/actionExecutor.ts @@ -7,9 +7,10 @@ import { actions } from "../actions"; */ export function findAction(query: string): Action | undefined { const normalizedQuery = query.toLowerCase().trim(); - return actions.find(action => - action.name.toLowerCase() === normalizedQuery || - action.similes.some(simile => simile.toLowerCase() === normalizedQuery) + return actions.find( + (action) => + action.name.toLowerCase() === normalizedQuery || + action.similes.some((simile) => simile.toLowerCase() === normalizedQuery), ); } @@ -19,18 +20,18 @@ export function findAction(query: string): Action | undefined { export async function executeAction( action: Action, agent: SolanaAgentKit, - input: Record + input: Record, ): Promise> { try { // Validate input using Zod schema const validatedInput = action.schema.parse(input); - + // Execute the action with validated input const result = await action.handler(agent, validatedInput); - + return { status: "success", - ...result + ...result, }; } catch (error: any) { // Handle Zod validation errors specially @@ -39,14 +40,14 @@ export async function executeAction( status: "error", message: "Validation error", details: error.errors, - code: "VALIDATION_ERROR" + code: "VALIDATION_ERROR", }; } - + return { status: "error", message: error.message, - code: error.code || "EXECUTION_ERROR" + code: error.code || "EXECUTION_ERROR", }; } } @@ -57,11 +58,11 @@ export async function executeAction( export function getActionExamples(action: Action): string { return action.examples .flat() - .map(example => { + .map((example) => { return `Input: ${JSON.stringify(example.input, null, 2)} Output: ${JSON.stringify(example.output, null, 2)} Explanation: ${example.explanation} ---`; }) .join("\n"); -} \ No newline at end of file +} diff --git a/src/utils/langchainWrapper.ts b/src/utils/langchainWrapper.ts deleted file mode 100644 index c7bf500..0000000 --- a/src/utils/langchainWrapper.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { Tool } from "langchain/tools"; -import { Action } from "../types/action"; -import { SolanaAgentKit } from "../agent"; -import { z } from "zod"; - -/** - * Convert a LangChain tool to our Action interface - */ -export function wrapLangChainTool(tool: Tool, agent: SolanaAgentKit): Action { - // Parse the description to extract input parameters - const inputParams = parseToolDescription(tool.description); - - return { - name: tool.name, - similes: [], // LangChain tools don't have similes - description: tool.description, - examples: [], // LangChain tools don't have examples - schema: createZodSchema(inputParams), - handler: async (agent: SolanaAgentKit, input: Record) => { - const result = await tool.call(JSON.stringify(input)); - try { - return JSON.parse(result); - } catch { - return { result }; - } - } - }; -} - -/** - * Parse tool description to extract input parameters - */ -function parseToolDescription(description: string): Array<{name: string, type: string, required: boolean}> { - const lines = description.split('\n'); - const params: Array<{name: string, type: string, required: boolean}> = []; - - let inInputsSection = false; - for (const line of lines) { - const trimmed = line.trim(); - - if (trimmed === 'Inputs:' || trimmed === 'Inputs (input is a JSON string):') { - inInputsSection = true; - continue; - } - - if (inInputsSection && trimmed) { - // Match patterns like: name: string, eg "value" (required) - const match = trimmed.match(/(\w+):\s*([\w\[\]]+)(?:,\s*eg[:\s]+"[^"]+")?(?:\s*\((required|optional)\))?/); - if (match) { - params.push({ - name: match[1], - type: match[2], - required: match[3] === 'required' - }); - } - } - } - - return params; -} - -/** - * Create a Zod schema from parsed parameters - */ -function createZodSchema(params: Array<{name: string, type: string, required: boolean}>): z.ZodType { - const schemaObj: Record> = {}; - - for (const param of params) { - let schema: z.ZodType; - - switch (param.type.toLowerCase()) { - case 'string': - schema = z.string(); - break; - case 'number': - schema = z.number(); - break; - case 'boolean': - schema = z.boolean(); - break; - case 'string[]': - schema = z.array(z.string()); - break; - default: - schema = z.any(); - } - - if (!param.required) { - schema = schema.optional(); - } - - schemaObj[param.name] = schema; - } - - return z.object(schemaObj); -} \ No newline at end of file diff --git a/test/index.ts b/test/index.ts index 5aae92e..d60f8d2 100644 --- a/test/index.ts +++ b/test/index.ts @@ -7,8 +7,6 @@ import { ChatOpenAI } from "@langchain/openai"; import * as dotenv from "dotenv"; import * as fs from "fs"; import * as readline from "readline"; -import { Tool } from "@langchain/core/tools"; -import { Action } from "../src/types/action"; dotenv.config();