feat: add more squads actions

This commit is contained in:
Arihant Bansal
2025-01-11 23:24:58 +05:30
parent cd72af002e
commit ea6430129b
5 changed files with 170 additions and 5 deletions

View File

@@ -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<string, any>) => {
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;

View File

@@ -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<string, any>) => {
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;

View File

@@ -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: [

View File

@@ -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";

View File

@@ -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<string, any>) => {
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;