Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

token 2022: add alloc_and_serialize_allow_repeating #5839

95 changes: 92 additions & 3 deletions token/client/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ use {
self, account_info::WithheldTokensInfo, ConfidentialTransferFeeAmount,
ConfidentialTransferFeeConfig,
},
cpi_guard, default_account_state, group_pointer, interest_bearing_mint, memo_transfer,
metadata_pointer, transfer_fee, transfer_hook, BaseStateWithExtensions, Extension,
ExtensionType, StateWithExtensionsOwned,
cpi_guard, default_account_state, group_member_pointer, group_pointer,
interest_bearing_mint, memo_transfer, metadata_pointer, transfer_fee, transfer_hook,
BaseStateWithExtensions, Extension, ExtensionType, StateWithExtensionsOwned,
},
instruction, offchain,
proof::ProofLocation,
Expand Down Expand Up @@ -176,6 +176,12 @@ pub enum ExtensionInitializationParams {
authority: Option<Pubkey>,
group_address: Option<Pubkey>,
},
GroupMemberPointer {
authority: Option<Pubkey>,
group_update_authority: Pubkey,
group_address: Pubkey,
member_address: Option<Pubkey>,
},
}
impl ExtensionInitializationParams {
/// Get the extension type associated with the init params
Expand All @@ -194,6 +200,7 @@ impl ExtensionInitializationParams {
ExtensionType::ConfidentialTransferFeeConfig
}
Self::GroupPointer { .. } => ExtensionType::GroupPointer,
Self::GroupMemberPointer { .. } => ExtensionType::GroupMemberPointer,
}
}
/// Generate an appropriate initialization instruction for the given mint
Expand Down Expand Up @@ -294,6 +301,19 @@ impl ExtensionInitializationParams {
authority,
group_address,
),
Self::GroupMemberPointer {
authority,
group_update_authority,
group_address,
member_address,
} => group_member_pointer::instruction::initialize(
token_program_id,
mint,
authority,
&group_update_authority,
&group_address,
member_address,
),
}
}
}
Expand Down Expand Up @@ -1700,6 +1720,33 @@ where
.await
}

/// Update group member pointer address
pub async fn update_group_member_address<S: Signers>(
&self,
authority: &Pubkey,
group_update_authority: &Pubkey,
group_address: &Pubkey,
new_member_address: Option<Pubkey>,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
let signing_pubkeys = signing_keypairs.pubkeys();
let multisig_signers = self.get_multisig_signers(authority, &signing_pubkeys);

self.process_ixs(
&[group_member_pointer::instruction::update(
&self.program_id,
self.get_address(),
authority,
group_update_authority,
&multisig_signers,
group_address,
new_member_address,
)?],
signing_keypairs,
)
.await
}

/// Update confidential transfer mint
pub async fn confidential_transfer_update_mint<S: Signers>(
&self,
Expand Down Expand Up @@ -3722,4 +3769,46 @@ where
));
self.process_ixs(&instructions, signing_keypairs).await
}

/// Update a token-group max size on a mint
pub async fn token_group_update_max_size<S: Signers>(
&self,
update_authority: &Pubkey,
new_max_size: u32,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
self.process_ixs(
&[
spl_token_group_interface::instruction::update_group_max_size(
&self.program_id,
&self.pubkey,
update_authority,
new_max_size,
),
],
signing_keypairs,
)
.await
}

/// Update the token-group authority in a mint
pub async fn token_group_update_authority<S: Signers>(
&self,
current_authority: &Pubkey,
new_authority: Option<Pubkey>,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
self.process_ixs(
&[
spl_token_group_interface::instruction::update_group_authority(
&self.program_id,
&self.pubkey,
current_authority,
new_authority,
),
],
signing_keypairs,
)
.await
}
}
38 changes: 22 additions & 16 deletions token/program-2022-test/tests/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,23 @@ async fn run_basic(context: TestContext) {
#[tokio::test]
async fn basic() {
let mut context = TestContext::new().await;
context.init_token_with_mint(vec![]).await.unwrap();
context.init_token_with_mint(vec![], &[]).await.unwrap();
run_basic(context).await;
}

#[tokio::test]
async fn basic_with_extension() {
let mut context = TestContext::new().await;
context
.init_token_with_mint(vec![ExtensionInitializationParams::TransferFeeConfig {
transfer_fee_config_authority: Some(Pubkey::new_unique()),
withdraw_withheld_authority: Some(Pubkey::new_unique()),
transfer_fee_basis_points: 100u16,
maximum_fee: 1_000u64,
}])
.init_token_with_mint(
vec![ExtensionInitializationParams::TransferFeeConfig {
transfer_fee_config_authority: Some(Pubkey::new_unique()),
withdraw_withheld_authority: Some(Pubkey::new_unique()),
transfer_fee_basis_points: 100u16,
maximum_fee: 1_000u64,
}],
&[],
)
.await
.unwrap();
run_basic(context).await;
Expand Down Expand Up @@ -149,20 +152,23 @@ async fn run_self_owned(context: TestContext) {
#[tokio::test]
async fn self_owned() {
let mut context = TestContext::new().await;
context.init_token_with_mint(vec![]).await.unwrap();
context.init_token_with_mint(vec![], &[]).await.unwrap();
run_self_owned(context).await;
}

#[tokio::test]
async fn self_owned_with_extension() {
let mut context = TestContext::new().await;
context
.init_token_with_mint(vec![ExtensionInitializationParams::TransferFeeConfig {
transfer_fee_config_authority: Some(Pubkey::new_unique()),
withdraw_withheld_authority: Some(Pubkey::new_unique()),
transfer_fee_basis_points: 100u16,
maximum_fee: 1_000u64,
}])
.init_token_with_mint(
vec![ExtensionInitializationParams::TransferFeeConfig {
transfer_fee_config_authority: Some(Pubkey::new_unique()),
withdraw_withheld_authority: Some(Pubkey::new_unique()),
transfer_fee_basis_points: 100u16,
maximum_fee: 1_000u64,
}],
&[],
)
.await
.unwrap();
run_self_owned(context).await;
Expand Down Expand Up @@ -288,13 +294,13 @@ async fn run_burn_and_close_system_or_incinerator(context: TestContext, non_owne
#[tokio::test]
async fn burn_and_close_incinerator_tokens() {
let mut context = TestContext::new().await;
context.init_token_with_mint(vec![]).await.unwrap();
context.init_token_with_mint(vec![], &[]).await.unwrap();
run_burn_and_close_system_or_incinerator(context, &solana_program::incinerator::id()).await;
}

#[tokio::test]
async fn burn_and_close_system_tokens() {
let mut context = TestContext::new().await;
context.init_token_with_mint(vec![]).await.unwrap();
context.init_token_with_mint(vec![], &[]).await.unwrap();
run_burn_and_close_system_or_incinerator(context, &solana_program::system_program::id()).await;
}
13 changes: 8 additions & 5 deletions token/program-2022-test/tests/close_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use {
async fn success_init_after_close_account() {
let mut context = TestContext::new().await;
let payer = Keypair::from_bytes(&context.context.lock().await.payer.to_bytes()).unwrap();
context.init_token_with_mint(vec![]).await.unwrap();
context.init_token_with_mint(vec![], &[]).await.unwrap();
let token = context.token_context.take().unwrap().token;
let token_program_id = spl_token_2022::id();
let owner = Keypair::new();
Expand Down Expand Up @@ -67,7 +67,7 @@ async fn success_init_after_close_account() {
async fn fail_init_after_close_account() {
let mut context = TestContext::new().await;
let payer = Keypair::from_bytes(&context.context.lock().await.payer.to_bytes()).unwrap();
context.init_token_with_mint(vec![]).await.unwrap();
context.init_token_with_mint(vec![], &[]).await.unwrap();
let token = context.token_context.take().unwrap().token;
let token_program_id = spl_token_2022::id();
let owner = Keypair::new();
Expand Down Expand Up @@ -119,9 +119,12 @@ async fn fail_init_after_close_mint() {
let mut context = TestContext::new().await;
let payer = Keypair::from_bytes(&context.context.lock().await.payer.to_bytes()).unwrap();
context
.init_token_with_mint(vec![ExtensionInitializationParams::MintCloseAuthority {
close_authority: Some(close_authority.pubkey()),
}])
.init_token_with_mint(
vec![ExtensionInitializationParams::MintCloseAuthority {
close_authority: Some(close_authority.pubkey()),
}],
&[],
)
.await
.unwrap();
let token = context.token_context.take().unwrap().token;
Expand Down
Loading