From 5a249b47c85f0a3378607fba6ec5918bbae4f25e Mon Sep 17 00:00:00 2001 From: CanvasL <746591811@qq.com> Date: Fri, 27 Sep 2024 23:26:48 +0800 Subject: [PATCH] feat: add accounts for cli commands --- extensions/puppet/client/index.ts | 25 ++++++++++++++++++------- extensions/puppet/tests/puppet.ts | 8 +++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/extensions/puppet/client/index.ts b/extensions/puppet/client/index.ts index 4ed6130..a732452 100644 --- a/extensions/puppet/client/index.ts +++ b/extensions/puppet/client/index.ts @@ -32,11 +32,17 @@ import path from "path"; const DEPHY_ID_PROGRAM = new PublicKey( "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" ); +const PROGRAM_PAYER = new PublicKey(""); const DEV_RPC = "https://api.devnet.solana.com"; const SECRET_KEY = fs.readFileSync( path.join(__dirname, "../keypair.json"), "utf-8" ); +const program = anchor.workspace.Puppet as Program; +const [GLOBAL_PDA] = PublicKey.findProgramAddressSync( + [Buffer.from("global"), PROGRAM_PAYER.toBuffer()], + program.programId +); yargs(hideBin(process.argv)) .command( @@ -92,23 +98,24 @@ yargs(hideBin(process.argv)) umi.use(signerIdentity(signer)); umi.use(mplTokenMetadata()); - const mint = generateSigner(umi); + const mplMint = generateSigner(umi); await createNft(umi, { - mint, + mint: mplMint, name: args.name, uri: args.url, sellerFeeBasisPoints: percentAmount(5.5), }).sendAndConfirm(umi); - const asset = await fetchDigitalAsset(umi, mint.publicKey); - console.log("asset:", asset.publicKey); - console.log("mpl_mint:", asset.mint.publicKey); + const mplMetadata = findMetadataPda(umi, { mint: mplMint.publicKey }); + + console.log("mplMint:", mplMint.publicKey); + console.log("mplMetadata:", mplMetadata); const collectionMint = publicKey(args.collection); const collectionMetadata = findMetadataPda(umi, { mint: collectionMint }); await setAndVerifyCollection(umi, { - metadata: findMetadataPda(umi, { mint: asset.mint.publicKey }), + metadata: mplMetadata, collectionAuthority: signer, collectionMint: collectionMint, collection: collectionMetadata, @@ -120,7 +127,7 @@ yargs(hideBin(process.argv)) console.log("collection verified"); const mplAta = await getAssociatedTokenAddress( - new anchor.web3.PublicKey(asset.mint.publicKey), // The mint address of the created NFT + new anchor.web3.PublicKey(mplMint.publicKey), // The mint address of the created NFT new anchor.web3.PublicKey(keypair.publicKey), // The wallet address of the NFT owner false, TOKEN_PROGRAM_ID, @@ -159,6 +166,7 @@ yargs(hideBin(process.argv)) mplCollection: new PublicKey(args.mplCollection), }) .accounts({ + global: GLOBAL_PDA, mplCollection: new PublicKey(args.mplCollection), vendor, payer: payer.publicKey, @@ -174,6 +182,7 @@ yargs(hideBin(process.argv)) "Bind device to metaplex nft", { device: { type: "string", demandOption: true }, // device address + mplMetadata: { type: "string", demandOption: true }, mplAta: { type: "string", demandOption: true }, // Metaplex associated token address }, async (args) => { @@ -228,6 +237,8 @@ yargs(hideBin(process.argv)) mplAta: new PublicKey(args.mplAta), }) .accounts({ + global: GLOBAL_PDA, + mplMetadata: args.mplMetadata, mplAssociatedToken, // The ATA for the Metaplex NFT deviceAssociatedToken, deviceCollectionBinding: deviceCollectionBindingPda[0], // Device collection binding PDA diff --git a/extensions/puppet/tests/puppet.ts b/extensions/puppet/tests/puppet.ts index bb8ac19..3c7f434 100644 --- a/extensions/puppet/tests/puppet.ts +++ b/extensions/puppet/tests/puppet.ts @@ -326,13 +326,13 @@ const createMplNft = async ( sellerFeeBasisPoints: percentAmount(5.5), }).sendAndConfirm(umi); - // const asset = await fetchDigitalAsset(umi, mplMint.publicKey); - const collectionMint = publicKey(collection); const collectionMetadata = findMetadataPda(umi, { mint: collectionMint }); + const mplMetadata = findMetadataPda(umi, { mint: mplMint.publicKey }); + await setAndVerifyCollection(umi, { - metadata: findMetadataPda(umi, { mint: mplMint.publicKey }), + metadata: mplMetadata, collectionAuthority: signer, collectionMint: collectionMint, collection: collectionMetadata, @@ -349,8 +349,6 @@ const createMplNft = async ( ASSOCIATED_TOKEN_PROGRAM_ID ); - const mplMetadata = findMetadataPda(umi, { mint: mplMint.publicKey }); - return { mplMint: mplMint.publicKey.toString(), mplAta: mplAta.toString(),