Merge branch 'main' into feature/totalbalance

This commit is contained in:
Michael Essiet
2025-01-07 09:12:32 +01:00
committed by GitHub
83 changed files with 32124 additions and 819 deletions

View File

@@ -2,7 +2,6 @@ import { Action } from "../types/action";
import { SolanaAgentKit } from "../agent";
import { z } from "zod";
import { PublicKey } from "@solana/web3.js";
import { BN } from "@coral-xyz/anchor";
import { Decimal } from "decimal.js";
import { orcaCreateSingleSidedLiquidityPool } from "../tools";

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;

View File

@@ -0,0 +1,29 @@
import { z } from "zod";
import { SolanaAgentKit } from "..";
import { get_wallet_address } from "../tools";
import { Action } from "../types/action";
const getWalletAddressAction: Action = {
name: "GET_WALLET_ADDRESS",
similes: ["wallet address", "address", "wallet"],
description: "Get wallet address of the agent",
examples: [
[
{
input: {},
output: {
status: "success",
address: "0x1234567890abcdef",
},
explanation: "The agent's wallet address is 0x1234567890abcdef",
},
],
],
schema: z.object({}),
handler: async (agent: SolanaAgentKit) => ({
status: "success",
address: get_wallet_address(agent),
}),
};
export default getWalletAddressAction;

View File

@@ -10,6 +10,7 @@ import getTokenDataAction from "./getTokenData";
import getTPSAction from "./getTPS";
import fetchPriceAction from "./fetchPrice";
import stakeWithJupAction from "./stakeWithJup";
import stakeWithSolayerAction from "./stakeWithSolayer";
import registerDomainAction from "./registerDomain";
import lendAssetAction from "./lendAsset";
import createGibworkTaskAction from "./createGibworkTask";
@@ -26,8 +27,12 @@ import raydiumCreateCpmmAction from "./raydiumCreateCpmm";
import raydiumCreateAmmV4Action from "./raydiumCreateAmmV4";
import createOrcaSingleSidedWhirlpoolAction from "./createOrcaSingleSidedWhirlpool";
import launchPumpfunTokenAction from "./launchPumpfunToken";
import getWalletAddressAction from "./getWalletAddress";
import flashOpenTradeAction from "./flashOpenTrade";
import flashCloseTradeAction from "./flashCloseTrade";
export const ACTIONS = {
WALLET_ADDRESS_ACTION: getWalletAddressAction,
DEPLOY_TOKEN_ACTION: deployTokenAction,
BALANCE_ACTION: balanceAction,
TRANSFER_ACTION: transferAction,
@@ -40,6 +45,7 @@ export const ACTIONS = {
GET_TPS_ACTION: getTPSAction,
FETCH_PRICE_ACTION: fetchPriceAction,
STAKE_WITH_JUP_ACTION: stakeWithJupAction,
STAKE_WITH_SOLAYER_ACTION: stakeWithSolayerAction,
REGISTER_DOMAIN_ACTION: registerDomainAction,
LEND_ASSET_ACTION: lendAssetAction,
CREATE_GIBWORK_TASK_ACTION: createGibworkTaskAction,
@@ -57,6 +63,8 @@ export const ACTIONS = {
CREATE_ORCA_SINGLE_SIDED_WHIRLPOOL_ACTION:
createOrcaSingleSidedWhirlpoolAction,
LAUNCH_PUMPFUN_TOKEN_ACTION: launchPumpfunTokenAction,
FLASH_OPEN_TRADE_ACTION: flashOpenTradeAction,
FLASH_CLOSE_TRADE_ACTION: flashCloseTradeAction,
};
export type { Action, ActionExample, Handler } from "../types/action";

View File

@@ -1,7 +1,7 @@
import { Action } from "../types/action";
import { SolanaAgentKit } from "../agent";
import { z } from "zod";
import { pythFetchPrice } from "../tools";
import { fetchPythPrice, fetchPythPriceFeedID } from "../tools";
const pythFetchPriceAction: Action = {
name: "PYTH_FETCH_PRICE",
@@ -18,7 +18,7 @@ const pythFetchPriceAction: Action = {
[
{
input: {
priceFeedId: "Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD", // SOL/USD price feed
tokenSymbol: "SOL", // SOL/USD price feed
},
output: {
status: "success",
@@ -30,15 +30,19 @@ const pythFetchPriceAction: Action = {
],
],
schema: z.object({
priceFeedId: z
tokenSymbol: z
.string()
.min(1)
.describe("The Pyth price feed ID to fetch the price from"),
.describe("The token symbol to fetch the price for"),
}),
handler: async (_agent: SolanaAgentKit, input: Record<string, any>) => {
try {
const priceFeedId = input.tokenId as string;
const priceStr = await pythFetchPrice(priceFeedId);
const priceFeedId = await fetchPythPriceFeedID(
input.tokenSymbol as string,
);
const priceStr = await fetchPythPrice(priceFeedId);
return {
status: "success",
price: priceStr,

View File

@@ -0,0 +1,60 @@
import { Action } from "../types/action";
import { SolanaAgentKit } from "../agent";
import { z } from "zod";
import { stakeWithSolayer } from "../tools";
const stakeWithSolayerAction: Action = {
name: "STAKE_WITH_SOLAYER",
similes: [
"stake sol",
"solayer sol",
"ssol",
"stake with solayer",
"solayer restaking",
"solayer staking",
"stake with sol",
"liquid staking solayer",
"get solayer sol",
"solayer sol restaking",
"solayer sol staking",
],
description:
"Stake native SOL with Solayer's restaking protocol to receive Solayer SOL (sSOL)",
examples: [
[
{
input: {
amount: 1.0,
},
output: {
status: "success",
signature: "3FgHn9...",
message: "Successfully staked 1.0 SOL for Solayer SOL (sSOL)",
},
explanation: "Stake 1.0 SOL to receive Solayer SOL (sSOL)",
},
],
],
schema: z.object({
amount: z.number().positive().describe("Amount of SOL to stake"),
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
try {
const amount = input.amount as number;
const res = await stakeWithSolayer(agent, amount);
return {
status: "success",
res,
message: `Successfully staked ${amount} SOL for Solayer SOL (sSOL)`,
};
} catch (error: any) {
return {
status: "error",
message: `Solayer staking failed: ${error.message}`,
};
}
},
};
export default stakeWithSolayerAction;