11use crate :: account_set:: { AccountSet , HasOwnerProgram , Program , SignedAccount , WritableAccount } ;
22use crate :: anyhow:: Result ;
3- use crate :: client:: ClientAccountSet ;
3+ use crate :: client:: { ClientAccountSet , MakeCpi } ;
44use crate :: prelude:: { StarFrameProgram , SyscallInvoke , SystemProgram } ;
5+ use crate :: program:: system_program:: { Transfer , TransferCpiAccounts } ;
56use anyhow:: anyhow;
67use solana_program:: account_info:: AccountInfo ;
78use solana_program:: instruction:: AccountMeta ;
89use solana_program:: program_error:: ProgramError ;
910use solana_program:: pubkey:: Pubkey ;
10- use solana_program:: system_instruction:: transfer;
1111use star_frame:: client:: CpiAccountSet ;
1212use std:: cell:: { Ref , RefMut } ;
1313use std:: cmp:: Ordering ;
@@ -146,8 +146,8 @@ where
146146}
147147
148148pub trait CanCloseAccount < ' info > : SingleAccountSet < ' info > {
149- /// Closes the account by zeroing the lamports and leaving the data as the
150- /// [`StarFrameProgram::CLOSED_ACCOUNT_DISCRIMINANT`], reallocating down to size.
149+ /// Closes the account by zeroing the lamports and replacing the discriminant with all `u8::MAX`,
150+ /// reallocating down to size.
151151 fn close ( & self , recipient : & impl WritableAccount < ' info > ) -> Result < ( ) >
152152 where
153153 Self : HasOwnerProgram ,
@@ -185,7 +185,7 @@ pub trait CanModifyRent<'info>: SingleAccountSet<'info> {
185185 fn normalize_rent < F : WritableAccount < ' info > + SignedAccount < ' info > > (
186186 & self ,
187187 funder : & F ,
188- system_program : & Program < ' info , SystemProgram > ,
188+ _system_program : & Program < ' info , SystemProgram > ,
189189 syscalls : & impl SyscallInvoke < ' info > ,
190190 ) -> Result < ( ) > {
191191 let rent = syscalls. get_rent ( ) ?;
@@ -199,25 +199,20 @@ pub trait CanModifyRent<'info>: SingleAccountSet<'info> {
199199 return Ok ( ( ) ) ;
200200 }
201201 let transfer_amount = rent_lamports - lamports;
202- if funder. owner ( ) == system_program. key ( ) {
203- let transfer_ix = transfer ( funder. key ( ) , self . key ( ) , transfer_amount) ;
204- let transfer_accounts =
205- & [ self . account_info_cloned ( ) , funder. account_info_cloned ( ) ] ;
206- match funder. signer_seeds ( ) {
207- None => syscalls
208- . invoke ( & transfer_ix, transfer_accounts)
209- . map_err ( Into :: into) ,
210- Some ( seeds) => syscalls
211- . invoke_signed ( & transfer_ix, transfer_accounts, & [ & seeds] )
212- . map_err ( Into :: into) ,
213- }
214- } else {
215- Err ( anyhow ! (
216- "Funder account `{}` is not owned by the system program, owned by `{}`" ,
217- funder. key( ) ,
218- funder. owner( )
219- ) )
220- }
202+ let cpi = SystemProgram :: cpi (
203+ & Transfer {
204+ lamports : transfer_amount,
205+ } ,
206+ TransferCpiAccounts {
207+ funder : funder. account_info_cloned ( ) ,
208+ recipient : self . account_info_cloned ( ) ,
209+ } ,
210+ ) ?;
211+ match funder. signer_seeds ( ) {
212+ None => cpi. invoke ( syscalls) ?,
213+ Some ( seeds) => cpi. invoke_signed ( syscalls, & [ & seeds] ) ?,
214+ } ;
215+ Ok ( ( ) )
221216 }
222217 Ordering :: Less => {
223218 let transfer_amount = lamports - rent_lamports;
0 commit comments