From 9ab3658153a09c04e226e9d6932b787d21d1c362 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 18 Oct 2023 15:41:56 +0200 Subject: [PATCH] token 2022: add `InitializeMember` instruction from SPL Token Group interface --- token/client/src/token.rs | 26 ++++--------------- .../tests/token_group_initialize_member.rs | 11 +++----- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/token/client/src/token.rs b/token/client/src/token.rs index f16812f5ae7..a265c4c5873 100644 --- a/token/client/src/token.rs +++ b/token/client/src/token.rs @@ -1,3 +1,5 @@ +use spl_token_group_interface::state::TokenGroupMember; + use { crate::{ client::{ProgramClient, ProgramClientError, SendTransaction, SimulateTransaction}, @@ -3834,26 +3836,6 @@ where .await } - async fn get_additional_rent_for_new_member(&self) -> TokenResult { - let account = self.get_account(self.pubkey).await?; - let account_lamports = account.lamports; - let mint_state = self.unpack_mint_info(account)?; - let new_account_len = mint_state - .try_get_account_len()? - .checked_add(ExtensionType::try_calculate_account_len::(&[ - ExtensionType::TokenGroupMember, - ])?) - .ok_or(TokenError::Program( - spl_token_2022::error::TokenError::Overflow.into(), - ))?; - let new_rent_exempt_minimum = self - .client - .get_minimum_balance_for_rent_exemption(new_account_len) - .await - .map_err(TokenError::Client)?; - Ok(new_rent_exempt_minimum.saturating_sub(account_lamports)) - } - /// Initialize a token-group member on a mint #[allow(clippy::too_many_arguments)] pub async fn token_group_initialize_member_with_rent_transfer( @@ -3864,7 +3846,9 @@ where group_update_authority: &Pubkey, signing_keypairs: &S, ) -> TokenResult { - let additional_lamports = self.get_additional_rent_for_new_member().await?; + let additional_lamports = self + .get_additional_rent_for_fixed_len_extension::() + .await?; let mut instructions = vec![]; if additional_lamports > 0 { instructions.push(system_instruction::transfer( diff --git a/token/program-2022-test/tests/token_group_initialize_member.rs b/token/program-2022-test/tests/token_group_initialize_member.rs index 7635279a8aa..e138fb87e56 100644 --- a/token/program-2022-test/tests/token_group_initialize_member.rs +++ b/token/program-2022-test/tests/token_group_initialize_member.rs @@ -246,16 +246,11 @@ async fn success_initialize_member() { // fail double-init let error = member1_token_context .token - .token_group_initialize_member_with_rent_transfer( - &payer.pubkey(), + .token_group_initialize_member( &member1_token_context.mint_authority.pubkey(), &group_mint_keypair.pubkey(), &group_authority.pubkey(), - &[ - &payer, - &member1_token_context.mint_authority, - &group_authority, - ], + &[&member1_token_context.mint_authority, &group_authority], ) .await .unwrap_err(); @@ -263,7 +258,7 @@ async fn success_initialize_member() { error, TokenClientError::Client(Box::new(TransportError::TransactionError( TransactionError::InstructionError( - 1, + 0, InstructionError::Custom(TokenError::ExtensionAlreadyInitialized as u32) ) )))