|
43 | 43 | ConfidentialTransferFeeConfig,
|
44 | 44 | },
|
45 | 45 | cpi_guard, default_account_state, group_pointer, interest_bearing_mint, memo_transfer,
|
46 |
| - metadata_pointer, transfer_fee, transfer_hook, BaseStateWithExtensions, ExtensionType, |
47 |
| - StateWithExtensionsOwned, |
| 46 | + metadata_pointer, transfer_fee, transfer_hook, BaseStateWithExtensions, Extension, |
| 47 | + ExtensionType, StateWithExtensionsOwned, |
48 | 48 | },
|
49 | 49 | instruction, offchain,
|
50 | 50 | proof::ProofLocation,
|
|
61 | 61 | },
|
62 | 62 | state::{Account, AccountState, Mint, Multisig},
|
63 | 63 | },
|
| 64 | + spl_token_group_interface::state::TokenGroup, |
64 | 65 | spl_token_metadata_interface::state::{Field, TokenMetadata},
|
65 | 66 | std::{
|
66 | 67 | fmt, io,
|
@@ -3649,4 +3650,76 @@ where
|
3649 | 3650 | )
|
3650 | 3651 | .await
|
3651 | 3652 | }
|
| 3653 | + |
| 3654 | + /// Initialize token-group on a mint |
| 3655 | + pub async fn token_group_initialize<S: Signers>( |
| 3656 | + &self, |
| 3657 | + mint_authority: &Pubkey, |
| 3658 | + update_authority: &Pubkey, |
| 3659 | + max_size: u32, |
| 3660 | + signing_keypairs: &S, |
| 3661 | + ) -> TokenResult<T::Output> { |
| 3662 | + self.process_ixs( |
| 3663 | + &[spl_token_group_interface::instruction::initialize_group( |
| 3664 | + &self.program_id, |
| 3665 | + &self.pubkey, |
| 3666 | + &self.pubkey, |
| 3667 | + mint_authority, |
| 3668 | + Some(*update_authority), |
| 3669 | + max_size, |
| 3670 | + )], |
| 3671 | + signing_keypairs, |
| 3672 | + ) |
| 3673 | + .await |
| 3674 | + } |
| 3675 | + |
| 3676 | + async fn get_additional_rent_for_fixed_len_extension<V: Extension + Pod>( |
| 3677 | + &self, |
| 3678 | + ) -> TokenResult<u64> { |
| 3679 | + let account = self.get_account(self.pubkey).await?; |
| 3680 | + let account_lamports = account.lamports; |
| 3681 | + let mint_state = self.unpack_mint_info(account)?; |
| 3682 | + if mint_state.get_extension::<V>().is_ok() { |
| 3683 | + Ok(0) |
| 3684 | + } else { |
| 3685 | + let new_account_len = mint_state.try_get_new_account_len::<V>()?; |
| 3686 | + let new_rent_exempt_minimum = self |
| 3687 | + .client |
| 3688 | + .get_minimum_balance_for_rent_exemption(new_account_len) |
| 3689 | + .await |
| 3690 | + .map_err(TokenError::Client)?; |
| 3691 | + Ok(new_rent_exempt_minimum.saturating_sub(account_lamports)) |
| 3692 | + } |
| 3693 | + } |
| 3694 | + |
| 3695 | + /// Initialize token-group on a mint |
| 3696 | + pub async fn token_group_initialize_with_rent_transfer<S: Signers>( |
| 3697 | + &self, |
| 3698 | + payer: &Pubkey, |
| 3699 | + mint_authority: &Pubkey, |
| 3700 | + update_authority: &Pubkey, |
| 3701 | + max_size: u32, |
| 3702 | + signing_keypairs: &S, |
| 3703 | + ) -> TokenResult<T::Output> { |
| 3704 | + let additional_lamports = self |
| 3705 | + .get_additional_rent_for_fixed_len_extension::<TokenGroup>() |
| 3706 | + .await?; |
| 3707 | + let mut instructions = vec![]; |
| 3708 | + if additional_lamports > 0 { |
| 3709 | + instructions.push(system_instruction::transfer( |
| 3710 | + payer, |
| 3711 | + &self.pubkey, |
| 3712 | + additional_lamports, |
| 3713 | + )); |
| 3714 | + } |
| 3715 | + instructions.push(spl_token_group_interface::instruction::initialize_group( |
| 3716 | + &self.program_id, |
| 3717 | + &self.pubkey, |
| 3718 | + &self.pubkey, |
| 3719 | + mint_authority, |
| 3720 | + Some(*update_authority), |
| 3721 | + max_size, |
| 3722 | + )); |
| 3723 | + self.process_ixs(&instructions, signing_keypairs).await |
| 3724 | + } |
3652 | 3725 | }
|
0 commit comments