Use Case

A core invariant of lending protocols is that the tokens borrowed are not more than the tokens deposited.

Explanation

Check that the tokens borrowed are not more than the tokens deposited.

Code Example

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import {Assertion} from "../lib/credible-std/Assertion.sol";

interface IMorpho {
    function totalSupplyAsset() external view returns (uint256);

    function totalBorrowedAsset() external view returns (uint256);
}

// Assert that the total supply of assets is greater than or equal to the total borrowed assets
contract TokensBorrowedInvariant is Assertion {
    IMorpho public morpho = IMorpho(address(0xbeef));

    function fnSelectors() external pure override returns (Trigger[] memory) {
        Trigger[] memory triggers = new Trigger[](1); // Define the number of triggers
        triggers[0] = Trigger(TriggerType.STORAGE, this.assertionBorrowedInvariant.selector); // Define the trigger
        return triggers;
    }

    // Check that the total supply of assets is greater than or equal to the total borrowed assets
    // return true indicates a valid state
    // return false indicates an invalid state
    function assertionBorrowedInvariant() external returns (bool) {
        ph.forkPostState();
        uint256 totalSupplyAsset = morpho.totalSupplyAsset();
        uint256 totalBorrowedAsset = morpho.totalBorrowedAsset();
        return totalSupplyAsset >= totalBorrowedAsset;
    }
}