If not cached, the solidity compiler will always read the length of the array during each iteration. That is, if it is a storage array, this is an extra sload operation (100 additional extra gas for each iteration except for the first) and if it is a memory array, this is an extra mload operation (3 additional gas for each iteration except for the first).
File: src/DSCEngine.sol
26: import {DecentralizedStableCoin} from "./DecentralizedStableCoin.sol";
27: import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
27: import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
27: import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
28: import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
28: import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
28: import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
28: import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
29: import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
29: import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
29: import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
29: import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
29: import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
30: import {OracleLib} from "./libraries/OracleLib.sol";
30: import {OracleLib} from "./libraries/OracleLib.sol";
72: uint256 private constant LIQUIDATION_THRESHOLD = 50;
72: uint256 private constant LIQUIDATION_THRESHOLD = 50;
75: uint256 private constant LIQUIDATION_BONUS = 10;
75: uint256 private constant LIQUIDATION_BONUS = 10;
77: mapping(address token => address priceFeed) private s_priceFeeds;
77: mapping(address token => address priceFeed) private s_priceFeeds;
118: for (uint256 i = 0; i < tokenAddresses.length; i++) {
118: for (uint256 i = 0; i < tokenAddresses.length; i++) {
155: s_collateralDeposited[msg.sender][tokenCollateralAddress] += amountCollateral;
198: s_DSCMinted[msg.sender] += amountDscToMint;
214: _revertIfHealthFactorIsBroken(msg.sender);
214: _revertIfHealthFactorIsBroken(msg.sender);
251: uint256 bonusCollateral = (tokenAmountFromDebtCovered * LIQUIDATION_BONUS) / LIQUIDATION_PRECISION;
251: uint256 bonusCollateral = (tokenAmountFromDebtCovered * LIQUIDATION_BONUS) / LIQUIDATION_PRECISION;
252: uint256 totalCollateralToRedeem = tokenAmountFromDebtCovered + bonusCollateral;
273: s_DSCMinted[onBehalfOf] -= amountDscToBurn;
285: s_collateralDeposited[from][tokenCollateralAddress] -= amountCollateral;
330: uint256 collateralAdjustedForThreshold = (collateralValueInUsd * LIQUIDATION_THRESHOLD) / LIQUIDATION_PRECISION;
330: uint256 collateralAdjustedForThreshold = (collateralValueInUsd * LIQUIDATION_THRESHOLD) / LIQUIDATION_PRECISION;
331: return (collateralAdjustedForThreshold * 1e18) / totalDscMinted;
331: return (collateralAdjustedForThreshold * 1e18) / totalDscMinted;
347: return (usdAmountInWei * PRECISION) / (uint256(price) * ADDITIONAL_FEED_PRECISION);
347: return (usdAmountInWei * PRECISION) / (uint256(price) * ADDITIONAL_FEED_PRECISION);
347: return (usdAmountInWei * PRECISION) / (uint256(price) * ADDITIONAL_FEED_PRECISION);
353: for (uint256 i = 0; i < s_collateralTokens.length; i++) {
353: for (uint256 i = 0; i < s_collateralTokens.length; i++) {
356: totalCollateralValueInUsd += getUsdValue(token, amount);
366: return ((uint256(price) * ADDITIONAL_FEED_PRECISION) * amount) / PRECISION;
366: return ((uint256(price) * ADDITIONAL_FEED_PRECISION) * amount) / PRECISION;
366: return ((uint256(price) * ADDITIONAL_FEED_PRECISION) * amount) / PRECISION;
File: src/DecentralizedStableCoin.sol
26: import {ERC20Burnable, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
26: import {ERC20Burnable, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
26: import {ERC20Burnable, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
26: import {ERC20Burnable, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
26: import {ERC20Burnable, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
27: import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
27: import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
27: import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";