Skip to content
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

token 2022: add InitializeMember instruction from SPL Token Group interface #5629

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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