@@ -9,6 +9,8 @@ use error::ErrorCode;
9
9
10
10
declare_id ! ( "GFPM2LncpbWiLkePLs3QjcLVPw31B2h23FwFfhig79fh" ) ;
11
11
12
+ const BASE : f64 = 10.0 ;
13
+
12
14
#[ program]
13
15
pub mod sol_anchor_contract {
14
16
use super :: * ;
@@ -44,12 +46,12 @@ pub mod sol_anchor_contract {
44
46
. checked_mul ( loan_qty)
45
47
. ok_or ( ErrorCode :: Overflow ) ?;
46
48
49
+ // Note : f64 should not be used in smart contracts, but we use it here so it gets displayed nicely in the logs.
47
50
// lets get the maximum loan value based on computation
48
51
// i.e {} * 10^({})
49
52
// loan_max_value * 10^(loan_price.expo)
50
- let base: i32 = 10 ;
51
53
let exponent: i32 = loan_price. expo ;
52
- let result = ( base as f64 ) . powi ( exponent. abs ( ) ) ;
54
+ let result = ( BASE as f64 ) . powi ( exponent. abs ( ) ) ;
53
55
let result = if exponent < 0 { 1.0 / result } else { result } ;
54
56
let result_loan_value = loan_max_value as f64 * result;
55
57
@@ -76,13 +78,13 @@ pub mod sol_anchor_contract {
76
78
. checked_mul ( collateral_qty)
77
79
. ok_or ( ErrorCode :: Overflow ) ?;
78
80
81
+ // Note : f64 should not be used in smart contracts, but we use it here so it gets displayed nicely in the logs.
79
82
// lets get the minimum collateral value based on computation
80
83
// i.e {} * 10^({})
81
84
// i.e collateral_min_value * 10^(collateral_price.expo)
82
- let base: i32 = 10 ;
83
85
let exponent: i32 = collateral_price. expo ;
84
- let result = ( base as f64 ) . powi ( exponent. abs ( ) ) ;
85
- let result = if exponent < 0 { 1.0 / result } else { result } ;
86
+ let result = ( BASE ) . powi ( exponent. abs ( ) ) ;
87
+ let result: f64 = if exponent < 0 { 1.0 / result } else { result } ;
86
88
let result_collateral_value = collateral_min_value as f64 * result;
87
89
88
90
msg ! (
0 commit comments