Skip to content

Commit

Permalink
feat: optimial_rate range validation (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI authored Sep 19, 2023
1 parent 50c1d62 commit e3e6226
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/irms/default_interest_rate_model.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
mod errors {
const INVALID_OPTIMAL_RATE: felt252 = 'DIRM_INVALID_OPTIMAL_RATE';
}

// TODO: manually create copies of this contract with hard-coded values instead of using storage
#[starknet::contract]
mod DefaultInterestRateModel {
Expand All @@ -9,6 +13,8 @@ mod DefaultInterestRateModel {
use crate::interfaces::{IInterestRateModel, ModelRates};
use crate::libraries::{safe_decimal_math, safe_math};

use super::errors;

#[storage]
struct Storage {
curve_params: CurveParams
Expand All @@ -30,7 +36,11 @@ mod DefaultInterestRateModel {
y_intercept: felt252,
optimal_rate: felt252
) {
// TODO: check `optimal_rate` range
assert(
Into::<_, u256>::into(optimal_rate) <= Into::<_, u256>::into(safe_decimal_math::SCALE),
errors::INVALID_OPTIMAL_RATE
);

self.curve_params.write(CurveParams { slope_0, slope_1, y_intercept, optimal_rate });
}

Expand Down

0 comments on commit e3e6226

Please sign in to comment.