diff --git a/compressed-nfts/CNFTvZm6BPd5ZH2Lbn3mMnSsUYWirqjvRWo9wbcbfAB2.json b/compressed-nfts/CNFTvZm6BPd5ZH2Lbn3mMnSsUYWirqjvRWo9wbcbfAB2.json new file mode 100644 index 0000000..1824952 --- /dev/null +++ b/compressed-nfts/CNFTvZm6BPd5ZH2Lbn3mMnSsUYWirqjvRWo9wbcbfAB2.json @@ -0,0 +1 @@ +[163,191,238,222,165,10,196,219,229,157,128,66,219,37,37,137,230,137,252,234,163,154,232,213,75,96,189,118,2,192,220,227,168,226,27,159,122,121,34,241,0,179,208,143,53,28,173,200,205,132,163,204,167,203,73,5,177,44,177,96,24,90,78,249] \ No newline at end of file diff --git a/compressed-nfts/CoLNfQzbj4nmGgG1XxFMDaebknRZLcztS7V6Umngb9An.json b/compressed-nfts/CoLNfQzbj4nmGgG1XxFMDaebknRZLcztS7V6Umngb9An.json new file mode 100644 index 0000000..4077c24 --- /dev/null +++ b/compressed-nfts/CoLNfQzbj4nmGgG1XxFMDaebknRZLcztS7V6Umngb9An.json @@ -0,0 +1 @@ +[246,254,110,193,43,97,213,126,71,247,230,76,57,115,124,27,82,141,189,212,168,21,70,220,222,53,134,19,135,83,195,130,175,79,45,216,48,217,128,189,145,148,243,172,30,134,15,162,92,232,55,141,228,72,21,124,80,108,183,3,218,195,74,183] \ No newline at end of file diff --git a/compressed-nfts/TREyXNrxJSgrsWoYKU5xo8XYNCBNoZnSBdP5PkC1W2B.json b/compressed-nfts/TREyXNrxJSgrsWoYKU5xo8XYNCBNoZnSBdP5PkC1W2B.json new file mode 100644 index 0000000..1b90a7f --- /dev/null +++ b/compressed-nfts/TREyXNrxJSgrsWoYKU5xo8XYNCBNoZnSBdP5PkC1W2B.json @@ -0,0 +1 @@ +[198,123,251,189,215,99,58,111,17,19,25,26,121,152,53,110,133,101,9,49,17,19,255,94,177,194,181,46,118,100,141,129,6,196,130,166,155,106,83,52,123,142,240,222,51,94,141,240,236,134,47,251,115,163,210,99,94,236,228,125,144,213,0,104] \ No newline at end of file diff --git a/compressed-nfts/createTree.ts b/compressed-nfts/createTree.ts new file mode 100644 index 0000000..d1891e8 --- /dev/null +++ b/compressed-nfts/createTree.ts @@ -0,0 +1,61 @@ +import { createCreateTreeInstruction, PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from "@metaplex-foundation/mpl-bubblegum"; +import { loadWalletKey, sendVersionedTx } from "./utils"; +import { Connection, Keypair, PublicKey, SystemProgram, Transaction, VersionedMessage } from "@solana/web3.js"; +import { SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, SPL_NOOP_PROGRAM_ID, ValidDepthSizePair, getConcurrentMerkleTreeAccountSize } from "@solana/spl-account-compression"; +import { SYSTEM_PROGRAM_ID } from "@raydium-io/raydium-sdk"; + +async function createTree() { + // Load the wallet key for the user who will create the merkle tree + const keypair = loadWalletKey("CNFTvZm6BPd5ZH2Lbn3mMnSsUYWirqjvRWo9wbcbfAB2.json"); + + // Create a connection to the network + const connection = new Connection("https://api.devnet.solana.com"); + + // Load the wallet key for the merkle tree account + const merkleTree = loadWalletKey("TREyXNrxJSgrsWoYKU5xo8XYNCBNoZnSBdP5PkC1W2B.json"); + + // Find the tree authority public key and bump seed + const [treeAuthority, _bump] = PublicKey.findProgramAddressSync( + [merkleTree.publicKey.toBuffer()], + BUBBLEGUM_PROGRAM_ID, + ); + + // Define the depth and buffer size of the merkle tree + const depthSizePair: ValidDepthSizePair = { + maxDepth: 14, + maxBufferSize: 64, + }; + + // Calculate the required account space for the merkle tree + const space = getConcurrentMerkleTreeAccountSize(depthSizePair.maxDepth, depthSizePair.maxBufferSize); + + // Create an account instruction to allocate space for the merkle tree + const createAccountIx = SystemProgram.createAccount({ + newAccountPubkey: merkleTree.publicKey, + fromPubkey: keypair.publicKey, + space: space, + lamports: await connection.getMinimumBalanceForRentExemption(space), + programId: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, + }); + + // Create a merkle tree instruction + const createTreeIx = createCreateTreeInstruction({ + merkleTree: merkleTree.publicKey, + treeAuthority: treeAuthority, + payer: keypair.publicKey, + treeCreator: keypair.publicKey, + compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, + logWrapper: SPL_NOOP_PROGRAM_ID, + systemProgram: SYSTEM_PROGRAM_ID, + }, { + maxDepth: depthSizePair.maxDepth, + maxBufferSize: depthSizePair.maxBufferSize, + public: false, + }); + + // Send the transaction with both instructions + const sx = await sendVersionedTx(connection, [createAccountIx, createTreeIx], keypair.publicKey, [keypair, merkleTree]); + console.log(sx); +} + +createTree(); diff --git a/compressed-nfts/package.json b/compressed-nfts/package.json new file mode 100644 index 0000000..920f604 --- /dev/null +++ b/compressed-nfts/package.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "@metaplex-foundation/mpl-bubblegum": "^0.6.2", + "@raydium-io/raydium-sdk": "^1.3.0-beta.17", + "@solana/spl-token": "^0.3.7" + } +} diff --git a/compressed-nfts/utils.ts b/compressed-nfts/utils.ts new file mode 100644 index 0000000..f49ed93 --- /dev/null +++ b/compressed-nfts/utils.ts @@ -0,0 +1,24 @@ +import { Connection, Keypair, PublicKey, Signer, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js"; + +export function loadWalletKey(keypairFile:string): Keypair { + const fs = require ("fs") + return Keypair. fromSecretKey( + new Uint8Array(JSON.parse(fs.readFileSync(keypairFile).toString())), + ); +} +export async function sendVersionedTx( + connection: Connection, + instructions: TransactionInstruction[], + payer: PublicKey, + signers: Signer[]){ + let latestBlockhash = await connection.getLatestBlockhash() + const messageLegacy = new TransactionMessage({ + payerKey: payer, + recentBlockhash: latestBlockhash.blockhash, + instructions, + }).compileToLegacyMessage(); + const transation = new VersionedTransaction(messageLegacy) + transation.sign(signers); + const signature = await connection.sendTransaction(transation); + return signature; + } \ No newline at end of file