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

interface: Support multiple programs with the same interface via token-2022 #2386

Merged
merged 12 commits into from
Feb 27, 2023

Conversation

joncinque
Copy link
Contributor

Problem

Token-2022 is close to ready for mainnet adoption, but Anchor doesn't support it yet.

Solution

Support both programs, and take it a step further by adding support for "interface" programs and accounts.

As a coincidence, a lot of this work resembles the excellent work at #2363, so I hope that our efforts can be combined!

Overall, things are very similar, except for the implementation / naming for the interface account, which are called "multi-program" in the other PR. The main difference is relaxing type constraints in order to maximally reuse Account and Program implementations.

#2363 also adds a token program constraint, which would be a very useful addition for dual-token-program support.

This also adds test support for two token programs in the escrow and token-proxy test programs, to show that this actually works. Each commit in this PR is deliberate, showing the succession of PRs that would require to get this in:

  • add "interface" concept in the anchor-lang
  • add token-2022 support in anchor-spl
  • support token-2022 across anchor
  • add token-interface, using the "interface" from the first step
  • use these new types in the tests

If this looks ok, I'm happy to work with @elliotkennedy on getting everything in!

@vercel
Copy link

vercel bot commented Feb 3, 2023

@joncinque is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@elliotkennedy
Copy link
Contributor

Love the naming of this @joncinque - far more succinct than my word salad!

Keen to push for this to get merged - as well as the token_program constraint.

@elliotkennedy
Copy link
Contributor

This is great but I think it needs some tests around the init Mint and TokenAccount paths.

Ability to use only the spl-token-2022 program would be useful too.

i.e.

    pub token_program: Program<'info, anchor_spl:token_2022::Token2022>,

This can be added separately though.

@joncinque
Copy link
Contributor Author

This is great but I think it needs some tests around the init Mint and TokenAccount paths.

I've added some init tests for mints, accounts, and associated accounts. Thanks for the feedback!

@Henry-E
Copy link
Contributor

Henry-E commented Feb 20, 2023

This looks pretty much ready to merge I think. @joncinque is there anything else you have left on your todo list? Do you think it's ready to merge.

@joncinque
Copy link
Contributor Author

joncinque commented Feb 20, 2023

@Henry-E this is good to go from my side! Let me know if you want me to make any of the proposed changes we've discussed (renaming owner and reverting the TryFrom implementation), and then I'm all good

@Henry-E
Copy link
Contributor

Henry-E commented Feb 22, 2023

No that's ok, both the TryFrom and Owner things seem fine to leave as they are. Just more thinking out loud.

Great, I will probably do one more quick readthrough and then merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants