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

Commit 2a56a1d

Browse files
committed
token 2022: add InitializeMember instruction from SPL Token Group interface
1 parent 106a697 commit 2a56a1d

File tree

5 files changed

+727
-8
lines changed

5 files changed

+727
-8
lines changed

token/client/src/token.rs

+55-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use {
6161
},
6262
state::{Account, AccountState, Mint, Multisig},
6363
},
64-
spl_token_group_interface::state::TokenGroup,
64+
spl_token_group_interface::state::{TokenGroup, TokenGroupMember},
6565
spl_token_metadata_interface::state::{Field, TokenMetadata},
6666
std::{
6767
fmt, io,
@@ -3801,4 +3801,58 @@ where
38013801
)
38023802
.await
38033803
}
3804+
3805+
/// Initialize a token-group member on a mint
3806+
pub async fn token_group_initialize_member<S: Signers>(
3807+
&self,
3808+
mint_authority: &Pubkey,
3809+
group_mint: &Pubkey,
3810+
group_update_authority: &Pubkey,
3811+
signing_keypairs: &S,
3812+
) -> TokenResult<T::Output> {
3813+
self.process_ixs(
3814+
&[spl_token_group_interface::instruction::initialize_member(
3815+
&self.program_id,
3816+
&self.pubkey,
3817+
&self.pubkey,
3818+
mint_authority,
3819+
group_mint,
3820+
group_update_authority,
3821+
)],
3822+
signing_keypairs,
3823+
)
3824+
.await
3825+
}
3826+
3827+
/// Initialize a token-group member on a mint
3828+
#[allow(clippy::too_many_arguments)]
3829+
pub async fn token_group_initialize_member_with_rent_transfer<S: Signers>(
3830+
&self,
3831+
payer: &Pubkey,
3832+
mint_authority: &Pubkey,
3833+
group_mint: &Pubkey,
3834+
group_update_authority: &Pubkey,
3835+
signing_keypairs: &S,
3836+
) -> TokenResult<T::Output> {
3837+
let additional_lamports = self
3838+
.get_additional_rent_for_fixed_len_extension::<TokenGroupMember>()
3839+
.await?;
3840+
let mut instructions = vec![];
3841+
if additional_lamports > 0 {
3842+
instructions.push(system_instruction::transfer(
3843+
payer,
3844+
&self.pubkey,
3845+
additional_lamports,
3846+
));
3847+
}
3848+
instructions.push(spl_token_group_interface::instruction::initialize_member(
3849+
&self.program_id,
3850+
&self.pubkey,
3851+
&self.pubkey,
3852+
mint_authority,
3853+
group_mint,
3854+
group_update_authority,
3855+
));
3856+
self.process_ixs(&instructions, signing_keypairs).await
3857+
}
38043858
}

0 commit comments

Comments
 (0)