feat: send transaction with proiority fee

This commit is contained in:
shivaji43
2025-01-08 01:31:05 +05:30
parent 2de1a7365d
commit 4a270c4a0d
6 changed files with 171 additions and 26 deletions

View File

@@ -100,6 +100,51 @@ import {
SolanaGetAllAssetsByOwner,
} from "./index";
export class SolanaSendTransactionWithPriorityFee extends Tool {
name = "solana_send_transaction_with_priority_fee";
description = `Sends a Solana transaction with a user-defined priority fee.
**Inputs (JSON-encoded string)**:
- priorityLevel: string — the priority level ("NONE", "Min", "Low", "Medium", "High", "VeryHigh", or "UnsafeMax")
- amount: number — the amount of SOL to send
- to: string — the recipient's wallet address (public key in base58);`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const { priorityLevel, amount, to } = JSON.parse(input);
if (!priorityLevel || !amount || !to) {
throw new Error(
`Missing required fields. Received: priorityLevel=${priorityLevel}, amount=${amount}, to=${to}`,
);
}
const toPubkey = new PublicKey(to);
const priorityFeeTx = await this.solanaKit.sendTranctionWithPriority(
priorityLevel,
amount,
toPubkey,
);
return JSON.stringify({
status: "success",
message: "Transaction sent successfully",
priorityFeeTx,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export function createSolanaTools(solanaKit: SolanaAgentKit) {
return [
new SolanaBalanceTool(solanaKit),