@@ -1219,6 +1219,9 @@ impl SurfnetCheatcodes for SurfnetCheatcodesRpc {
12191219 Err ( e) => return e. into ( ) ,
12201220 } ;
12211221
1222+ let is_native_mint = mint == spl_token_interface:: native_mint:: id ( ) ;
1223+ let token_amount = update. amount . unwrap_or ( 0 ) ;
1224+
12221225 let token_program_id = match some_token_program_str {
12231226 Some ( token_program_str) => match verify_pubkey ( & token_program_str) {
12241227 Ok ( res) => res,
@@ -1245,6 +1248,19 @@ impl SurfnetCheatcodes for SurfnetCheatcodesRpc {
12451248 . inner ;
12461249 svm_locker. write_account_update ( get_mint_result) ;
12471250
1251+ let minimum_rent = svm_locker. with_svm_reader ( |svm_reader| {
1252+ svm_reader. inner . minimum_balance_for_rent_exemption (
1253+ TokenAccount :: get_packed_len_for_token_program_id ( & token_program_id) ,
1254+ )
1255+ } ) ;
1256+
1257+ let ( rent_exempt_reserve, initial_lamports) = if is_native_mint {
1258+ // For native mint, we need to allocate enough lamports to cover the wrapped SOL amount
1259+ ( Some ( minimum_rent) , minimum_rent + token_amount) // 1 SOL wrapped
1260+ } else {
1261+ ( None , minimum_rent)
1262+ } ;
1263+
12481264 let SvmAccessContext {
12491265 slot,
12501266 inner : mut token_account,
@@ -1253,21 +1269,14 @@ impl SurfnetCheatcodes for SurfnetCheatcodesRpc {
12531269 . get_account (
12541270 & remote_ctx,
12551271 & associated_token_account,
1256- Some ( Box :: new ( move |svm_locker| {
1257- let minimum_rent = svm_locker. with_svm_reader ( |svm_reader| {
1258- svm_reader. inner . minimum_balance_for_rent_exemption (
1259- TokenAccount :: get_packed_len_for_token_program_id (
1260- & token_program_id,
1261- ) ,
1262- )
1263- } ) ;
1264-
1265- let default = TokenAccount :: new ( & token_program_id, owner, mint) ;
1272+ Some ( Box :: new ( move |_| {
1273+ let default =
1274+ TokenAccount :: new ( & token_program_id, owner, mint, rent_exempt_reserve) ;
12661275 let data = default. pack_into_vec ( ) ;
12671276 GetAccountResult :: FoundAccount (
12681277 associated_token_account,
12691278 Account {
1270- lamports : minimum_rent ,
1279+ lamports : initial_lamports ,
12711280 owner : token_program_id,
12721281 executable : false ,
12731282 rent_epoch : 0 ,
@@ -1288,6 +1297,8 @@ impl SurfnetCheatcodes for SurfnetCheatcodesRpc {
12881297
12891298 let final_account_bytes = token_account_data. pack_into_vec ( ) ;
12901299 token_account. apply_update ( |account| {
1300+ // If this is a native mint, we need to adjust the lamports to match the wrapped SOL amount + rent
1301+ account. lamports = initial_lamports;
12911302 account. data = final_account_bytes. clone ( ) ;
12921303 Ok ( ( ) )
12931304 } ) ?;
0 commit comments