-
Notifications
You must be signed in to change notification settings - Fork 7
Sync metadata to Spl Token #247
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
use { | ||
crate::{error::TokenWrapError, metaplex::metaplex_to_token_2022_metadata}, | ||
mpl_token_metadata::ID as MPL_TOKEN_METADATA_ID, | ||
mpl_token_metadata::{accounts::Metadata as MetaplexMetadata, ID as MPL_TOKEN_METADATA_ID}, | ||
solana_account_info::AccountInfo, | ||
solana_cpi::{get_return_data, invoke}, | ||
solana_program_error::ProgramError, | ||
|
@@ -88,3 +88,35 @@ pub fn resolve_token_2022_source_metadata<'a>( | |
cpi_emit_and_decode(owner_program_info, metadata_info) | ||
} | ||
} | ||
|
||
/// Extracts the token metadata from the unwrapped mint | ||
pub fn extract_token_metadata<'a>( | ||
unwrapped_mint_info: &AccountInfo<'a>, | ||
source_metadata_info: Option<&AccountInfo<'a>>, | ||
owner_program_info: Option<&AccountInfo<'a>>, | ||
) -> Result<TokenMetadata, ProgramError> { | ||
let unwrapped_metadata = if *unwrapped_mint_info.owner == spl_token_2022::id() { | ||
// Source is Token-2022: resolve metadata pointer | ||
resolve_token_2022_source_metadata( | ||
unwrapped_mint_info, | ||
source_metadata_info, | ||
owner_program_info, | ||
)? | ||
} else if *unwrapped_mint_info.owner == spl_token::id() { | ||
// Source is spl-token: read from Metaplex PDA | ||
let metaplex_metadata_info = | ||
source_metadata_info.ok_or(ProgramError::NotEnoughAccountKeys)?; | ||
let (expected_metaplex_pda, _) = MetaplexMetadata::find_pda(unwrapped_mint_info.key); | ||
if *metaplex_metadata_info.owner != mpl_token_metadata::ID { | ||
return Err(ProgramError::InvalidAccountOwner); | ||
} | ||
if *metaplex_metadata_info.key != expected_metaplex_pda { | ||
return Err(TokenWrapError::MetaplexMetadataMismatch.into()); | ||
} | ||
metaplex_to_token_2022_metadata(unwrapped_mint_info, metaplex_metadata_info)? | ||
} else { | ||
return Err(ProgramError::IncorrectProgramId); | ||
}; | ||
|
||
Ok(unwrapped_metadata) | ||
} | ||
Comment on lines
+92
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used for both sync instructions so abstracting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Sadly, the metaplex metadata program requires a payer for the create instruction. Pre-funding the PDA is not an option, so this instruction uses the wrapped_mint_authority PDA as the signer and requires the user to transfer to that account.
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.
Yuck, that really stinks. I don't love the solution, but I can't come up with anything better. It's slick since the wrapped mint authority is required to sign create / update metadata