Skip to content
Verified contractExactMIT

LoanVerifier

Address0x768aad15a60c940d03e6ff159c2a22db0471db23
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
Yes, 200 runs
EVM version
osaka
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,372,482
Creation transaction
0xc8d2268959…d75d3e7955

src/LoanVerifier.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ILoanVerifier} from "./interfaces/ILoanVerifier.sol";

/**
 * @title LoanVerifier
 * @notice Stores oracle-attested loan hashes for on-chain verification
 * @dev Backend hashes (borrower, amount, loanId, loanType, originationFeeBps,
 *      exitFeeBps) and the oracle posts the result here. eUSDte checks this
 *      mapping before executing any loan operation. V3 preimage:
 *      keccak256(abi.encode(LOAN_TYPEHASH, borrower, amount, loanId,
 *      uint8(loanType), originationFeeBps, exitFeeBps)), loanType 0 = Fiat,
 *      1 = Onchain. Binding both fee rates into the hash means the oracle signs
 *      the full economics of a protocol loan, exactly as it does for partner
 *      market terms; the owner cannot issue a loan with fees the backend did
 *      not attest. V1/V2 used abi.encodePacked without fees; no attestation of
 *      that form was ever registered on the live deployment, so no migration.
 *
 *      When eUSDte originates a loan it marks the attestation as originated;
 *      an originated attestation can no longer be removed by the oracle, so
 *      settlement of a live loan (repayment, interest, liquidation) can never
 *      be frozen by un-attesting it.
 *
 *      V2 adds a second attestation scheme for PartnerLoanMarket, where the
 *      funder is an independent liquidity provider rather than the protocol.
 *      There the whole {LoanTerms} struct is hashed, so every economic field —
 *      principal, origination fee rate, interest rate, term, exit fee, funding deadline — is
 *      signed by the oracle. Neither the protocol nor the partner can alter a
 *      term of an offer the other one agreed to. The two schemes have separate
 *      originators: eUSDte can only consume legacy attestations and the market
 *      can only consume terms attestations.
 */
contract LoanVerifier is Initializable, Ownable2StepUpgradeable {
    // ============ State ============
    // Storage below is append-only: V2 fields are added after the V1 fields and
    // no existing slot moves, so the live proxy can be upgraded in place.

    /// @notice Oracle EOA that can register/remove loan hashes
    address public oracle;

    /// @notice keccak256(abi.encodePacked(borrower, amount, loanId, uint8(loanType))) => registered
    mapping(bytes32 => bool) public verifiedLoans;

    /// @notice eUSDte contract allowed to mark attestations as originated
    address public originator;

    /// @notice Attestation hashes whose loans have been originated (principal disbursed);
    ///         locked against removal so live-loan settlement cannot be frozen
    mapping(bytes32 => bool) public originatedLoans;

    // ---- V2: partner market ----

    /// @notice PartnerLoanMarket, the only contract allowed to consume terms attestations
    address public termsOriginator;

    /// @notice computeTermsHash(terms) => registered
    mapping(bytes32 => bool) public verifiedTerms;

    /// @notice Terms hashes whose loan has been funded; locked against removal
    mapping(bytes32 => bool) public originatedTerms;

    /// @notice loanId => already funded through the terms path
    /// @dev Two different term sets sharing a loanId hash differently, so without
    ///      this a re-priced offer could be registered and funded a second time
    ///      for one real-world loan
    mapping(bytes32 => bool) public usedLoanIds;

    /// @dev Reserved for future upgrades
    uint256[46] private __gap;

    // ============ Constants ============

    /// @notice Domain tag for the terms hash; documents the exact struct layout
    ///         the backend must encode and prevents collisions with any other
    ///         hashing scheme stored in this contract
    bytes32 public constant TERMS_TYPEHASH =
        keccak256(
            "LoanTerms(address partner,address borrower,uint256 principal,uint256 originationFeeBps,uint256 rateBps,uint256 numberOfPayments,uint256 maturity,uint256 exitFeeBps,uint256 fundingDeadline,bytes32 loanId)"
        );

    /// @notice Domain tag for the V3 loan attestation hash (eUSDte path); documents
    ///         the exact field order the backend must encode
    bytes32 public constant LOAN_TYPEHASH =
        keccak256(
            "Loan(address borrower,uint256 amount,bytes32 loanId,uint8 loanType,uint256 originationFeeBps,uint256 exitFeeBps)"
        );

    // ============ Events ============

    event OracleUpdated(address indexed oldOracle, address indexed newOracle);
    event LoanRegistered(
        bytes32 indexed loanHash,
        address indexed borrower,
        uint256 amount,
        bytes32 indexed loanId,
        ILoanVerifier.LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    );
    event LoanRemoved(bytes32 indexed loanHash);
    event OriginatorUpdated(address indexed oldOriginator, address indexed newOriginator);
    event LoanOriginated(bytes32 indexed loanHash);

    event TermsOriginatorUpdated(address indexed oldOriginator, address indexed newOriginator);
    event TermsRegistered(
        bytes32 indexed termsHash,
        address indexed borrower,
        bytes32 indexed loanId,
        address partner,
        uint256 principal,
        uint256 originationFeeBps,
        uint256 fundingDeadline
    );
    event TermsRemoved(bytes32 indexed termsHash, bytes32 indexed loanId);
    event TermsOriginated(bytes32 indexed termsHash, bytes32 indexed loanId);

    // ============ Errors ============

    error NotOracle();
    error NotOriginator();
    error InvalidAddress();
    error LoanAlreadyRegistered();
    error LoanNotRegistered();
    error LoanAlreadyOriginated();
    error NotTermsOriginator();
    error TermsAlreadyRegistered();
    error TermsNotRegistered();
    error TermsAlreadyOriginated();
    error LoanIdAlreadyUsed();

    // ============ Modifiers ============

    modifier onlyOracle() {
        if (msg.sender != oracle) revert NotOracle();
        _;
    }

    modifier onlyOriginator() {
        if (msg.sender != originator) revert NotOriginator();
        _;
    }

    modifier onlyTermsOriginator() {
        if (msg.sender != termsOriginator) revert NotTermsOriginator();
        _;
    }

    // ============ Initializer ============

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize(address _owner, address _oracle, address _originator) external initializer {
        if (_oracle == address(0)) revert InvalidAddress();
        if (_originator == address(0)) revert InvalidAddress();

        __Ownable_init(_owner);
        __Ownable2Step_init();

        oracle = _oracle;
        originator = _originator;
    }

    // ============ Owner Functions ============

    /// @notice Update the oracle address
    function setOracle(address _oracle) external onlyOwner {
        if (_oracle == address(0)) revert InvalidAddress();
        address old = oracle;
        oracle = _oracle;
        emit OracleUpdated(old, _oracle);
    }

    /// @notice Set the originator (eUSDte) address allowed to lock attestations
    /// @dev Must be configured before eUSDte can originate loans
    function setOriginator(address _originator) external onlyOwner {
        if (_originator == address(0)) revert InvalidAddress();
        address old = originator;
        originator = _originator;
        emit OriginatorUpdated(old, _originator);
    }

    /// @notice Set the PartnerLoanMarket address allowed to consume terms attestations
    /// @dev Must be configured before the market can fund loans
    function setTermsOriginator(address _termsOriginator) external onlyOwner {
        if (_termsOriginator == address(0)) revert InvalidAddress();
        address old = termsOriginator;
        termsOriginator = _termsOriginator;
        emit TermsOriginatorUpdated(old, _termsOriginator);
    }

    // ============ Oracle Functions ============

    /**
     * @notice Register a loan attestation: principal, loan kind and both fee rates
     * @dev Deliberately does not validate the fee rates; eUSDte enforces its caps
     *      at issuance, so the two cannot drift apart
     * @param borrower Recipient of the principal
     * @param amount Principal in USDte (gross, before the origination fee is withheld)
     * @param loanId Unique loan identifier
     * @param loanType Fiat or Onchain
     * @param originationFeeBps Fee withheld from the disbursed principal, bps
     * @param exitFeeBps Closing fee charged on principal repayment, bps
     */
    function registerLoan(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        ILoanVerifier.LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) external onlyOracle {
        bytes32 hash = computeHash(borrower, amount, loanId, loanType, originationFeeBps, exitFeeBps);
        if (verifiedLoans[hash]) revert LoanAlreadyRegistered();
        verifiedLoans[hash] = true;
        emit LoanRegistered(hash, borrower, amount, loanId, loanType, originationFeeBps, exitFeeBps);
    }

    /// @notice Remove a loan attestation
    /// @dev Reverts once the loan has been originated: removing the attestation
    ///      of a live loan would freeze its repayment and liquidation paths
    function removeLoan(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        ILoanVerifier.LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) external onlyOracle {
        bytes32 hash = computeHash(borrower, amount, loanId, loanType, originationFeeBps, exitFeeBps);
        if (!verifiedLoans[hash]) revert LoanNotRegistered();
        if (originatedLoans[hash]) revert LoanAlreadyOriginated();
        verifiedLoans[hash] = false;
        emit LoanRemoved(hash);
    }

    /**
     * @notice Register a full loan offer for the partner market
     * @dev Deliberately does not validate the economics — the market is the
     *      single rule engine for what makes a valid loan, and duplicating those
     *      checks here would let the two drift apart.
     */
    function registerTerms(ILoanVerifier.LoanTerms calldata terms) external onlyOracle {
        bytes32 hash = computeTermsHash(terms);
        if (verifiedTerms[hash]) revert TermsAlreadyRegistered();
        if (usedLoanIds[terms.loanId]) revert LoanIdAlreadyUsed();

        verifiedTerms[hash] = true;

        emit TermsRegistered(
            hash,
            terms.borrower,
            terms.loanId,
            terms.partner,
            terms.principal,
            terms.originationFeeBps,
            terms.fundingDeadline
        );
    }

    /**
     * @notice Withdraw an offer that has not been funded yet
     * @dev Reverts once funded, for the same reason as {removeLoan}
     */
    function removeTerms(ILoanVerifier.LoanTerms calldata terms) external onlyOracle {
        bytes32 hash = computeTermsHash(terms);
        if (!verifiedTerms[hash]) revert TermsNotRegistered();
        if (originatedTerms[hash]) revert TermsAlreadyOriginated();

        verifiedTerms[hash] = false;

        emit TermsRemoved(hash, terms.loanId);
    }

    // ============ Originator Functions ============

    /**
     * @notice Mark a loan attestation as originated, locking it against removal
     * @dev Called by eUSDte at origination, when principal leaves the pool
     */
    function markOriginated(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        ILoanVerifier.LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) external onlyOriginator {
        bytes32 hash = computeHash(borrower, amount, loanId, loanType, originationFeeBps, exitFeeBps);
        if (!verifiedLoans[hash]) revert LoanNotRegistered();
        originatedLoans[hash] = true;
        emit LoanOriginated(hash);
    }

    /**
     * @notice Consume an offer at funding time, locking it against removal
     * @dev Takes the whole struct and hashes it here rather than accepting a
     *      precomputed hash, so the caller cannot claim one loanId while funding
     *      the terms of another. Marks the loanId used: the same loan can never
     *      be funded twice, not even if the oracle re-registered it under
     *      different terms.
     */
    function markTermsOriginated(ILoanVerifier.LoanTerms calldata terms) external onlyTermsOriginator {
        bytes32 hash = computeTermsHash(terms);
        if (!verifiedTerms[hash]) revert TermsNotRegistered();
        if (originatedTerms[hash]) revert TermsAlreadyOriginated();
        if (usedLoanIds[terms.loanId]) revert LoanIdAlreadyUsed();

        originatedTerms[hash] = true;
        usedLoanIds[terms.loanId] = true;

        emit TermsOriginated(hash, terms.loanId);
    }

    // ============ View Functions ============

    /// @notice Check whether a loan attestation with exactly these terms is registered
    function isVerified(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        ILoanVerifier.LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) external view returns (bool) {
        return verifiedLoans[computeHash(borrower, amount, loanId, loanType, originationFeeBps, exitFeeBps)];
    }

    /**
     * @notice Compute the V3 loan attestation hash (same formula the backend must use)
     * @dev abi.encode prefixed with LOAN_TYPEHASH: unambiguous for six fields and
     *      domain-separated from both the V1/V2 packed scheme and the terms scheme
     */
    function computeHash(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        ILoanVerifier.LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) public pure returns (bytes32) {
        return
            keccak256(
                abi.encode(LOAN_TYPEHASH, borrower, amount, loanId, uint8(loanType), originationFeeBps, exitFeeBps)
            );
    }

    /// @notice Check whether a partner-market offer is attested and not yet funded
    function isTermsVerified(ILoanVerifier.LoanTerms calldata terms) external view returns (bool) {
        bytes32 hash = computeTermsHash(terms);
        return verifiedTerms[hash] && !originatedTerms[hash];
    }

    /**
     * @notice Compute the terms hash (same formula the backend must use)
     * @dev abi.encode, not encodePacked: the struct has ten fields and packed
     *      encoding invites ambiguity. Prefixed with TERMS_TYPEHASH so this
     *      preimage can never collide with the legacy computeHash scheme stored
     *      in the same contract.
     */
    function computeTermsHash(ILoanVerifier.LoanTerms calldata terms) public pure returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    TERMS_TYPEHASH,
                    terms.partner,
                    terms.borrower,
                    terms.principal,
                    terms.originationFeeBps,
                    terms.rateBps,
                    terms.numberOfPayments,
                    terms.maturity,
                    terms.exitFeeBps,
                    terms.fundingDeadline,
                    terms.loanId
                )
            );
    }
}

node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

import {OwnableUpgradeable} from "./OwnableUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * This extension of the {Ownable} contract includes a two-step mechanism to transfer
 * ownership, where the new owner must call {acceptOwnership} in order to replace the
 * old one. This can help prevent common mistakes, such as transfers of ownership to
 * incorrect accounts, or to contracts that are unable to interact with the
 * permission system.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable2Step
    struct Ownable2StepStorage {
        address _pendingOwner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable2Step")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant Ownable2StepStorageLocation = 0x237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c00;

    function _getOwnable2StepStorage() private pure returns (Ownable2StepStorage storage $) {
        assembly {
            $.slot := Ownable2StepStorageLocation
        }
    }

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    function __Ownable2Step_init() internal onlyInitializing {
    }

    function __Ownable2Step_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        Ownable2StepStorage storage $ = _getOwnable2StepStorage();
        return $._pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     *
     * Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        Ownable2StepStorage storage $ = _getOwnable2StepStorage();
        $._pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        Ownable2StepStorage storage $ = _getOwnable2StepStorage();
        delete $._pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}

node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable
    struct OwnableStorage {
        address _owner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;

    function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
        assembly {
            $.slot := OwnableStorageLocation
        }
    }

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    function __Ownable_init(address initialOwner) internal onlyInitializing {
        __Ownable_init_unchained(initialOwner);
    }

    function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        OwnableStorage storage $ = _getOwnableStorage();
        return $._owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        OwnableStorage storage $ = _getOwnableStorage();
        address oldOwner = $._owner;
        $._owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reinitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
     *
     * NOTE: Consider following the ERC-7201 formula to derive storage locations.
     */
    function _initializableStorageSlot() internal pure virtual returns (bytes32) {
        return INITIALIZABLE_STORAGE;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        bytes32 slot = _initializableStorageSlot();
        assembly {
            $.slot := slot
        }
    }
}

node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

src/interfaces/ILoanVerifier.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @title ILoanVerifier
 * @notice Interface for the LoanVerifier oracle contract
 * @dev Two attestation schemes live side by side:
 *
 *      1. Loan attestations (V3) — keyed on
 *         keccak256(abi.encode(LOAN_TYPEHASH, borrower, amount, loanId,
 *         uint8(loanType), originationFeeBps, exitFeeBps)).
 *         Used by eUSDte for its own oracle-driven lending. Since V3 the oracle
 *         signs both fee rates together with the principal, so the owner can
 *         only issue the loan with the economics the backend attested.
 *
 *      2. Terms attestations — keyed on the hash of a full {LoanTerms} struct.
 *         Used by PartnerLoanMarket, where the funder is an independent
 *         liquidity provider rather than the protocol, so every economic field
 *         has to be signed by the oracle: neither the protocol nor the partner
 *         may alter a single term of an offer the other one agreed to.
 */
interface ILoanVerifier {
    // ============ Types ============

    /// @notice Loan origination type, bound into the attestation hash so a
    ///         single attestation cannot authorize more than one loan kind
    enum LoanType {
        Fiat,
        Onchain
    }

    /**
     * @notice A complete, oracle-signed loan offer for the partner market
     * @param partner Partner allowed to fund this offer; address(0) means any
     *        whitelisted partner may take it (open market, first funder wins)
     * @param borrower Recipient of the principal
     * @param principal Amount disbursed to the borrower
     * @param originationFeeBps Fee in bps of principal, withheld from the disbursement
     *        and sent to the protocol treasury: the borrower receives principal minus
     *        the fee and owes the full principal. In the partner market the partner
     *        funds exactly the principal; in eUSDte the vault does. The amount is
     *        principal * originationFeeBps / 10000, rounded down. Bps, like
     *        exitFeeBps and like the eUSDte loans, so every loan fee in the
     *        protocol is expressed the same way
     * @param rateBps Annual interest rate in basis points
     * @param numberOfPayments Number of equal interest periods over the term;
     *        maturity must be an exact multiple of it
     * @param maturity Total loan duration in seconds
     * @param exitFeeBps Closing fee in bps of principal, borrower pays the treasury
     * @param fundingDeadline Unix timestamp after which the offer can no longer be funded
     * @param loanId Unique loan identifier; consumed once funded
     */
    struct LoanTerms {
        address partner;
        address borrower;
        uint256 principal;
        uint256 originationFeeBps;
        uint256 rateBps;
        uint256 numberOfPayments;
        uint256 maturity;
        uint256 exitFeeBps;
        uint256 fundingDeadline;
        bytes32 loanId;
    }

    // ============ Events ============

    event OracleUpdated(address indexed oldOracle, address indexed newOracle);
    event LoanRegistered(
        bytes32 indexed loanHash,
        address indexed borrower,
        uint256 amount,
        bytes32 indexed loanId,
        LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    );
    event LoanRemoved(bytes32 indexed loanHash);
    event OriginatorUpdated(address indexed oldOriginator, address indexed newOriginator);
    event LoanOriginated(bytes32 indexed loanHash);

    event TermsOriginatorUpdated(address indexed oldOriginator, address indexed newOriginator);
    event TermsRegistered(
        bytes32 indexed termsHash,
        address indexed borrower,
        bytes32 indexed loanId,
        address partner,
        uint256 principal,
        uint256 originationFeeBps,
        uint256 fundingDeadline
    );
    event TermsRemoved(bytes32 indexed termsHash, bytes32 indexed loanId);
    event TermsOriginated(bytes32 indexed termsHash, bytes32 indexed loanId);

    // ============ Errors ============

    error NotOracle();
    error NotOriginator();
    error InvalidAddress();
    error LoanAlreadyRegistered();
    error LoanNotRegistered();
    error LoanAlreadyOriginated();
    error NotTermsOriginator();
    error TermsAlreadyRegistered();
    error TermsNotRegistered();
    error TermsAlreadyOriginated();
    error LoanIdAlreadyUsed();

    // ============ Functions ============

    function initialize(address _owner, address _oracle, address _originator) external;

    function oracle() external view returns (address);
    function verifiedLoans(bytes32 loanHash) external view returns (bool);
    function originator() external view returns (address);
    function originatedLoans(bytes32 loanHash) external view returns (bool);

    function setOracle(address _oracle) external;
    function setOriginator(address _originator) external;
    function LOAN_TYPEHASH() external view returns (bytes32);

    function registerLoan(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) external;
    function removeLoan(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) external;
    function markOriginated(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) external;

    function isVerified(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) external view returns (bool);
    function computeHash(
        address borrower,
        uint256 amount,
        bytes32 loanId,
        LoanType loanType,
        uint256 originationFeeBps,
        uint256 exitFeeBps
    ) external pure returns (bytes32);

    // ---- Terms attestations (partner market) ----

    function termsOriginator() external view returns (address);
    function verifiedTerms(bytes32 termsHash) external view returns (bool);
    function originatedTerms(bytes32 termsHash) external view returns (bool);
    function usedLoanIds(bytes32 loanId) external view returns (bool);

    function setTermsOriginator(address _termsOriginator) external;

    function registerTerms(LoanTerms calldata terms) external;
    function removeTerms(LoanTerms calldata terms) external;
    function markTermsOriginated(LoanTerms calldata terms) external;

    function isTermsVerified(LoanTerms calldata terms) external view returns (bool);
    function computeTermsHash(LoanTerms calldata terms) external pure returns (bytes32);
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "osaka",
  "remappings": [
    "@openzeppelin/=node_modules/@openzeppelin/",
    "forge-std/=lib/forge-std/src/",
    "hardhat/=node_modules/hardhat/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.