import { getAddressEncoder, getBytesEncoder, getProgramDerivedAddress, type Address, type ProgramDerivedAddress, } from "@solana/kit"; import { findVaultLpMintPda, VOLTR_VAULT_PROGRAM_ADDRESS } from "../generated"; /** * Metaplex Token Metadata program ID. Codama can't derive PDAs that depend on * an external program, so we keep this helper hand-written. */ export const METAPLEX_METADATA_PROGRAM_ADDRESS = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s" as Address<"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s">; const METADATA_SEED = new Uint8Array([ 109, 101, 116, 97, 100, 97, 116, 97, ]); // "metadata" /** * Derives the LP metadata PDA owned by the Metaplex Token Metadata program for * a given Voltr vault. Mirrors the legacy SDK's `findLpMetadataAccount(vault)` * convenience: caller supplies the vault, we compute the LP mint PDA and then * the metadata PDA off of it. */ export async function findLpMetadataPda( seeds: { vault: Address }, config: { voltrProgramAddress?: Address } = {}, ): Promise { const [lpMint] = await findVaultLpMintPda( { vault: seeds.vault }, { programAddress: config.voltrProgramAddress ?? VOLTR_VAULT_PROGRAM_ADDRESS, }, ); return await getProgramDerivedAddress({ programAddress: METAPLEX_METADATA_PROGRAM_ADDRESS, seeds: [ getBytesEncoder().encode(METADATA_SEED), getAddressEncoder().encode(METAPLEX_METADATA_PROGRAM_ADDRESS), getAddressEncoder().encode(lpMint), ], }); }