import { PublicKey , SYSVAR_RENT_PUBKEY , TransactionInstruction , } from '@solana/web3.js' ; import { getGovernanceSchema } from './serialisation' ; import { serialize } from 'borsh' ; import { DepositGoverningTokensArgs } from './instructions' ; import { getTokenOwnerRecordAddress , GOVERNANCE_PROGRAM_SEED , } from './accounts' ; import BN from 'bn.js' ; import { SYSTEM_PROGRAM_ID } from '../tools/sdk/runtime' ; import { TOKEN_PROGRAM_ID } from '../tools/sdk/splToken' ; export const withDepositGoverningTokens = async ( instructions , programId , programVersion , realm , governingTokenSource , governingTokenMint , governingTokenOwner , transferAuthority , payer , amount ) => { const args = new DepositGoverningTokensArgs ( { amount } ) ; const data = Buffer . from ( serialize ( getGovernanceSchema ( programVersion ) , args ) ) ; const tokenOwnerRecordAddress = await getTokenOwnerRecordAddress ( programId , realm , governingTokenMint , governingTokenOwner ) ; const [ governingTokenHoldingAddress ] = await PublicKey . findProgramAddress ( [ Buffer . from ( GOVERNANCE_PROGRAM_SEED ) , realm . toBuffer ( ) , governingTokenMint . toBuffer ( ) , ] , programId ) ; const keys = [ { pubkey : realm , isWritable : false , isSigner : false , } , { pubkey : governingTokenHoldingAddress , isWritable : true , isSigner : false , } , { pubkey : governingTokenSource , isWritable : true , isSigner : false , } , { pubkey : governingTokenOwner , isWritable : false , isSigner : true , } , { pubkey : transferAuthority , isWritable : false , isSigner : true , } , { pubkey : tokenOwnerRecordAddress , isWritable : true , isSigner : false , } , { pubkey : payer , isWritable : false , isSigner : true , } , { pubkey : SYSTEM_PROGRAM_ID , isWritable : false , isSigner : false , } , { pubkey : TOKEN_PROGRAM_ID , isWritable : false , isSigner : false , } , { pubkey : SYSVAR_RENT_PUBKEY , isWritable : false , isSigner : false , } , ] ; instructions . push ( new TransactionInstruction ( { keys , programId , data , } ) ) ; return tokenOwnerRecordAddress ; } ;