-
Notifications
You must be signed in to change notification settings - Fork 7
Sync metadata from spl-token to token-2022 #229
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
|
||
[workspace.dependencies] | ||
anyhow = "1.0.98" | ||
borsh = "0.10.4" |
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 version of borsh synced to the version used in mpl-token-metadata
due to compatibility reasons
fn extract_additional_metadata( | ||
metaplex_metadata: &MetaplexMetadata, | ||
) -> Result<Vec<(String, String)>, ProgramError> { |
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 idea behind this is to convert the remaining metaplex metadata fields to token-2022-metadata-ext-compatible. And for that it has to be added to the additional_metadata: Vec<(String, String)>
field. Using serde to serialize the value. This may be overkill 🤷 . Worth discussing.
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 this works for me! Nice!
4b687cd
to
825aa70
Compare
/// 4. `[]` (Optional) `Metaplex` Metadata PDA. Required if the unwrapped | ||
/// mint is an `spl-token` mint. |
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.
Shoot, this actually reminds me that TokenMetadata
can actually exist in a separate account for Token2022 mints as well. The MetadataPointer
can point to another account.
As followup work, maybe here in this optional account slot, we can just say "Token Metadata account, if separate" or something like that, and also mention the Metaplex PDA?
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.
Oh! Totally forgot about that case. That feels like independent conditional branch of work. Cool if it goes in the next PR?
fn extract_additional_metadata( | ||
metaplex_metadata: &MetaplexMetadata, | ||
) -> Result<Vec<(String, String)>, ProgramError> { |
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 this works for me! Nice!
// Source is Token-2022: read from extension | ||
let unwrapped_mint_data = unwrapped_mint_info.try_borrow_data()?; | ||
let unwrapped_mint_state = PodStateWithExtensions::<PodMint>::unpack(&unwrapped_mint_data)?; | ||
unwrapped_mint_state | ||
.get_variable_len_extension::<TokenMetadata>() | ||
.map_err(|_| TokenWrapError::UnwrappedMintHasNoMetadata)? |
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.
Here is where you'd have a check to see if the address in the MetadataPointer
is the mint, or if it's another account, which should have been provided last.
This PR extends the
SyncMetadataToToken2022
instruction to support syncing metadata from an spl-token's metaplex PDA to the wrapped token's metadata extension.Note that this copies over non-overlapping fields as
addditional_metadata
serialized to json. Up for discussion if this is ok or overkill.