move types and created actions

This commit is contained in:
UjjwalGupta49
2025-01-06 17:50:39 +05:30
parent 224d7ff5b3
commit de4e724365
38 changed files with 241 additions and 79 deletions

View File

@@ -0,0 +1,68 @@
import { Action } from "../types/action";
import { SolanaAgentKit } from "../agent";
import { z } from "zod";
import { flashCloseTrade } from "../tools";
const flashCloseTradeAction: Action = {
name: "FLASH_CLOSE_TRADE",
similes: [
"close trade",
"close leveraged trade",
"exit position",
"close position",
"exit trade",
"close long",
"close short",
"take profit",
"stop loss",
],
description:
"Close an existing leveraged trading position on Flash.Trade protocol",
examples: [
[
{
input: {
token: "SOL",
side: "long",
},
output: {
status: "success",
signature: "4xKpN2...",
message: "Successfully closed long position on SOL",
},
explanation: "Close an existing long position on SOL",
},
],
],
schema: z.object({
token: z
.string()
.describe("Token symbol of the position to close (e.g. SOL, ETH)"),
side: z
.enum(["long", "short"])
.describe("Position side to close - long or short"),
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
try {
const params = {
token: input.token as string,
side: input.side as "long" | "short",
};
const response = await flashCloseTrade(agent, params);
return {
status: "success",
signature: response,
message: `Successfully closed ${params.side} position on ${params.token}`,
};
} catch (error: any) {
return {
status: "error",
message: `Flash trade close failed: ${error.message}`,
};
}
},
};
export default flashCloseTradeAction;

View File

@@ -0,0 +1,78 @@
import { Action } from "../types/action";
import { SolanaAgentKit } from "../agent";
import { z } from "zod";
import { flashOpenTrade } from "../tools";
const flashOpenTradeAction: Action = {
name: "FLASH_OPEN_TRADE",
similes: [
"open trade",
"open leveraged trade",
"start trading position",
"open position",
"long position",
"short position",
"leverage trade",
"margin trade",
],
description: "Open a leveraged trading position on Flash.Trade protocol",
examples: [
[
{
input: {
token: "SOL",
side: "long",
collateralUsd: 100,
leverage: 5,
},
output: {
status: "success",
signature: "4xKpN2...",
message:
"Successfully opened 5x long position on SOL with $100 collateral",
},
explanation:
"Open a 5x leveraged long position on SOL using $100 as collateral",
},
],
],
schema: z.object({
token: z.string().describe("Token symbol to trade (e.g. SOL, ETH)"),
side: z
.enum(["long", "short"])
.describe("Trading direction - long or short"),
collateralUsd: z
.number()
.positive()
.describe("Amount of collateral in USD"),
leverage: z
.number()
.positive()
.describe("Leverage multiplier for the trade"),
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
try {
const params = {
token: input.token as string,
side: input.side as "long" | "short",
collateralUsd: input.collateralUsd as number,
leverage: input.leverage as number,
};
const response = await flashOpenTrade(agent, params);
return {
status: "success",
signature: response,
message: `Successfully opened ${params.leverage}x ${params.side} position on ${params.token} with $${params.collateralUsd} collateral`,
};
} catch (error: any) {
return {
status: "error",
message: `Flash trade failed: ${error.message}`,
};
}
},
};
export default flashOpenTradeAction;