added write functionalities ie, swap and transfer

This commit is contained in:
Deepak
2024-12-27 16:53:12 +05:30
parent ab9259d4e2
commit 3cdd45d623
13 changed files with 572 additions and 17 deletions

View File

@@ -0,0 +1,48 @@
import { StructuredOutputParser } from "@langchain/core/output_parsers";
import { z } from "zod";
import { PromptTemplate } from "@langchain/core/prompts";
export const parser = StructuredOutputParser.fromZodSchema(
z.object({
isSolanaReadQuery: z
.boolean()
.describe("Query requires reading data from Solana blockchain"),
isSolanaWriteQuery: z
.boolean()
.describe("Query requires writing/modifying data on Solana blockchain"),
isGeneralQuery: z
.boolean()
.describe("Query is about non-blockchain topics"),
}),
);
export const prompt = PromptTemplate.fromTemplate(
`
You are the Chief Routing Officer for a multi-blockchain agent network. Your role is to:
1. Analyze and classify incoming queries
2. Determine if the query requires Solana read operations, write operations, or is general
Format your response according to:
{formatInstructions}
Classification Guidelines:
- Solana Read Operations include:
* Checking account balances
* Viewing NFT metadata
* Getting program data
* Querying transaction history
* Checking token prices or holdings
- Solana Write Operations include:
* Creating or updating programs
* Sending tokens or SOL
* Minting NFTs
* Creating accounts
* Any transaction that modifies blockchain state
- General queries include:
* Non-blockchain topics
* Internet searches
* General knowledge questions
\n {messages} \n
`,
);

View File

@@ -0,0 +1,43 @@
import {
ChatPromptTemplate,
MessagesPlaceholder,
} from "@langchain/core/prompts";
import { tokenList } from "../helper/tokenList";
// Convert token list to a more readable format for the prompt
const formattedTokenList = tokenList
.map(
(token) =>
`- ${token.name} (${token.ticker}) - Decimals: ${token.decimal} - Address: ${token.mintAddress}`,
)
.join("\n ");
export const transferSwapPrompt = ChatPromptTemplate.fromMessages([
[
"system",
`You are an agent that is an expert in Solana transactions, specialized in token transfers and swaps. You can execute these transactions using the available tools based on user input.
When processing token amounts:
1. Use EXACTLY the decimal amount specified by the user without any modifications
2. Do not round or adjust the numbers
3. Maintain precise decimal places as provided in the user input
For transfers:
- User must specify the token, amount, and recipient address
- The same token will be used for input and output
For swaps:
- User must specify the input token, output token, and amount to swap
- Input and output tokens must be different
- Select tokens from this list of supported tokens:
${formattedTokenList}
Example amounts:
If you say "0.01 SOL", I will use exactly 0.01 (not 0.010 or 0.0100)
If you say "1.234 USDC", I will use exactly 1.234 (not 1.23 or 1.2340)
For swaps, have the slippage be 200 bps
`,
],
new MessagesPlaceholder("messages"),
]);