Skip to content

Commit

Permalink
feat: add accounts for cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
CanvasL committed Sep 27, 2024
1 parent 1ab3a6f commit 5a249b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
25 changes: 18 additions & 7 deletions extensions/puppet/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Puppet>;
const [GLOBAL_PDA] = PublicKey.findProgramAddressSync(
[Buffer.from("global"), PROGRAM_PAYER.toBuffer()],
program.programId
);

yargs(hideBin(process.argv))
.command(
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions extensions/puppet/tests/puppet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down

0 comments on commit 5a249b4

Please sign in to comment.