-
Notifications
You must be signed in to change notification settings - Fork 7
Sync metadata to token-2022 pt. 1 #221
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
9e5e2df
to
b0d4176
Compare
fn pre_initialize_extensions( | ||
wrapped_mint_account: &AccountInfo, | ||
wrapped_token_program_account: &AccountInfo, | ||
) -> ProgramResult; | ||
|
||
/// Customizes extensions for the wrapped mint *after* the base mint is | ||
/// initialized. This is for extensions that require the mint to be | ||
/// initialized, like `TokenMetadata`. | ||
fn post_initialize_extensions<'a>( | ||
wrapped_mint_account: &AccountInfo<'a>, | ||
wrapped_token_program_account: &AccountInfo, | ||
wrapped_mint_authority_account: &AccountInfo<'a>, | ||
mint_authority_signer_seeds: &[&[u8]], | ||
) -> ProgramResult; |
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.
Simplifying this interface and removing the pre-post-mint-init pattern here (given we don't do anything post init in CreateMint anymore)
invoke_signed( | ||
&initialize_token_metadata( | ||
wrapped_token_program_account.key, | ||
wrapped_mint_account.key, | ||
&wrapped_mint_authority, | ||
wrapped_mint_account.key, | ||
&wrapped_mint_authority, | ||
// Initialized as empty, but separate instructions are available | ||
// to update these fields | ||
"".to_string(), | ||
"".to_string(), | ||
"".to_string(), | ||
), | ||
&cpi_accounts, | ||
&[mint_authority_signer_seeds], | ||
)?; |
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.
Removing this saves rent on those wrapped mints without unwrapped mint metadata
/// Calculate the exact mint account length including all extensions | ||
pub fn calc_mint_len(mint_key: &Pubkey, extensions: &[MintExtension]) -> usize { |
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.
Even though this is just for tests, went a bit down the rabbit hole trying to understand exactly how to calculate space for multiple scenarios:
- no extensions
- only fixed extensions
- only variable extensions
- mixed
Maybe there is some util I am missing, but this was not easy. Eventually this will be used in the cli/client code.
check-cfg = [ | ||
'cfg(target_os, values("solana"))', | ||
'cfg(feature, values("frozen-abi", "no-entrypoint"))', | ||
'cfg(feature, values("custom-heap", "custom-panic"))', |
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.
New lint warnings require this
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.
Nice, this looks great! I left two small comments, but then this can land from my side.
b0d4176
to
db6a1b9
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.
Looks great! Just a small point
Ok(()) | ||
} | ||
|
||
type FieldExtractor = Vec<(Field, fn(&TokenMetadata) -> &str)>; |
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 might have changed since I last worked on stuff like this, but function pointers tend to be less performant than closures because the compiler will never inline the code, so typically, Fn
is much better than fn
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.
The challenge is that, for Fn, putting multiple extractors in a vec requires a trait object like Box<dyn Fn(..)>
which is not inlineable either. If we really want to inline this though, we can revert the update_fields_if_changed()
helper entirely and just do the checks one-after-the-other (prior).
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.
Ah right, I forgot about that part, sorry. Never mind then, probably easiest to stick to a function pointer then.
Adds
SyncMetadataToToken2022
instruction to syncTokenMetadata
from an unwrapped Token-2022 mint (later will be adding spl-token) to its wrapped Token-2022 mint. Initializes if missing, otherwise updates only changed fields and removes stale additional_metadata keys.CreateMint
no longer initializesTokenMetadata
. This is a follow up from Add metadata extensions onCreateMint
#208 (comment).MintCustomizer trait methods simplified further to only what is needed.