import { PublicKey , SYSVAR_CLOCK_PUBKEY , TransactionInstruction , } from '@solana/web3.js' ; import { GOVERNANCE_SCHEMA } from './serialisation' ; import { serialize } from 'borsh' ; import { ExecuteInstructionArgs } from './instructions' ; import { AccountMetaData , getNativeTreasuryAddress , InstructionData , } from './accounts' ; export const withExecuteInstruction = async ( instructions , programId , governance , proposal , instructionAddress , instruction ) => { const args = new ExecuteInstructionArgs ( ) ; const data = Buffer . from ( serialize ( GOVERNANCE_SCHEMA , args ) ) ; const nativeTreasury = await getNativeTreasuryAddress ( programId , governance ) ; instruction . accounts = instruction . accounts . map ( a => ( a . pubkey . toBase58 ( ) === governance . toBase58 ( ) || a . pubkey . toBase58 ( ) === nativeTreasury . toBase58 ( ) ) && a . isSigner ? new AccountMetaData ( { pubkey : a . pubkey , isWritable : a . isWritable , isSigner : false , } ) : a ) ; let keys = [ { pubkey : governance , isWritable : false , isSigner : false , } , { pubkey : proposal , isWritable : true , isSigner : false , } , { pubkey : instructionAddress , isWritable : true , isSigner : false , } , { pubkey : SYSVAR_CLOCK_PUBKEY , isSigner : false , isWritable : false , } , { pubkey : instruction . programId , isWritable : false , isSigner : false , } , ... instruction . accounts , ] ; instructions . push ( new TransactionInstruction ( { keys , programId , data , } ) ) ; } ;