@@ -8,7 +8,7 @@ use anchor_spl::token_2022::spl_token_2022::extension::{
88} ;
99use anchor_spl:: token_2022:: spl_token_2022:: state:: Mint as MintInner ;
1010use anchor_spl:: token_interface:: {
11- self , CloseAccount , Mint , TokenAccount , TokenInterface , Transfer , TransferChecked ,
11+ self , Burn , CloseAccount , Mint , MintTo , TokenAccount , TokenInterface , Transfer , TransferChecked ,
1212} ;
1313
1414pub fn send_from_program_vault < ' info > (
@@ -106,6 +106,58 @@ pub fn close_vault<'info>(
106106 token_interface:: close_account ( cpi_context)
107107}
108108
109+ pub fn mint_tokens < ' info > (
110+ token_program : & Interface < ' info , TokenInterface > ,
111+ destination : & InterfaceAccount < ' info , TokenAccount > ,
112+ authority : & AccountInfo < ' info > ,
113+ nonce : u8 ,
114+ amount : u64 ,
115+ mint : & InterfaceAccount < ' info , Mint > ,
116+ ) -> Result < ( ) > {
117+ let signature_seeds = get_signer_seeds ( & nonce) ;
118+ let signers = & [ & signature_seeds[ ..] ] ;
119+
120+ let mint_account_info = mint. to_account_info ( ) ;
121+
122+ validate_mint_fee ( & mint_account_info) ?;
123+
124+ let cpi_accounts = MintTo {
125+ mint : mint_account_info,
126+ to : destination. to_account_info ( ) ,
127+ authority : authority. to_account_info ( ) ,
128+ } ;
129+
130+ let cpi_program = token_program. to_account_info ( ) ;
131+ let cpi_context = CpiContext :: new_with_signer ( cpi_program, cpi_accounts, signers) ;
132+ token_interface:: mint_to ( cpi_context, amount)
133+ }
134+
135+ pub fn burn_tokens < ' info > (
136+ token_program : & Interface < ' info , TokenInterface > ,
137+ destination : & InterfaceAccount < ' info , TokenAccount > ,
138+ authority : & AccountInfo < ' info > ,
139+ nonce : u8 ,
140+ amount : u64 ,
141+ mint : & InterfaceAccount < ' info , Mint > ,
142+ ) -> Result < ( ) > {
143+ let signature_seeds = get_signer_seeds ( & nonce) ;
144+ let signers = & [ & signature_seeds[ ..] ] ;
145+
146+ let mint_account_info = mint. to_account_info ( ) ;
147+
148+ validate_mint_fee ( & mint_account_info) ?;
149+
150+ let cpi_accounts = Burn {
151+ mint : mint_account_info,
152+ from : destination. to_account_info ( ) ,
153+ authority : authority. to_account_info ( ) ,
154+ } ;
155+
156+ let cpi_program = token_program. to_account_info ( ) ;
157+ let cpi_context = CpiContext :: new_with_signer ( cpi_program, cpi_accounts, signers) ;
158+ token_interface:: burn ( cpi_context, amount)
159+ }
160+
109161pub fn validate_mint_fee ( account_info : & AccountInfo ) -> Result < ( ) > {
110162 let mint_data = account_info. try_borrow_data ( ) ?;
111163 let mint_with_extension = StateWithExtensions :: < MintInner > :: unpack ( & mint_data) ?;
0 commit comments