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

lang: Add declare_program! macro #2857

Merged

Conversation

acheroncrypto
Copy link
Collaborator

Problem

Adding dependencies in order to invoke CPIs or client interactions has a high chance of eventually resulting in a dependency hell.

anchor-gen was created in order to create a CPI client from IDLs without having to depend on the actual program crate, however, it has the following problems:

  • Not compatible with the new IDL
  • Only used for CPI
  • Requires a separate crate for the external program

Solution

Add declare_program! macro to generate program declaration from the program's IDL:

declare_program!(program_name);

This creates a module named program_name with the following submodules:

  • accounts: Program account type definitions
  • client: Off-chain client helpers
  • constants: Program constants
  • cpi: On-chain CPI helpers
  • events: Program event type definitions
  • program: Program definition
  • types: Program type definitions (excluding accounts and events)

This allows to interact with programs, both from on-chain and off-chain, without having to add the program's crate as a dependency.

Note that creating a separate crate (like with anchor-gen) is not required.

Copy link

vercel bot commented Mar 19, 2024

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

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto added lang next Required for the next release labels Mar 19, 2024
@acheroncrypto acheroncrypto marked this pull request as ready for review March 25, 2024 21:59
@acheroncrypto acheroncrypto merged commit 0f60909 into coral-xyz:master Mar 25, 2024
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang next Required for the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant