From ea6430129bf395698dfcc512be10e20a7950af56 Mon Sep 17 00:00:00 2001 From: Arihant Bansal <17180950+arihantbansal@users.noreply.github.com> Date: Sat, 11 Jan 2025 23:24:58 +0530 Subject: [PATCH] feat: add more squads actions --- src/actions/approveMultisigProposal.ts | 50 ++++++++++++++++++ src/actions/createMultisigProposal.ts | 53 +++++++++++++++++++ src/actions/depositToMultisigTreasury.ts | 10 ++-- src/actions/index.ts | 6 +++ src/actions/transferFromMultisigTreasury.ts | 56 +++++++++++++++++++++ 5 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 src/actions/approveMultisigProposal.ts create mode 100644 src/actions/createMultisigProposal.ts create mode 100644 src/actions/transferFromMultisigTreasury.ts diff --git a/src/actions/approveMultisigProposal.ts b/src/actions/approveMultisigProposal.ts new file mode 100644 index 0000000..c60a8a1 --- /dev/null +++ b/src/actions/approveMultisigProposal.ts @@ -0,0 +1,50 @@ +import { Action } from "../types/action"; +import { SolanaAgentKit } from "../agent"; +import { z } from "zod"; +import { multisig_approve_proposal } from "../tools"; + +const approveMultisigProposalAction: Action = { + name: "APPROVE_MULTISIG_PROPOSAL_ACTION", + similes: [ + "approve proposal", + "approve proposal to transfer funds", + "approve proposal to transfer funds from 2-of-2 multisig", + "approve proposal to transfer funds from 2-of-2 multisig account", + "approve proposal to transfer funds from 2-of-2 multisig account on Solana", + ], + description: `Approve a proposal to transfer funds from a 2-of-2 multisig account on Solana with the user and the agent, where both approvals will be required to run the transactions. + + Note: For one AI agent, only one 2-by-2 multisig can be created as it is pair-wise.`, + examples: [ + [ + { + input: { + transactionIndex: 0, + }, + output: { + status: "success", + message: "Proposal approved successfully", + transaction: "4xKpN2...", + transactionIndex: "0", + }, + explanation: + "Approve a proposal to transfer 1 SOL from 2-of-2 multisig account on Solana", + }, + ], + ], + schema: z.object({ + transactionIndex: z.number().optional(), + }), + handler: async (agent: SolanaAgentKit, input: Record) => { + const tx = await multisig_approve_proposal(agent, input.transactionIndex); + + return { + status: "success", + message: "Proposal approved successfully", + transaction: tx, + transactionIndex: input.transactionIndex.toString(), + }; + }, +}; + +export default approveMultisigProposalAction; diff --git a/src/actions/createMultisigProposal.ts b/src/actions/createMultisigProposal.ts new file mode 100644 index 0000000..9c83ab5 --- /dev/null +++ b/src/actions/createMultisigProposal.ts @@ -0,0 +1,53 @@ +import { Action } from "../types/action"; +import { SolanaAgentKit } from "../agent"; +import { z } from "zod"; +import { multisig_create_proposal } from "../tools"; + +const createMultisigProposalAction: Action = { + name: "CREATE_MULTISIG_PROPOSAL_ACTION", + similes: [ + "create proposal", + "create proposal to transfer funds", + "create proposal to transfer funds from 2-of-2 multisig", + "create proposal to transfer funds from 2-of-2 multisig account", + "create proposal to transfer funds from 2-of-2 multisig account on Solana", + ], + description: `Create a proposal to transfer funds from a 2-of-2 multisig account on Solana with the user and the agent, where both approvals will be required to run the transactions. + + If transactionIndex is not provided, the latest index will automatically be fetched and used.`, + examples: [ + [ + { + input: { + transactionIndex: 0, + }, + output: { + status: "success", + message: "Proposal created successfully", + transaction: "4xKpN2...", + transactionIndex: "0", + }, + explanation: + "Create a proposal to transfer 1 SOL from 2-of-2 multisig account on Solana", + }, + ], + ], + schema: z.object({ + transactionIndex: z.number().optional(), + }), + handler: async (agent: SolanaAgentKit, input: Record) => { + const multisig = await multisig_create_proposal( + agent, + input.transactionIndex as number, + ); + + return { + status: "success", + message: "Proposal created successfully", + transaction: multisig, + transactionIndex: input.transactionIndex as number, + }; + }, +}; + +export default createMultisigProposalAction; diff --git a/src/actions/depositToMultisigTreasury.ts b/src/actions/depositToMultisigTreasury.ts index b0e1985..520dc62 100644 --- a/src/actions/depositToMultisigTreasury.ts +++ b/src/actions/depositToMultisigTreasury.ts @@ -1,17 +1,17 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; import { z } from "zod"; -import { create_squads_multisig, multisig_deposit_to_treasury } from "../tools"; +import { multisig_deposit_to_treasury } from "../tools"; const depositToMultisigAction: Action = { name: "DEPOSIT_TO_MULTISIG_ACTION", similes: [ "deposit to multisig", "deposit to squads multisig", - "deposit to 2-by-2 multisig", - "deposit to 2-of-2 multisig", - "deposit SOL to 2-of-2 multisig account on Solana", - "deposit SPL tokens to 2-of-2 multisig account", + "deposit to 2-of-2 multisig account", + "deposit to 2-of-2 multisig account on Solana", + "deposit SOL to 2-of-2 multisig", + "deposit SPL tokens to 2-of-2 multisig", ], description: `Deposit funds to a 2-of-2 multisig account on Solana with the user and the agent, where both approvals will be required to run the transactions.`, examples: [ diff --git a/src/actions/index.ts b/src/actions/index.ts index 74ff542..c29483a 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -32,6 +32,9 @@ import flashOpenTradeAction from "./flashOpenTrade"; import flashCloseTradeAction from "./flashCloseTrade"; import createMultisigAction from "./createMultisig"; import depositToMultisigAction from "./depositToMultisigTreasury"; +import transferFromMultisigAction from "./transferFromMultisigTreasury"; +import createMultisigProposalAction from "./createMultisigProposal"; +import approveMultisigProposalAction from "./approveMultisigProposal"; export const ACTIONS = { WALLET_ADDRESS_ACTION: getWalletAddressAction, @@ -69,6 +72,9 @@ export const ACTIONS = { FLASH_CLOSE_TRADE_ACTION: flashCloseTradeAction, CREATE_MULTISIG_ACTION: createMultisigAction, DEPOSIT_TO_MULTISIG_ACTION: depositToMultisigAction, + TRANSFER_FROM_MULTISIG_ACTION: transferFromMultisigAction, + CREATE_MULTISIG_PROPOSAL_ACTION: createMultisigProposalAction, + APPROVE_MULTISIG_PROPOSAL_ACTION: approveMultisigProposalAction, }; export type { Action, ActionExample, Handler } from "../types/action"; diff --git a/src/actions/transferFromMultisigTreasury.ts b/src/actions/transferFromMultisigTreasury.ts new file mode 100644 index 0000000..cddb205 --- /dev/null +++ b/src/actions/transferFromMultisigTreasury.ts @@ -0,0 +1,56 @@ +import { Action } from "../types/action"; +import { SolanaAgentKit } from "../agent"; +import { z } from "zod"; +import { multisig_transfer_from_treasury } from "../tools"; +import { PublicKey } from "@solana/web3.js"; + +const transferFromMultisigAction: Action = { + name: "TRANSFER_FROM_MULTISIG_ACTION", + similes: [ + "transfer from multisig", + "transfer from squads multisig", + "transfer SOL from 2-by-2 multisig", + "transfer from 2-of-2 multisig account", + "transfer from 2-of-2 multisig account on Solana", + ], + description: `Create a transaction to transfer funds from a 2-of-2 multisig account on Solana using Squads with the user and the agent, where both approvals will be required to run the transactions.`, + examples: [ + [ + { + input: { + amount: 1, + recipient: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN", + }, + output: { + status: "success", + message: "Transaction added to 2-by-2 multisig account successfully", + transaction: "4xKpN2...", + amount: "1", + recipient: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN", + }, + explanation: "Transfer 1 SOL from 2-of-2 multisig account on Solana", + }, + ], + ], + schema: z.object({ + amount: z.number().min(0, "Amount must be greater than 0"), + recipient: z.string().optional(), + }), + handler: async (agent: SolanaAgentKit, input: Record) => { + const multisig = await multisig_transfer_from_treasury( + agent, + input.amount as number, + new PublicKey(input.recipient as string), + ); + + return { + status: "success", + message: "Transaction added to 2-by-2 multisig account successfully", + transaction: multisig, + amount: input.amount, + recipient: input.recipient, + }; + }, +}; + +export default transferFromMultisigAction;