feat: Refactor actions to use tool functions for improved code clarity and maintainability

This commit is contained in:
Fahri Bilici
2024-12-28 16:24:57 +01:00
parent 9326da25b1
commit 378fea201d
30 changed files with 118 additions and 654 deletions

View File

@@ -2,6 +2,7 @@ import { PublicKey } from "@solana/web3.js";
import { Action, ActionExample } from "../types/action";
import { SolanaAgentKit } from "../agent";
import { z } from "zod";
import { deploy_token } from "../tools";
const deployTokenAction: Action = {
name: "deploy_token",
@@ -55,19 +56,27 @@ const deployTokenAction: Action = {
initialSupply: z.number().optional()
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
const result = await agent.deployToken(
input.name,
input.uri,
input.symbol,
input.decimals,
input.initialSupply
);
try {
const result = await deploy_token(
agent,
input.name,
input.uri,
input.symbol,
input.decimals,
input.initialSupply
);
return {
mint: result.mint.toString(),
status: "success",
message: "Token deployed successfully"
};
return {
mint: result.mint.toString(),
status: "success",
message: "Token deployed successfully"
};
} catch (error: any) {
return {
status: "error",
message: `Token deployment failed: ${error.message}`
};
}
}
}