From e3e62264adc02b2667b167e8b6b699c1c5afdd53 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Tue, 19 Sep 2023 11:21:31 -0600 Subject: [PATCH] feat: `optimial_rate` range validation (#60) --- src/irms/default_interest_rate_model.cairo | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/irms/default_interest_rate_model.cairo b/src/irms/default_interest_rate_model.cairo index c59ea1e..b4848dc 100644 --- a/src/irms/default_interest_rate_model.cairo +++ b/src/irms/default_interest_rate_model.cairo @@ -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 { @@ -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 @@ -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 }); }