import { deserializeUnchecked } from "borsh" ; import { clusterApiUrl , Connection , Commitment , PublicKey , } from "@solana/web3.js" ; import { METADATA_SCHEMA , Metadata , METADATA_PREFIX , METADATA_PROGRAM , } from "./config/metaplex" ; import { extendBorsh } from "./config/borsh" ; extendBorsh ( ) ; const metaProgamPublicKey = new PublicKey ( METADATA_PROGRAM ) ; const metaProgamPublicKeyBuffer = metaProgamPublicKey . toBuffer ( ) ; const metaProgamPrefixBuffer = Buffer . from ( METADATA_PREFIX ) ; export const decodeTokenMetadata = async ( buffer ) => deserializeUnchecked ( METADATA_SCHEMA , Metadata , buffer ) ; /**
 * Get Addresses of Metadata account assosiated with Mint Token
 */ export async function getSolanaMetadataAddress ( tokenMint ) { const metaProgamPublicKey = new PublicKey ( METADATA_PROGRAM ) ; return ( await PublicKey . findProgramAddress ( [ metaProgamPrefixBuffer , metaProgamPublicKeyBuffer , tokenMint . toBuffer ( ) ] , metaProgamPublicKey ) ) [ 0 ] ; } /**
 * Check if passed address is Solana address
 */ export const isValidSolanaAddress = ( address ) => { try { new PublicKey ( address ) ; return true ; } catch ( error ) { return false ; } } ; export const createConnectionConfig = ( clusterApi = clusterApiUrl ( "mainnet-beta" ) , commitment = "confirmed" ) => new Connection ( clusterApi , commitment as Commitment ) ;