|
41 | 41 | ConfidentialTransferFeeConfig,
|
42 | 42 | },
|
43 | 43 | cpi_guard, default_account_state, group_pointer, interest_bearing_mint, memo_transfer,
|
44 |
| - metadata_pointer, transfer_fee, transfer_hook, BaseStateWithExtensions, ExtensionType, |
45 |
| - StateWithExtensionsOwned, |
| 44 | + metadata_pointer, transfer_fee, transfer_hook, BaseStateWithExtensions, Extension, |
| 45 | + ExtensionType, Length, StateWithExtensionsOwned, |
46 | 46 | },
|
47 | 47 | instruction, offchain,
|
48 | 48 | proof::ProofLocation,
|
|
59 | 59 | },
|
60 | 60 | state::{Account, AccountState, Mint, Multisig},
|
61 | 61 | },
|
| 62 | + spl_token_group_interface::state::TokenGroup, |
62 | 63 | spl_token_metadata_interface::state::{Field, TokenMetadata},
|
63 | 64 | std::{
|
64 | 65 | fmt, io,
|
@@ -3848,4 +3849,77 @@ where
|
3848 | 3849 | )
|
3849 | 3850 | .await
|
3850 | 3851 | }
|
| 3852 | + |
| 3853 | + /// Initialize token-group on a mint |
| 3854 | + pub async fn token_group_initialize<S: Signers>( |
| 3855 | + &self, |
| 3856 | + mint_authority: &Pubkey, |
| 3857 | + update_authority: &Pubkey, |
| 3858 | + max_size: u32, |
| 3859 | + signing_keypairs: &S, |
| 3860 | + ) -> TokenResult<T::Output> { |
| 3861 | + self.process_ixs( |
| 3862 | + &[spl_token_group_interface::instruction::initialize_group( |
| 3863 | + &self.program_id, |
| 3864 | + &self.pubkey, |
| 3865 | + &self.pubkey, |
| 3866 | + mint_authority, |
| 3867 | + Some(*update_authority), |
| 3868 | + max_size, |
| 3869 | + )], |
| 3870 | + signing_keypairs, |
| 3871 | + ) |
| 3872 | + .await |
| 3873 | + } |
| 3874 | + |
| 3875 | + async fn get_additional_rent_for_fixed_len_extension<V: Extension + Pod>( |
| 3876 | + &self, |
| 3877 | + ) -> TokenResult<u64> { |
| 3878 | + let account = self.get_account(self.pubkey).await?; |
| 3879 | + let account_lamports = account.lamports; |
| 3880 | + let new_account_len = account |
| 3881 | + .data |
| 3882 | + .len() |
| 3883 | + .saturating_add(size_of::<ExtensionType>()) |
| 3884 | + .saturating_add(size_of::<Length>()) |
| 3885 | + .saturating_add(size_of::<V>()); |
| 3886 | + let new_rent_exempt_minimum = self |
| 3887 | + .client |
| 3888 | + .get_minimum_balance_for_rent_exemption(new_account_len) |
| 3889 | + .await |
| 3890 | + .map_err(TokenError::Client)?; |
| 3891 | + Ok(new_rent_exempt_minimum.saturating_sub(account_lamports)) |
| 3892 | + } |
| 3893 | + |
| 3894 | + /// Initialize token-group on a mint |
| 3895 | + #[allow(clippy::too_many_arguments)] |
| 3896 | + pub async fn token_group_initialize_with_rent_transfer<S: Signers>( |
| 3897 | + &self, |
| 3898 | + payer: &Pubkey, |
| 3899 | + mint_authority: &Pubkey, |
| 3900 | + update_authority: &Pubkey, |
| 3901 | + max_size: u32, |
| 3902 | + signing_keypairs: &S, |
| 3903 | + ) -> TokenResult<T::Output> { |
| 3904 | + let additional_lamports = self |
| 3905 | + .get_additional_rent_for_fixed_len_extension::<TokenGroup>() |
| 3906 | + .await?; |
| 3907 | + let mut instructions = vec![]; |
| 3908 | + if additional_lamports > 0 { |
| 3909 | + instructions.push(system_instruction::transfer( |
| 3910 | + payer, |
| 3911 | + &self.pubkey, |
| 3912 | + additional_lamports, |
| 3913 | + )); |
| 3914 | + } |
| 3915 | + instructions.push(spl_token_group_interface::instruction::initialize_group( |
| 3916 | + &self.program_id, |
| 3917 | + &self.pubkey, |
| 3918 | + &self.pubkey, |
| 3919 | + mint_authority, |
| 3920 | + Some(*update_authority), |
| 3921 | + max_size, |
| 3922 | + )); |
| 3923 | + self.process_ixs(&instructions, signing_keypairs).await |
| 3924 | + } |
3851 | 3925 | }
|
0 commit comments