mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-13 23:16:55 +00:00
feat: add rejectMultisigProposal method to SolanaAgentKit and implement proposal rejection functionality
This commit is contained in:
@@ -55,6 +55,7 @@ import { transfer_from_multisig } from "../tools/squads_multisig/transfer_from_m
|
||||
import { create_proposal } from "../tools/squads_multisig/create_proposal";
|
||||
import { approve_proposal } from "../tools/squads_multisig/approve_proposal";
|
||||
import { execute_transaction } from "../tools/squads_multisig/execute_proposal";
|
||||
import { reject_proposal } from "../tools/squads_multisig/reject_proposal";
|
||||
|
||||
/**
|
||||
* Main class for interacting with Solana blockchain
|
||||
@@ -397,6 +398,12 @@ export class SolanaAgentKit {
|
||||
return approve_proposal(this, transactionIndex);
|
||||
}
|
||||
|
||||
async rejectMultisigProposal(
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
return reject_proposal(this, transactionIndex);
|
||||
}
|
||||
|
||||
async executeMultisigTransaction(
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
|
||||
52
src/tools/squads_multisig/reject_proposal.ts
Normal file
52
src/tools/squads_multisig/reject_proposal.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import * as multisig from "@sqds/multisig";
|
||||
const { Multisig } = multisig.accounts;
|
||||
|
||||
/**
|
||||
* Rejects a proposal in a Solana multisig setup.
|
||||
*
|
||||
* @param agent - The SolanaAgentKit instance containing the wallet and connection.
|
||||
* @param transactionIndex - Optional. The index of the transaction to reject. If not provided, the current transaction index will be used.
|
||||
* @returns A promise that resolves to the transaction ID of the rejection transaction.
|
||||
* @throws Will throw an error if the transaction fails.
|
||||
*/
|
||||
export async function reject_proposal(
|
||||
agent: SolanaAgentKit,
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
if (!transactionIndex) {
|
||||
transactionIndex = BigInt(currentTransactionIndex);
|
||||
} else if (typeof transactionIndex !== "bigint") {
|
||||
transactionIndex = BigInt(transactionIndex);
|
||||
}
|
||||
// const [proposalPda, proposalBump] = multisig.getProposalPda({
|
||||
// multisigPda,
|
||||
// transactionIndex,
|
||||
// });
|
||||
const multisigTx = multisig.transactions.proposalReject({
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet.publicKey,
|
||||
multisigPda,
|
||||
transactionIndex: transactionIndex,
|
||||
member: agent.wallet.publicKey,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Transfer failed: ${error}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user