-
Notifications
You must be signed in to change notification settings - Fork 124
Permissioned burn extension #818
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
Draft
Szegoo
wants to merge
10
commits into
solana-program:main
Choose a base branch
from
Szegoo:permissioned-burn
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
905f41e
Permissioned Burn Extension
Szegoo f0175dc
compiles
Szegoo ea637bd
handle permissioned burn in processor
Szegoo d918f27
cleanup
Szegoo 6a2e5bd
typo
Szegoo 21b2e65
fmt
Szegoo e5ca5d4
remove unnecessary PermissionedBurnAccount
Szegoo d533794
Update interface/src/extension/mod.rs
Szegoo c22a5fe
add missing unpack & change index to 46
Szegoo f9133d3
implement authority type
Szegoo 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #[cfg(feature = "serde")] | ||
| use serde::{Deserialize, Serialize}; | ||
| use { | ||
| crate::{ | ||
| check_program_account, | ||
| instruction::{encode_instruction, TokenInstruction}, | ||
| }, | ||
| bytemuck::{Pod, Zeroable}, | ||
| num_enum::{IntoPrimitive, TryFromPrimitive}, | ||
| solana_instruction::{AccountMeta, Instruction}, | ||
| solana_program_error::ProgramError, | ||
| solana_pubkey::Pubkey, | ||
| }; | ||
|
|
||
| /// Permissioned Burn extension instructions | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
| #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] | ||
| #[derive(Clone, Copy, Debug, PartialEq, IntoPrimitive, TryFromPrimitive)] | ||
| #[repr(u8)] | ||
| pub enum PermissionedBurnInstruction { | ||
| /// Require permissioned burn for the given mint account | ||
| /// | ||
| /// Accounts expected by this instruction: | ||
| /// | ||
| /// 0. `[writable]` The mint account to initialize. | ||
| /// | ||
| /// Data expected by this instruction: | ||
| /// `crate::extension::permissioned_burn::instruction::InitializeInstructionData` | ||
| Initialize, | ||
| } | ||
|
|
||
| /// Data expected by `PermissionedBurnInstruction::Initialize` | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
| #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] | ||
| #[derive(Clone, Copy, Pod, Zeroable)] | ||
| #[repr(C)] | ||
| pub struct InitializeInstructionData { | ||
| /// The public key for the account that is required for token burning. | ||
| pub authority: Pubkey, | ||
| } | ||
|
|
||
| /// Create an `Initialize` instruction | ||
| pub fn initialize( | ||
| token_program_id: &Pubkey, | ||
| mint: &Pubkey, | ||
| authority: &Pubkey, | ||
| ) -> Result<Instruction, ProgramError> { | ||
| check_program_account(token_program_id)?; | ||
| let accounts = vec![AccountMeta::new(*mint, false)]; | ||
| Ok(encode_instruction( | ||
| token_program_id, | ||
| accounts, | ||
| TokenInstruction::PermissionedBurnExtension, | ||
| PermissionedBurnInstruction::Initialize, | ||
| &InitializeInstructionData { | ||
| authority: *authority, | ||
| }, | ||
| )) | ||
| } |
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,24 @@ | ||
| #[cfg(feature = "serde")] | ||
| use serde::{Deserialize, Serialize}; | ||
| use { | ||
| crate::extension::{Extension, ExtensionType}, | ||
| bytemuck::{Pod, Zeroable}, | ||
| spl_pod::optional_keys::OptionalNonZeroPubkey | ||
| }; | ||
|
|
||
| /// Instruction types for the permissioned burn extension | ||
| pub mod instruction; | ||
|
|
||
| /// Indicates that the tokens from this mint require permissioned burn | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
| #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] | ||
| #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] | ||
| #[repr(C)] | ||
| pub struct PermissionedBurnConfig { | ||
| /// Authority that is required for burning | ||
| pub authority: OptionalNonZeroPubkey, | ||
| } | ||
|
|
||
| impl Extension for PermissionedBurnConfig { | ||
| const TYPE: ExtensionType = ExtensionType::PermissionedBurn; | ||
| } |
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,5 @@ | ||
| #![deprecated( | ||
| since = "9.1.0", | ||
| note = "Use spl_token_2022_interface instead and remove spl_token_2022 as a dependency" | ||
| )] | ||
| pub use spl_token_2022_interface::extension::permissioned_burn::instruction::*; |
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,10 @@ | ||
| /// Instruction types for the permissioned burn extension | ||
| pub mod instruction; | ||
| /// Instruction processor for the permissioned burn extension | ||
| pub mod processor; | ||
|
|
||
| #[deprecated( | ||
| since = "9.1.0", | ||
| note = "Use spl_token_2022_interface instead and remove spl_token_2022 as a dependency" | ||
| )] | ||
| pub use spl_token_2022_interface::extension::permissioned_burn::PermissionedBurnConfig; |
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,50 @@ | ||
| use { | ||
| solana_account_info::{next_account_info, AccountInfo}, | ||
| solana_msg::msg, | ||
| solana_program_error::ProgramResult, | ||
| solana_pubkey::Pubkey, | ||
| spl_token_2022_interface::{ | ||
| check_program_account, | ||
| extension::{ | ||
| permissioned_burn::{ | ||
| instruction::{InitializeInstructionData, PermissionedBurnInstruction}, | ||
| PermissionedBurnConfig, | ||
| }, | ||
| BaseStateWithExtensionsMut, PodStateWithExtensionsMut, | ||
| }, | ||
| instruction::{decode_instruction_data, decode_instruction_type}, | ||
| pod::PodMint, | ||
| }, | ||
| }; | ||
|
|
||
| fn process_initialize( | ||
| _program_id: &Pubkey, | ||
| accounts: &[AccountInfo], | ||
| authority: &Pubkey, | ||
| ) -> ProgramResult { | ||
| let account_info_iter = &mut accounts.iter(); | ||
| let mint_account_info = next_account_info(account_info_iter)?; | ||
| let mut mint_data = mint_account_info.data.borrow_mut(); | ||
| let mut mint = PodStateWithExtensionsMut::<PodMint>::unpack_uninitialized(&mut mint_data)?; | ||
|
|
||
| let extension = mint.init_extension::<PermissionedBurnConfig>(true)?; | ||
| extension.authority = Some(*authority).try_into()?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub(crate) fn process_instruction( | ||
| program_id: &Pubkey, | ||
| accounts: &[AccountInfo], | ||
| input: &[u8], | ||
| ) -> ProgramResult { | ||
| check_program_account(program_id)?; | ||
|
|
||
| match decode_instruction_type(input)? { | ||
| PermissionedBurnInstruction::Initialize => { | ||
| msg!("PermissionedBurnInstruction::Initialize"); | ||
| let InitializeInstructionData { authority } = decode_instruction_data(input)?; | ||
| process_initialize(program_id, accounts, authority) | ||
| } | ||
| } | ||
| } |
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.
Seeing this, I think we should add a new variant to
Burn, likeBurnCheckedWithPermission, which explicitly takes in the authority. Otherwise, the account order for multisig owners will break, since you'll need to do:It would be better to be clear, and have a new instruction which orders the accounts as:
We can add it as another instruction under the
PermissionedBurnextension.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.
Makes sense; definitely better than making a breaking change.