Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for remaining accounts resolution #55

Merged
merged 6 commits into from
Aug 4, 2023

Conversation

lorisleiva
Copy link
Collaborator

Adds two strategy for resolving remaining accounts on a given instruction:

  • arg, which expects an array of PublicKey, Signer or both as an (extra) argument, and use that arg to fill remaining accounts.
  • resolver for custom remaining accounts resolution.

For example, imagine the following example that burns Compressed NFTs and accepts the "Proof" of the leaf to burn as remaining accounts.

await burn(umi, {
  // ...
}).sendAndConfirm(umi);

Given an array of PublicKey as the Proof, before this PR we would need to do the following:

const proofs = [...];

await burn(umi, {
  // ...
})
  .addRemainingAccounts(proofs.map(pubkey) => {
    pubkey,
    isSigner: false,
    isWritable: false,
  })
  .sendAndConfirm(umi);

After this PR, we can now pass the proof directly as an extra argument of the burn instruction like so:

const proofs = [...];

await burn(umi, {
  proofs,
  // ...
}).sendAndConfirm(umi);

To make this work, we simply need to tell Kinobi that the remaining accounts of the burn instruction rely on an extra argument called proof.

kinobi.update(
  new k.UpdateInstructionsVisitor({
    burn: {
      args: {
        // Add the "proof" extra argument defaulting to an empty array.
        proof: {
          type: k.arrayTypeNode(k.publicKeyTypeNode(), { size: k.remainderSize() }),
          defaultsTo: k.valueDefault(k.vList([])),
        },
      },
      // Use the "proof" argument to fill remaining accounts.
      remainingAccounts: k.remainingAccountsFromArg('proof'),
    },
  })
);

@changeset-bot
Copy link

changeset-bot bot commented Aug 4, 2023

🦋 Changeset detected

Latest commit: b792c5b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@metaplex-foundation/kinobi Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@febo febo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lorisleiva lorisleiva merged commit f669542 into main Aug 4, 2023
6 checks passed
@lorisleiva lorisleiva deleted the loris/resolve-remaining-accounts branch August 4, 2023 11:58
@github-actions github-actions bot mentioned this pull request Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants