-
Notifications
You must be signed in to change notification settings - Fork 7
Introduce MintCustomizer
trait
#201
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use { | ||
solana_account_info::AccountInfo, | ||
solana_program_error::{ProgramError, ProgramResult}, | ||
solana_pubkey::Pubkey, | ||
}; | ||
|
||
/// The interface for customizing attributes of the new wrapped mint. | ||
pub trait MintCustomizer { | ||
/// Calculates the total space required for a new spl-token-2022 mint | ||
/// account, including any custom extensions | ||
fn get_token_2022_mint_space( | ||
&self, | ||
unwrapped_mint_account: &AccountInfo, | ||
all_accounts: &[AccountInfo], | ||
) -> Result<usize, ProgramError>; | ||
|
||
/// Customizes initialization for the extensions for the wrapped mint | ||
/// (only relevant if creating spl-token-2022 mint) | ||
fn initialize_extensions( | ||
&self, | ||
wrapped_mint_account: &AccountInfo, | ||
unwrapped_mint_account: &AccountInfo, | ||
wrapped_token_program_account: &AccountInfo, | ||
all_accounts: &[AccountInfo], | ||
) -> ProgramResult; | ||
|
||
/// Customize the freeze authority and decimals for the wrapped mint | ||
fn get_freeze_auth_and_decimals( | ||
&self, | ||
unwrapped_mint_account: &AccountInfo, | ||
all_accounts: &[AccountInfo], | ||
) -> Result<(Option<Pubkey>, u8), ProgramError>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//! Mint `customizer` interface and implementations | ||
|
||
/// `MintCustomizer` trait definition | ||
pub mod interface; | ||
/// No extensions version of the mint | ||
pub mod no_extensions; | ||
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use { | ||
crate::mint_customizer::interface::MintCustomizer, | ||
solana_account_info::AccountInfo, | ||
solana_program_error::{ProgramError, ProgramResult}, | ||
solana_pubkey::Pubkey, | ||
spl_token_2022::{ | ||
extension::{ExtensionType, PodStateWithExtensions}, | ||
pod::PodMint, | ||
state::Mint, | ||
}, | ||
}; | ||
|
||
/// This implementation does not add any extensions. | ||
pub struct NoExtensionCustomizer; | ||
|
||
impl MintCustomizer for NoExtensionCustomizer { | ||
fn get_token_2022_mint_space( | ||
&self, | ||
_unwrapped_mint_account: &AccountInfo, | ||
_all_accounts: &[AccountInfo], | ||
) -> Result<usize, ProgramError> { | ||
let extensions = vec![]; | ||
ExtensionType::try_calculate_account_len::<Mint>(&extensions) | ||
} | ||
|
||
fn initialize_extensions( | ||
&self, | ||
_wrapped_mint_account: &AccountInfo, | ||
_unwrapped_mint_account: &AccountInfo, | ||
_wrapped_token_program_account: &AccountInfo, | ||
_all_accounts: &[AccountInfo], | ||
) -> ProgramResult { | ||
Ok(()) | ||
} | ||
|
||
fn get_freeze_auth_and_decimals( | ||
&self, | ||
unwrapped_mint_account: &AccountInfo, | ||
_all_accounts: &[AccountInfo], | ||
) -> Result<(Option<Pubkey>, u8), ProgramError> { | ||
// Copy fields over from original mint | ||
let unwrapped_mint_data = unwrapped_mint_account.try_borrow_data()?; | ||
let pod_mint = PodStateWithExtensions::<PodMint>::unpack(&unwrapped_mint_data)?.base; | ||
let freeze_authority = pod_mint.freeze_authority.ok_or(()).ok(); | ||
let decimals = pod_mint.decimals; | ||
Ok((freeze_authority, decimals)) | ||
} | ||
} |
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
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.
Upcoming PRs will add additional mint customizers here