Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 8d0a2e1

Browse files
authored
token-2022: Add PermanentDelegate extension (#3725)
* token-2022: Add PermanentDelegate extension * Address feedback * Refactor getting permanent delegate * Rename function * More cleanup * Fix ATA
1 parent 0ddbd71 commit 8d0a2e1

File tree

23 files changed

+529
-76
lines changed

23 files changed

+529
-76
lines changed

associated-token-account/program-test/tests/extended_mint.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use {
1717
},
1818
spl_token_2022::{
1919
error::TokenError,
20-
extension::{transfer_fee, ExtensionType, StateWithExtensionsOwned},
20+
extension::{
21+
transfer_fee, BaseStateWithExtensions, ExtensionType, StateWithExtensionsOwned,
22+
},
2123
state::{Account, Mint},
2224
},
2325
};

token-swap/program/src/processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use spl_token_2022::{
3333
error::TokenError,
3434
extension::{
3535
mint_close_authority::MintCloseAuthority, transfer_fee::TransferFeeConfig,
36-
StateWithExtensions,
36+
BaseStateWithExtensions, StateWithExtensions,
3737
},
3838
state::{Account, Mint},
3939
};

token/cli/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use spl_token_2022::{
4343
memo_transfer::MemoTransfer,
4444
mint_close_authority::MintCloseAuthority,
4545
transfer_fee::{TransferFeeAmount, TransferFeeConfig},
46-
ExtensionType, StateWithExtensionsOwned,
46+
BaseStateWithExtensions, ExtensionType, StateWithExtensionsOwned,
4747
},
4848
instruction::*,
4949
state::{Account, AccountState, Mint},
@@ -744,6 +744,7 @@ async fn command_authorize(
744744
AuthorityType::TransferFeeConfig => "transfer fee authority",
745745
AuthorityType::WithheldWithdraw => "withdraw withheld authority",
746746
AuthorityType::InterestRate => "interest rate authority",
747+
AuthorityType::PermanentDelegate => "permanent delegate",
747748
};
748749

749750
let (mint_pubkey, previous_authority) = if !config.sign_only {
@@ -781,6 +782,7 @@ async fn command_authorize(
781782
Err(format!("Mint `{}` is not interest-bearing", account))
782783
}
783784
}
785+
AuthorityType::PermanentDelegate => unimplemented!(),
784786
}?;
785787

786788
Ok((account, previous_authority))
@@ -813,7 +815,8 @@ async fn command_authorize(
813815
| AuthorityType::CloseMint
814816
| AuthorityType::TransferFeeConfig
815817
| AuthorityType::WithheldWithdraw
816-
| AuthorityType::InterestRate => Err(format!(
818+
| AuthorityType::InterestRate
819+
| AuthorityType::PermanentDelegate => Err(format!(
817820
"Authority type `{}` not supported for SPL Token accounts",
818821
auth_str
819822
)),
@@ -3662,6 +3665,7 @@ async fn process_command<'a>(
36623665
"transfer-fee-config" => AuthorityType::TransferFeeConfig,
36633666
"withheld-withdraw" => AuthorityType::WithheldWithdraw,
36643667
"interest-rate" => AuthorityType::InterestRate,
3668+
"permanent-delegate" => AuthorityType::PermanentDelegate,
36653669
_ => unreachable!(),
36663670
};
36673671

token/client/src/token.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use {
2121
spl_token_2022::{
2222
extension::{
2323
confidential_transfer, cpi_guard, default_account_state, interest_bearing_mint,
24-
memo_transfer, transfer_fee, ExtensionType, StateWithExtensionsOwned,
24+
memo_transfer, transfer_fee, BaseStateWithExtensions, ExtensionType,
25+
StateWithExtensionsOwned,
2526
},
2627
instruction,
2728
solana_zk_token_sdk::{
@@ -122,6 +123,9 @@ pub enum ExtensionInitializationParams {
122123
rate: i16,
123124
},
124125
NonTransferable,
126+
PermanentDelegate {
127+
delegate: Pubkey,
128+
},
125129
}
126130
impl ExtensionInitializationParams {
127131
/// Get the extension type associated with the init params
@@ -133,6 +137,7 @@ impl ExtensionInitializationParams {
133137
Self::TransferFeeConfig { .. } => ExtensionType::TransferFeeConfig,
134138
Self::InterestBearingConfig { .. } => ExtensionType::InterestBearingConfig,
135139
Self::NonTransferable => ExtensionType::NonTransferable,
140+
Self::PermanentDelegate { .. } => ExtensionType::PermanentDelegate,
136141
}
137142
}
138143
/// Generate an appropriate initialization instruction for the given mint
@@ -188,6 +193,9 @@ impl ExtensionInitializationParams {
188193
Self::NonTransferable => {
189194
instruction::initialize_non_transferable_mint(token_program_id, mint)
190195
}
196+
Self::PermanentDelegate { delegate } => {
197+
instruction::initialize_permanent_delegate(token_program_id, mint, &delegate)
198+
}
191199
}
192200
}
193201
}

token/program-2022-test/tests/confidential_transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use {
1515
confidential_transfer::{
1616
ConfidentialTransferAccount, ConfidentialTransferMint, EncryptedWithheldAmount,
1717
},
18-
ExtensionType,
18+
BaseStateWithExtensions, ExtensionType,
1919
},
2020
solana_zk_token_sdk::{
2121
encryption::{auth_encryption::*, elgamal::*},

token/program-2022-test/tests/cpi_guard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use {
1717
error::TokenError,
1818
extension::{
1919
cpi_guard::{self, CpiGuard},
20-
ExtensionType,
20+
BaseStateWithExtensions, ExtensionType,
2121
},
2222
instruction::{self, AuthorityType},
2323
processor::Processor as SplToken2022Processor,

token/program-2022-test/tests/default_account_state.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ use {
99
signer::keypair::Keypair, transaction::TransactionError, transport::TransportError,
1010
},
1111
spl_token_2022::{
12-
error::TokenError, extension::default_account_state::DefaultAccountState,
13-
instruction::AuthorityType, state::AccountState,
12+
error::TokenError,
13+
extension::{default_account_state::DefaultAccountState, BaseStateWithExtensions},
14+
instruction::AuthorityType,
15+
state::AccountState,
1416
},
1517
spl_token_client::token::{ExtensionInitializationParams, TokenError as TokenClientError},
1618
std::convert::TryFrom,

token/program-2022-test/tests/initialize_account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use {
1717
error::TokenError,
1818
extension::{
1919
transfer_fee::{self, TransferFeeAmount},
20-
ExtensionType, StateWithExtensions,
20+
BaseStateWithExtensions, ExtensionType, StateWithExtensions,
2121
},
2222
instruction,
2323
state::{Account, Mint},

token/program-2022-test/tests/initialize_mint.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use {
1616
},
1717
spl_token_2022::{
1818
error::TokenError,
19-
extension::{mint_close_authority::MintCloseAuthority, transfer_fee, ExtensionType},
19+
extension::{
20+
mint_close_authority::MintCloseAuthority, transfer_fee, BaseStateWithExtensions,
21+
ExtensionType,
22+
},
2023
instruction, native_mint,
2124
state::Mint,
2225
},

token/program-2022-test/tests/interest_bearing_mint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use {
2323
},
2424
spl_token_2022::{
2525
error::TokenError,
26-
extension::interest_bearing_mint::InterestBearingConfig,
26+
extension::{interest_bearing_mint::InterestBearingConfig, BaseStateWithExtensions},
2727
instruction::{amount_to_ui_amount, ui_amount_to_amount, AuthorityType},
2828
processor::Processor,
2929
},

0 commit comments

Comments
 (0)