UNPKG

@blockassetlabs/minter

Version:

Blockasset Minter

40 lines (35 loc) 965 B
import { utils } from "@project-serum/anchor"; import { PublicKey } from "@solana/web3.js"; import { MINTER_ADDRESS, MINTER_PREFIX, REDEEMED_MINTS_PREFIX, TOKEN_METADATA_PROGRAM_ID, } from "./constants"; /** * Finds the minter id. * @returns */ export const findMinterId = (identifier: PublicKey): PublicKey => PublicKey.findProgramAddressSync( [utils.bytes.utf8.encode(MINTER_PREFIX), identifier.toBuffer()], MINTER_ADDRESS )[0]; /** * Finds the redeemed mints id. * @returns */ export const findRedeemedMintsId = (minterId: PublicKey): PublicKey => PublicKey.findProgramAddressSync( [utils.bytes.utf8.encode(REDEEMED_MINTS_PREFIX), minterId.toBuffer()], MINTER_ADDRESS )[0]; export const getMetadataId = (mint: PublicKey): PublicKey => PublicKey.findProgramAddressSync( [ Buffer.from("metadata"), TOKEN_METADATA_PROGRAM_ID.toBuffer(), mint.toBuffer(), ], TOKEN_METADATA_PROGRAM_ID )[0];