@@ -41,7 +41,7 @@ impl Processor {
41
41
return Err ( TokenError :: AlreadyInUse . into ( ) ) ;
42
42
}
43
43
44
- if mint_info. lamports ( ) < rent . minimum_balance ( mint_info_data_len) {
44
+ if !rent . is_exempt ( mint_info. lamports ( ) , mint_info_data_len) {
45
45
return Err ( TokenError :: NotRentExempt . into ( ) ) ;
46
46
}
47
47
@@ -68,7 +68,7 @@ impl Processor {
68
68
return Err ( TokenError :: AlreadyInUse . into ( ) ) ;
69
69
}
70
70
71
- if new_account_info. lamports ( ) < rent . minimum_balance ( new_account_info_data_len) {
71
+ if !rent . is_exempt ( new_account_info. lamports ( ) , new_account_info_data_len) {
72
72
return Err ( TokenError :: NotRentExempt . into ( ) ) ;
73
73
}
74
74
@@ -80,6 +80,7 @@ impl Processor {
80
80
if * mint_info. key == crate :: native_mint:: id ( ) {
81
81
account. is_native = true ;
82
82
account. amount = new_account_info. lamports ( ) ;
83
+ account. rent_exempt_reserve = rent. minimum_balance ( new_account_info_data_len) ;
83
84
} else {
84
85
account. is_native = false ;
85
86
account. amount = 0 ;
@@ -101,7 +102,7 @@ impl Processor {
101
102
return Err ( TokenError :: AlreadyInUse . into ( ) ) ;
102
103
}
103
104
104
- if multisig_info. lamports ( ) < rent . minimum_balance ( multisig_info_data_len) {
105
+ if !rent . is_exempt ( multisig_info. lamports ( ) , multisig_info_data_len) {
105
106
return Err ( TokenError :: NotRentExempt . into ( ) ) ;
106
107
}
107
108
@@ -183,6 +184,10 @@ impl Processor {
183
184
. ok_or ( TokenError :: Overflow ) ?;
184
185
185
186
if source_account. is_native {
187
+ // Ensure that wrapped SOL accounts remain rent-exempt
188
+ if source_account_info. lamports ( ) < source_account. rent_exempt_reserve + amount {
189
+ return Err ( TokenError :: InsufficientFunds . into ( ) ) ;
190
+ }
186
191
* * source_account_info. lamports . borrow_mut ( ) -= amount;
187
192
* * dest_account_info. lamports . borrow_mut ( ) += amount;
188
193
}
@@ -2827,8 +2832,11 @@ mod tests {
2827
2832
let mut mint_account =
2828
2833
SolanaAccount :: new ( mint_minimum_balance ( ) , size_of :: < Mint > ( ) , & program_id) ;
2829
2834
let account_key = pubkey_rand ( ) ;
2830
- let mut account_account =
2831
- SolanaAccount :: new ( account_minimum_balance ( ) , size_of :: < Account > ( ) , & program_id) ;
2835
+ let mut account_account = SolanaAccount :: new (
2836
+ account_minimum_balance ( ) + 40 ,
2837
+ size_of :: < Account > ( ) ,
2838
+ & program_id,
2839
+ ) ;
2832
2840
let account2_key = pubkey_rand ( ) ;
2833
2841
let mut account2_account =
2834
2842
SolanaAccount :: new ( account_minimum_balance ( ) , size_of :: < Account > ( ) , & program_id) ;
@@ -2857,7 +2865,7 @@ mod tests {
2857
2865
. unwrap ( ) ;
2858
2866
let account: & mut Account = state:: unpack ( & mut account_account. data ) . unwrap ( ) ;
2859
2867
assert ! ( account. is_native) ;
2860
- assert_eq ! ( account. amount, account_minimum_balance( ) ) ;
2868
+ assert_eq ! ( account. amount, account_minimum_balance( ) + 40 ) ;
2861
2869
2862
2870
// initialize native account
2863
2871
do_process_instruction (
@@ -2927,8 +2935,8 @@ mod tests {
2927
2935
2928
2936
let account: & mut Account = state:: unpack ( & mut account_account. data ) . unwrap ( ) ;
2929
2937
assert ! ( account. is_native) ;
2930
- assert_eq ! ( account_account. lamports, account_minimum_balance( ) - 40 ) ;
2931
- assert_eq ! ( account. amount, account_minimum_balance( ) - 40 ) ;
2938
+ assert_eq ! ( account_account. lamports, account_minimum_balance( ) ) ;
2939
+ assert_eq ! ( account. amount, account_minimum_balance( ) ) ;
2932
2940
let account: & mut Account = state:: unpack ( & mut account2_account. data ) . unwrap ( ) ;
2933
2941
assert ! ( account. is_native) ;
2934
2942
assert_eq ! ( account2_account. lamports, account_minimum_balance( ) + 40 ) ;
@@ -2948,10 +2956,7 @@ mod tests {
2948
2956
assert ! ( account. is_native) ;
2949
2957
assert_eq ! ( account_account. lamports, 0 ) ;
2950
2958
assert_eq ! ( account. amount, 0 ) ;
2951
- assert_eq ! (
2952
- account3_account. lamports,
2953
- 2 * account_minimum_balance( ) - 40
2954
- ) ;
2959
+ assert_eq ! ( account3_account. lamports, 2 * account_minimum_balance( ) ) ;
2955
2960
}
2956
2961
2957
2962
#[ test]
0 commit comments