import { utils } from '@oyster/common' ; import { PublicKey , SYSVAR_CLOCK_PUBKEY , SYSVAR_RENT_PUBKEY , TransactionInstruction , } from '@solana/web3.js' ; export async function createUpgradeInstruction ( programId , bufferAddress , upgradeAuthority , spillAddress ) { const { bpf_upgrade_loader : bpfUpgradableLoaderId } = utils . programIds ( ) ; const [ programDataAddress ] = await PublicKey . findProgramAddress ( [ programId . toBuffer ( ) ] , bpfUpgradableLoaderId ) ; const keys = [ { pubkey : programDataAddress , isWritable : true , isSigner : false , } , { pubkey : programId , isWritable : true , isSigner : false , } , { pubkey : bufferAddress , isWritable : true , isSigner : false , } , { pubkey : spillAddress , isWritable : true , isSigner : false , } , { pubkey : SYSVAR_RENT_PUBKEY , isWritable : false , isSigner : false , } , { pubkey : SYSVAR_CLOCK_PUBKEY , isWritable : false , isSigner : false , } , { pubkey : upgradeAuthority , isWritable : false , isSigner : true , } , ] ; return new TransactionInstruction ( { keys , programId : bpfUpgradableLoaderId , data : Buffer . from ( [ 3 , 0 , 0 , 0 ] ) , } ) ; }