Skip to content

Commit

Permalink
token 2022: add InitializeMember instruction from SPL Token Group i…
Browse files Browse the repository at this point in the history
…nterface
  • Loading branch information
buffalojoec committed Nov 21, 2023
1 parent 106a697 commit b3a3295
Show file tree
Hide file tree
Showing 5 changed files with 760 additions and 8 deletions.
56 changes: 55 additions & 1 deletion token/client/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use {
},
state::{Account, AccountState, Mint, Multisig},
},
spl_token_group_interface::state::TokenGroup,
spl_token_group_interface::state::{TokenGroup, TokenGroupMember},
spl_token_metadata_interface::state::{Field, TokenMetadata},
std::{
fmt, io,
Expand Down Expand Up @@ -3801,4 +3801,58 @@ where
)
.await
}

/// Initialize a token-group member on a mint
pub async fn token_group_initialize_member<S: Signers>(
&self,
mint_authority: &Pubkey,
group_mint: &Pubkey,
group_update_authority: &Pubkey,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
self.process_ixs(
&[spl_token_group_interface::instruction::initialize_member(
&self.program_id,
&self.pubkey,
&self.pubkey,
mint_authority,
group_mint,
group_update_authority,
)],
signing_keypairs,
)
.await
}

/// Initialize a token-group member on a mint
#[allow(clippy::too_many_arguments)]
pub async fn token_group_initialize_member_with_rent_transfer<S: Signers>(
&self,
payer: &Pubkey,
mint_authority: &Pubkey,
group_mint: &Pubkey,
group_update_authority: &Pubkey,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
let additional_lamports = self
.get_additional_rent_for_fixed_len_extension::<TokenGroupMember>()
.await?;
let mut instructions = vec![];
if additional_lamports > 0 {
instructions.push(system_instruction::transfer(
payer,
&self.pubkey,
additional_lamports,
));
}
instructions.push(spl_token_group_interface::instruction::initialize_member(
&self.program_id,
&self.pubkey,
&self.pubkey,
mint_authority,
group_mint,
group_update_authority,
));
self.process_ixs(&instructions, signing_keypairs).await
}
}
Loading

0 comments on commit b3a3295

Please sign in to comment.