import { PublicKey , SYSVAR_CLOCK_PUBKEY , SYSVAR_RENT_PUBKEY , TransactionInstruction , } from '@solana/web3.js' ; import { getGovernanceSchema } from './serialisation' ; import { serialize } from 'borsh' ; import { CastVoteArgs , Vote } from './instructions' ; import { getVoteRecordAddress } from './accounts' ; import { PROGRAM_VERSION_V1 } from '../registry/constants' ; import { SYSTEM_PROGRAM_ID } from '../tools/sdk/runtime' ; export const withCastVote = async ( instructions , programId , programVersion , realm , governance , proposal , proposalOwnerRecord , tokenOwnerRecord , governanceAuthority , governingTokenMint , vote , payer ) => { const args = new CastVoteArgs ( programVersion === PROGRAM_VERSION_V1 ? { yesNoVote : vote . toYesNoVote ( ) , vote : undefined } : { yesNoVote : undefined , vote : vote } ) ; const data = Buffer . from ( serialize ( getGovernanceSchema ( programVersion ) , args ) ) ; const voteRecordAddress = await getVoteRecordAddress ( programId , proposal , tokenOwnerRecord ) ; const keys = [ { pubkey : realm , isWritable : false , isSigner : false , } , { pubkey : governance , isWritable : false , isSigner : false , } , { pubkey : proposal , isWritable : true , isSigner : false , } , { pubkey : proposalOwnerRecord , isWritable : true , isSigner : false , } , { pubkey : tokenOwnerRecord , isWritable : true , isSigner : false , } , { pubkey : governanceAuthority , isWritable : false , isSigner : true , } , { pubkey : voteRecordAddress , isWritable : true , isSigner : false , } , { pubkey : governingTokenMint , isWritable : false , isSigner : false , } , { pubkey : payer , isWritable : false , isSigner : true , } , { pubkey : SYSTEM_PROGRAM_ID , isSigner : false , isWritable : false , } , { pubkey : SYSVAR_RENT_PUBKEY , isSigner : false , isWritable : false , } , { pubkey : SYSVAR_CLOCK_PUBKEY , isSigner : false , isWritable : false , } , ] ; instructions . push ( new TransactionInstruction ( { keys , programId , data , } ) ) ; return voteRecordAddress ; } ;