Skip to content

Commit 4591105

Browse files
committed
Add warnign
1 parent e024c96 commit 4591105

File tree

1 file changed

+7
-5
lines changed
  • examples/sol-anchor-contract/programs/sol-anchor-contract/src

1 file changed

+7
-5
lines changed

examples/sol-anchor-contract/programs/sol-anchor-contract/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use error::ErrorCode;
99

1010
declare_id!("GFPM2LncpbWiLkePLs3QjcLVPw31B2h23FwFfhig79fh");
1111

12+
const BASE : f64 = 10.0;
13+
1214
#[program]
1315
pub mod sol_anchor_contract {
1416
use super::*;
@@ -44,12 +46,12 @@ pub mod sol_anchor_contract {
4446
.checked_mul(loan_qty)
4547
.ok_or(ErrorCode::Overflow)?;
4648

49+
// Note : f64 should not be used in smart contracts, but we use it here so it gets displayed nicely in the logs.
4750
// lets get the maximum loan value based on computation
4851
// i.e {} * 10^({})
4952
// loan_max_value * 10^(loan_price.expo)
50-
let base: i32 = 10;
5153
let exponent: i32 = loan_price.expo;
52-
let result = (base as f64).powi(exponent.abs());
54+
let result = (BASE as f64).powi(exponent.abs());
5355
let result = if exponent < 0 { 1.0 / result } else { result };
5456
let result_loan_value = loan_max_value as f64 * result;
5557

@@ -76,13 +78,13 @@ pub mod sol_anchor_contract {
7678
.checked_mul(collateral_qty)
7779
.ok_or(ErrorCode::Overflow)?;
7880

81+
// Note : f64 should not be used in smart contracts, but we use it here so it gets displayed nicely in the logs.
7982
// lets get the minimum collateral value based on computation
8083
// i.e {} * 10^({})
8184
// i.e collateral_min_value * 10^(collateral_price.expo)
82-
let base: i32 = 10;
8385
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 };
8688
let result_collateral_value = collateral_min_value as f64 * result;
8789

8890
msg!(

0 commit comments

Comments
 (0)