12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import * as anchor from "@coral-xyz/anchor";
- import { decode, mapProof } from "../utils";
- import { PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from "@metaplex-foundation/mpl-bubblegum";
- import {
- SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
- SPL_NOOP_PROGRAM_ID,
- } from "@solana/spl-account-compression";
- import { getAsset, getAssetProof } from "../readAPI";
- import { program, programID } from "./constants";
- async function main() {
- const [vaultPDA, _bump] = anchor.web3.PublicKey.findProgramAddressSync(
- [Buffer.from("cNFT-vault", "utf8")],
- programID
- );
- const tree = new anchor.web3.PublicKey(
- "trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B"
- );
- const receiver = new anchor.web3.PublicKey(
- "Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM"
- );
- const [treeAuthority, _bump2] = anchor.web3.PublicKey.findProgramAddressSync(
- [tree.toBuffer()],
- BUBBLEGUM_PROGRAM_ID
- );
- const assetId = "DGWU3mHenDerCvjkeDsKYEbsvXbWvqdo1bVoXy3dkeTd";
- const asset = await getAsset(assetId);
- // console.log(res)
- const proof = await getAssetProof(assetId);
- const proofPathAsAccounts = mapProof(proof);
- const root = decode(proof.root);
- const dataHash = decode(asset.compression.data_hash);
- const creatorHash = decode(asset.compression.creator_hash);
- const nonce = new anchor.BN(asset.compression.leaf_id);
- const index = asset.compression.leaf_id;
- const tx = await program.methods
- .withdrawCnft(root, dataHash, creatorHash, nonce, index)
- .accounts({
- leafOwner: vaultPDA,
- merkleTree: tree,
- newLeafOwner: receiver,
- treeAuthority: treeAuthority,
- bubblegumProgram: BUBBLEGUM_PROGRAM_ID,
- compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
- logWrapper: SPL_NOOP_PROGRAM_ID,
- systemProgram: anchor.web3.SystemProgram.programId,
- })
- .remainingAccounts(proofPathAsAccounts)
- .rpc();
- console.log(tx);
- }
- main();
|