@@ -9,7 +9,7 @@ use anchor_spl::token_2022::spl_token_2022::extension::{
99} ;
1010use anchor_spl:: token_2022:: spl_token_2022:: state:: Mint as MintInner ;
1111use anchor_spl:: token_interface:: {
12- self , CloseAccount , Mint , TokenAccount , TokenInterface , Transfer , TransferChecked ,
12+ self , Burn , CloseAccount , Mint , MintTo , TokenAccount , TokenInterface , Transfer , TransferChecked ,
1313} ;
1414use std:: iter:: Peekable ;
1515use std:: slice:: Iter ;
@@ -25,7 +25,31 @@ pub fn send_from_program_vault<'info>(
2525 remaining_accounts : Option < & mut Peekable < Iter < ' info , AccountInfo < ' info > > > > ,
2626) -> Result < ( ) > {
2727 let signature_seeds = get_signer_seeds ( & nonce) ;
28- let signers = & [ & signature_seeds[ ..] ] ;
28+
29+ send_from_program_vault_with_signature_seeds (
30+ token_program,
31+ from,
32+ to,
33+ authority,
34+ & signature_seeds,
35+ amount,
36+ mint,
37+ remaining_accounts,
38+ )
39+ }
40+
41+ #[ inline]
42+ pub fn send_from_program_vault_with_signature_seeds < ' info > (
43+ token_program : & Interface < ' info , TokenInterface > ,
44+ from : & InterfaceAccount < ' info , TokenAccount > ,
45+ to : & InterfaceAccount < ' info , TokenAccount > ,
46+ authority : & AccountInfo < ' info > ,
47+ signature_seeds : & [ & [ u8 ] ] ,
48+ amount : u64 ,
49+ mint : & Option < InterfaceAccount < ' info , Mint > > ,
50+ remaining_accounts : Option < & mut Peekable < Iter < ' info , AccountInfo < ' info > > > > ,
51+ ) -> Result < ( ) > {
52+ let signers = & [ signature_seeds] ;
2953
3054 if let Some ( mint) = mint {
3155 if let Some ( remaining_accounts) = remaining_accounts {
@@ -137,6 +161,56 @@ pub fn close_vault<'info>(
137161 token_interface:: close_account ( cpi_context)
138162}
139163
164+ pub fn mint_tokens < ' info > (
165+ token_program : & Interface < ' info , TokenInterface > ,
166+ destination : & InterfaceAccount < ' info , TokenAccount > ,
167+ authority : & AccountInfo < ' info > ,
168+ signature_seeds : & [ & [ u8 ] ] ,
169+ amount : u64 ,
170+ mint : & InterfaceAccount < ' info , Mint > ,
171+ ) -> Result < ( ) > {
172+ let signers = & [ signature_seeds] ;
173+
174+ let mint_account_info = mint. to_account_info ( ) ;
175+
176+ validate_mint_fee ( & mint_account_info) ?;
177+
178+ let cpi_accounts = MintTo {
179+ mint : mint_account_info,
180+ to : destination. to_account_info ( ) ,
181+ authority : authority. to_account_info ( ) ,
182+ } ;
183+
184+ let cpi_program = token_program. to_account_info ( ) ;
185+ let cpi_context = CpiContext :: new_with_signer ( cpi_program, cpi_accounts, signers) ;
186+ token_interface:: mint_to ( cpi_context, amount)
187+ }
188+
189+ pub fn burn_tokens < ' info > (
190+ token_program : & Interface < ' info , TokenInterface > ,
191+ destination : & InterfaceAccount < ' info , TokenAccount > ,
192+ authority : & AccountInfo < ' info > ,
193+ signature_seeds : & [ & [ u8 ] ] ,
194+ amount : u64 ,
195+ mint : & InterfaceAccount < ' info , Mint > ,
196+ ) -> Result < ( ) > {
197+ let signers = & [ signature_seeds] ;
198+
199+ let mint_account_info = mint. to_account_info ( ) ;
200+
201+ validate_mint_fee ( & mint_account_info) ?;
202+
203+ let cpi_accounts = Burn {
204+ mint : mint_account_info,
205+ from : destination. to_account_info ( ) ,
206+ authority : authority. to_account_info ( ) ,
207+ } ;
208+
209+ let cpi_program = token_program. to_account_info ( ) ;
210+ let cpi_context = CpiContext :: new_with_signer ( cpi_program, cpi_accounts, signers) ;
211+ token_interface:: burn ( cpi_context, amount)
212+ }
213+
140214pub fn validate_mint_fee ( account_info : & AccountInfo ) -> Result < ( ) > {
141215 let mint_data = account_info. try_borrow_data ( ) ?;
142216 let mint_with_extension = StateWithExtensions :: < MintInner > :: unpack ( & mint_data) ?;
0 commit comments