-
Notifications
You must be signed in to change notification settings - Fork 8
Introduce canonical pointer PDA #374
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
Conversation
| pub(crate) fn get_wrapped_mint_address_with_seed( | ||
| unwrapped_mint: &Pubkey, | ||
| wrapped_token_program_id: &Pubkey, | ||
| ) -> (Pubkey, u8) { | ||
| get_wrapped_mint_address_with_seed_for_program(unwrapped_mint, wrapped_token_program_id, &id()) | ||
| } | ||
|
|
||
| pub(crate) fn get_wrapped_mint_address_with_seed_for_program( | ||
| unwrapped_mint: &Pubkey, | ||
| wrapped_token_program_id: &Pubkey, | ||
| program_id: &Pubkey, | ||
| ) -> (Pubkey, u8) { | ||
| Pubkey::find_program_address( | ||
| &get_wrapped_mint_seeds(unwrapped_mint, wrapped_token_program_id), | ||
| &id(), | ||
| program_id, | ||
| ) | ||
| } |
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.
Adding a _for_program() variants to allow for these forks to utilize our package for their address lookups
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.
Tbh I'd just have them all just take program_id and not support duplicate versions of all of the helpers.
If this is easier for SemVer, though, nbd.
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.
id() is so deeply embedded into the program+clients that requiring the program_id is a far reaching change. I think I'll keep this forward compatible for now and revisit for a later breaking change if we find lots of folks forking and wanting the simpler name.
buffalojoec
left a comment
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.
Lgtm! A few nits, take them or leave them!
| pub(crate) fn get_wrapped_mint_address_with_seed( | ||
| unwrapped_mint: &Pubkey, | ||
| wrapped_token_program_id: &Pubkey, | ||
| ) -> (Pubkey, u8) { | ||
| get_wrapped_mint_address_with_seed_for_program(unwrapped_mint, wrapped_token_program_id, &id()) | ||
| } | ||
|
|
||
| pub(crate) fn get_wrapped_mint_address_with_seed_for_program( | ||
| unwrapped_mint: &Pubkey, | ||
| wrapped_token_program_id: &Pubkey, | ||
| program_id: &Pubkey, | ||
| ) -> (Pubkey, u8) { | ||
| Pubkey::find_program_address( | ||
| &get_wrapped_mint_seeds(unwrapped_mint, wrapped_token_program_id), | ||
| &id(), | ||
| program_id, | ||
| ) | ||
| } |
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.
Tbh I'd just have them all just take program_id and not support duplicate versions of all of the helpers.
If this is easier for SemVer, though, nbd.
program/src/state.rs
Outdated
| /// The mint authority of an unwrapped mint's on-chain signal another token-wrap | ||
| /// deployment is the "canonical" one. |
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.
nit: this comment is a little bit confusing. Do you think we can clarify it a bit?
| return Err(ProgramError::MissingRequiredSignature); | ||
| } | ||
|
|
||
| let mint_data = unwrapped_mint_info.try_borrow_data()?; |
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.
Should we be checking the mint's owner here? Maybe it's inconsequential, since the mint address can't be duplicated.
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.
Sure thing, will add a check+test
Integrating feedback from Foundation
Problem
It's likely that a few high profile mint authorities will not consider the original deployment of token-wrap the one they want folks to use for their mint. They may prefer an alternative configuration (especially for token-2022s) and will fork+deploy their own. These authorities need a way to signal on-chain that a different token wrap deployment is the "canonical" one for their mint.
Solution
This PR adds a
CanonicalPointerPDA which allows mint authorities to set a field with a pubkey to the alternative deployment. One instruction is added to create/update this PDA.Edge cases
If there is no authority, a pointer cannot be created. If one is created and later the mint authority is set to None, the canonical pointer state is frozen as well.