import { PublicKey } from '@solana/web3.js' ; import * as anchor from '@project-serum/anchor' ; export async function getClearingHouseStateAccountPublicKeyAndNonce ( programId ) { return anchor . web3 . PublicKey . findProgramAddress ( [ Buffer . from ( anchor . utils . bytes . utf8 . encode ( 'clearing_house' ) ) ] , programId ) ; } export async function getClearingHouseStateAccountPublicKey ( programId ) { return ( await getClearingHouseStateAccountPublicKeyAndNonce ( programId ) ) [ 0 ] ; } export async function getUserAccountPublicKeyAndNonce ( programId , authority ) { return anchor . web3 . PublicKey . findProgramAddress ( [ Buffer . from ( anchor . utils . bytes . utf8 . encode ( 'user' ) ) , authority . toBuffer ( ) ] , programId ) ; } export async function getUserAccountPublicKey ( programId , authority ) { return ( await getUserAccountPublicKeyAndNonce ( programId , authority ) ) [ 0 ] ; }