-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: declare program allow overriding address #3435
base: master
Are you sure you want to change the base?
feat: declare program allow overriding address #3435
Conversation
@Arrowana is attempting to deploy a commit to the coral-xyz Team on Vercel. A member of the Team first needs to authorize it. |
bc11aa1
to
5e8ddce
Compare
5e8ddce
to
cec825e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should support this. However, I think we should avoid adding new arguments to the declare_program
macro to keep things simple and make things work out of the box.
This is what I had in mind when adding the idl.metadata.deployments
field, which is an optional field that stores the program ids in different clusters:
Lines 52 to 57 in 5767365
pub struct IdlDeployments { | |
pub mainnet: Option<String>, | |
pub testnet: Option<String>, | |
pub devnet: Option<String>, | |
pub localnet: Option<String>, | |
} |
So we could use that information in declare_program!
with feature names as the field names, e.g. if the program gets compiled with devnet
feature activated, declare_program!
impl would use the program id from idl.metadata.deployments.devnet
.
This would also avoid having multiple declare_program!
calls with different feature configurations, as this would be handled inside the macro impl automatically.
Wdyt?
This works but is a bit rigid, what if there are 2 contracts on mainnet, production and staging? That's a likely case. |
Each program has its own instance, so their IDLs are not guaranteed to be the same. You'll be able to achieve what you want with the help of the #[cfg(feature = "production")]
declare_program!(name);
#[cfg(feature = "staging")]
declare_program!(name_staging as name); Imo adding overrides should be used as the last resort, only if there are no other options available. |
You can also create a common module to achieve the same thing: mod name {
#[cfg(feature = "production")]
anchor_lang::declare_program!(name);
#[cfg(feature = "staging")]
anchor_lang::declare_program!(name_staging);
#[cfg(feature = "production")]
pub use name::*;
#[cfg(feature = "staging")]
pub use name_staging::*;
} |
Problem:
A given application might need to target multiple environments with the same program interface, right now to do so it would need to rewrite the entire IDL editing the address field
Solution:
Implement
address = "..."
to override the IDL addressPotential issue, if any pda based on the program id is hardcoded at compilation time elsewhere it will not be compatible