mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-06-02 23:26:50 +00:00
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { PublicKey } from "@solana/web3.js";
|
|
import { Tool } from "langchain/tools";
|
|
import { SolanaAgentKit } from "../../agent";
|
|
|
|
export class SolanaCancelAllOrdersTool extends Tool {
|
|
name = "solana_cancel_all_orders";
|
|
description = `This tool can be used to cancel all orders from a Manifest market.
|
|
|
|
Input ( input is a JSON string ):
|
|
marketId: string, eg "ENhU8LsaR7vDD2G1CsWcsuSGNrih9Cv5WZEk7q9kPapQ" for SOL/USDC (required)`;
|
|
|
|
constructor(private solanaKit: SolanaAgentKit) {
|
|
super();
|
|
}
|
|
|
|
protected async _call(input: string): Promise<string> {
|
|
try {
|
|
const marketId = new PublicKey(input.trim());
|
|
const tx = await this.solanaKit.cancelAllOrders(marketId);
|
|
|
|
return JSON.stringify({
|
|
status: "success",
|
|
message: "Cancel orders successfully",
|
|
transaction: tx,
|
|
marketId,
|
|
});
|
|
} catch (error: any) {
|
|
return JSON.stringify({
|
|
status: "error",
|
|
message: error.message,
|
|
code: error.code || "UNKNOWN_ERROR",
|
|
});
|
|
}
|
|
}
|
|
}
|