Omniscia Steadefi Audit

LendingPoolConfig Code Style Findings

LendingPoolConfig Code Style Findings

LPC-01C: Ineffectual Usage of Safe Arithmetics

TypeSeverityLocation
Language SpecificLendingPoolConfig.sol:L91

Description:

The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

contracts/lending/LendingPoolConfig.sol
87// If utilization above kink2, return a higher interest rate
88// (base + rate + excess utilization above kink 2 * jumpMultiplier)
89if (utilizationRate > kink2) {
90 return baseRate + (kink1 * multiplier / SAFE_MULTIPLIER)
91 + ((utilizationRate - kink2) * jumpMultiplier / SAFE_MULTIPLIER);
92}

Recommendation:

Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statement to be wrapped in an unchecked code block thereby optimizing its execution cost.

Alleviation (7c9b2b09dbe1f75d8c5ad379e658030ecf1be3a0):

The Steadefi team evaluated this optimization and opted to retain the checked arithmetics in place as in order to apply it the legibility of the calculations would significantly decrease. As such, we consider this exhibit acknowledged and we agree with Steadefi's assessment.

LPC-02C: Redundant Pre-Calculation of Rate

TypeSeverityLocation
Gas OptimizationLendingPoolConfig.sol:L85

Description:

The LendingPoolConfig::_calculateInterestRate function will calculate the default rate prior to evaluating whether the utilization rate falls within the "kinks" of the system that apply special interest rates and thus re-calculate and yield a different rate.

Example:

contracts/lending/LendingPoolConfig.sol
72/**
73 * Return the interest rate based on the utilization rate
74 * @param _debt Total borrowed amount
75 * @param _floating Total available liquidity
76 * @return rate Current interest rate in 1e18
77*/
78function _calculateInterestRate(uint256 _debt, uint256 _floating) internal view returns (uint256) {
79 if (_debt == 0 && _floating == 0) return 0;
80
81 uint256 total = _debt + _floating;
82 uint256 utilizationRate = _debt * SAFE_MULTIPLIER / total;
83
84 // calculate borrow rate for slope up to kink 1
85 uint256 rate = baseRate + (utilizationRate * multiplier / SAFE_MULTIPLIER);
86
87 // If utilization above kink2, return a higher interest rate
88 // (base + rate + excess utilization above kink 2 * jumpMultiplier)
89 if (utilizationRate > kink2) {
90 return baseRate + (kink1 * multiplier / SAFE_MULTIPLIER)
91 + ((utilizationRate - kink2) * jumpMultiplier / SAFE_MULTIPLIER);
92 }
93
94 // If utilization between kink1 and kink2, rates are flat
95 if (kink1 < utilizationRate && utilizationRate < kink2) {
96 return baseRate + (kink1 * multiplier / SAFE_MULTIPLIER);
97 }
98
99 // If utilization below kink1, return rate
100 return rate;
101}

Recommendation:

We advise the rate local variable to be omitted and its calculation to be relocated to the return statement directly, optimizing the function's gas cost.

Alleviation (4325253d6de0ea91c1e9fb9e01d2e7e98f3d83a9):

The calculation was relocated to the return statement as advised, optimizing all invocations of the LendingPoolConfig::_calculateInterestRate function.