From 7084d0f25299b90b137ef77479bb76396f4a926c Mon Sep 17 00:00:00 2001 From: Kirk Date: Tue, 2 Jan 2024 14:34:01 +0100 Subject: [PATCH] Create withRemoveSignatory Implemented RemoveSignatory in withRemoveSignatory --- .../src/governance/withRemoveSignatory | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 packages/governance-sdk/src/governance/withRemoveSignatory diff --git a/packages/governance-sdk/src/governance/withRemoveSignatory b/packages/governance-sdk/src/governance/withRemoveSignatory new file mode 100644 index 00000000..040e8ec1 --- /dev/null +++ b/packages/governance-sdk/src/governance/withRemoveSignatory @@ -0,0 +1,84 @@ +import { + PublicKey, + SYSVAR_RENT_PUBKEY, + TransactionInstruction, +} from '@solana/web3.js'; +import { getGovernanceInstructionSchema } from './serialisation'; +import { serialize } from 'borsh'; +import { RemoveSignatoryArgs } from './instructions'; +import { getSignatoryRecordAddress } from './accounts'; +import { SYSTEM_PROGRAM_ID } from '../tools/sdk/runtime'; +import { PROGRAM_VERSION_V1 } from '../registry/constants'; + +export const withAddSignatory = async ( + instructions: TransactionInstruction[], + programId: PublicKey, + programVersion: number, + proposal: PublicKey, + tokenOwnerRecord: PublicKey, + governanceAuthority: PublicKey, + signatory: PublicKey, + payer: PublicKey, +) => { + const args = new RemoveSignatoryArgs({ signatory }); + const data = Buffer.from( + serialize(getGovernanceInstructionSchema(programVersion), args), + ); + + const signatoryRecordAddress = await getSignatoryRecordAddress( + programId, + proposal, + signatory, + ); + + const keys = [ + { + pubkey: proposal, + isWritable: true, + isSigner: false, + }, + { + pubkey: tokenOwnerRecord, + isWritable: false, + isSigner: false, + }, + { + pubkey: governanceAuthority, + isWritable: false, + isSigner: true, + }, + { + pubkey: signatoryRecordAddress, + isWritable: true, + isSigner: false, + }, + { + pubkey: payer, + isWritable: true, + isSigner: true, + }, + { + pubkey: SYSTEM_PROGRAM_ID, + isSigner: false, + isWritable: false, + }, + ]; + + if (programVersion === PROGRAM_VERSION_V1) { + keys.push({ + pubkey: SYSVAR_RENT_PUBKEY, + isSigner: false, + isWritable: false, + }); + } + + instructions.push( + new TransactionInstruction({ + keys, + programId, + data, + }), + ); + + return signatoryRecordAddress; +};