mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-23 23:26:45 +00:00
36 lines
967 B
TypeScript
36 lines
967 B
TypeScript
import { Tool } from "langchain/tools";
|
|
import { SolanaAgentKit } from "../../agent";
|
|
|
|
export class SolanaStakeTool extends Tool {
|
|
name = "solana_stake";
|
|
description = `This tool can be used to stake your SOL (Solana), also called as SOL staking or liquid staking.
|
|
|
|
Inputs ( input is a JSON string ):
|
|
amount: number, eg 1 or 0.01 (required)`;
|
|
|
|
constructor(private solanaKit: SolanaAgentKit) {
|
|
super();
|
|
}
|
|
|
|
protected async _call(input: string): Promise<string> {
|
|
try {
|
|
const parsedInput = JSON.parse(input) || Number(input);
|
|
|
|
const tx = await this.solanaKit.stake(parsedInput.amount);
|
|
|
|
return JSON.stringify({
|
|
status: "success",
|
|
message: "Staked successfully",
|
|
transaction: tx,
|
|
amount: parsedInput.amount,
|
|
});
|
|
} catch (error: any) {
|
|
return JSON.stringify({
|
|
status: "error",
|
|
message: error.message,
|
|
code: error.code || "UNKNOWN_ERROR",
|
|
});
|
|
}
|
|
}
|
|
}
|