-
Notifications
You must be signed in to change notification settings - Fork 7
Add confidential transfer ext by default #167
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
3 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
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,68 @@ | ||
use { | ||
crate::helpers::{create_unwrapped_mint, execute_create_mint, setup_test_env}, | ||
serial_test::serial, | ||
spl_token_2022::{ | ||
extension::{ | ||
confidential_transfer::ConfidentialTransferMint, BaseStateWithExtensions, | ||
PodStateWithExtensions, | ||
}, | ||
pod::PodMint, | ||
}, | ||
std::process::Command, | ||
}; | ||
|
||
mod helpers; | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
#[serial] | ||
async fn test_confidential_transfer_with_wrap_and_deposit() { | ||
let env = setup_test_env().await; | ||
let unwrapped_token_program = spl_token_2022::id(); | ||
let wrapped_token_program = spl_token_2022::id(); | ||
let unwrapped_mint = create_unwrapped_mint(&env, &unwrapped_token_program).await; | ||
|
||
execute_create_mint(&env, &unwrapped_mint, &wrapped_token_program).await; | ||
let wrapped_mint_address = | ||
spl_token_wrap::get_wrapped_mint_address(&unwrapped_mint, &wrapped_token_program); | ||
|
||
// Verify the wrapped mint's confidential transfer configuration | ||
let wrapped_mint_account = env | ||
.rpc_client | ||
.get_account(&wrapped_mint_address) | ||
.await | ||
.unwrap(); | ||
let wrapped_mint_state = | ||
PodStateWithExtensions::<PodMint>::unpack(&wrapped_mint_account.data).unwrap(); | ||
let ct_mint = wrapped_mint_state | ||
.get_extension::<ConfidentialTransferMint>() | ||
.unwrap(); | ||
|
||
assert_eq!(ct_mint.authority, Default::default()); | ||
assert!(bool::from(ct_mint.auto_approve_new_accounts)); | ||
assert_eq!(ct_mint.auditor_elgamal_pubkey, Default::default()); | ||
|
||
// Create a ATA for the new wrapped mint | ||
let create_status = Command::new("spl-token") | ||
.args([ | ||
"--config", | ||
&env.config_file_path, | ||
"create-account", | ||
&wrapped_mint_address.to_string(), | ||
]) | ||
.status() | ||
.unwrap(); | ||
assert!(create_status.success()); | ||
|
||
// Configure ATA for confidential transfers to verify confidential transfer | ||
// extension working properly | ||
let config_status = Command::new("spl-token") | ||
.args([ | ||
"--config", | ||
&env.config_file_path, | ||
"configure-confidential-transfer-account", | ||
&wrapped_mint_address.to_string(), | ||
]) | ||
.status() | ||
.unwrap(); | ||
assert!(config_status.success()); | ||
} |
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,56 @@ | ||
use { | ||
crate::mint_customizer::interface::MintCustomizer, | ||
solana_account_info::AccountInfo, | ||
solana_cpi::invoke, | ||
solana_program_error::{ProgramError, ProgramResult}, | ||
solana_pubkey::Pubkey, | ||
spl_token_2022::{ | ||
extension::{ | ||
confidential_transfer::instruction::initialize_mint as initialize_confidential_transfer_mint, | ||
ExtensionType, PodStateWithExtensions, | ||
}, | ||
pod::PodMint, | ||
state::Mint, | ||
}, | ||
}; | ||
|
||
/// This implementation adds the `ConfidentialTransferMint` extension by | ||
/// default. | ||
pub struct DefaultToken2022Customizer; | ||
|
||
impl MintCustomizer for DefaultToken2022Customizer { | ||
fn get_token_2022_mint_space() -> Result<usize, ProgramError> { | ||
let extensions = vec![ExtensionType::ConfidentialTransferMint]; | ||
ExtensionType::try_calculate_account_len::<Mint>(&extensions) | ||
} | ||
|
||
fn initialize_extensions( | ||
wrapped_mint_account: &AccountInfo, | ||
_unwrapped_mint_account: &AccountInfo, | ||
wrapped_token_program_account: &AccountInfo, | ||
_all_accounts: &[AccountInfo], | ||
) -> ProgramResult { | ||
invoke( | ||
&initialize_confidential_transfer_mint( | ||
wrapped_token_program_account.key, | ||
wrapped_mint_account.key, | ||
None, // Immutable. No one can later change privacy settings. | ||
true, // No approvals necessary to use. | ||
None, // No auditor can decrypt transaction amounts. | ||
)?, | ||
&[wrapped_mint_account.clone()], | ||
) | ||
} | ||
|
||
fn get_freeze_auth_and_decimals( | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.