{"constructor_args":"0x0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e","is_partially_verified":true,"is_changed_bytecode":false,"abi":[{"inputs":[{"internalType":"address","name":"_protocolConfig","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadySet","type":"error"},{"inputs":[],"name":"BelowMinimumBorrow","type":"error"},{"inputs":[],"name":"CannotCloseFutureCycle","type":"error"},{"inputs":[],"name":"DebtCapExceeded","type":"error"},{"inputs":[],"name":"InconsistentInput","type":"error"},{"inputs":[],"name":"InsufficientBorrowAmount","type":"error"},{"inputs":[],"name":"InsufficientCollateral","type":"error"},{"inputs":[],"name":"InsufficientLiquidity","type":"error"},{"inputs":[],"name":"InvalidCycleDuration","type":"error"},{"inputs":[],"name":"InvalidCycleId","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"IrmNotEnabled","type":"error"},{"inputs":[],"name":"LltvNotEnabled","type":"error"},{"inputs":[],"name":"MarketAlreadyCreated","type":"error"},{"inputs":[],"name":"MarketFrozen","type":"error"},{"inputs":[],"name":"MarketNotCreated","type":"error"},{"inputs":[],"name":"MaxFeeExceeded","type":"error"},{"inputs":[],"name":"MaxLltvExceeded","type":"error"},{"inputs":[],"name":"MaxUint128Exceeded","type":"error"},{"inputs":[],"name":"MustPayFullObligation","type":"error"},{"inputs":[],"name":"NoCode","type":"error"},{"inputs":[],"name":"NoCyclesExist","type":"error"},{"inputs":[],"name":"NotCreditLine","type":"error"},{"inputs":[],"name":"NotHelper","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"NotUsd3","type":"error"},{"inputs":[],"name":"OutstandingRepayment","type":"error"},{"inputs":[],"name":"Paused","type":"error"},{"inputs":[],"name":"RepaymentExceedsHundredPercent","type":"error"},{"inputs":[],"name":"TransferFromReturnedFalse","type":"error"},{"inputs":[],"name":"TransferFromReverted","type":"error"},{"inputs":[],"name":"TransferReturnedFalse","type":"error"},{"inputs":[],"name":"TransferReverted","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"settler","type":"address"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"writtenOffAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"writtenOffShares","type":"uint256"}],"name":"AccountSettled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"prevBorrowRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"interest","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeShares","type":"uint256"}],"name":"AccrueInterest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"onBehalf","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Borrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldMarkdown","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newMarkdown","type":"uint256"}],"name":"BorrowerMarkdownUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint128","name":"oldRate","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"newRate","type":"uint128"}],"name":"BorrowerPremiumRateSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"indexed":false,"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"name":"CreateMarket","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"}],"name":"DefaultCleared","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"DefaultStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"irm","type":"address"}],"name":"EnableIrm","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"lltv","type":"uint256"}],"name":"EnableLltv","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"cycleId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startDate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endDate","type":"uint256"}],"name":"PaymentCycleCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"premiumAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"}],"name":"PremiumAccrued","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"onBehalf","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Repay","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cycleId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endingBalance","type":"uint256"}],"name":"RepaymentObligationPosted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"payment","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"remainingDue","type":"uint256"}],"name":"RepaymentTracked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"credit","type":"uint256"}],"name":"SetCreditLine","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"SetFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"SetFeeRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"SetOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"onBehalf","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Supply","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"onBehalf","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"name":"accrueInterest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"address[]","name":"borrowers","type":"address[]"}],"name":"accruePremiumsForBorrowers","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"address[]","name":"borrowers","type":"address[]"},{"internalType":"uint256[]","name":"repaymentBps","type":"uint256[]"},{"internalType":"uint256[]","name":"endingBalances","type":"uint256[]"}],"name":"addObligationsToLatestCycle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"onBehalf","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"name":"borrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"}],"name":"borrowerPremium","outputs":[{"internalType":"uint128","name":"lastAccrualTime","type":"uint128"},{"internalType":"uint128","name":"rate","type":"uint128"},{"internalType":"uint128","name":"borrowAssetsAtLastAccrual","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"endDate","type":"uint256"},{"internalType":"address[]","name":"borrowers","type":"address[]"},{"internalType":"uint256[]","name":"repaymentBps","type":"uint256[]"},{"internalType":"uint256[]","name":"endingBalances","type":"uint256[]"}],"name":"closeCycleAndPostObligations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"name":"createMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"irm","type":"address"}],"name":"enableIrm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lltv","type":"uint256"}],"name":"enableLltv","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"slots","type":"bytes32[]"}],"name":"extSloads","outputs":[{"internalType":"bytes32[]","name":"res","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"helper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"","type":"bytes32"}],"name":"idToMarketParams","outputs":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isIrmEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"isLltvEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"}],"name":"markdownState","outputs":[{"internalType":"uint128","name":"lastCalculatedMarkdown","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"","type":"bytes32"}],"name":"market","outputs":[{"internalType":"uint128","name":"totalSupplyAssets","type":"uint128"},{"internalType":"uint128","name":"totalSupplyShares","type":"uint128"},{"internalType":"uint128","name":"totalBorrowAssets","type":"uint128"},{"internalType":"uint128","name":"totalBorrowShares","type":"uint128"},{"internalType":"uint128","name":"lastUpdate","type":"uint128"},{"internalType":"uint128","name":"fee","type":"uint128"},{"internalType":"uint128","name":"totalMarkdownAmount","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"","type":"bytes32"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"paymentCycle","outputs":[{"internalType":"uint256","name":"endDate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"}],"name":"position","outputs":[{"internalType":"uint256","name":"supplyShares","type":"uint256"},{"internalType":"uint128","name":"borrowShares","type":"uint128"},{"internalType":"uint128","name":"collateral","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolConfig","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"onBehalf","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"repay","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"}],"name":"repaymentObligation","outputs":[{"internalType":"uint128","name":"paymentCycleId","type":"uint128"},{"internalType":"uint128","name":"amountDue","type":"uint128"},{"internalType":"uint128","name":"endingBalance","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"credit","type":"uint256"},{"internalType":"uint128","name":"premiumRate","type":"uint128"}],"name":"setCreditLine","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"setFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newHelper","type":"address"}],"name":"setHelper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newUsd3","type":"address"}],"name":"setUsd3","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"address","name":"borrower","type":"address"}],"name":"settleAccount","outputs":[{"internalType":"uint256","name":"writtenOffAssets","type":"uint256"},{"internalType":"uint256","name":"writtenOffShares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"onBehalf","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"supply","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"usd3","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"},{"internalType":"address","name":"creditLine","type":"address"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"onBehalf","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}],"conflicting_implementations":null,"certified":false,"additional_sources":[{"file_path":"lib/openzeppelin/contracts/proxy/utils/Initializable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Storage of the initializable contract.\n     *\n     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions\n     * when using with upgradeable contracts.\n     *\n     * @custom:storage-location erc7201:openzeppelin.storage.Initializable\n     */\n    struct InitializableStorage {\n        /**\n         * @dev Indicates that the contract has been initialized.\n         */\n        uint64 _initialized;\n        /**\n         * @dev Indicates that the contract is in the process of being initialized.\n         */\n        bool _initializing;\n    }\n\n    // keccak256(abi.encode(uint256(keccak256(\"openzeppelin.storage.Initializable\")) - 1)) & ~bytes32(uint256(0xff))\n    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;\n\n    /**\n     * @dev The contract is already initialized.\n     */\n    error InvalidInitialization();\n\n    /**\n     * @dev The contract is not initializing.\n     */\n    error NotInitializing();\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint64 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any\n     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in\n     * production.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        // solhint-disable-next-line var-name-mixedcase\n        InitializableStorage storage $ = _getInitializableStorage();\n\n        // Cache values to avoid duplicated sloads\n        bool isTopLevelCall = !$._initializing;\n        uint64 initialized = $._initialized;\n\n        // Allowed calls:\n        // - initialSetup: the contract is not in the initializing state and no previous version was\n        //                 initialized\n        // - construction: the contract is initialized at version 1 (no reinitialization) and the\n        //                 current contract is just being deployed\n        bool initialSetup = initialized == 0 && isTopLevelCall;\n        bool construction = initialized == 1 && address(this).code.length == 0;\n\n        if (!initialSetup && !construction) {\n            revert InvalidInitialization();\n        }\n        $._initialized = 1;\n        if (isTopLevelCall) {\n            $._initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            $._initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint64 version) {\n        // solhint-disable-next-line var-name-mixedcase\n        InitializableStorage storage $ = _getInitializableStorage();\n\n        if ($._initializing || $._initialized >= version) {\n            revert InvalidInitialization();\n        }\n        $._initialized = version;\n        $._initializing = true;\n        _;\n        $._initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        _checkInitializing();\n        _;\n    }\n\n    /**\n     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.\n     */\n    function _checkInitializing() internal view virtual {\n        if (!_isInitializing()) {\n            revert NotInitializing();\n        }\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        // solhint-disable-next-line var-name-mixedcase\n        InitializableStorage storage $ = _getInitializableStorage();\n\n        if ($._initializing) {\n            revert InvalidInitialization();\n        }\n        if ($._initialized != type(uint64).max) {\n            $._initialized = type(uint64).max;\n            emit Initialized(type(uint64).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint64) {\n        return _getInitializableStorage()._initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _getInitializableStorage()._initializing;\n    }\n\n    /**\n     * @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.\n     *\n     * NOTE: Consider following the ERC-7201 formula to derive storage locations.\n     */\n    function _initializableStorageSlot() internal pure virtual returns (bytes32) {\n        return INITIALIZABLE_STORAGE;\n    }\n\n    /**\n     * @dev Returns a pointer to the storage namespace.\n     */\n    // solhint-disable-next-line var-name-mixedcase\n    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {\n        bytes32 slot = _initializableStorageSlot();\n        assembly {\n            $.slot := slot\n        }\n    }\n}\n"},{"file_path":"src/Morpho.sol","source_code":"// SPDX-License-Identifier: BUSL-1.1\npragma solidity 0.8.22;\n\nimport {\n    Id,\n    IMorphoStaticTyping,\n    IMorphoBase,\n    MarketParams,\n    Position,\n    Market,\n    Authorization,\n    Signature\n} from \"./interfaces/IMorpho.sol\";\nimport {IMorphoRepayCallback, IMorphoSupplyCallback} from \"./interfaces/IMorphoCallbacks.sol\";\nimport {IIrm} from \"./interfaces/IIrm.sol\";\nimport {IERC20} from \"./interfaces/IERC20.sol\";\nimport {IOracle} from \"./interfaces/IOracle.sol\";\n\nimport \"./libraries/ConstantsLib.sol\";\nimport {UtilsLib} from \"./libraries/UtilsLib.sol\";\nimport {EventsLib} from \"./libraries/EventsLib.sol\";\nimport {ErrorsLib} from \"./libraries/ErrorsLib.sol\";\nimport {MathLib, WAD} from \"./libraries/MathLib.sol\";\nimport {SharesMathLib} from \"./libraries/SharesMathLib.sol\";\nimport {MarketParamsLib} from \"./libraries/MarketParamsLib.sol\";\nimport {SafeTransferLib} from \"./libraries/SafeTransferLib.sol\";\nimport {Initializable} from \"../lib/openzeppelin/contracts/proxy/utils/Initializable.sol\";\n\n/// @title Morpho\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice The Morpho contract.\nabstract contract Morpho is IMorphoStaticTyping, Initializable {\n    using MathLib for uint128;\n    using MathLib for uint256;\n    using UtilsLib for uint256;\n    using SharesMathLib for uint256;\n    using SafeTransferLib for IERC20;\n    using MarketParamsLib for MarketParams;\n\n    /* STORAGE */\n\n    /// @inheritdoc IMorphoBase\n    address public owner;\n    /// @inheritdoc IMorphoBase\n    address public feeRecipient;\n    /// @inheritdoc IMorphoStaticTyping\n    mapping(Id => mapping(address => Position)) public position;\n    /// @inheritdoc IMorphoStaticTyping\n    mapping(Id => Market) public market;\n    /// @inheritdoc IMorphoBase\n    mapping(address => bool) public isIrmEnabled;\n    /// @inheritdoc IMorphoBase\n    mapping(uint256 => bool) public isLltvEnabled;\n    /// @inheritdoc IMorphoBase\n    mapping(address => uint256) public nonce;\n    /// @inheritdoc IMorphoStaticTyping\n    mapping(Id => MarketParams) public idToMarketParams;\n    /// @inheritdoc IMorphoBase\n    bytes32 public DOMAIN_SEPARATOR;\n    /// @dev Storage gap for future upgrades (10 slots).\n    uint256[10] private __gap;\n\n    /* INITIALIZER */\n\n    /// @custom:oz-upgrades-unsafe-allow constructor\n    constructor() {\n        _disableInitializers();\n    }\n\n    /// @param newOwner The initial owner of the contract.\n    function __Morpho_init(address newOwner) internal onlyInitializing {\n        if (newOwner == address(0)) revert ErrorsLib.ZeroAddress();\n\n        DOMAIN_SEPARATOR = keccak256(abi.encode(DOMAIN_TYPEHASH, block.chainid, address(this)));\n        owner = newOwner;\n\n        emit EventsLib.SetOwner(newOwner);\n    }\n\n    /* MODIFIERS */\n\n    /// @dev Reverts if the caller is not the owner.\n    modifier onlyOwner() {\n        requireOwner();\n        _;\n    }\n\n    function requireOwner() internal {\n        if (msg.sender != owner) revert ErrorsLib.NotOwner();\n    }\n\n    /* ONLY OWNER FUNCTIONS */\n\n    /// @inheritdoc IMorphoBase\n    function setOwner(address newOwner) external onlyOwner {\n        if (newOwner == owner) revert ErrorsLib.AlreadySet();\n\n        owner = newOwner;\n\n        emit EventsLib.SetOwner(newOwner);\n    }\n\n    /// @inheritdoc IMorphoBase\n    function enableIrm(address irm) external onlyOwner {\n        if (isIrmEnabled[irm]) revert ErrorsLib.AlreadySet();\n\n        isIrmEnabled[irm] = true;\n\n        emit EventsLib.EnableIrm(irm);\n    }\n\n    /// @inheritdoc IMorphoBase\n    function enableLltv(uint256 lltv) external onlyOwner {\n        if (isLltvEnabled[lltv]) revert ErrorsLib.AlreadySet();\n        if (lltv >= WAD) revert ErrorsLib.MaxLltvExceeded();\n\n        isLltvEnabled[lltv] = true;\n\n        emit EventsLib.EnableLltv(lltv);\n    }\n\n    /// @inheritdoc IMorphoBase\n    function setFee(MarketParams memory marketParams, uint256 newFee) external onlyOwner {\n        Id id = marketParams.id();\n        if (market[id].lastUpdate == 0) revert ErrorsLib.MarketNotCreated();\n        if (newFee == market[id].fee) revert ErrorsLib.AlreadySet();\n        if (newFee > MAX_FEE) revert ErrorsLib.MaxFeeExceeded();\n\n        // Accrue interest using the previous fee set before changing it.\n        _accrueInterest(marketParams, id);\n\n        // Safe \"unchecked\" cast.\n        market[id].fee = uint128(newFee);\n\n        emit EventsLib.SetFee(id, newFee);\n    }\n\n    /// @inheritdoc IMorphoBase\n    function setFeeRecipient(address newFeeRecipient) external onlyOwner {\n        if (newFeeRecipient == feeRecipient) revert ErrorsLib.AlreadySet();\n\n        feeRecipient = newFeeRecipient;\n\n        emit EventsLib.SetFeeRecipient(newFeeRecipient);\n    }\n\n    /* MARKET CREATION */\n\n    /// @inheritdoc IMorphoBase\n    function createMarket(MarketParams memory marketParams) external onlyOwner {\n        Id id = marketParams.id();\n        if (!isIrmEnabled[marketParams.irm]) revert ErrorsLib.IrmNotEnabled();\n        if (!isLltvEnabled[marketParams.lltv]) revert ErrorsLib.LltvNotEnabled();\n        if (market[id].lastUpdate != 0) revert ErrorsLib.MarketAlreadyCreated();\n\n        // Safe \"unchecked\" cast.\n        market[id].lastUpdate = uint128(block.timestamp);\n        idToMarketParams[id] = marketParams;\n\n        emit EventsLib.CreateMarket(id, marketParams);\n\n        if (marketParams.irm != address(0)) IIrm(marketParams.irm).borrowRate(marketParams, market[id]);\n    }\n\n    /* SUPPLY MANAGEMENT */\n\n    /// @inheritdoc IMorphoBase\n    function supply(\n        MarketParams memory marketParams,\n        uint256 assets,\n        uint256 shares,\n        address onBehalf,\n        bytes calldata data\n    ) external returns (uint256, uint256) {\n        Id id = marketParams.id();\n        if (market[id].lastUpdate == 0) revert ErrorsLib.MarketNotCreated();\n        if (!UtilsLib.exactlyOneZero(assets, shares)) revert ErrorsLib.InconsistentInput();\n        if (onBehalf == address(0)) revert ErrorsLib.ZeroAddress();\n\n        _accrueInterest(marketParams, id);\n\n        if (assets > 0) shares = assets.toSharesDown(market[id].totalSupplyAssets, market[id].totalSupplyShares);\n        else assets = shares.toAssetsUp(market[id].totalSupplyAssets, market[id].totalSupplyShares);\n\n        _beforeSupply(marketParams, id, onBehalf, assets, shares, data);\n\n        position[id][onBehalf].supplyShares += shares;\n        market[id].totalSupplyShares += shares.toUint128();\n        market[id].totalSupplyAssets += assets.toUint128();\n\n        emit EventsLib.Supply(id, msg.sender, onBehalf, assets, shares);\n\n        if (data.length > 0) IMorphoSupplyCallback(msg.sender).onMorphoSupply(assets, data);\n\n        IERC20(marketParams.loanToken).safeTransferFrom(msg.sender, address(this), assets);\n\n        return (assets, shares);\n    }\n\n    /// @inheritdoc IMorphoBase\n    function withdraw(\n        MarketParams memory marketParams,\n        uint256 assets,\n        uint256 shares,\n        address onBehalf,\n        address receiver\n    ) external returns (uint256, uint256) {\n        Id id = marketParams.id();\n        if (market[id].lastUpdate == 0) revert ErrorsLib.MarketNotCreated();\n        if (!UtilsLib.exactlyOneZero(assets, shares)) revert ErrorsLib.InconsistentInput();\n        if (receiver == address(0)) revert ErrorsLib.ZeroAddress();\n\n        _accrueInterest(marketParams, id);\n\n        if (assets > 0) shares = assets.toSharesUp(market[id].totalSupplyAssets, market[id].totalSupplyShares);\n        else assets = shares.toAssetsDown(market[id].totalSupplyAssets, market[id].totalSupplyShares);\n\n        _beforeWithdraw(marketParams, id, onBehalf, assets, shares);\n\n        position[id][onBehalf].supplyShares -= shares;\n        market[id].totalSupplyShares -= shares.toUint128();\n        market[id].totalSupplyAssets -= assets.toUint128();\n\n        if (market[id].totalBorrowAssets > market[id].totalSupplyAssets) revert ErrorsLib.InsufficientLiquidity();\n\n        emit EventsLib.Withdraw(id, msg.sender, onBehalf, receiver, assets, shares);\n\n        IERC20(marketParams.loanToken).safeTransfer(receiver, assets);\n\n        return (assets, shares);\n    }\n\n    /* BORROW MANAGEMENT */\n\n    /// @inheritdoc IMorphoBase\n    function borrow(\n        MarketParams memory marketParams,\n        uint256 assets,\n        uint256 shares,\n        address onBehalf,\n        address receiver\n    ) external returns (uint256, uint256) {\n        Id id = marketParams.id();\n        if (market[id].lastUpdate == 0) revert ErrorsLib.MarketNotCreated();\n        if (!UtilsLib.exactlyOneZero(assets, shares)) revert ErrorsLib.InconsistentInput();\n        if (receiver == address(0)) revert ErrorsLib.ZeroAddress();\n\n        _accrueInterest(marketParams, id);\n\n        if (assets > 0) shares = assets.toSharesUp(market[id].totalBorrowAssets, market[id].totalBorrowShares);\n        else assets = shares.toAssetsDown(market[id].totalBorrowAssets, market[id].totalBorrowShares);\n\n        _beforeBorrow(marketParams, id, onBehalf, assets, shares);\n\n        if (assets == 0 && shares > 0) revert ErrorsLib.InsufficientBorrowAmount();\n\n        position[id][onBehalf].borrowShares += shares.toUint128();\n        market[id].totalBorrowShares += shares.toUint128();\n        market[id].totalBorrowAssets += assets.toUint128();\n\n        if (!_isHealthy(marketParams, id, onBehalf)) revert ErrorsLib.InsufficientCollateral();\n        if (market[id].totalBorrowAssets > market[id].totalSupplyAssets) revert ErrorsLib.InsufficientLiquidity();\n\n        emit EventsLib.Borrow(id, msg.sender, onBehalf, receiver, assets, shares);\n\n        _afterBorrow(marketParams, id, onBehalf);\n\n        IERC20(marketParams.loanToken).safeTransfer(receiver, assets);\n\n        return (assets, shares);\n    }\n\n    /// @inheritdoc IMorphoBase\n    function repay(\n        MarketParams memory marketParams,\n        uint256 assets,\n        uint256 shares,\n        address onBehalf,\n        bytes calldata data\n    ) external returns (uint256, uint256) {\n        Id id = marketParams.id();\n        if (market[id].lastUpdate == 0) revert ErrorsLib.MarketNotCreated();\n        if (!UtilsLib.exactlyOneZero(assets, shares)) revert ErrorsLib.InconsistentInput();\n        if (onBehalf == address(0)) revert ErrorsLib.ZeroAddress();\n\n        _accrueInterest(marketParams, id);\n\n        if (assets > 0) shares = assets.toSharesDown(market[id].totalBorrowAssets, market[id].totalBorrowShares);\n        else assets = shares.toAssetsUp(market[id].totalBorrowAssets, market[id].totalBorrowShares);\n\n        _beforeRepay(marketParams, id, onBehalf, assets, shares);\n\n        position[id][onBehalf].borrowShares -= shares.toUint128();\n        market[id].totalBorrowShares -= shares.toUint128();\n        market[id].totalBorrowAssets = UtilsLib.zeroFloorSub(market[id].totalBorrowAssets, assets).toUint128();\n\n        // `assets` may be greater than `totalBorrowAssets` by 1.\n        emit EventsLib.Repay(id, msg.sender, onBehalf, assets, shares);\n\n        _afterRepay(marketParams, id, onBehalf, assets);\n\n        if (data.length > 0) IMorphoRepayCallback(msg.sender).onMorphoRepay(assets, data);\n\n        IERC20(marketParams.loanToken).safeTransferFrom(msg.sender, address(this), assets);\n\n        return (assets, shares);\n    }\n\n    /* LIQUIDATION - REMOVED */\n\n    // Liquidation logic has been removed in favor of the markdown system.\n    // The markdown system replaces traditional liquidations with dynamic debt write-offs\n    // managed by an external markdown manager contract.\n\n    /* FLASH LOANS - REMOVED */\n\n    // Flash loan logic has been removed in favor of multi-block unsecured loans.\n\n    /* AUTHORIZATION - REMOVED */\n\n    // Authorization logic has been removed.\n    // All borrows will be executed via a wrapper helper which performs fraud checks.\n    // All withdraws will be executed by a single yield-bearing dollar contract.\n\n    /* INTEREST MANAGEMENT */\n\n    /// @inheritdoc IMorphoBase\n    function accrueInterest(MarketParams memory marketParams) external {\n        Id id = marketParams.id();\n        if (market[id].lastUpdate == 0) revert ErrorsLib.MarketNotCreated();\n\n        _accrueInterest(marketParams, id);\n    }\n\n    /// @dev Accrues interest for the given market `marketParams`.\n    /// @dev Assumes that the inputs `marketParams` and `id` match.\n    function _accrueInterest(MarketParams memory marketParams, Id id) internal {\n        uint256 elapsed = block.timestamp - market[id].lastUpdate;\n        if (elapsed == 0) return;\n\n        if (marketParams.irm != address(0)) {\n            uint256 borrowRate = IIrm(marketParams.irm).borrowRate(marketParams, market[id]);\n            uint256 interest = market[id].totalBorrowAssets.wMulDown(borrowRate.wTaylorCompounded(elapsed));\n            market[id].totalBorrowAssets += interest.toUint128();\n            market[id].totalSupplyAssets += interest.toUint128();\n\n            uint256 feeShares;\n            if (market[id].fee != 0) {\n                uint256 feeAmount = interest.wMulDown(market[id].fee);\n                // The fee amount is subtracted from the total supply in this calculation to compensate for the fact\n                // that total supply is already increased by the full interest (including the fee amount).\n                feeShares =\n                    feeAmount.toSharesDown(market[id].totalSupplyAssets - feeAmount, market[id].totalSupplyShares);\n                position[id][feeRecipient].supplyShares += feeShares;\n                market[id].totalSupplyShares += feeShares.toUint128();\n            }\n\n            emit EventsLib.AccrueInterest(id, borrowRate, interest, feeShares);\n        }\n\n        // Safe \"unchecked\" cast.\n        market[id].lastUpdate = uint128(block.timestamp);\n    }\n\n    /* HEALTH CHECK */\n\n    /// @dev Returns whether the position of `borrower` in the given market `marketParams` is healthy.\n    /// @dev Assumes that the inputs `marketParams` and `id` match.\n    function _isHealthy(MarketParams memory marketParams, Id id, address borrower)\n        internal\n        view\n        virtual\n        returns (bool)\n    {\n        if (position[id][borrower].borrowShares == 0) return true;\n\n        uint256 collateralPrice = IOracle(marketParams.oracle).price();\n\n        return _isHealthy(marketParams, id, borrower, collateralPrice);\n    }\n\n    /// @dev Returns whether the position of `borrower` in the given market `marketParams` with the given\n    /// `collateralPrice` is healthy.\n    /// @dev Assumes that the inputs `marketParams` and `id` match.\n    /// @dev Rounds in favor of the protocol, so one might not be able to borrow exactly `maxBorrow` but one unit less.\n    function _isHealthy(MarketParams memory marketParams, Id id, address borrower, uint256 collateralPrice)\n        internal\n        view\n        virtual\n        returns (bool)\n    {\n        uint256 borrowed = uint256(position[id][borrower].borrowShares)\n            .toAssetsUp(market[id].totalBorrowAssets, market[id].totalBorrowShares);\n        uint256 maxBorrow = uint256(position[id][borrower].collateral).mulDivDown(collateralPrice, ORACLE_PRICE_SCALE)\n            .wMulDown(marketParams.lltv);\n\n        return maxBorrow >= borrowed;\n    }\n\n    /* HOOKS */\n\n    /// @dev Hook called before supply operations to allow for particular pre-processing.\n    /// @param marketParams The market parameters.\n    /// @param id The market id.\n    /// @param onBehalf The address that will receive the debt.\n    /// @param assets The amount of assets to borrow.\n    /// @param shares The amount of shares to borrow.\n    /// @param data Additional data to pass to the callback.\n    function _beforeSupply(\n        MarketParams memory marketParams,\n        Id id,\n        address onBehalf,\n        uint256 assets,\n        uint256 shares,\n        bytes calldata data\n    ) internal virtual {}\n\n    /// @dev Hook called before withdraw operations to allow for particular pre-processing.\n    /// @param marketParams The market parameters.\n    /// @param id The market id.\n    /// @param onBehalf The address that will receive the debt.\n    /// @param assets The amount of assets to borrow.\n    /// @param shares The amount of shares to borrow.\n    function _beforeWithdraw(MarketParams memory marketParams, Id id, address onBehalf, uint256 assets, uint256 shares)\n        internal\n        virtual {}\n\n    /// @dev Hook called before borrow operations to allow for premium accrual or other pre-processing.\n    /// @param marketParams The market parameters.\n    /// @param id The market id.\n    /// @param onBehalf The address that will receive the debt.\n    /// @param assets The amount of assets to borrow.\n    /// @param shares The amount of shares to borrow.\n    function _beforeBorrow(MarketParams memory marketParams, Id id, address onBehalf, uint256 assets, uint256 shares)\n        internal\n        virtual {}\n\n    /// @dev Hook called before repay operations to allow for premium accrual or other pre-processing.\n    /// @param marketParams The market parameters.\n    /// @param id The market id.\n    /// @param onBehalf The address whose debt is being repaid.\n    /// @param assets The amount of assets to repay.\n    /// @param shares The amount of shares to repay.\n    function _beforeRepay(MarketParams memory marketParams, Id id, address onBehalf, uint256 assets, uint256 shares)\n        internal\n        virtual {}\n\n    /// @dev Hook called after borrow operations to allow for post-processing.\n    /// @param marketParams The market parameters.\n    /// @param id The market id.\n    /// @param onBehalf The address that borrowed.\n    function _afterBorrow(MarketParams memory marketParams, Id id, address onBehalf) internal virtual {}\n\n    /// @dev Hook called after repay operations to allow for post-processing.\n    /// @param marketParams The market parameters.\n    /// @param id The market id.\n    /// @param onBehalf The address whose debt was repaid.\n    /// @param assets The amount of assets repaid.\n    function _afterRepay(MarketParams memory marketParams, Id id, address onBehalf, uint256 assets) internal virtual {}\n\n    /* STORAGE VIEW */\n\n    /// @inheritdoc IMorphoBase\n    function extSloads(bytes32[] calldata slots) external view returns (bytes32[] memory res) {\n        uint256 nSlots = slots.length;\n\n        res = new bytes32[](nSlots);\n\n        for (uint256 i; i < nSlots;) {\n            bytes32 slot = slots[i++];\n\n            assembly (\"memory-safe\") {\n                mstore(add(res, mul(i, 32)), sload(slot))\n            }\n        }\n    }\n}\n"},{"file_path":"src/interfaces/ICreditLine.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport {Id} from \"./IMorpho.sol\";\n\n/// @title ICreditLine\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Interface that credit line used by Morpho must implement.\n/// @dev It is the user's responsibility to select markets with safe credit line.\ninterface ICreditLine {\n    /// @notice The defender\n    function ozd() external view returns (address);\n\n    /// @notice The zktls prover\n    function prover() external view returns (address);\n\n    /// @notice The morpho contract.\n    function MORPHO() external view returns (address);\n\n    /// @notice The markdown manager\n    function mm() external view returns (address);\n\n    /// @notice Sets `newOzd` as `ozd` of the contract.\n    /// @dev Warning: No two-step transfer ownership.\n    /// @dev Warning: The ozd can be set to the zero address.\n    function setOzd(address newOzd) external;\n\n    /// @notice Sets `newProver` as `prover` of the contract.\n    /// @dev Warning: No two-step transfer ownership.\n    /// @dev Warning: The prover can be set to the zero address.\n    function setProver(address newProver) external;\n\n    /// @notice Sets `newMm` as `mm` of the contract.\n    /// @dev Warning: No two-step transfer ownership.\n    /// @dev Warning: The mm can be set to the zero address.\n    function setMm(address newMm) external;\n\n    /// @notice Sets credit line\n    function setCreditLines(\n        Id[] calldata ids,\n        address[] calldata borrowers,\n        uint256[] calldata vv,\n        uint256[] calldata credit,\n        uint128[] calldata drp\n    ) external;\n\n    /// @notice Sets the insurance fund address\n    /// @param newInsuranceFund The new insurance fund address\n    function setInsuranceFund(address newInsuranceFund) external;\n}\n"},{"file_path":"src/interfaces/IERC20.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title IERC20\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @dev Empty because we only call library functions. It prevents calling transfer (transferFrom) instead of\n/// safeTransfer (safeTransferFrom).\ninterface IERC20 {\n    function approve(address spender, uint256 value) external returns (bool);\n}\n"},{"file_path":"src/interfaces/IIrm.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.18;\n\nimport {MarketParams, Market} from \"./IMorpho.sol\";\n\n/// @title IIrm\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Interface that Interest Rate Models (IRMs) used by Morpho must implement.\ninterface IIrm {\n    /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams`.\n    /// @dev Assumes that `market` corresponds to `marketParams`.\n    function borrowRate(MarketParams memory marketParams, Market memory market) external returns (uint256);\n\n    /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams` without modifying any\n    /// storage.\n    /// @dev Assumes that `market` corresponds to `marketParams`.\n    function borrowRateView(MarketParams memory marketParams, Market memory market) external view returns (uint256);\n}\n"},{"file_path":"src/interfaces/IMarkdownController.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport {Id} from \"./IMorpho.sol\";\n\n/// @title IMarkdownController\n/// @notice Interface for controlling debt markdowns and JANE token redistribution for borrowers in default\ninterface IMarkdownController {\n    /// @notice Calculate the markdown amount for a borrower's position\n    /// @param borrower The address of the borrower\n    /// @param borrowAmount The current borrow amount in assets\n    /// @param timeInDefault The duration in seconds since the borrower entered default\n    /// @return markdownAmount The amount to reduce from the face value\n    function calculateMarkdown(address borrower, uint256 borrowAmount, uint256 timeInDefault)\n        external\n        view\n        returns (uint256 markdownAmount);\n\n    /// @notice Get the markdown multiplier for a given time in default\n    /// @param timeInDefault The duration in seconds since the borrower entered default\n    /// @return multiplier The value multiplier (1e18 = 100% value, 0 = 0% value)\n    function getMarkdownMultiplier(uint256 timeInDefault) external view returns (uint256 multiplier);\n\n    /// @notice Check if a borrower's JANE transfers are frozen\n    /// @param borrower The borrower address\n    /// @return True if the borrower is frozen\n    function isFrozen(address borrower) external view returns (bool);\n\n    /// @notice Redistributes JANE proportionally to markdown progression\n    /// @param borrower The borrower address\n    /// @param timeInDefault Time the borrower has been in default\n    /// @return slashed Amount of JANE redistributed\n    function slashJaneProportional(address borrower, uint256 timeInDefault) external returns (uint256 slashed);\n\n    /// @notice Redistributes all remaining JANE on settlement\n    /// @param borrower The borrower address\n    /// @return slashed Amount of JANE redistributed\n    function slashJaneFull(address borrower) external returns (uint256 slashed);\n\n    /// @notice Reset burn tracking state for a borrower\n    /// @param borrower The borrower address\n    function resetBorrowerState(address borrower) external;\n}\n"},{"file_path":"src/interfaces/IMorpho.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.18;\n\ntype Id is bytes32;\n\nstruct MarketParams {\n    address loanToken;\n    address collateralToken;\n    address oracle;\n    address irm;\n    uint256 lltv;\n    address creditLine;\n}\n\n/// @dev Warning: For `feeRecipient`, `supplyShares` does not contain the accrued shares since the last interest\n/// accrual.\nstruct Position {\n    uint256 supplyShares;\n    uint128 borrowShares;\n    uint128 collateral;\n}\n\n/// @dev Warning: `totalSupplyAssets` does not contain the accrued interest since the last interest accrual.\n/// @dev Warning: `totalBorrowAssets` does not contain the accrued interest since the last interest accrual.\n/// @dev Warning: `totalSupplyShares` does not contain the additional shares accrued by `feeRecipient` since the last\n/// interest accrual.\n/// @dev Warning: `totalMarkdownAmount` may be stale as markdowns are only updated when borrowers are touched.\nstruct Market {\n    uint128 totalSupplyAssets;\n    uint128 totalSupplyShares;\n    uint128 totalBorrowAssets;\n    uint128 totalBorrowShares;\n    uint128 lastUpdate;\n    uint128 fee;\n    uint128 totalMarkdownAmount; // Running tally of all borrower markdowns\n}\n\n/// @notice Per-borrower premium tracking\n/// @param lastAccrualTime Timestamp of the last premium accrual for this borrower\n/// @param rate Current risk premium rate per second (scaled by WAD)\n/// @param borrowAssetsAtLastAccrual Snapshot of borrow position at last premium accrual\nstruct BorrowerPremium {\n    uint128 lastAccrualTime;\n    uint128 rate;\n    uint128 borrowAssetsAtLastAccrual;\n}\n\n/// @notice Repayment tracking structures\nenum RepaymentStatus {\n    Current,\n    GracePeriod,\n    Delinquent,\n    Default\n}\n\nstruct PaymentCycle {\n    uint256 endDate;\n}\n\nstruct RepaymentObligation {\n    uint128 paymentCycleId;\n    uint128 amountDue;\n    uint128 endingBalance;\n}\n\n/// @notice Markdown state for tracking defaulted debt value reduction\n/// @param lastCalculatedMarkdown Last calculated markdown amount\nstruct MarkdownState {\n    uint128 lastCalculatedMarkdown;\n}\n\nstruct Authorization {\n    address authorizer;\n    address authorized;\n    bool isAuthorized;\n    uint256 nonce;\n    uint256 deadline;\n}\n\nstruct Signature {\n    uint8 v;\n    bytes32 r;\n    bytes32 s;\n}\n\n/// @dev This interface is used for factorizing IMorphoStaticTyping and IMorpho.\n/// @dev Consider using the IMorpho interface instead of this one.\ninterface IMorphoBase {\n    /// @notice The EIP-712 domain separator.\n    /// @dev Warning: Every EIP-712 signed message based on this domain separator can be reused on chains sharing the\n    /// same chain id and on forks because the domain separator would be the same.\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n\n    /// @notice The owner of the contract.\n    /// @dev It has the power to change the owner.\n    /// @dev It has the power to set fees on markets and set the fee recipient.\n    /// @dev It has the power to enable but not disable IRMs and LLTVs.\n    function owner() external view returns (address);\n\n    /// @notice The fee recipient of all markets.\n    /// @dev The recipient receives the fees of a given market through a supply position on that market.\n    function feeRecipient() external view returns (address);\n\n    /// @notice Whether the `irm` is enabled.\n    function isIrmEnabled(address irm) external view returns (bool);\n\n    /// @notice Whether the `lltv` is enabled.\n    function isLltvEnabled(uint256 lltv) external view returns (bool);\n\n    /// @notice The `authorizer`'s current nonce. Used to prevent replay attacks with EIP-712 signatures.\n    function nonce(address authorizer) external view returns (uint256);\n\n    /// @notice Sets `newOwner` as `owner` of the contract.\n    /// @dev Warning: No two-step transfer ownership.\n    /// @dev Warning: The owner can be set to the zero address.\n    function setOwner(address newOwner) external;\n\n    /// @notice Enables `irm` as a possible IRM for market creation.\n    /// @dev Warning: It is not possible to disable an IRM.\n    function enableIrm(address irm) external;\n\n    /// @notice Enables `lltv` as a possible LLTV for market creation.\n    /// @dev Warning: It is not possible to disable a LLTV.\n    function enableLltv(uint256 lltv) external;\n\n    /// @notice Sets the `newFee` for the given market `marketParams`.\n    /// @param newFee The new fee, scaled by WAD.\n    /// @dev Warning: The recipient can be the zero address.\n    function setFee(MarketParams memory marketParams, uint256 newFee) external;\n\n    /// @notice Sets `newFeeRecipient` as `feeRecipient` of the fee.\n    /// @dev Warning: If the fee recipient is set to the zero address, fees will accrue there and will be lost.\n    /// @dev Modifying the fee recipient will allow the new recipient to claim any pending fees not yet accrued. To\n    /// ensure that the current recipient receives all due fees, accrue interest manually prior to making any changes.\n    function setFeeRecipient(address newFeeRecipient) external;\n\n    /// @notice Creates the market `marketParams`.\n    /// @dev Here is the list of assumptions on the market's dependencies (tokens, IRM and oracle) that guarantees\n    /// Morpho behaves as expected:\n    /// - The token should be ERC-20 compliant, except that it can omit return values on `transfer` and `transferFrom`.\n    /// - The token balance of Morpho should only decrease on `transfer` and `transferFrom`. In particular, tokens with\n    /// burn functions are not supported.\n    /// - The token should not re-enter Morpho on `transfer` nor `transferFrom`.\n    /// - The token balance of the sender (resp. receiver) should decrease (resp. increase) by exactly the given amount\n    /// on `transfer` and `transferFrom`. In particular, tokens with fees on transfer are not supported.\n    /// - The IRM should not re-enter Morpho.\n    /// - The oracle should return a price with the correct scaling.\n    /// @dev Here is a list of assumptions on the market's dependencies which, if broken, could break Morpho's liveness\n    /// properties (funds could get stuck):\n    /// - The token should not revert on `transfer` and `transferFrom` if balances and approvals are right.\n    /// - The amount of assets supplied and borrowed should not go above ~1e35 (otherwise the computation of\n    /// `toSharesUp` and `toSharesDown` can overflow).\n    /// - The IRM should not revert on `borrowRate`.\n    /// - The IRM should not return a very high borrow rate (otherwise the computation of `interest` in\n    /// `_accrueInterest` can overflow).\n    /// - The oracle should not revert `price`.\n    /// - The oracle should not return a very high price (otherwise the computation of `maxBorrow` in `_isHealthy` or of\n    /// `assetsRepaid` in `liquidate` can overflow).\n    /// @dev The borrow share price of a market with less than 1e4 assets borrowed can be decreased by manipulations, to\n    /// the point where `totalBorrowShares` is very large and borrowing overflows.\n    function createMarket(MarketParams memory marketParams) external;\n\n    /// @notice Supplies `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's\n    /// `onMorphoSupply` function with the given `data`.\n    /// @dev Either `assets` or `shares` should be zero. Most use cases should rely on `assets` as an input so the\n    /// caller is guaranteed to have `assets` tokens pulled from their balance, but the possibility to mint a specific\n    /// amount of shares is given for full compatibility and precision.\n    /// @dev Supplying a large amount can revert for overflow.\n    /// @dev Supplying an amount of shares may lead to supply more or fewer assets than expected due to slippage.\n    /// Consider using the `assets` parameter to avoid this.\n    /// @param marketParams The market to supply assets to.\n    /// @param assets The amount of assets to supply.\n    /// @param shares The amount of shares to mint.\n    /// @param onBehalf The address that will own the increased supply position.\n    /// @param data Arbitrary data to pass to the `onMorphoSupply` callback. Pass empty data if not needed.\n    /// @return assetsSupplied The amount of assets supplied.\n    /// @return sharesSupplied The amount of shares minted.\n    function supply(\n        MarketParams memory marketParams,\n        uint256 assets,\n        uint256 shares,\n        address onBehalf,\n        bytes memory data\n    ) external returns (uint256 assetsSupplied, uint256 sharesSupplied);\n\n    /// @notice Withdraws `assets` or `shares` on behalf of `onBehalf` and sends the assets to `receiver`.\n    /// @dev Either `assets` or `shares` should be zero. To withdraw max, pass the `shares`'s balance of `onBehalf`.\n    /// @dev `msg.sender` must be authorized to manage `onBehalf`'s positions.\n    /// @dev Withdrawing an amount corresponding to more shares than supplied will revert for underflow.\n    /// @dev It is advised to use the `shares` input when withdrawing the full position to avoid reverts due to\n    /// conversion roundings between shares and assets.\n    /// @param marketParams The market to withdraw assets from.\n    /// @param assets The amount of assets to withdraw.\n    /// @param shares The amount of shares to burn.\n    /// @param onBehalf The address of the owner of the supply position.\n    /// @param receiver The address that will receive the withdrawn assets.\n    /// @return assetsWithdrawn The amount of assets withdrawn.\n    /// @return sharesWithdrawn The amount of shares burned.\n    function withdraw(\n        MarketParams memory marketParams,\n        uint256 assets,\n        uint256 shares,\n        address onBehalf,\n        address receiver\n    ) external returns (uint256 assetsWithdrawn, uint256 sharesWithdrawn);\n\n    /// @notice Borrows `assets` or `shares` on behalf of `onBehalf` and sends the assets to `receiver`.\n    /// @dev Either `assets` or `shares` should be zero. Most use cases should rely on `assets` as an input so the\n    /// caller is guaranteed to borrow `assets` of tokens, but the possibility to mint a specific amount of shares is\n    /// given for full compatibility and precision.\n    /// @dev `msg.sender` must be authorized to manage `onBehalf`'s positions.\n    /// @dev Borrowing a large amount can revert for overflow.\n    /// @dev Borrowing an amount of shares may lead to borrow fewer assets than expected due to slippage.\n    /// Consider using the `assets` parameter to avoid this.\n    /// @param marketParams The market to borrow assets from.\n    /// @param assets The amount of assets to borrow.\n    /// @param shares The amount of shares to mint.\n    /// @param onBehalf The address that will own the increased borrow position.\n    /// @param receiver The address that will receive the borrowed assets.\n    /// @return assetsBorrowed The amount of assets borrowed.\n    /// @return sharesBorrowed The amount of shares minted.\n    function borrow(\n        MarketParams memory marketParams,\n        uint256 assets,\n        uint256 shares,\n        address onBehalf,\n        address receiver\n    ) external returns (uint256 assetsBorrowed, uint256 sharesBorrowed);\n\n    /// @notice Repays `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's\n    /// `onMorphoRepay` function with the given `data`.\n    /// @dev Either `assets` or `shares` should be zero. To repay max, pass the `shares`'s balance of `onBehalf`.\n    /// @dev Repaying an amount corresponding to more shares than borrowed will revert for underflow.\n    /// @dev It is advised to use the `shares` input when repaying the full position to avoid reverts due to conversion\n    /// roundings between shares and assets.\n    /// @dev An attacker can front-run a repay with a small repay making the transaction revert for underflow.\n    /// @param marketParams The market to repay assets to.\n    /// @param assets The amount of assets to repay.\n    /// @param shares The amount of shares to burn.\n    /// @param onBehalf The address of the owner of the debt position.\n    /// @param data Arbitrary data to pass to the `onMorphoRepay` callback. Pass empty data if not needed.\n    /// @return assetsRepaid The amount of assets repaid.\n    /// @return sharesRepaid The amount of shares burned.\n    function repay(\n        MarketParams memory marketParams,\n        uint256 assets,\n        uint256 shares,\n        address onBehalf,\n        bytes memory data\n    ) external returns (uint256 assetsRepaid, uint256 sharesRepaid);\n\n    /// @notice Accrues interest for the given market `marketParams`.\n    function accrueInterest(MarketParams memory marketParams) external;\n\n    /// @notice Returns the data stored on the different `slots`.\n    function extSloads(bytes32[] memory slots) external view returns (bytes32[] memory);\n}\n\n/// @dev This interface is inherited by Morpho so that function signatures are checked by the compiler.\n/// @dev Consider using the IMorpho interface instead of this one.\ninterface IMorphoStaticTyping is IMorphoBase {\n    /// @notice The state of the position of `user` on the market corresponding to `id`.\n    /// @dev Warning: For `feeRecipient`, `supplyShares` does not contain the accrued shares since the last interest\n    /// accrual.\n    function position(Id id, address user)\n        external\n        view\n        returns (uint256 supplyShares, uint128 borrowShares, uint128 collateral);\n\n    /// @notice The state of the market corresponding to `id`.\n    /// @dev Warning: `totalSupplyAssets` does not contain the accrued interest since the last interest accrual.\n    /// @dev Warning: `totalBorrowAssets` does not contain the accrued interest since the last interest accrual.\n    /// @dev Warning: `totalSupplyShares` does not contain the accrued shares by `feeRecipient` since the last interest\n    /// accrual.\n    function market(Id id)\n        external\n        view\n        returns (\n            uint128 totalSupplyAssets,\n            uint128 totalSupplyShares,\n            uint128 totalBorrowAssets,\n            uint128 totalBorrowShares,\n            uint128 lastUpdate,\n            uint128 fee,\n            uint128 totalMarkdownAmount\n        );\n\n    /// @notice The market params corresponding to `id`.\n    /// @dev This mapping is not used in Morpho. It is there to enable reducing the cost associated to calldata on layer\n    /// 2s by creating a wrapper contract with functions that take `id` as input instead of `marketParams`.\n    function idToMarketParams(Id id)\n        external\n        view\n        returns (\n            address loanToken,\n            address collateralToken,\n            address oracle,\n            address irm,\n            uint256 lltv,\n            address creditLine\n        );\n}\n\n/// @title IMorpho\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @dev Use this interface for Morpho to have access to all the functions with the appropriate function signatures.\ninterface IMorpho is IMorphoBase {\n    /// @notice The state of the position of `user` on the market corresponding to `id`.\n    /// @dev Warning: For `feeRecipient`, `p.supplyShares` does not contain the accrued shares since the last interest\n    /// accrual.\n    function position(Id id, address user) external view returns (Position memory p);\n\n    /// @notice The state of the market corresponding to `id`.\n    /// @dev Warning: `m.totalSupplyAssets` does not contain the accrued interest since the last interest accrual.\n    /// @dev Warning: `m.totalBorrowAssets` does not contain the accrued interest since the last interest accrual.\n    /// @dev Warning: `m.totalSupplyShares` does not contain the accrued shares by `feeRecipient` since the last\n    /// interest accrual.\n    function market(Id id) external view returns (Market memory m);\n\n    /// @notice The market params corresponding to `id`.\n    /// @dev This mapping is not used in Morpho. It is there to enable reducing the cost associated to calldata on layer\n    /// 2s by creating a wrapper contract with functions that take `id` as input instead of `marketParams`.\n    function idToMarketParams(Id id) external view returns (MarketParams memory);\n}\n\n/// @title IMorphoCredit\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @dev Use this interface for Morpho to have access to all the functions with the appropriate function signatures.\ninterface IMorphoCredit {\n    /// @notice The helper of the contract.\n    function helper() external view returns (address);\n\n    /// @notice The usd3 contract\n    function usd3() external view returns (address);\n\n    /// @notice The protocol config of the contract.\n    function protocolConfig() external view returns (address);\n\n    /// @notice Sets `helper` as `helper` of the contract.\n    /// @param newHelper The new helper address\n    function setHelper(address newHelper) external;\n\n    /// @notice Sets `usd3` as `usd3` of the contract.\n    /// @param newUsd3 The new usd3 address\n    function setUsd3(address newUsd3) external;\n\n    /// @notice Sets the credit line and premium rate for a borrower\n    /// @param id The market ID\n    /// @param borrower The borrower address\n    /// @param credit The credit line amount\n    /// @param drp The drp per second in WAD\n    function setCreditLine(Id id, address borrower, uint256 credit, uint128 drp) external;\n\n    /// @notice Returns the premium data for a specific borrower in a market\n    /// @param id The market ID\n    /// @param borrower The borrower address\n    /// @return lastAccrualTime Timestamp of the last premium accrual\n    /// @return rate Current risk premium rate per second (scaled by WAD)\n    /// @return borrowAssetsAtLastAccrual Snapshot of borrow position at last premium accrual\n    function borrowerPremium(Id id, address borrower)\n        external\n        view\n        returns (uint128 lastAccrualTime, uint128 rate, uint128 borrowAssetsAtLastAccrual);\n\n    /// @notice Batch accrue premiums for multiple borrowers\n    /// @param id Market ID\n    /// @param borrowers Array of borrower addresses\n    /// @dev Gas usage scales linearly with array size. Callers should manage batch sizes based on block gas limits.\n    function accruePremiumsForBorrowers(Id id, address[] calldata borrowers) external;\n\n    /// @notice Close a payment cycle and post obligations for multiple borrowers\n    /// @param id Market ID\n    /// @param endDate Cycle end date\n    /// @param borrowers Array of borrower addresses\n    /// @param repaymentBps Array of repayment basis points (e.g., 500 = 5%)\n    /// @param endingBalances Array of ending balances for penalty calculations\n    function closeCycleAndPostObligations(\n        Id id,\n        uint256 endDate,\n        address[] calldata borrowers,\n        uint256[] calldata repaymentBps,\n        uint256[] calldata endingBalances\n    ) external;\n\n    /// @notice Add obligations to the latest payment cycle\n    /// @param id Market ID\n    /// @param borrowers Array of borrower addresses\n    /// @param repaymentBps Array of repayment basis points (e.g., 500 = 5%)\n    /// @param endingBalances Array of ending balances\n    function addObligationsToLatestCycle(\n        Id id,\n        address[] calldata borrowers,\n        uint256[] calldata repaymentBps,\n        uint256[] calldata endingBalances\n    ) external;\n\n    /// @notice Get repayment obligation for a borrower\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @return cycleId The payment cycle ID\n    /// @return amountDue The amount due\n    /// @return endingBalance The ending balance for penalty calculations\n    function repaymentObligation(Id id, address borrower)\n        external\n        view\n        returns (uint128 cycleId, uint128 amountDue, uint128 endingBalance);\n\n    /// @notice Get payment cycle end date\n    /// @param id Market ID\n    /// @param cycleId Cycle ID\n    /// @return endDate The cycle end date\n    function paymentCycle(Id id, uint256 cycleId) external view returns (uint256 endDate);\n\n    /// @notice Settle a borrower's account by writing off all remaining debt\n    /// @dev Only callable by credit line contract\n    /// @dev Should be called after any partial repayments have been made\n    /// @param marketParams The market parameters\n    /// @param borrower The borrower whose account to settle\n    /// @return writtenOffAssets Amount of assets written off\n    /// @return writtenOffShares Amount of shares written off\n    function settleAccount(MarketParams memory marketParams, address borrower)\n        external\n        returns (uint256 writtenOffAssets, uint256 writtenOffShares);\n\n    /// @notice Get markdown state for a borrower\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @return lastCalculatedMarkdown Last calculated markdown amount\n    function markdownState(Id id, address borrower) external view returns (uint128 lastCalculatedMarkdown);\n}\n"},{"file_path":"src/interfaces/IMorphoCallbacks.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title IMorphoRepayCallback\n/// @notice Interface that users willing to use `repay`'s callback must implement.\ninterface IMorphoRepayCallback {\n    /// @notice Callback called when a repayment occurs.\n    /// @dev The callback is called only if data is not empty.\n    /// @param assets The amount of repaid assets.\n    /// @param data Arbitrary data passed to the `repay` function.\n    function onMorphoRepay(uint256 assets, bytes calldata data) external;\n}\n\n/// @title IMorphoSupplyCallback\n/// @notice Interface that users willing to use `supply`'s callback must implement.\ninterface IMorphoSupplyCallback {\n    /// @notice Callback called when a supply occurs.\n    /// @dev The callback is called only if data is not empty.\n    /// @param assets The amount of supplied assets.\n    /// @param data Arbitrary data passed to the `supply` function.\n    function onMorphoSupply(uint256 assets, bytes calldata data) external;\n}\n"},{"file_path":"src/interfaces/IOracle.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title IOracle\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Interface that oracles used by Morpho must implement.\n/// @dev It is the user's responsibility to select markets with safe oracles.\ninterface IOracle {\n    /// @notice Returns the price of 1 asset of collateral token quoted in 1 asset of loan token, scaled by 1e36.\n    /// @dev It corresponds to the price of 10**(collateral token decimals) assets of collateral token quoted in\n    /// 10**(loan token decimals) assets of loan token with `36 + loan token decimals - collateral token decimals`\n    /// decimals of precision.\n    function price() external view returns (uint256);\n}\n"},{"file_path":"src/interfaces/IProtocolConfig.sol","source_code":"// SPDX-License-Identifier: GPL-20later\npragma solidity ^0.8.18;\n\n/// @notice Interface for the ProtocolConfig contract\n\n// Struct to hold market parameters\nstruct MarketConfig {\n    uint256 gracePeriod; // Duration of grace period after cycle end\n    uint256 delinquencyPeriod; // Duration of delinquency period before default\n    uint256 minBorrow; // Minimum outstanding loan balance to prevent dust\n    uint256 irp; // Penalty rate per second for delinquent borrowers\n}\n\n// Struct to hold credit line parameters\nstruct CreditLineConfig {\n    uint256 maxLTV;\n    uint256 maxVV;\n    uint256 maxCreditLine;\n    uint256 minCreditLine;\n    uint256 maxDRP;\n}\n\n// Struct to hold IRM parameters\nstruct IRMConfig {\n    uint256 curveSteepness;\n    uint256 adjustmentSpeed;\n    uint256 targetUtilization;\n    uint256 initialRateAtTarget;\n    uint256 minRateAtTarget;\n    uint256 maxRateAtTarget;\n}\n\n/// @notice Struct to hold IRM parameters with int256 types for internal calculations\nstruct IRMConfigTyped {\n    int256 curveSteepness;\n    int256 adjustmentSpeed;\n    int256 targetUtilization;\n    int256 initialRateAtTarget;\n    int256 minRateAtTarget;\n    int256 maxRateAtTarget;\n}\n\ninterface IProtocolConfig {\n    /// @dev Initialize the contract with the owner\n    /// @param newOwner The address of the new owner\n    function initialize(address newOwner) external;\n\n    /// @dev Set a configuration value\n    /// @param key The configuration key\n    /// @param value The configuration value\n    function setConfig(bytes32 key, uint256 value) external;\n\n    /// @dev Set emergency configuration with binary constraints\n    /// @param key The configuration key (IS_PAUSED, DEBT_CAP, MAX_ON_CREDIT, USD3_SUPPLY_CAP)\n    /// @param value The configuration value (binary constraints enforced)\n    function setEmergencyConfig(bytes32 key, uint256 value) external;\n\n    // Credit Line getters\n    /// @dev Get the credit line parameters\n    /// @return The credit line parameters\n    function getCreditLineConfig() external view returns (CreditLineConfig memory);\n\n    // Market getters\n    /// @dev Get the pause status\n    /// @return The pause status value\n    function getIsPaused() external view returns (uint256);\n\n    /// @dev Get the maximum on credit\n    /// @return The max on credit value\n    function getMaxOnCredit() external view returns (uint256);\n\n    /// @dev Get the market parameters\n    /// @return The market parameters\n    function getMarketConfig() external view returns (MarketConfig memory);\n\n    /// @dev Get the cycle duration for payment cycles\n    /// @return The cycle duration in seconds\n    function getCycleDuration() external view returns (uint256);\n\n    // IRM getters\n    /// @dev Get the IRM parameters\n    /// @return The IRM parameters\n    function getIRMConfig() external view returns (IRMConfig memory);\n\n    // USD3 & sUSD3 getters\n    /// @dev Get the tranche ratio\n    /// @return The tranche ratio value\n    function getTrancheRatio() external view returns (uint256);\n\n    /// @dev Get the tranche share variant\n    /// @return The tranche share variant value\n    function getTrancheShareVariant() external view returns (uint256);\n\n    /// @dev Get the SUSD3 lock duration\n    /// @return The SUSD3 lock duration value\n    function getSusd3LockDuration() external view returns (uint256);\n\n    /// @dev Get the SUSD3 cooldown period\n    /// @return The SUSD3 cooldown period value\n    function getSusd3CooldownPeriod() external view returns (uint256);\n\n    /// @dev Get the USD3 commitment time\n    /// @return The lock period in seconds\n    function getUsd3CommitmentTime() external view returns (uint256);\n\n    /// @dev Get the sUSD3 withdrawal window\n    /// @return The withdrawal window duration in seconds after cooldown\n    function getSusd3WithdrawalWindow() external view returns (uint256);\n\n    /// @dev Get the USD3 supply cap\n    /// @return The supply cap in asset units\n    function getUsd3SupplyCap() external view returns (uint256);\n\n    /// @dev Get configuration value by key\n    /// @param key The configuration key\n    /// @return The configuration value\n    function config(bytes32 key) external view returns (uint256);\n}\n"},{"file_path":"src/libraries/ConstantsLib.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.0;\n\n/// @dev The maximum fee a market can have (25%).\nuint256 constant MAX_FEE = 0.25e18;\n\n/// @dev Oracle price scale.\nuint256 constant ORACLE_PRICE_SCALE = 1e36;\n\n/// @dev Liquidation cursor.\nuint256 constant LIQUIDATION_CURSOR = 0.3e18;\n\n/// @dev Max liquidation incentive factor.\nuint256 constant MAX_LIQUIDATION_INCENTIVE_FACTOR = 1.15e18;\n\n/// @dev The EIP-712 typeHash for EIP712Domain.\nbytes32 constant DOMAIN_TYPEHASH = keccak256(\"EIP712Domain(uint256 chainId,address verifyingContract)\");\n\n/// @dev The EIP-712 typeHash for Authorization.\nbytes32 constant AUTHORIZATION_TYPEHASH =\n    keccak256(\"Authorization(address authorizer,address authorized,bool isAuthorized,uint256 nonce,uint256 deadline)\");\n"},{"file_path":"src/libraries/ErrorsLib.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.0;\n\n/// @title ErrorsLib\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Library exposing custom errors.\nlibrary ErrorsLib {\n    /// @notice Thrown when the caller is not the owner.\n    error NotOwner();\n\n    /// @notice Thrown when the caller is not the market's credit line.\n    error NotCreditLine();\n\n    /// @notice Thrown when the caller is not the market's helper.\n    error NotHelper();\n\n    /// @notice Thrown when the caller is not the market's usd3.\n    error NotUsd3();\n\n    /// @notice Thrown when the caller is not the owner or ozd.\n    error NotOwnerOrOzd();\n\n    /// @notice Thrown when the user is unverified.\n    error Unverified();\n\n    /// @notice Thrown when the LLTV to enable exceeds the maximum LLTV.\n    error MaxLltvExceeded();\n\n    /// @notice Thrown when the LTV to enable exceeds the maximum LTV.\n    error MaxLtvExceeded();\n\n    /// @notice Thrown when the VV to enable exceeds the maximum VV.\n    error MaxVvExceeded();\n\n    /// @notice Thrown when the credit to enable exceeds the maximum credit.\n    error MaxCreditLineExceeded();\n\n    /// @notice Thrown when the credit to enable is below the minimum credit.\n    error MinCreditLineExceeded();\n\n    /// @notice Thrown when the fee to set exceeds the maximum fee.\n    error MaxFeeExceeded();\n\n    /// @notice Thrown when the value is already set.\n    error AlreadySet();\n\n    /// @notice Thrown when the IRM is not enabled at market creation.\n    error IrmNotEnabled();\n\n    /// @notice Thrown when the LLTV is not enabled at market creation.\n    error LltvNotEnabled();\n\n    /// @notice Thrown when the market is already created.\n    error MarketAlreadyCreated();\n\n    /// @notice Thrown when a token to transfer doesn't have code.\n    error NoCode();\n\n    /// @notice Thrown when the market is not created.\n    error MarketNotCreated();\n\n    /// @notice Thrown when not exactly one of the input amount is zero.\n    error InconsistentInput();\n\n    /// @notice Thrown when zero assets is passed as input.\n    error ZeroAssets();\n\n    /// @notice Thrown when a zero address is passed as input.\n    error ZeroAddress();\n\n    /// @notice Thrown when an array has an invalid length.\n    error InvalidArrayLength();\n\n    /// @notice Thrown when the caller is not authorized to conduct an action.\n    error Unauthorized();\n\n    /// @notice Thrown when the collateral is insufficient to `borrow` or `withdrawCollateral`.\n    error InsufficientCollateral();\n\n    /// @notice Thrown when the liquidity is insufficient to `withdraw` or `borrow`.\n    error InsufficientLiquidity();\n\n    /// @notice Thrown when borrowing shares would result in borrowing zero assets.\n    error InsufficientBorrowAmount();\n\n    /// @notice Thrown when a token transfer reverted.\n    error TransferReverted();\n\n    /// @notice Thrown when a token transfer returned false.\n    error TransferReturnedFalse();\n\n    /// @notice Thrown when a token transferFrom reverted.\n    error TransferFromReverted();\n\n    /// @notice Thrown when a token transferFrom returned false\n    error TransferFromReturnedFalse();\n\n    /// @notice Thrown when the maximum uint128 is exceeded.\n    error MaxUint128Exceeded();\n\n    /// @notice Thrown when the premium rate exceeds the maximum allowed.\n    error MaxDrpExceeded();\n\n    /// @notice Thrown when the borrower has outstanding repayment obligations.\n    error OutstandingRepayment();\n\n    /// @notice Thrown when the protocol is paused.\n    error Paused();\n\n    /// @notice Thrown when trying to close a future cycle.\n    error CannotCloseFutureCycle();\n\n    /// @notice Thrown when cycle duration is invalid.\n    error InvalidCycleDuration();\n\n    /// @notice Thrown when no payment cycles exist.\n    error NoCyclesExist();\n\n    /// @notice Thrown when cycle ID is invalid.\n    error InvalidCycleId();\n\n    /// @notice Thrown when partial payment is attempted but full obligation payment is required.\n    error MustPayFullObligation();\n\n    /// @notice Thrown when repayment basis points exceed 100%.\n    error RepaymentExceedsHundredPercent();\n\n    /// @notice Thrown when an invalid markdown manager is set.\n    error InvalidMarkdownManager();\n\n    /// @notice Thrown when trying to settle non-existent debt.\n    error NoAccountToSettle();\n\n    /// @notice Thrown when the cover amount exceeds the assets amount.\n    error InvalidCoverAmount();\n\n    /// @notice Thrown when attempting operations on a frozen market.\n    error MarketFrozen();\n\n    /// @notice Thrown when a borrow would exceed the protocol debt cap.\n    error DebtCapExceeded();\n\n    /// @notice Thrown when borrow or repay would result in debt below minimum borrow amount.\n    error BelowMinimumBorrow();\n}\n"},{"file_path":"src/libraries/EventsLib.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.0;\n\nimport {Id, MarketParams} from \"../interfaces/IMorpho.sol\";\n\n/// @title EventsLib\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Library exposing events.\nlibrary EventsLib {\n    /// @notice Emitted when setting a new owner.\n    /// @param newOwner The new owner of the contract.\n    event SetOwner(address indexed newOwner);\n\n    /// @notice Emitted when setting a new helper.\n    /// @param newHelper The new helper of the contract.\n    event SetHelper(address indexed newHelper);\n\n    /// @notice Emitted when setting a new usd3.\n    /// @param newUsd3 The new usd3 of the contract.\n    event SetUsd3(address indexed newUsd3);\n\n    /// @notice Emitted when setting a new fee.\n    /// @param id The market id.\n    /// @param newFee The new fee.\n    event SetFee(Id indexed id, uint256 newFee);\n\n    /// @notice Emitted when setting a new fee recipient.\n    /// @param newFeeRecipient The new fee recipient.\n    event SetFeeRecipient(address indexed newFeeRecipient);\n\n    /// @notice Emitted when setting a credit line.\n    /// @param id The market id.\n    /// @param borrower The borrower.\n    /// @param credit The credit size.\n    event SetCreditLine(Id indexed id, address indexed borrower, uint256 credit);\n\n    /// @notice Emitted when enabling an IRM.\n    /// @param irm The IRM that was enabled.\n    event EnableIrm(address indexed irm);\n\n    /// @notice Emitted when enabling an LLTV.\n    /// @param lltv The LLTV that was enabled.\n    event EnableLltv(uint256 lltv);\n\n    /// @notice Emitted when creating a market.\n    /// @param id The market id.\n    /// @param marketParams The market that was created.\n    event CreateMarket(Id indexed id, MarketParams marketParams);\n\n    /// @notice Emitted on supply of assets.\n    /// @dev Warning: `feeRecipient` receives some shares during interest accrual without any supply event emitted.\n    /// @param id The market id.\n    /// @param caller The caller.\n    /// @param onBehalf The owner of the modified position.\n    /// @param assets The amount of assets supplied.\n    /// @param shares The amount of shares minted.\n    event Supply(Id indexed id, address indexed caller, address indexed onBehalf, uint256 assets, uint256 shares);\n\n    /// @notice Emitted on withdrawal of assets.\n    /// @param id The market id.\n    /// @param caller The caller.\n    /// @param onBehalf The owner of the modified position.\n    /// @param receiver The address that received the withdrawn assets.\n    /// @param assets The amount of assets withdrawn.\n    /// @param shares The amount of shares burned.\n    event Withdraw(\n        Id indexed id,\n        address caller,\n        address indexed onBehalf,\n        address indexed receiver,\n        uint256 assets,\n        uint256 shares\n    );\n\n    /// @notice Emitted on borrow of assets.\n    /// @param id The market id.\n    /// @param caller The caller.\n    /// @param onBehalf The owner of the modified position.\n    /// @param receiver The address that received the borrowed assets.\n    /// @param assets The amount of assets borrowed.\n    /// @param shares The amount of shares minted.\n    event Borrow(\n        Id indexed id,\n        address caller,\n        address indexed onBehalf,\n        address indexed receiver,\n        uint256 assets,\n        uint256 shares\n    );\n\n    /// @notice Emitted on repayment of assets.\n    /// @param id The market id.\n    /// @param caller The caller.\n    /// @param onBehalf The owner of the modified position.\n    /// @param assets The amount of assets repaid. May be 1 over the corresponding market's `totalBorrowAssets`.\n    /// @param shares The amount of shares burned.\n    event Repay(Id indexed id, address indexed caller, address indexed onBehalf, uint256 assets, uint256 shares);\n\n    /// @notice Emitted when accruing interest.\n    /// @param id The market id.\n    /// @param prevBorrowRate The previous borrow rate.\n    /// @param interest The amount of interest accrued.\n    /// @param feeShares The amount of shares minted as fee.\n    event AccrueInterest(Id indexed id, uint256 prevBorrowRate, uint256 interest, uint256 feeShares);\n\n    /// @notice Emitted when premium is accrued for a borrower.\n    /// @param id Market ID.\n    /// @param borrower Borrower address.\n    /// @param premiumAmount Amount of premium accrued.\n    /// @param feeAmount Protocol fee on the premium.\n    event PremiumAccrued(Id indexed id, address indexed borrower, uint256 premiumAmount, uint256 feeAmount);\n\n    /// @notice Emitted when a borrower's premium rate is updated.\n    /// @param id Market ID.\n    /// @param borrower Borrower address.\n    /// @param oldRate Previous premium rate.\n    /// @param newRate New premium rate.\n    event BorrowerPremiumRateSet(Id indexed id, address indexed borrower, uint128 oldRate, uint128 newRate);\n\n    /// @notice Emitted when a payment cycle is created.\n    /// @param id Market id.\n    /// @param cycleId Payment cycle ID.\n    /// @param startDate Cycle start date.\n    /// @param endDate Cycle end date.\n    event PaymentCycleCreated(Id indexed id, uint256 cycleId, uint256 startDate, uint256 endDate);\n\n    /// @notice Emitted when a repayment obligation is posted.\n    /// @param id Market id.\n    /// @param borrower Borrower address.\n    /// @param amount Amount due.\n    /// @param cycleId Payment cycle ID.\n    /// @param endingBalance Balance at cycle end for penalty calculations.\n    event RepaymentObligationPosted(\n        Id indexed id, address indexed borrower, uint256 amount, uint256 cycleId, uint256 endingBalance\n    );\n\n    /// @notice Emitted when a repayment is tracked against an obligation.\n    /// @param id Market id.\n    /// @param borrower Borrower address.\n    /// @param payment Payment amount made.\n    /// @param remainingDue Remaining amount due after payment.\n    event RepaymentTracked(Id indexed id, address indexed borrower, uint256 payment, uint256 remainingDue);\n\n    /// @notice Emitted when a borrower's markdown is updated.\n    /// @param id Market id.\n    /// @param borrower Borrower address.\n    /// @param oldMarkdown Previous markdown amount.\n    /// @param newMarkdown New markdown amount.\n    event BorrowerMarkdownUpdated(Id indexed id, address indexed borrower, uint256 oldMarkdown, uint256 newMarkdown);\n\n    /// @notice Emitted when a borrower enters default status.\n    /// @param id Market id.\n    /// @param borrower Borrower address.\n    /// @param timestamp Timestamp when default started.\n    event DefaultStarted(Id indexed id, address indexed borrower, uint256 timestamp);\n\n    /// @notice Emitted when a borrower clears default status.\n    /// @param id Market id.\n    /// @param borrower Borrower address.\n    event DefaultCleared(Id indexed id, address indexed borrower);\n\n    /// @notice Emitted when a markdown manager is set for a market.\n    /// @param id Market id.\n    /// @param oldManager Previous markdown manager.\n    /// @param newManager New markdown manager.\n    event MarkdownManagerSet(Id indexed id, address oldManager, address newManager);\n\n    /// @notice Emitted when an account is settled with all remaining debt written off.\n    /// @param id Market id.\n    /// @param settler Address that initiated the settlement.\n    /// @param borrower Borrower whose account is settled.\n    /// @param writtenOffAmount Amount written off (forgiven).\n    /// @param writtenOffShares Shares written off.\n    event AccountSettled(\n        Id indexed id,\n        address indexed settler,\n        address indexed borrower,\n        uint256 writtenOffAmount,\n        uint256 writtenOffShares\n    );\n}\n"},{"file_path":"src/libraries/MarketParamsLib.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.0;\n\nimport {Id, MarketParams} from \"../interfaces/IMorpho.sol\";\n\n/// @title MarketParamsLib\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Library to convert a market to its id.\nlibrary MarketParamsLib {\n    /// @notice The length of the data used to compute the id of a market.\n    /// @dev The length is 6 * 32 because `MarketParams` has 6 variables of 32 bytes each.\n    uint256 internal constant MARKET_PARAMS_BYTES_LENGTH = 6 * 32;\n\n    /// @notice Returns the id of the market `marketParams`.\n    function id(MarketParams memory marketParams) internal pure returns (Id marketParamsId) {\n        assembly (\"memory-safe\") {\n            marketParamsId := keccak256(marketParams, MARKET_PARAMS_BYTES_LENGTH)\n        }\n    }\n}\n"},{"file_path":"src/libraries/MathLib.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.0;\n\nuint256 constant WAD = 1e18;\n\n/// @title MathLib\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Library to manage fixed-point arithmetic.\nlibrary MathLib {\n    /// @dev Returns (`x` * `y`) / `WAD` rounded down.\n    function wMulDown(uint256 x, uint256 y) internal pure returns (uint256) {\n        return mulDivDown(x, y, WAD);\n    }\n\n    /// @dev Returns (`x` * `WAD`) / `y` rounded down.\n    function wDivDown(uint256 x, uint256 y) internal pure returns (uint256) {\n        return mulDivDown(x, WAD, y);\n    }\n\n    /// @dev Returns (`x` * `WAD`) / `y` rounded up.\n    function wDivUp(uint256 x, uint256 y) internal pure returns (uint256) {\n        return mulDivUp(x, WAD, y);\n    }\n\n    /// @dev Returns (`x` * `y`) / `d` rounded down.\n    function mulDivDown(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) {\n        return (x * y) / d;\n    }\n\n    /// @dev Returns (`x` * `y`) / `d` rounded up.\n    function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) {\n        return (x * y + (d - 1)) / d;\n    }\n\n    /// @dev Returns the sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1, to approximate a\n    /// continuous compound interest rate.\n    function wTaylorCompounded(uint256 x, uint256 n) internal pure returns (uint256) {\n        uint256 firstTerm = x * n;\n        uint256 secondTerm = mulDivDown(firstTerm, firstTerm, 2 * WAD);\n        uint256 thirdTerm = mulDivDown(secondTerm, firstTerm, 3 * WAD);\n\n        return firstTerm + secondTerm + thirdTerm;\n    }\n\n    /// @dev Computes the inverse of wTaylorCompounded, finding the rate that produces the given growth factor.\n    /// Uses a 3-term Taylor series approximation of ln(x) to solve for rate in the compound interest formula.\n    /// Formula: rate = ln(x) / n ≈ [(x-1) - (x-1)²/2 + (x-1)³/3] / n\n    ///\n    /// Accuracy notes:\n    /// - The Taylor approximation of ln(x) is most accurate for x close to 1\n    /// - At growth factor x = 1.69*WAD (69% growth), approximation error < 2%\n    /// - At growth factor x = 2*WAD (100% growth, where ln(2) ≈ 0.69), approximation error < 5%\n    /// - Accuracy decreases for larger growth factors; not recommended for x > 2.5*WAD (150% growth)\n    ///\n    /// Example: If debt grew from 1000 to 1105 over 1 year (10.5% growth):\n    /// - x = 1.105*WAD (growth factor)\n    /// - n = 365 days (time period)\n    /// - Returns ~10% APR as rate per second\n    ///\n    /// @param x The growth factor scaled by WAD (e.g., 1.1*WAD for 10% growth). Must be >= WAD.\n    /// @param n The time period over which the growth occurred (in seconds)\n    /// @return The continuously compounded rate per second that would produce this growth (scaled by WAD)\n    function wInverseTaylorCompounded(uint256 x, uint256 n) internal pure returns (uint256) {\n        require(x >= WAD, \"ln undefined\");\n\n        uint256 firstTerm = x - WAD;\n        uint256 secondTerm = wMulDown(firstTerm, firstTerm);\n        uint256 thirdTerm = wMulDown(secondTerm, firstTerm);\n\n        uint256 series = firstTerm - secondTerm / 2 + thirdTerm / 3;\n\n        return series / n;\n    }\n}\n"},{"file_path":"src/libraries/ProtocolConfigLib.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.0;\n\n/// @title ProtocolConfigLib\n/// @notice Library containing all configuration keys for ProtocolConfig\n/// @dev Centralizes all configuration keys to avoid magic strings and improve maintainability\nlibrary ProtocolConfigLib {\n    // Market Control Keys\n    bytes32 internal constant IS_PAUSED = keccak256(\"IS_PAUSED\");\n    bytes32 internal constant MAX_ON_CREDIT = keccak256(\"MAX_ON_CREDIT\");\n    bytes32 internal constant DEBT_CAP = keccak256(\"DEBT_CAP\");\n\n    // Credit Line Keys\n    bytes32 internal constant MIN_LOAN_DURATION = keccak256(\"MIN_LOAN_DURATION\");\n    bytes32 internal constant LATE_REPAYMENT_THRESHOLD = keccak256(\"LATE_REPAYMENT_THRESHOLD\");\n    bytes32 internal constant DEFAULT_THRESHOLD = keccak256(\"DEFAULT_THRESHOLD\");\n    bytes32 internal constant GRACE_PERIOD = keccak256(\"GRACE_PERIOD\");\n\n    // Interest Rate Keys\n    bytes32 internal constant CURVE_STEEPNESS = keccak256(\"CURVE_STEEPNESS\");\n    bytes32 internal constant ADJUSTMENT_SPEED = keccak256(\"ADJUSTMENT_SPEED\");\n    bytes32 internal constant TARGET_UTILIZATION = keccak256(\"TARGET_UTILIZATION\");\n    bytes32 internal constant INITIAL_RATE_AT_TARGET = keccak256(\"INITIAL_RATE_AT_TARGET\");\n    bytes32 internal constant MIN_RATE_AT_TARGET = keccak256(\"MIN_RATE_AT_TARGET\");\n    bytes32 internal constant MAX_RATE_AT_TARGET = keccak256(\"MAX_RATE_AT_TARGET\");\n\n    // Tranche Keys (USD3 & sUSD3)\n    bytes32 internal constant TRANCHE_RATIO = keccak256(\"TRANCHE_RATIO\");\n    bytes32 internal constant TRANCHE_SHARE_VARIANT = keccak256(\"TRANCHE_SHARE_VARIANT\");\n    bytes32 internal constant MIN_SUSD3_BACKING_RATIO = keccak256(\"MIN_SUSD3_BACKING_RATIO\");\n\n    // Timing Keys\n    bytes32 internal constant SUSD3_LOCK_DURATION = keccak256(\"SUSD3_LOCK_DURATION\");\n    bytes32 internal constant SUSD3_COOLDOWN_PERIOD = keccak256(\"SUSD3_COOLDOWN_PERIOD\");\n    bytes32 internal constant USD3_COMMITMENT_TIME = keccak256(\"USD3_COMMITMENT_TIME\");\n    bytes32 internal constant SUSD3_WITHDRAWAL_WINDOW = keccak256(\"SUSD3_WITHDRAWAL_WINDOW\");\n\n    // Supply Cap Keys\n    bytes32 internal constant USD3_SUPPLY_CAP = keccak256(\"USD3_SUPPLY_CAP\");\n\n    // Markdown Keys\n    bytes32 internal constant FULL_MARKDOWN_DURATION = keccak256(\"FULL_MARKDOWN_DURATION\");\n}\n"},{"file_path":"src/libraries/SafeTransferLib.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.0;\n\nimport {IERC20} from \"../interfaces/IERC20.sol\";\n\nimport {ErrorsLib} from \"../libraries/ErrorsLib.sol\";\n\ninterface IERC20Internal {\n    function transfer(address to, uint256 value) external returns (bool);\n    function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n\n/// @title SafeTransferLib\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Library to manage transfers of tokens, even if calls to the transfer or transferFrom functions are not\n/// returning a boolean.\nlibrary SafeTransferLib {\n    function safeTransfer(IERC20 token, address to, uint256 value) internal {\n        if (address(token).code.length == 0) revert ErrorsLib.NoCode();\n\n        (bool success, bytes memory returndata) =\n            address(token).call(abi.encodeCall(IERC20Internal.transfer, (to, value)));\n        if (!success) revert ErrorsLib.TransferReverted();\n        if (returndata.length != 0 && !abi.decode(returndata, (bool))) revert ErrorsLib.TransferReturnedFalse();\n    }\n\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n        if (address(token).code.length == 0) revert ErrorsLib.NoCode();\n\n        (bool success, bytes memory returndata) =\n            address(token).call(abi.encodeCall(IERC20Internal.transferFrom, (from, to, value)));\n        if (!success) revert ErrorsLib.TransferFromReverted();\n        if (returndata.length != 0 && !abi.decode(returndata, (bool))) revert ErrorsLib.TransferFromReturnedFalse();\n    }\n}\n"},{"file_path":"src/libraries/SharesMathLib.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.0;\n\nimport {MathLib} from \"./MathLib.sol\";\n\n/// @title SharesMathLib\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Shares management library.\n/// @dev This implementation mitigates share price manipulations, using OpenZeppelin's method of virtual shares:\n/// https://docs.openzeppelin.com/contracts/4.x/erc4626#inflation-attack.\nlibrary SharesMathLib {\n    using MathLib for uint256;\n\n    /// @dev The number of virtual shares has been chosen low enough to prevent overflows, and high enough to ensure\n    /// high precision computations.\n    /// @dev Virtual shares can never be redeemed for the assets they are entitled to, but it is assumed the share price\n    /// stays low enough not to inflate these assets to a significant value.\n    /// @dev Warning: The assets to which virtual borrow shares are entitled behave like unrealizable bad debt.\n    uint256 internal constant VIRTUAL_SHARES = 1e6;\n\n    /// @dev A number of virtual assets of 1 enforces a conversion rate between shares and assets when a market is\n    /// empty.\n    uint256 internal constant VIRTUAL_ASSETS = 1;\n\n    /// @dev Calculates the value of `assets` quoted in shares, rounding down.\n    function toSharesDown(uint256 assets, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) {\n        return assets.mulDivDown(totalShares + VIRTUAL_SHARES, totalAssets + VIRTUAL_ASSETS);\n    }\n\n    /// @dev Calculates the value of `shares` quoted in assets, rounding down.\n    function toAssetsDown(uint256 shares, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) {\n        return shares.mulDivDown(totalAssets + VIRTUAL_ASSETS, totalShares + VIRTUAL_SHARES);\n    }\n\n    /// @dev Calculates the value of `assets` quoted in shares, rounding up.\n    function toSharesUp(uint256 assets, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) {\n        return assets.mulDivUp(totalShares + VIRTUAL_SHARES, totalAssets + VIRTUAL_ASSETS);\n    }\n\n    /// @dev Calculates the value of `shares` quoted in assets, rounding up.\n    function toAssetsUp(uint256 shares, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) {\n        return shares.mulDivUp(totalAssets + VIRTUAL_ASSETS, totalShares + VIRTUAL_SHARES);\n    }\n}\n"},{"file_path":"src/libraries/UtilsLib.sol","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.0;\n\nimport {ErrorsLib} from \"../libraries/ErrorsLib.sol\";\n\n/// @title UtilsLib\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Library exposing helpers.\n/// @dev Inspired by https://github.com/morpho-org/morpho-utils.\nlibrary UtilsLib {\n    /// @dev Returns true if there is exactly one zero among `x` and `y`.\n    function exactlyOneZero(uint256 x, uint256 y) internal pure returns (bool z) {\n        assembly {\n            z := xor(iszero(x), iszero(y))\n        }\n    }\n\n    /// @dev Returns the min of `x` and `y`.\n    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        assembly {\n            z := xor(x, mul(xor(x, y), lt(y, x)))\n        }\n    }\n\n    /// @dev Returns `x` safely cast to uint128.\n    function toUint128(uint256 x) internal pure returns (uint128) {\n        if (x > type(uint128).max) revert ErrorsLib.MaxUint128Exceeded();\n        return uint128(x);\n    }\n\n    /// @dev Returns max(0, x - y).\n    function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        assembly {\n            z := mul(gt(x, y), sub(x, y))\n        }\n    }\n}\n"}],"is_verified_via_sourcify":false,"can_be_visualized_via_sol2uml":true,"evm_version":"shanghai","language":"solidity","is_verified_via_eth_bytecode_db":false,"is_fully_verified":false,"license_type":"none","is_blueprint":false,"name":"MorphoCredit","creation_bytecode":"0x60a034620000d557601f6200616138819003918201601f19168301916001600160401b03831184841017620000d957808492602094604052833981010312620000d557516001600160a01b038116808203620000d5576200005f620000ed565b15620000c35760805262000072620000ed565b604051615fd490816200018d82396080518181816103b50152818161162f01528181611cc6015281816122e201528181612b5101528181614e7a01528181614ffb015281816159fb0152615b710152f35b60405163d92e233d60e01b8152600490fd5b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805460ff8160401c166200017a576001600160401b036002600160401b0319828216016200013b57505050565b6001600160401b031990911681179091556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a1565b60405163f92ee8a960e01b8152600490fdfe60806040526004361015610011575f80fd5b5f3560e01c8063107ddb0314612a7257806313042cac14612a1357806313af4035146129645780631b0cc946146126da5780631e4711cf1461266e5780632c34602d146125ec5780632c3c91571461254f5780633644e51514612514578063370160a01461220e57806346904840146121bd5780634d98a93b146120d457806358e83ce014611bb65780635a64f51e14611af25780635c60e39a14611a545780635e10e65c14611a035780635ec5c10d146118b457806363b0e66a14611863578063653ecd8e146117a357806370ae92d214611740578063772789a8146113525780637784c6851461122257806378c56d65146110f35780638da5cb5b146110a357806393c520621461100d578063986ccc7f14610f8b5780639c4828ca14610f0e578063a0b16cc714610c8c578063b485f3b814610c3f578063c4d66de814610963578063c904d53a146108e1578063ca499989146105df578063e74b981b14610505578063e761c2a514610441578063f2b863ce146103d9578063f5efbb4f1461036b5763fc588422146101a5575f80fd5b346103675760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675767ffffffffffffffff600435602435828111610367576101f8903690600401613413565b9160443584811161036757610211903690600401613413565b9390946064359081116103675761022c903690600401613413565b956102368461435c565b85831480159061035d575b61033357835f52601660205260405f20541561030957835f52601660205260405f2054927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84019384116102dc575f5b81811061029a57005b806102d689878c6102ce856102c6818f6102ba60019b8d6102bf936134ef565b6134ff565b968c6134ef565b35928b6134ef565b35928b6145c4565b01610291565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b60046040517f64ed67af000000000000000000000000000000000000000000000000000000008152fd5b60046040517ff0732dd7000000000000000000000000000000000000000000000000000000008152fd5b5086861415610241565b5f80fd5b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff6104256131d4565b165f526004602052602060ff60405f2054166040519015158152f35b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576104786131f7565b6004355f52601560205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f5260205260405f2060016105018254926fffffffffffffffffffffffffffffffff9283910154166040519384938160801c91168491604091949360608401956fffffffffffffffffffffffffffffffff9283809216865216602085015216910152565b0390f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675761053c6131d4565b610544614312565b60015473ffffffffffffffffffffffffffffffffffffffff80921691811682146105b5577fffffffffffffffffffffffff00000000000000000000000000000000000000001681176001557f2e979f80fe4d43055c584cf4a8467c55875ea36728fc37176c05acd784eb7a735f80a2005b60046040517fa741a045000000000000000000000000000000000000000000000000000000008152fd5b346103675760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576106173661321a565b61061f614312565b60c0812090606081019173ffffffffffffffffffffffffffffffffffffffff808451165f526020936004855260ff60405f205416156108b7576080840180515f526005865260ff60405f2054161561088d57835f52600386526fffffffffffffffffffffffffffffffff80600260405f2001541661086357845f5260038752600260405f20019042167fffffffffffffffffffffffffffffffff0000000000000000000000000000000082541617905560078652600560405f2084875116927fffffffffffffffffffffffff0000000000000000000000000000000000000000938483541617825560018201868a8a01511685825416179055600282018660408a0151168582541617905560038201868651168582541617905551600482015501908360a08701511690825416179055827f4ddfbf4ac40080d324e78aeea911a6e2fca97d4a6af53c4739d95c6ce079bb4b60c06040516107d1818960a0908173ffffffffffffffffffffffffffffffffffffffff9182815116855282602082015116602086015282604082015116604086015282606082015116606086015260808101516080860152015116910152565ba2511691826107dc57005b6108239284925f526003835260405f20915f6040518096819582947ff3ae2a0f00000000000000000000000000000000000000000000000000000000845260048401613cde565b03925af1801561085857610834575b005b813d8311610851575b6108478183613193565b8101031261036757005b503d61083d565b6040513d5f823e3d90fd5b60046040517fd7d82e58000000000000000000000000000000000000000000000000000000008152fd5b60046040517f61cb7fc0000000000000000000000000000000000000000000000000000000008152fd5b60046040517f068fe9e1000000000000000000000000000000000000000000000000000000008152fd5b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576109186131f7565b6004355f52601860205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f5260205260206fffffffffffffffffffffffffffffffff60405f205416604051908152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675761099a6131d4565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0090815460ff8160401c161567ffffffffffffffff9182811680159081610c37575b6001149081610c2d575b159081610c24575b50610bfa578160017fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000008316178655610bc5575b5083549260ff8460401c1615610b9b5773ffffffffffffffffffffffffffffffffffffffff168015610b715760405160208101907f47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218825246604082015230606082015260608152608081019481861090861117610b445784604052519020600855807fffffffffffffffffffffffff00000000000000000000000000000000000000005f5416175f557f167d3e9c1016ab80e58802ca9da10ce5c6a0f4debc46a2e7a2cd9e56899a4fb55f80a2610af457005b7fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2927fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff60209316905560018152a1005b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60046040517fd92e233d000000000000000000000000000000000000000000000000000000008152fd5b60046040517fd7e6bcf8000000000000000000000000000000000000000000000000000000008152fd5b7fffffffffffffffffffffffffffffffffffffffffffffff000000000000000000166801000000000000000117845584610a21565b60046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b905015866109ee565b303b1591506109e6565b8391506109dc565b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576004355f526005602052602060ff60405f2054166040519015158152f35b3461036757610c9a366132c2565b929082949294829460c0852091825f526003956020958787526fffffffffffffffffffffffffffffffff9081600260405f2001541615610ee457159983158b146103335773ffffffffffffffffffffffffffffffffffffffff938486169b8c15610b7157610d088886613da2565b610ebe575050845f52878752610d2960405f2054828160801c91168b61409f565b975b610d3487614d34565b855f52600288528360405f20971696875f52885260405f20610d578a82546134e2565b9055610dbd610d658a614110565b875f52828a52610d7d60405f2091825460801c6134c0565b6fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b610dc68a614110565b865f5281895260405f20907fffffffffffffffffffffffffffffffff0000000000000000000000000000000084610e018454938285166134c0565b169116179055855f52875260405f20908060018301541691541610610e9457604098610e8a9589957fa56fc0ad5702ec05ce63666221f796fb62437c32db1aa1aa075fc6484cf58fbf8c5180610e808d8b338460409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0390a451166141cc565b8351928352820152f35b60046040517fbb55fd27000000000000000000000000000000000000000000000000000000008152fd5b610ede91999a50865f528a895260405f205490838260801c921690614071565b98610d2b565b60046040517f96e13529000000000000000000000000000000000000000000000000000000008152fd5b346103675760e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757610f463661321a565b60c4359073ffffffffffffffffffffffffffffffffffffffff821682036103675760409181610f7a60c0610f7f942061435c565b613564565b82519182526020820152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff610fd76131d4565b610fdf614312565b167fffffffffffffffffffffffff000000000000000000000000000000000000000060135416176013555f80f35b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576110446131f7565b6004355f52600260205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f52602052606060405f20600181549101546040519182526fffffffffffffffffffffffffffffffff8116602083015260801c6040820152f35b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602073ffffffffffffffffffffffffffffffffffffffff5f5416604051908152f35b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675760043560243567ffffffffffffffff811161036757611145903690600401613413565b825f5260036020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee457825f52600760205260405f20926111e48160405161118981613147565b73ffffffffffffffffffffffffffffffffffffffff80885416825260056001988260018201541660208501528260028201541660408501528260038201541660608501526004810154608085015201541660a0820152613da2565b5f5b8281106111ef57005b8061121c6112026102ba889487896134ef565b61120c8186614731565b611216818661533f565b846151c3565b016111e6565b34610367576020807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675760043567ffffffffffffffff811161036757611272903690600401613413565b9061127c82613520565b9061128a6040519283613193565b82825261129683613520565b927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe085840194013685375f905b80821061130d575050509060405192839281840190828552518091526040840192915f5b8281106112f657505050500390f35b8351855286955093810193928101926001016112e7565b817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146102dc57600161134491019282856134ef565b35548260051b8501526112c3565b346103675760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675760248035906004359067ffffffffffffffff90604435828111610367576113ac903690600401613413565b9290606435828111610367576113c6903690600401613413565b90608435848111610367576113df903690600401613413565b90926113ea8961435c565b808814801590611736575b61033357428a1161170c57885f526020976016895260405f209889545f9a816115b2575b50508a5f526016815260405f2097604051908282019082821090821117611586576040528c8152885468010000000000000000811015611586576114659060019a600182018155613333565b91909161155b5790601692915190558b5f525260405f2054977fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff890198891161153057505f5b8181106114f1575060408051898152602081018b90529081018c90528a907fbd4a7b3b6ad66f13b3e4d519ca7459b576a8bf0a623247d5cecadae2059d8fff90606090a2005b8061152a8c8b8989611523868f988f818d8f936102ba8f916115169261151c966134ef565b966134ef565b35946134ef565b35936145c4565b016114ab565b7f4e487b71000000000000000000000000000000000000000000000000000000005f5260116004525ffd5b8a7f4e487b71000000000000000000000000000000000000000000000000000000005f525f6004525ffd5b8a7f4e487b71000000000000000000000000000000000000000000000000000000005f5260416004525ffd5b90919a507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82019182116116e057906115ea91613333565b5054986040517fbd5da9ac000000000000000000000000000000000000000000000000000000008152818160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa908115610858575f916116b3575b5080151590816116a0575b50611676578c80611419565b60046040517fec682162000000000000000000000000000000000000000000000000000000008152fd5b6116ab91508b613468565b8c108d61166a565b90508181813d83116116d9575b6116ca8183613193565b8101031261036757518d61165f565b503d6116c0565b897f4e487b71000000000000000000000000000000000000000000000000000000005f5260116004525ffd5b60046040517f2a4bbe99000000000000000000000000000000000000000000000000000000008152fd5b50818114156113f5565b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff61178c6131d4565b165f526006602052602060405f2054604051908152f35b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576117da6131f7565b6004355f52601760205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f5260205260405f2060016105018254926fffffffffffffffffffffffffffffffff9283910154166040519384938160801c91168491604091949360608401956fffffffffffffffffffffffffffffffff9283809216865216602085015216910152565b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602073ffffffffffffffffffffffffffffffffffffffff60135416604051908152f35b346103675760e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576118ec3661321a565b60c435906118f8614312565b60c0812091825f5260036020526fffffffffffffffffffffffffffffffff9081600260405f2001541615610ee457835f526003602052600260405f20015460801c81146105b5576703782dace9d9000081116119d9576119d060209261197f867f139d6f58e9a127229667c8e3b36e88890a66cfc8ab1024ddc513e189e125b75b96613da2565b855f52600384528216600260405f2001906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b604051908152a2005b60046040517ff4df6ae5000000000000000000000000000000000000000000000000000000008152fd5b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602073ffffffffffffffffffffffffffffffffffffffff60145416604051908152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576004355f52600360205260e060405f208054906fffffffffffffffffffffffffffffffff906001810154918060036002840154930154169260405194828116865260801c6020860152818116604086015260801c60608501528116608084015260801c60a083015260c0820152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff611b3e6131d4565b611b46614312565b16805f52600460205260ff60405f2054166105b557805f52600460205260405f2060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790557f590e04cdebeccba40f566186b9746ad295a4cd358ea4fefaaea6ce79630d96c05f80a2005b3461036757611bc436613375565b9491938394819560c0852095865f52600393846020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee45715811581146103335773ffffffffffffffffffffffffffffffffffffffff841615610b7157611c288888613da2565b61209a575050845f5281602052611c5d600160405f2001546fffffffffffffffffffffffffffffffff8160801c91168861443a565b945b611c6881614e28565b61207057611c768282614731565b611c80828261533f565b604051927f614bd944000000000000000000000000000000000000000000000000000000008452608093848160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa8015610858576040915f91612043575b50015180611f23575b50611e6a93611d11898585615844565b611db8611d1d89614110565b91845f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff87165f52602052600160405f20016fffffffffffffffffffffffffffffffff611d6c8254958287166134c0565b167fffffffffffffffffffffffffffffffff00000000000000000000000000000000809516179055610d7d611da08b614110565b865f5285602052600160405f2001928354901c6134c0565b825f5281602052611de86fffffffffffffffffffffffffffffffff600160405f200154168a808203911102614110565b91835f526020526fffffffffffffffffffffffffffffffff600160405f200192169082541617905560405187815286602082015273ffffffffffffffffffffffffffffffffffffffff831690827f52acb05cebbd3cd39715469f22afbf5a17496295ef3bc9bb5944056c63ccaa0960403393a4611e6582826151c3565b61533f565b84611e99575b60408484610f7f8273ffffffffffffffffffffffffffffffffffffffff8751163090339061445f565b333b1561036757611edb945f9160405196879283927f05b4591c0000000000000000000000000000000000000000000000000000000084528860048501613475565b038183335af19384156108585773ffffffffffffffffffffffffffffffffffffffff610f7f928592604097611f14575b50925050611e70565b611f1d90613163565b87611f0b565b825f528160205288611ff360405f2087604051611f3f8161312b565b82546fffffffffffffffffffffffffffffffff81168252821c602082015260c06fffffffffffffffffffffffffffffffff886001860154956040850196838116885260608601961c86528d600282015490848216818801521c60a0860152015416910152865f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff89165f526020526fffffffffffffffffffffffffffffffff8080600160405f2001541693511691511691614417565b818111612002575b5050611d01565b9061200c916134e2565b1061201957898881611ffb565b60046040517f92684f93000000000000000000000000000000000000000000000000000000008152fd5b6120639150863d8811612069575b61205b8183613193565b8101906140c1565b8b611cf8565b503d612051565b60046040517fb2ce2a93000000000000000000000000000000000000000000000000000000008152fd5b866120ce929798505f5283602052600160405f200154906fffffffffffffffffffffffffffffffff8260801c921690614417565b95611c5f565b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675760043561210e614312565b805f52600560205260ff60405f2054166105b557670de0b6b3a7640000811015612193576020817f297b80e7a896fad470c630f6575072d609bde997260ff3db851939405ec29139925f526005825260405f2060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00825416179055604051908152a1005b60046040517fc9600612000000000000000000000000000000000000000000000000000000008152fd5b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602073ffffffffffffffffffffffffffffffffffffffff60015416604051908152f35b346103675761221c36613375565b8394939291849560c08820805f52602095600387526fffffffffffffffffffffffffffffffff9788600260405f2001541615610ee4571592801584146103335773ffffffffffffffffffffffffffffffffffffffff809716938415610b7157612285848d613da2565b6124ed575050805f52600386526122a760405f2054888160801c91168a61443a565b965b856014541633036124c3576040517ff2a6f21500000000000000000000000000000000000000000000000000000000815287816004818a7f0000000000000000000000000000000000000000000000000000000000000000165afa908115610858575f91612496575b5061246c57815f526002875260405f20835f52875260405f20612336898254613468565b905561235d61234489614110565b835f5260038952610d7d60405f2091825460801c613444565b61236689614110565b825f52600388527fffffffffffffffffffffffffffffffff0000000000000000000000000000000060405f20926123a1845493828516613444565b1691161790556040519088825287878301527fedf8870433c83823eb071d3df1caa8d008f12f6440918c20d75a3602cda30fe060403393a4816123f4575b505083610e8a9160409651163090339061445f565b919091333b1561036757612439925f9160405194859283927f2075be030000000000000000000000000000000000000000000000000000000084528a60048501613475565b038183335af190811561085857604096610e8a93879361245d575b509650916123df565b61246690613163565b88612454565b60046040517f9e87fac8000000000000000000000000000000000000000000000000000000008152fd5b90508781813d83116124bc575b6124ad8183613193565b8101031261036757518b612312565b503d6124a3565b60046040517f2e29d74a000000000000000000000000000000000000000000000000000000008152fd5b61250e91989950825f526003885260405f2054908a8260801c921690614417565b976122a9565b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576020600854604051908152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576004355f52600760205260c060405f2073ffffffffffffffffffffffffffffffffffffffff80825416918160018201541691806002830154168160038401541691600560048501549401541693604051958652602086015260408501526060840152608083015260a0820152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff6126386131d4565b612640614312565b167fffffffffffffffffffffffff000000000000000000000000000000000000000060145416176014555f80f35b346103675760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576126a63661321a565b60c08120805f5260036020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee45761083291613da2565b346103675760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576004356127146131f7565b90604435916064356fffffffffffffffffffffffffffffffff808216809203610367576127408461435c565b73ffffffffffffffffffffffffffffffffffffffff91828416958615610b71577f98ae8997910895a35e546cf84a1f3c82ee4f89894401f773132427e8a24a5ec394612873876040968a827f0ebab34b6b7a4a637f38ab2b80f568ef92cdf83472f4ddb4051f81f316320bea876127b961281599614110565b90835f526020998a92600284528e5f20875f52845260018f5f2001906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b8c51908152a3815f5260078552875f2090600589519261283484613147565b8281541684528260018201541688850152826002820154168b8501528260038201541660608501526004810154608085015201541660a0820152613da2565b865f5260028252845f20885f528252836001865f20015416151580612955575b875f5260158352855f20895f5283526129256128b0875f206143da565b85858201978851169752895f5260158552875f208b5f528552875f208151602083015160801b7fffffffffffffffffffffffffffffffff000000000000000000000000000000009081166fffffffffffffffffffffffffffffffff928316178355916040906001019301511690825416179055565b8061294c575b61293c575b508351928352820152a3005b61294690876151c3565b87612930565b5082151561292b565b61295f8289614731565b612893565b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675761299b6131d4565b6129a3614312565b5f5473ffffffffffffffffffffffffffffffffffffffff80921691811682146105b5577fffffffffffffffffffffffff0000000000000000000000000000000000000000829116175f557f167d3e9c1016ab80e58802ca9da10ce5c6a0f4debc46a2e7a2cd9e56899a4fb55f80a2005b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576024356004355f52601660205260405f20805482101561036757602091612a6891613333565b5054604051908152f35b3461036757612a80366132c2565b928293819460c0872092835f5260036020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee4571594801586146103335773ffffffffffffffffffffffffffffffffffffffff8316958615610b7157612ae3858a613da2565b6130f0575050815f526003602052612b19600160405f2001546fffffffffffffffffffffffffffffffff8160801c91168761409f565b935b73ffffffffffffffffffffffffffffffffffffffff6013541633036130c65773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016966040517ff2a6f2150000000000000000000000000000000000000000000000000000000081526020816004818c5afa908115610858575f91613094575b5061246c57612bbd84614e28565b61207057612bcb8585614f46565b5060048110156130675761303d57612be38585614731565b6040517fcc718f760000000000000000000000000000000000000000000000000000000081527f4dc3aed3c9d2d8f55e7befc9c664516bd7ff894dca4521a6c8d71cbce4e9c37660048201526020816024818c5afa908115610858575f9161300b575b508015908115612fd7575b50612fad5760405180987f614bd94400000000000000000000000000000000000000000000000000000000825281600460809b8c935afa8015610858576040915f91612f90575b50015180612eba575b50861580612eb1575b612e8757612cb786614110565b845f526002602052612d5860405f209973ffffffffffffffffffffffffffffffffffffffff88169a8b5f52602052600160405f20016fffffffffffffffffffffffffffffffff612d0b825495828716613444565b167fffffffffffffffffffffffffffffffff00000000000000000000000000000000809516179055610d7d612d3f8a614110565b885f526003602052600160405f2001928354901c613444565b612d6188614110565b855f526003602052600160405f2001916fffffffffffffffffffffffffffffffff612d90845493828516613444565b169116179055612da085856150db565b15612e5d57835f52600360205260405f206fffffffffffffffffffffffffffffffff8060018301541691541610610e9457612e56610f7f958573ffffffffffffffffffffffffffffffffffffffff9460409b8b987f570954540bed6b1304a87dfe815a5eda4a648f7097a16240dcd85c9b5fd42a438c8f612e4e8d9151928392338460409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0390a46151c3565b51166141cc565b60046040517f3a23d825000000000000000000000000000000000000000000000000000000008152fd5b60046040517f1abfe8a7000000000000000000000000000000000000000000000000000000008152fd5b50851515612caa565b845f526003602052612f8588612f8060405f208c6fffffffffffffffffffffffffffffffff600360405193612eee8561312b565b80548381168652841c602086015260018101549383851660408701526060860194811c8552600282015490848216818801521c60a086015201541660c0830152895f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff8c165f526020526fffffffffffffffffffffffffffffffff806040816001825f200154169401511691511691614417565b613468565b106120195788612ca1565b612fa791508a3d8c116120695761205b8183613193565b8a612c98565b60046040517f7db9106f000000000000000000000000000000000000000000000000000000008152fd5b9050845f526003602052613004886fffffffffffffffffffffffffffffffff600160405f20015416613468565b1189612c51565b90506020813d602011613035575b8161302660209383613193565b81010312610367575189612c46565b3d9150613019565b60046040517feb39f13b000000000000000000000000000000000000000000000000000000008152fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b90506020813d6020116130be575b816130af60209383613193565b81010312610367575189612baf565b3d91506130a2565b60046040517f96e31905000000000000000000000000000000000000000000000000000000008152fd5b61312591959650835f526003602052600160405f200154906fffffffffffffffffffffffffffffffff8260801c921690614071565b94612b1b565b60e0810190811067ffffffffffffffff821117610b4457604052565b60c0810190811067ffffffffffffffff821117610b4457604052565b67ffffffffffffffff8111610b4457604052565b6060810190811067ffffffffffffffff821117610b4457604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117610b4457604052565b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361036757565b6024359073ffffffffffffffffffffffffffffffffffffffff8216820361036757565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60c0910112610367576040519061325182613147565b73ffffffffffffffffffffffffffffffffffffffff826004358281168103610367578152602435828116810361036757602082015260443582811681036103675760408201526064358281168103610367576060820152608435608082015260a43591821682036103675760a00152565b6101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc820112610367576132f69061321a565b9060c4359060e4359073ffffffffffffffffffffffffffffffffffffffff9061010435828116810361036757916101243590811681036103675790565b8054821015613348575f5260205f2001905f90565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b906101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc830112610367576133aa8261321a565b9160c4359160e435916101043573ffffffffffffffffffffffffffffffffffffffff8116810361036757916101243567ffffffffffffffff9283821161036757806023830112156103675781600401359384116103675760248483010111610367576024019190565b9181601f840112156103675782359167ffffffffffffffff8311610367576020808501948460051b01011161036757565b9190916fffffffffffffffffffffffffffffffff808094169116019182116102dc57565b919082018092116102dc57565b9183606094601f927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe094865260406020870152816040870152868601375f8582860101520116010190565b6fffffffffffffffffffffffffffffffff91821690821603919082116102dc57565b919082039182116102dc57565b91908110156133485760051b0190565b3573ffffffffffffffffffffffffffffffffffffffff811681036103675790565b67ffffffffffffffff8111610b445760051b60200190565b90816020910312610367575173ffffffffffffffffffffffffffffffffffffffff811681036103675790565b909161357460c083208093613da2565b61357e8383614731565b815f526002916020838152604091825f209273ffffffffffffffffffffffffffffffffffffffff80971693845f5283526fffffffffffffffffffffffffffffffff956001908782845f20015416978815613a1f57845f52600392838752613636855f2086516135ec8161312b565b8154858116825260801c8a820152838201549060c0868981851694858d86015260801c958660608601528a810154838116608087015260801c60a08601520154169101528c614417565b9a865f5260078852600488826005895f200154168851928380927fe90eaa510000000000000000000000000000000000000000000000000000000082525afa908115613a15575f916139e8575b5016878161396a575b5050855f5260188752845f20885f5287528180865f20541691875f52848952865f208a5f52895280875f2001947fffffffffffffffffffffffffffffffff0000000000000000000000000000000095868154169055885f528952865f208a5f52895280875f2001828154169055875f5260188952865f208a5f528952865f205f9055875f5260178952865f208a5f52895280875f205f8155015f9055875f5260158952865f208a5f52895280875f205f8155015f9055875f528589528c828d838a5f20015460801c9061375e916134e2565b61376790614110565b8a5f52888c52838a5f2001906137b99082906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b5416906137c5916134e2565b6137ce90614110565b885f52868a5282885f2092830191168682541617905554166137f08c83614cf0565b905f8213156138a95761382c7f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce97969594939261383192613468565b614110565b875f5284895282865f209116848254161790555b8061385e575b50505050868151948986528501523393a4565b865f528388528184865f200154168181115f146138a0576138829161382c916134e2565b925b865f52808852845f20019216908254161790555f80808061384b565b50505f92613884565b905f81126138df575b5050907f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce94939291613845565b6138e890614d08565b908181106139415761382c7f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce979695949392613923926134e2565b875f5284895282865f2091168482541617905590919293945f6138b2565b600487517fbb55fd27000000000000000000000000000000000000000000000000000000008152fd5b5f9160248b895194859384927fbd49979d00000000000000000000000000000000000000000000000000000000845260048401525af180156139de579088916139b5575b508061368c565b813d83116139d7575b6139c88183613193565b8101031261036757865f6139ae565b503d6139be565b86513d5f823e3d90fd5b613a089150893d8b11613a0e575b613a008183613193565b810190613538565b5f613683565b503d6139f6565b87513d5f823e3d90fd5b98509091928094959697505f5260188552825f20865f52855287835f20541697845f52818652835f20875f52865282845f2001917fffffffffffffffffffffffffffffffff0000000000000000000000000000000092838154169055855f528652835f20875f52865282845f2001818154169055845f5260188652835f20875f5286525f84812055845f5260178652835f20875f5286525f838582208281550155845f5260158652835f20875f5286525f838582208281550155845f5280600393848852613b5082613af883895f20015460801c614110565b895f52878b52613b49848a5f20019182906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b5416614110565b875f5285895282875f209283019116858254161790555416985f81135f14613c2057613ba461382c827f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce98999a9b9c613468565b875f5284895282865f209116848254161790555b80613bd5575b505050505f8151948186528501523393a45f905f90565b865f528388528184865f200154168181115f14613c1757613bf99161382c916134e2565b925b865f52808852845f20019216908254161790555f808080613bbe565b50505f92613bfb565b5f8112613c54575b7f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce959697989950613bb8565b613c5d81614d08565b998a8110613cb55761382c7f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce9798999a9b613c97926134e2565b875f5284895282865f20911684825416179055899897969550613c28565b600486517fbb55fd27000000000000000000000000000000000000000000000000000000008152fd5b90929161018090613d45836101a081019660a0908173ffffffffffffffffffffffffffffffffffffffff9182815116855282602082015116602086015282604082015116604086015282606082015116606086015260808101516080860152015116910152565b60038154916fffffffffffffffffffffffffffffffff9283811660c087015260801c60e0860152600181015483811661010087015260801c610120860152600281015483811661014087015260801c610160860152015416910152565b815f526003916020928084526fffffffffffffffffffffffffffffffff93604092613dd5866002865f20015416426134e2565b80156140685773ffffffffffffffffffffffffffffffffffffffff958660608201511680613e37575b505050600294505f52525f20019042167fffffffffffffffffffffffffffffffff00000000000000000000000000000000825416179055565b613e7d92918591855f52878352885f20915f8a518097819582947ff3ae2a0f00000000000000000000000000000000000000000000000000000000845260048401613cde565b03925af19182156139de57908892915f92614036575b50917f9d9bd501d0657d7dfe415f779a620a62b78bc508ddc0891fbbd8b7ac0f8fce8791613fa1613ee98960029b8a8a8a998a5f52828252613eef896001875f20015416670de0b6b3a76400009788938b614da7565b9061457a565b0497613efa89614110565b8b5f528383526001865f200182613f15825493828516613444565b167fffffffffffffffffffffffffffffffff00000000000000000000000000000000809316179055613f468a614110565b8c5f52848452865f209183613f5f845493828516613444565b1691161790555f948b5f528383526002815f20015460801c9687613fac575b509495505050505051938493846040919493926060820195825260208201520152565b0390a25f8080613dfe565b613fe49650613fc0613fd19596988c61457a565b049485938d5f52525f2054166134e2565b885f528b8b528c5f205460801c9161443a565b90865f528b89528a5f2090600154165f528852895f20614005828254613468565b905561402a61401382614110565b875f528a8a52610d7d8c5f2091825460801c613444565b805f8a8a8f8e84613f7e565b85809294508193503d8311614061575b6140508183613193565b810103126103675751879183613e93565b503d614046565b50505050505050565b60018201929183106102dc57620f424082018092116102dc5761409c926140979161457a565b61458d565b90565b91620f424081018091116102dc57600182018092116102dc5761409c92614de5565b908160809103126103675760405190608082019082821067ffffffffffffffff831117610b44576060916040528051835260208101516020840152604081015160408401520151606082015290565b6fffffffffffffffffffffffffffffffff9081811161412d571690565b60046040517f6acc9c8f000000000000000000000000000000000000000000000000000000008152fd5b3d156141af573d9067ffffffffffffffff8211610b4457604051916141a460207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8401160184613193565b82523d5f602084013e565b606090565b90816020910312610367575180151581036103675790565b90919073ffffffffffffffffffffffffffffffffffffffff16803b156142e8576040517fa9059cbb000000000000000000000000000000000000000000000000000000006020820190815273ffffffffffffffffffffffffffffffffffffffff9490941660248201526044808201939093529182525f9283928390614252606482613193565b51925af161425e614157565b90156142be5780519081151591826142a3575b505061427957565b60046040517f2f0470fc000000000000000000000000000000000000000000000000000000008152fd5b6142b692506020809183010191016141b4565b155f80614271565b60046040517face2a47e000000000000000000000000000000000000000000000000000000008152fd5b60046040517ff046a714000000000000000000000000000000000000000000000000000000008152fd5b73ffffffffffffffffffffffffffffffffffffffff5f5416330361433257565b60046040517f30cd7471000000000000000000000000000000000000000000000000000000008152fd5b805f5260036020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee4575f52600760205273ffffffffffffffffffffffffffffffffffffffff600560405f2001541633036143b057565b60046040517f0f7f7bcd000000000000000000000000000000000000000000000000000000008152fd5b906040516143e781613177565b6040819360018154916fffffffffffffffffffffffffffffffff92838116865260801c6020860152015416910152565b9190600181018091116102dc57620f424082018092116102dc5761409c92614de5565b620f424083018093116102dc57600182018092116102dc5761409c926140979161457a565b909273ffffffffffffffffffffffffffffffffffffffff80921691823b156142e857604051938160208601967f23b872dd00000000000000000000000000000000000000000000000000000000885216602486015216604484015260648301526064825260a082019282841067ffffffffffffffff851117610b44575f809493819460405251925af16144f0614157565b9015614550578051908115159182614535575b505061450b57565b60046040517f1eded19c000000000000000000000000000000000000000000000000000000008152fd5b61454892506020809183010191016141b4565b155f80614503565b60046040517fe65b7a77000000000000000000000000000000000000000000000000000000008152fd5b818102929181159184041417156102dc57565b8115614597570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b92909391612710808211614707577f9492bafec7fdce8259c23f7dec34550603e9a6de90e2b2a9b21eb69337896af8936146e991865f5260176020526146ce60409173ffffffffffffffffffffffffffffffffffffffff835f209a16998a5f5260205261463c614635845f206143da565b968561457a565b0494602081016fffffffffffffffffffffffffffffffff80825116156146ee575b87169052885f526017602052825f208a5f52602052825f208151602083015160801b7fffffffffffffffffffffffffffffffff000000000000000000000000000000009081166fffffffffffffffffffffffffffffffff928316178355916040906001019301511690825416179055565b51938493846040919493926060820195825260208201520152565b0390a3565b8089168352806146fd87614110565b168584015261465d565b60046040517f11fff5a0000000000000000000000000000000000000000000000000000000008152fd5b61473b8282614f46565b50815f52601560205260405f2073ffffffffffffffffffffffffffffffffffffffff84165f5260205261477060405f206143da565b906fffffffffffffffffffffffffffffffff6020830151161580614cdf575b614cd957825f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff85165f526020526fffffffffffffffffffffffffffffffff600160405f2001541615614cd9576148ce816148c46148d494865f5260036020526148ba60405f20604051906148018261312b565b80546fffffffffffffffffffffffffffffffff8116835260801c60208301526fffffffffffffffffffffffffffffffff60036001830154928284166040860152606085019360801c84526002810154838116608087015260801c60a086015201541660c0830152895f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff8c165f526020526fffffffffffffffffffffffffffffffff806040816001825f200154169401511691511691614417565b9485918989615910565b9283918787615a9f565b90613468565b60018110614cd457815f52600360205260405f206fffffffffffffffffffffffffffffffff6149e26149d66149626040519461490f8661312b565b8054858116875260801c602087015284600360018301549282841660408a01528360801c60608a0152600281015483811660808b015260801c60a08a015201541660c0870152848160801c91168761409f565b61496b81614110565b875f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff8a165f52602052600160405f2001907fffffffffffffffffffffffffffffffff00000000000000000000000000000000866149cb845493828516613444565b169116179055614110565b82606085015116613444565b1660608201526fffffffffffffffffffffffffffffffff614a11614a0584614110565b82604085015116613444565b1660408201526fffffffffffffffffffffffffffffffff614a3d614a3484614110565b82845116613444565b1681525f906fffffffffffffffffffffffffffffffff60a08201511680614c2f575b505f84815260036020818152604090922083519284015160801b7fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff93841617815560c09190604085015160608601517fffffffffffffffffffffffffffffffff0000000000000000000000000000000090861660801b169085166fffffffffffffffffffffffffffffffff1617600182015560808581015160a08701516fffffffffffffffffffffffffffffffff9187169190911690861690911b7fffffffffffffffffffffffffffffffff000000000000000000000000000000001617600282015501920151167fffffffffffffffffffffffffffffffff000000000000000000000000000000008254161790556040519182526020820152817f090eee6ac5af73cf4534c51b1be6693f7fae2db8acd16126d8ad373dc78188c6604073ffffffffffffffffffffffffffffffffffffffff861693a35f52601560205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f5260205260405f206fffffffffffffffffffffffffffffffff42167fffffffffffffffffffffffffffffffff00000000000000000000000000000000825416179055565b670de0b6b3a7640000919250614c45908461457a565b04906fffffffffffffffffffffffffffffffff614cc8614cbc614c7c614c6e86858751166134e2565b84602087015116908761443a565b875f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff600154165f5260205260405f20614cb5828254613468565b9055614110565b82602085015116613444565b1660208201525f614a5f565b505050565b50505050565b50600481101561306757801561478f565b81810392915f1380158285131691841216176102dc57565b7f800000000000000000000000000000000000000000000000000000000000000081146102dc575f0390565b73ffffffffffffffffffffffffffffffffffffffff80601454163314614da3578060015416908133149283614d97575b505050614d955760046040517f2e29d74a000000000000000000000000000000000000000000000000000000008152fd5b565b161490505f8080614d64565b5050565b61409c91614db49161457a565b612f80671bc16d674ec80000614dca838061457a565b046729a2241af62c0000614dde848361457a565b0492613468565b90614def9161457a565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101918183116102dc5761409c9261409791613468565b805f5260206016815260405f205491604051917fbd5da9ac000000000000000000000000000000000000000000000000000000008352808360048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa928315610858575f93614f17575b5083158015614f0f575b614f06576016915f525260405f207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83019283116102dc57614f0092614ef991613333565b5054613468565b42101590565b50505050600190565b508215614eb4565b9080935081813d8311614f3f575b614f2f8183613193565b810103126103675751915f614eaa565b503d614f25565b90815f5260209060178252604092835f2073ffffffffffffffffffffffffffffffffffffffff8093165f528352614f7e845f206143da565b906fffffffffffffffffffffffffffffffff90818584015116156150cf5781835116815f5260168652865f205411156150a657600492608092614fcd925f5260168752875f2091511690613333565b5054928551928380927f614bd9440000000000000000000000000000000000000000000000000000000082527f0000000000000000000000000000000000000000000000000000000000000000165afa93841561509d57505f9361507c575b50615038835182613468565b42111561507257825161504a91613468565b9101615057815183613468565b421061506c575161506791613468565b600391565b50600291565b9291505060019190565b61509691935060803d6080116120695761205b8183613193565b915f61502c565b513d5f823e3d90fd5b600486517f11baffb2000000000000000000000000000000000000000000000000000000008152fd5b5050505050505f905f90565b90815f52600260205260409073ffffffffffffffffffffffffffffffffffffffff825f2091165f52602052805f2091600182519361511885613177565b805485520154926fffffffffffffffffffffffffffffffff92838516816020840193828552019560801c8652156151b9576151b1925f52600360205283815f209282516151648161312b565b8454838116825260801c602082015260c08360036001880154828116809886015260801c978860608601526002810154838116608087015260801c60a08601520154169101525116614417565b915116101590565b5050505050600190565b614d9591815f526020906015825260409173ffffffffffffffffffffffffffffffffffffffff835f20921691825f5281526151ff835f206143da565b93805f5260038252835f206152b161529c86519261521c8461312b565b8054936fffffffffffffffffffffffffffffffff94858116825260801c8782015260018201549060c08660038c8401958286168752606085019560801c86526002810154838116608087015260801c60a0860152015416910152855f5260028752885f20885f52875284808060018c5f2001541693511691511691614417565b82885116158015615328575b61531e57614110565b16848601525f5260158152825f20915f52525f208151602083015160801b7fffffffffffffffffffffffffffffffff000000000000000000000000000000009081166fffffffffffffffffffffffffffffffff928316178355916040906001019301511690825416179055565b8242168852614110565b508287890151161580156152a857508015156152a8565b5f815f526020926007845273ffffffffffffffffffffffffffffffffffffffff9380604092866005855f200154168451938480927fe90eaa5100000000000000000000000000000000000000000000000000000000825260049687915afa90811561583a579088915f9161581d575b50169283156154b057865f5260188352845f2097821697885f5283526fffffffffffffffffffffffffffffffff9182865f205416946153ed828a614f46565b90848110156157f157600314959493929190888a8c8e8a6157e7575b8b158b806157e0575b15615794575050505050813b156103675788517fcb6b88550000000000000000000000000000000000000000000000000000000081528c858201525f8160248183875af1801561578a57918d918d9361576b575b5091818c938c969593837f28bb2b50e85ab8cb3028aa7ee85d6a0e4f8ae610956f2d4d09b62c7450f11df88c8a51858152a35b849a615540575b50505050505050508383036154ba575b5050505050505050565b8486887fdfc0c058da6e22e40bf226987ffd5316a213e4ad1ec60802bc07aef3f75a76a198526018845220885f528252845f209083167fffffffffffffffffffffffffffffffff0000000000000000000000000000000082541617905561552a6155248484614cf0565b87615c35565b8351928352820152a35f808080808080806154b0565b879a50966156446155ea8b948b899a9b958c9a968042115f146157615761556790426134e2565b9c8d9a5b84815260038a528181209482516155818161312b565b8654868116825260801c8c82015260c0600188015496600386840199828a168b52606085019960801c8a526002810154838116608087015260801c60a0860152015416910152815260028a5220905f5287528c808060018d5f2001541693511691511691614417565b9889975197889485947f49190203000000000000000000000000000000000000000000000000000000008652850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0381845afa92831561575757908792918c94615723575b5083948c6156ba959a8d51968795869485937f852be02900000000000000000000000000000000000000000000000000000000855284016020909392919373ffffffffffffffffffffffffffffffffffffffff60408201951681520152565b03925af180156157195783929186916156ea575b5050116156e2575b858188818b8d826154a0565b92505f6156d6565b90809293503d8311615712575b6157018183613193565b81010312610367578190845f6156ce565b503d6156f7565b88513d8b823e3d90fd5b8381949295503d8311615750575b61573b8183613193565b81010312610367576156ba928792519361565b565b503d615731565b8a513d8d823e3d90fd5b50899c8d9a61556b565b8b9594929c5061577c919350613163565b8b5f9b919394929092615466565b8a513d5f823e3d90fd5b8b9796949795919293951590816157d7575b50156154995781837ffcba921102de188664e72818df26311ac84b9f31348028598cbaaf8801d422e55f80a3615499565b9050155f6157a6565b5080615412565b8415159a50615409565b6021857f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b6158349150843d8611613a0e57613a008183613193565b5f6153ae565b85513d5f823e3d90fd5b9091815f52601760205260409073ffffffffffffffffffffffffffffffffffffffff825f20941693845f52602052815f205460801c80156159095781106158e057907f9f3566c9415b4b8515c473fc1ef06cb3271e69346db61e985f9a223f1f81844b91835f526017602052815f20855f52602052815f206fffffffffffffffffffffffffffffffff815416905581519081525f6020820152a3565b600482517f9efe3019000000000000000000000000000000000000000000000000000000008152fd5b5050505050565b939092916fffffffffffffffffffffffffffffffff9061593382825116426134e2565b948515615a94576301e13380808711615a8c575b5082602083015116946004811015613067578015159081615a80575b50615979575b5061409c95506040015116615e2c565b60806159cc886004995f52601760205260405f2073ffffffffffffffffffffffffffffffffffffffff8095165f526020526159b660405f206143da565b905f5260166020528560405f2091511690613333565b505491604051988980927f614bd9440000000000000000000000000000000000000000000000000000000082527f0000000000000000000000000000000000000000000000000000000000000000165afa9081156108585761409c975f92615a5f575b50615a408484511691835190613468565b101561596957604091946060615a5892015190613468565b9390615969565b615a7991925060803d6080116120695761205b8183613193565b905f615a2f565b6001915014155f615963565b95505f615947565b505050505050505f90565b929193909360048110156130675760028114159081615c29575b50615c2157600490835f5260156020526040805f209073ffffffffffffffffffffffffffffffffffffffff80971691825f52602052615af9815f206143da565b91865f526017602052815f20905f52602052615b16815f206143da565b955f526016602052805f20916080615b436fffffffffffffffffffffffffffffffff94858a511690613333565b5054988351968780927f614bd9440000000000000000000000000000000000000000000000000000000082527f0000000000000000000000000000000000000000000000000000000000000000165afa948515615c17575f95615bf4575b5082905116615bb1855189613468565b10615a9457615bc361409c97426134e2565b956301e13380808811615beb575b5001511692606091615be291613468565b91015191615e2c565b96506060615bd1565b83919550615c109060803d6080116120695761205b8183613193565b9490615ba1565b82513d5f823e3d90fd5b505050505f90565b6003915014155f615ab9565b908015614da357815f52600360205260405f209060405191615c568361312b565b8054926fffffffffffffffffffffffffffffffff9283928386168352602083019560801c865283600182015484604081018383168152606082019260801c835283600286015493816080850197818716895260a086019660801c875260030154169c60c085019d8e528d5f8a135f149b615dcc9a615d7b9760039e615de1578161382c9184615d05949281835116809111615dd9575b61382c84615cf9926134e2565b16905283855116613468565b1690525b5f90815260208b90526040902098519b516fffffffffffffffffffffffffffffffff9c83168d16908316608090811b7fffffffffffffffffffffffffffffffff00000000000000000000000000000000908116929092178b5593519151918316909c16911690911b8a16176001870155565b81600286019351168884541617835551166fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b0192511690825416179055565b925082615cec565b61382c90615df1615e1c93614d08565b9084865116808311615e24575b5084615e1061382c8483855116613468565b169052838551166134e2565b169052615d09565b91505f615dfe565b909181158015615fcc575b615c21575f925f90838111615e82575b50670de0b6b3a76400009394615e64615e699493613ee993613468565b614da7565b049080821115615e7c5761409c916134e2565b50505f90565b93505090615e9081846134e2565b93670de0b6b3a764000093848102908082048614901517156102dc577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83018381116102dc576140978491615ee493613468565b90848210615f6e577ffffffffffffffffffffffffffffffffffffffffffffffffff21f494c589c000082019182116102dc57615e64615e6994615f6183614097896003615f5989670de0b6b3a76400009d615f4282613ee99d61457a565b0493615f4e828661457a565b049360011c906134e2565b910490613468565b9350939450509493615e47565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f6c6e20756e646566696e656400000000000000000000000000000000000000006044820152fd5b508315615e37560000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e","external_libraries":[],"proxy_type":null,"implementations":[],"verified_at":"2025-12-30T18:28:15.080673Z","is_verified_via_verifier_alliance":false,"compiler_version":"v0.8.22+commit.4fc1097e","decoded_constructor_args":[["0x6b276A2A7dd8b629adBA8A06AD6573d01C84f34E",{"internalType":"address","name":"_protocolConfig","type":"address"}]],"sourcify_repo_url":null,"optimization_runs":999999,"compiler_settings":{"evmVersion":"shanghai","libraries":{},"metadata":{"appendCBOR":false,"bytecodeHash":"none","useLiteralContent":false},"optimizer":{"enabled":true,"runs":999999},"outputSelection":{"*":{"":["*"],"*":["*"]}},"remappings":["forge-std/=lib/forge-std/src/","halmos-cheatcodes/=lib/halmos-cheatcodes/src/","@tokenized-strategy/=lib/tokenized-strategy/src/","@periphery/=lib/tokenized-strategy-periphery/src/","openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/","@openzeppelin/=lib/tokenized-strategy-periphery/lib/openzeppelin-contracts/","@yearn-vaults/=lib/tokenized-strategy-periphery/lib/yearn-vaults-v3/contracts/","createx-forge/=lib/createx-forge/","ds-test/=lib/forge-std/lib/ds-test/src/","erc4626-tests/=lib/tokenized-strategy/lib/erc4626-tests/","openzeppelin-contracts/=lib/tokenized-strategy/lib/openzeppelin-contracts/","openzeppelin/=lib/openzeppelin/","tokenized-strategy-periphery/=lib/tokenized-strategy-periphery/","tokenized-strategy/=lib/tokenized-strategy/","yearn-vaults-v3/=lib/tokenized-strategy-periphery/lib/yearn-vaults-v3/"],"viaIR":true},"is_verified":true,"verified_twin_address_hash":null,"optimization_enabled":true,"deployed_bytecode":"0x60806040526004361015610011575f80fd5b5f3560e01c8063107ddb0314612a7257806313042cac14612a1357806313af4035146129645780631b0cc946146126da5780631e4711cf1461266e5780632c34602d146125ec5780632c3c91571461254f5780633644e51514612514578063370160a01461220e57806346904840146121bd5780634d98a93b146120d457806358e83ce014611bb65780635a64f51e14611af25780635c60e39a14611a545780635e10e65c14611a035780635ec5c10d146118b457806363b0e66a14611863578063653ecd8e146117a357806370ae92d214611740578063772789a8146113525780637784c6851461122257806378c56d65146110f35780638da5cb5b146110a357806393c520621461100d578063986ccc7f14610f8b5780639c4828ca14610f0e578063a0b16cc714610c8c578063b485f3b814610c3f578063c4d66de814610963578063c904d53a146108e1578063ca499989146105df578063e74b981b14610505578063e761c2a514610441578063f2b863ce146103d9578063f5efbb4f1461036b5763fc588422146101a5575f80fd5b346103675760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675767ffffffffffffffff600435602435828111610367576101f8903690600401613413565b9160443584811161036757610211903690600401613413565b9390946064359081116103675761022c903690600401613413565b956102368461435c565b85831480159061035d575b61033357835f52601660205260405f20541561030957835f52601660205260405f2054927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84019384116102dc575f5b81811061029a57005b806102d689878c6102ce856102c6818f6102ba60019b8d6102bf936134ef565b6134ff565b968c6134ef565b35928b6134ef565b35928b6145c4565b01610291565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b60046040517f64ed67af000000000000000000000000000000000000000000000000000000008152fd5b60046040517ff0732dd7000000000000000000000000000000000000000000000000000000008152fd5b5086861415610241565b5f80fd5b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e168152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff6104256131d4565b165f526004602052602060ff60405f2054166040519015158152f35b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576104786131f7565b6004355f52601560205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f5260205260405f2060016105018254926fffffffffffffffffffffffffffffffff9283910154166040519384938160801c91168491604091949360608401956fffffffffffffffffffffffffffffffff9283809216865216602085015216910152565b0390f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675761053c6131d4565b610544614312565b60015473ffffffffffffffffffffffffffffffffffffffff80921691811682146105b5577fffffffffffffffffffffffff00000000000000000000000000000000000000001681176001557f2e979f80fe4d43055c584cf4a8467c55875ea36728fc37176c05acd784eb7a735f80a2005b60046040517fa741a045000000000000000000000000000000000000000000000000000000008152fd5b346103675760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576106173661321a565b61061f614312565b60c0812090606081019173ffffffffffffffffffffffffffffffffffffffff808451165f526020936004855260ff60405f205416156108b7576080840180515f526005865260ff60405f2054161561088d57835f52600386526fffffffffffffffffffffffffffffffff80600260405f2001541661086357845f5260038752600260405f20019042167fffffffffffffffffffffffffffffffff0000000000000000000000000000000082541617905560078652600560405f2084875116927fffffffffffffffffffffffff0000000000000000000000000000000000000000938483541617825560018201868a8a01511685825416179055600282018660408a0151168582541617905560038201868651168582541617905551600482015501908360a08701511690825416179055827f4ddfbf4ac40080d324e78aeea911a6e2fca97d4a6af53c4739d95c6ce079bb4b60c06040516107d1818960a0908173ffffffffffffffffffffffffffffffffffffffff9182815116855282602082015116602086015282604082015116604086015282606082015116606086015260808101516080860152015116910152565ba2511691826107dc57005b6108239284925f526003835260405f20915f6040518096819582947ff3ae2a0f00000000000000000000000000000000000000000000000000000000845260048401613cde565b03925af1801561085857610834575b005b813d8311610851575b6108478183613193565b8101031261036757005b503d61083d565b6040513d5f823e3d90fd5b60046040517fd7d82e58000000000000000000000000000000000000000000000000000000008152fd5b60046040517f61cb7fc0000000000000000000000000000000000000000000000000000000008152fd5b60046040517f068fe9e1000000000000000000000000000000000000000000000000000000008152fd5b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576109186131f7565b6004355f52601860205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f5260205260206fffffffffffffffffffffffffffffffff60405f205416604051908152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675761099a6131d4565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0090815460ff8160401c161567ffffffffffffffff9182811680159081610c37575b6001149081610c2d575b159081610c24575b50610bfa578160017fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000008316178655610bc5575b5083549260ff8460401c1615610b9b5773ffffffffffffffffffffffffffffffffffffffff168015610b715760405160208101907f47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218825246604082015230606082015260608152608081019481861090861117610b445784604052519020600855807fffffffffffffffffffffffff00000000000000000000000000000000000000005f5416175f557f167d3e9c1016ab80e58802ca9da10ce5c6a0f4debc46a2e7a2cd9e56899a4fb55f80a2610af457005b7fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2927fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff60209316905560018152a1005b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60046040517fd92e233d000000000000000000000000000000000000000000000000000000008152fd5b60046040517fd7e6bcf8000000000000000000000000000000000000000000000000000000008152fd5b7fffffffffffffffffffffffffffffffffffffffffffffff000000000000000000166801000000000000000117845584610a21565b60046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b905015866109ee565b303b1591506109e6565b8391506109dc565b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576004355f526005602052602060ff60405f2054166040519015158152f35b3461036757610c9a366132c2565b929082949294829460c0852091825f526003956020958787526fffffffffffffffffffffffffffffffff9081600260405f2001541615610ee457159983158b146103335773ffffffffffffffffffffffffffffffffffffffff938486169b8c15610b7157610d088886613da2565b610ebe575050845f52878752610d2960405f2054828160801c91168b61409f565b975b610d3487614d34565b855f52600288528360405f20971696875f52885260405f20610d578a82546134e2565b9055610dbd610d658a614110565b875f52828a52610d7d60405f2091825460801c6134c0565b6fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b610dc68a614110565b865f5281895260405f20907fffffffffffffffffffffffffffffffff0000000000000000000000000000000084610e018454938285166134c0565b169116179055855f52875260405f20908060018301541691541610610e9457604098610e8a9589957fa56fc0ad5702ec05ce63666221f796fb62437c32db1aa1aa075fc6484cf58fbf8c5180610e808d8b338460409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0390a451166141cc565b8351928352820152f35b60046040517fbb55fd27000000000000000000000000000000000000000000000000000000008152fd5b610ede91999a50865f528a895260405f205490838260801c921690614071565b98610d2b565b60046040517f96e13529000000000000000000000000000000000000000000000000000000008152fd5b346103675760e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757610f463661321a565b60c4359073ffffffffffffffffffffffffffffffffffffffff821682036103675760409181610f7a60c0610f7f942061435c565b613564565b82519182526020820152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff610fd76131d4565b610fdf614312565b167fffffffffffffffffffffffff000000000000000000000000000000000000000060135416176013555f80f35b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576110446131f7565b6004355f52600260205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f52602052606060405f20600181549101546040519182526fffffffffffffffffffffffffffffffff8116602083015260801c6040820152f35b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602073ffffffffffffffffffffffffffffffffffffffff5f5416604051908152f35b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675760043560243567ffffffffffffffff811161036757611145903690600401613413565b825f5260036020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee457825f52600760205260405f20926111e48160405161118981613147565b73ffffffffffffffffffffffffffffffffffffffff80885416825260056001988260018201541660208501528260028201541660408501528260038201541660608501526004810154608085015201541660a0820152613da2565b5f5b8281106111ef57005b8061121c6112026102ba889487896134ef565b61120c8186614731565b611216818661533f565b846151c3565b016111e6565b34610367576020807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675760043567ffffffffffffffff811161036757611272903690600401613413565b9061127c82613520565b9061128a6040519283613193565b82825261129683613520565b927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe085840194013685375f905b80821061130d575050509060405192839281840190828552518091526040840192915f5b8281106112f657505050500390f35b8351855286955093810193928101926001016112e7565b817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146102dc57600161134491019282856134ef565b35548260051b8501526112c3565b346103675760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675760248035906004359067ffffffffffffffff90604435828111610367576113ac903690600401613413565b9290606435828111610367576113c6903690600401613413565b90608435848111610367576113df903690600401613413565b90926113ea8961435c565b808814801590611736575b61033357428a1161170c57885f526020976016895260405f209889545f9a816115b2575b50508a5f526016815260405f2097604051908282019082821090821117611586576040528c8152885468010000000000000000811015611586576114659060019a600182018155613333565b91909161155b5790601692915190558b5f525260405f2054977fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff890198891161153057505f5b8181106114f1575060408051898152602081018b90529081018c90528a907fbd4a7b3b6ad66f13b3e4d519ca7459b576a8bf0a623247d5cecadae2059d8fff90606090a2005b8061152a8c8b8989611523868f988f818d8f936102ba8f916115169261151c966134ef565b966134ef565b35946134ef565b35936145c4565b016114ab565b7f4e487b71000000000000000000000000000000000000000000000000000000005f5260116004525ffd5b8a7f4e487b71000000000000000000000000000000000000000000000000000000005f525f6004525ffd5b8a7f4e487b71000000000000000000000000000000000000000000000000000000005f5260416004525ffd5b90919a507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82019182116116e057906115ea91613333565b5054986040517fbd5da9ac000000000000000000000000000000000000000000000000000000008152818160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e165afa908115610858575f916116b3575b5080151590816116a0575b50611676578c80611419565b60046040517fec682162000000000000000000000000000000000000000000000000000000008152fd5b6116ab91508b613468565b8c108d61166a565b90508181813d83116116d9575b6116ca8183613193565b8101031261036757518d61165f565b503d6116c0565b897f4e487b71000000000000000000000000000000000000000000000000000000005f5260116004525ffd5b60046040517f2a4bbe99000000000000000000000000000000000000000000000000000000008152fd5b50818114156113f5565b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff61178c6131d4565b165f526006602052602060405f2054604051908152f35b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576117da6131f7565b6004355f52601760205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f5260205260405f2060016105018254926fffffffffffffffffffffffffffffffff9283910154166040519384938160801c91168491604091949360608401956fffffffffffffffffffffffffffffffff9283809216865216602085015216910152565b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602073ffffffffffffffffffffffffffffffffffffffff60135416604051908152f35b346103675760e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576118ec3661321a565b60c435906118f8614312565b60c0812091825f5260036020526fffffffffffffffffffffffffffffffff9081600260405f2001541615610ee457835f526003602052600260405f20015460801c81146105b5576703782dace9d9000081116119d9576119d060209261197f867f139d6f58e9a127229667c8e3b36e88890a66cfc8ab1024ddc513e189e125b75b96613da2565b855f52600384528216600260405f2001906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b604051908152a2005b60046040517ff4df6ae5000000000000000000000000000000000000000000000000000000008152fd5b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602073ffffffffffffffffffffffffffffffffffffffff60145416604051908152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576004355f52600360205260e060405f208054906fffffffffffffffffffffffffffffffff906001810154918060036002840154930154169260405194828116865260801c6020860152818116604086015260801c60608501528116608084015260801c60a083015260c0820152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff611b3e6131d4565b611b46614312565b16805f52600460205260ff60405f2054166105b557805f52600460205260405f2060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790557f590e04cdebeccba40f566186b9746ad295a4cd358ea4fefaaea6ce79630d96c05f80a2005b3461036757611bc436613375565b9491938394819560c0852095865f52600393846020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee45715811581146103335773ffffffffffffffffffffffffffffffffffffffff841615610b7157611c288888613da2565b61209a575050845f5281602052611c5d600160405f2001546fffffffffffffffffffffffffffffffff8160801c91168861443a565b945b611c6881614e28565b61207057611c768282614731565b611c80828261533f565b604051927f614bd944000000000000000000000000000000000000000000000000000000008452608093848160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e165afa8015610858576040915f91612043575b50015180611f23575b50611e6a93611d11898585615844565b611db8611d1d89614110565b91845f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff87165f52602052600160405f20016fffffffffffffffffffffffffffffffff611d6c8254958287166134c0565b167fffffffffffffffffffffffffffffffff00000000000000000000000000000000809516179055610d7d611da08b614110565b865f5285602052600160405f2001928354901c6134c0565b825f5281602052611de86fffffffffffffffffffffffffffffffff600160405f200154168a808203911102614110565b91835f526020526fffffffffffffffffffffffffffffffff600160405f200192169082541617905560405187815286602082015273ffffffffffffffffffffffffffffffffffffffff831690827f52acb05cebbd3cd39715469f22afbf5a17496295ef3bc9bb5944056c63ccaa0960403393a4611e6582826151c3565b61533f565b84611e99575b60408484610f7f8273ffffffffffffffffffffffffffffffffffffffff8751163090339061445f565b333b1561036757611edb945f9160405196879283927f05b4591c0000000000000000000000000000000000000000000000000000000084528860048501613475565b038183335af19384156108585773ffffffffffffffffffffffffffffffffffffffff610f7f928592604097611f14575b50925050611e70565b611f1d90613163565b87611f0b565b825f528160205288611ff360405f2087604051611f3f8161312b565b82546fffffffffffffffffffffffffffffffff81168252821c602082015260c06fffffffffffffffffffffffffffffffff886001860154956040850196838116885260608601961c86528d600282015490848216818801521c60a0860152015416910152865f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff89165f526020526fffffffffffffffffffffffffffffffff8080600160405f2001541693511691511691614417565b818111612002575b5050611d01565b9061200c916134e2565b1061201957898881611ffb565b60046040517f92684f93000000000000000000000000000000000000000000000000000000008152fd5b6120639150863d8811612069575b61205b8183613193565b8101906140c1565b8b611cf8565b503d612051565b60046040517fb2ce2a93000000000000000000000000000000000000000000000000000000008152fd5b866120ce929798505f5283602052600160405f200154906fffffffffffffffffffffffffffffffff8260801c921690614417565b95611c5f565b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675760043561210e614312565b805f52600560205260ff60405f2054166105b557670de0b6b3a7640000811015612193576020817f297b80e7a896fad470c630f6575072d609bde997260ff3db851939405ec29139925f526005825260405f2060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00825416179055604051908152a1005b60046040517fc9600612000000000000000000000000000000000000000000000000000000008152fd5b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261036757602073ffffffffffffffffffffffffffffffffffffffff60015416604051908152f35b346103675761221c36613375565b8394939291849560c08820805f52602095600387526fffffffffffffffffffffffffffffffff9788600260405f2001541615610ee4571592801584146103335773ffffffffffffffffffffffffffffffffffffffff809716938415610b7157612285848d613da2565b6124ed575050805f52600386526122a760405f2054888160801c91168a61443a565b965b856014541633036124c3576040517ff2a6f21500000000000000000000000000000000000000000000000000000000815287816004818a7f0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e165afa908115610858575f91612496575b5061246c57815f526002875260405f20835f52875260405f20612336898254613468565b905561235d61234489614110565b835f5260038952610d7d60405f2091825460801c613444565b61236689614110565b825f52600388527fffffffffffffffffffffffffffffffff0000000000000000000000000000000060405f20926123a1845493828516613444565b1691161790556040519088825287878301527fedf8870433c83823eb071d3df1caa8d008f12f6440918c20d75a3602cda30fe060403393a4816123f4575b505083610e8a9160409651163090339061445f565b919091333b1561036757612439925f9160405194859283927f2075be030000000000000000000000000000000000000000000000000000000084528a60048501613475565b038183335af190811561085857604096610e8a93879361245d575b509650916123df565b61246690613163565b88612454565b60046040517f9e87fac8000000000000000000000000000000000000000000000000000000008152fd5b90508781813d83116124bc575b6124ad8183613193565b8101031261036757518b612312565b503d6124a3565b60046040517f2e29d74a000000000000000000000000000000000000000000000000000000008152fd5b61250e91989950825f526003885260405f2054908a8260801c921690614417565b976122a9565b34610367575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576020600854604051908152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576004355f52600760205260c060405f2073ffffffffffffffffffffffffffffffffffffffff80825416918160018201541691806002830154168160038401541691600560048501549401541693604051958652602086015260408501526060840152608083015260a0820152f35b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675773ffffffffffffffffffffffffffffffffffffffff6126386131d4565b612640614312565b167fffffffffffffffffffffffff000000000000000000000000000000000000000060145416176014555f80f35b346103675760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576126a63661321a565b60c08120805f5260036020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee45761083291613da2565b346103675760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576004356127146131f7565b90604435916064356fffffffffffffffffffffffffffffffff808216809203610367576127408461435c565b73ffffffffffffffffffffffffffffffffffffffff91828416958615610b71577f98ae8997910895a35e546cf84a1f3c82ee4f89894401f773132427e8a24a5ec394612873876040968a827f0ebab34b6b7a4a637f38ab2b80f568ef92cdf83472f4ddb4051f81f316320bea876127b961281599614110565b90835f526020998a92600284528e5f20875f52845260018f5f2001906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b8c51908152a3815f5260078552875f2090600589519261283484613147565b8281541684528260018201541688850152826002820154168b8501528260038201541660608501526004810154608085015201541660a0820152613da2565b865f5260028252845f20885f528252836001865f20015416151580612955575b875f5260158352855f20895f5283526129256128b0875f206143da565b85858201978851169752895f5260158552875f208b5f528552875f208151602083015160801b7fffffffffffffffffffffffffffffffff000000000000000000000000000000009081166fffffffffffffffffffffffffffffffff928316178355916040906001019301511690825416179055565b8061294c575b61293c575b508351928352820152a3005b61294690876151c3565b87612930565b5082151561292b565b61295f8289614731565b612893565b346103675760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103675761299b6131d4565b6129a3614312565b5f5473ffffffffffffffffffffffffffffffffffffffff80921691811682146105b5577fffffffffffffffffffffffff0000000000000000000000000000000000000000829116175f557f167d3e9c1016ab80e58802ca9da10ce5c6a0f4debc46a2e7a2cd9e56899a4fb55f80a2005b346103675760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610367576024356004355f52601660205260405f20805482101561036757602091612a6891613333565b5054604051908152f35b3461036757612a80366132c2565b928293819460c0872092835f5260036020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee4571594801586146103335773ffffffffffffffffffffffffffffffffffffffff8316958615610b7157612ae3858a613da2565b6130f0575050815f526003602052612b19600160405f2001546fffffffffffffffffffffffffffffffff8160801c91168761409f565b935b73ffffffffffffffffffffffffffffffffffffffff6013541633036130c65773ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e16966040517ff2a6f2150000000000000000000000000000000000000000000000000000000081526020816004818c5afa908115610858575f91613094575b5061246c57612bbd84614e28565b61207057612bcb8585614f46565b5060048110156130675761303d57612be38585614731565b6040517fcc718f760000000000000000000000000000000000000000000000000000000081527f4dc3aed3c9d2d8f55e7befc9c664516bd7ff894dca4521a6c8d71cbce4e9c37660048201526020816024818c5afa908115610858575f9161300b575b508015908115612fd7575b50612fad5760405180987f614bd94400000000000000000000000000000000000000000000000000000000825281600460809b8c935afa8015610858576040915f91612f90575b50015180612eba575b50861580612eb1575b612e8757612cb786614110565b845f526002602052612d5860405f209973ffffffffffffffffffffffffffffffffffffffff88169a8b5f52602052600160405f20016fffffffffffffffffffffffffffffffff612d0b825495828716613444565b167fffffffffffffffffffffffffffffffff00000000000000000000000000000000809516179055610d7d612d3f8a614110565b885f526003602052600160405f2001928354901c613444565b612d6188614110565b855f526003602052600160405f2001916fffffffffffffffffffffffffffffffff612d90845493828516613444565b169116179055612da085856150db565b15612e5d57835f52600360205260405f206fffffffffffffffffffffffffffffffff8060018301541691541610610e9457612e56610f7f958573ffffffffffffffffffffffffffffffffffffffff9460409b8b987f570954540bed6b1304a87dfe815a5eda4a648f7097a16240dcd85c9b5fd42a438c8f612e4e8d9151928392338460409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0390a46151c3565b51166141cc565b60046040517f3a23d825000000000000000000000000000000000000000000000000000000008152fd5b60046040517f1abfe8a7000000000000000000000000000000000000000000000000000000008152fd5b50851515612caa565b845f526003602052612f8588612f8060405f208c6fffffffffffffffffffffffffffffffff600360405193612eee8561312b565b80548381168652841c602086015260018101549383851660408701526060860194811c8552600282015490848216818801521c60a086015201541660c0830152895f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff8c165f526020526fffffffffffffffffffffffffffffffff806040816001825f200154169401511691511691614417565b613468565b106120195788612ca1565b612fa791508a3d8c116120695761205b8183613193565b8a612c98565b60046040517f7db9106f000000000000000000000000000000000000000000000000000000008152fd5b9050845f526003602052613004886fffffffffffffffffffffffffffffffff600160405f20015416613468565b1189612c51565b90506020813d602011613035575b8161302660209383613193565b81010312610367575189612c46565b3d9150613019565b60046040517feb39f13b000000000000000000000000000000000000000000000000000000008152fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b90506020813d6020116130be575b816130af60209383613193565b81010312610367575189612baf565b3d91506130a2565b60046040517f96e31905000000000000000000000000000000000000000000000000000000008152fd5b61312591959650835f526003602052600160405f200154906fffffffffffffffffffffffffffffffff8260801c921690614071565b94612b1b565b60e0810190811067ffffffffffffffff821117610b4457604052565b60c0810190811067ffffffffffffffff821117610b4457604052565b67ffffffffffffffff8111610b4457604052565b6060810190811067ffffffffffffffff821117610b4457604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117610b4457604052565b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361036757565b6024359073ffffffffffffffffffffffffffffffffffffffff8216820361036757565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60c0910112610367576040519061325182613147565b73ffffffffffffffffffffffffffffffffffffffff826004358281168103610367578152602435828116810361036757602082015260443582811681036103675760408201526064358281168103610367576060820152608435608082015260a43591821682036103675760a00152565b6101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc820112610367576132f69061321a565b9060c4359060e4359073ffffffffffffffffffffffffffffffffffffffff9061010435828116810361036757916101243590811681036103675790565b8054821015613348575f5260205f2001905f90565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b906101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc830112610367576133aa8261321a565b9160c4359160e435916101043573ffffffffffffffffffffffffffffffffffffffff8116810361036757916101243567ffffffffffffffff9283821161036757806023830112156103675781600401359384116103675760248483010111610367576024019190565b9181601f840112156103675782359167ffffffffffffffff8311610367576020808501948460051b01011161036757565b9190916fffffffffffffffffffffffffffffffff808094169116019182116102dc57565b919082018092116102dc57565b9183606094601f927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe094865260406020870152816040870152868601375f8582860101520116010190565b6fffffffffffffffffffffffffffffffff91821690821603919082116102dc57565b919082039182116102dc57565b91908110156133485760051b0190565b3573ffffffffffffffffffffffffffffffffffffffff811681036103675790565b67ffffffffffffffff8111610b445760051b60200190565b90816020910312610367575173ffffffffffffffffffffffffffffffffffffffff811681036103675790565b909161357460c083208093613da2565b61357e8383614731565b815f526002916020838152604091825f209273ffffffffffffffffffffffffffffffffffffffff80971693845f5283526fffffffffffffffffffffffffffffffff956001908782845f20015416978815613a1f57845f52600392838752613636855f2086516135ec8161312b565b8154858116825260801c8a820152838201549060c0868981851694858d86015260801c958660608601528a810154838116608087015260801c60a08601520154169101528c614417565b9a865f5260078852600488826005895f200154168851928380927fe90eaa510000000000000000000000000000000000000000000000000000000082525afa908115613a15575f916139e8575b5016878161396a575b5050855f5260188752845f20885f5287528180865f20541691875f52848952865f208a5f52895280875f2001947fffffffffffffffffffffffffffffffff0000000000000000000000000000000095868154169055885f528952865f208a5f52895280875f2001828154169055875f5260188952865f208a5f528952865f205f9055875f5260178952865f208a5f52895280875f205f8155015f9055875f5260158952865f208a5f52895280875f205f8155015f9055875f528589528c828d838a5f20015460801c9061375e916134e2565b61376790614110565b8a5f52888c52838a5f2001906137b99082906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b5416906137c5916134e2565b6137ce90614110565b885f52868a5282885f2092830191168682541617905554166137f08c83614cf0565b905f8213156138a95761382c7f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce97969594939261383192613468565b614110565b875f5284895282865f209116848254161790555b8061385e575b50505050868151948986528501523393a4565b865f528388528184865f200154168181115f146138a0576138829161382c916134e2565b925b865f52808852845f20019216908254161790555f80808061384b565b50505f92613884565b905f81126138df575b5050907f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce94939291613845565b6138e890614d08565b908181106139415761382c7f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce979695949392613923926134e2565b875f5284895282865f2091168482541617905590919293945f6138b2565b600487517fbb55fd27000000000000000000000000000000000000000000000000000000008152fd5b5f9160248b895194859384927fbd49979d00000000000000000000000000000000000000000000000000000000845260048401525af180156139de579088916139b5575b508061368c565b813d83116139d7575b6139c88183613193565b8101031261036757865f6139ae565b503d6139be565b86513d5f823e3d90fd5b613a089150893d8b11613a0e575b613a008183613193565b810190613538565b5f613683565b503d6139f6565b87513d5f823e3d90fd5b98509091928094959697505f5260188552825f20865f52855287835f20541697845f52818652835f20875f52865282845f2001917fffffffffffffffffffffffffffffffff0000000000000000000000000000000092838154169055855f528652835f20875f52865282845f2001818154169055845f5260188652835f20875f5286525f84812055845f5260178652835f20875f5286525f838582208281550155845f5260158652835f20875f5286525f838582208281550155845f5280600393848852613b5082613af883895f20015460801c614110565b895f52878b52613b49848a5f20019182906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b5416614110565b875f5285895282875f209283019116858254161790555416985f81135f14613c2057613ba461382c827f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce98999a9b9c613468565b875f5284895282865f209116848254161790555b80613bd5575b505050505f8151948186528501523393a45f905f90565b865f528388528184865f200154168181115f14613c1757613bf99161382c916134e2565b925b865f52808852845f20019216908254161790555f808080613bbe565b50505f92613bfb565b5f8112613c54575b7f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce959697989950613bb8565b613c5d81614d08565b998a8110613cb55761382c7f9a818da8acec89bc538114164065c0111126cc2b0da357a65bff980e3c9e79ce9798999a9b613c97926134e2565b875f5284895282865f20911684825416179055899897969550613c28565b600486517fbb55fd27000000000000000000000000000000000000000000000000000000008152fd5b90929161018090613d45836101a081019660a0908173ffffffffffffffffffffffffffffffffffffffff9182815116855282602082015116602086015282604082015116604086015282606082015116606086015260808101516080860152015116910152565b60038154916fffffffffffffffffffffffffffffffff9283811660c087015260801c60e0860152600181015483811661010087015260801c610120860152600281015483811661014087015260801c610160860152015416910152565b815f526003916020928084526fffffffffffffffffffffffffffffffff93604092613dd5866002865f20015416426134e2565b80156140685773ffffffffffffffffffffffffffffffffffffffff958660608201511680613e37575b505050600294505f52525f20019042167fffffffffffffffffffffffffffffffff00000000000000000000000000000000825416179055565b613e7d92918591855f52878352885f20915f8a518097819582947ff3ae2a0f00000000000000000000000000000000000000000000000000000000845260048401613cde565b03925af19182156139de57908892915f92614036575b50917f9d9bd501d0657d7dfe415f779a620a62b78bc508ddc0891fbbd8b7ac0f8fce8791613fa1613ee98960029b8a8a8a998a5f52828252613eef896001875f20015416670de0b6b3a76400009788938b614da7565b9061457a565b0497613efa89614110565b8b5f528383526001865f200182613f15825493828516613444565b167fffffffffffffffffffffffffffffffff00000000000000000000000000000000809316179055613f468a614110565b8c5f52848452865f209183613f5f845493828516613444565b1691161790555f948b5f528383526002815f20015460801c9687613fac575b509495505050505051938493846040919493926060820195825260208201520152565b0390a25f8080613dfe565b613fe49650613fc0613fd19596988c61457a565b049485938d5f52525f2054166134e2565b885f528b8b528c5f205460801c9161443a565b90865f528b89528a5f2090600154165f528852895f20614005828254613468565b905561402a61401382614110565b875f528a8a52610d7d8c5f2091825460801c613444565b805f8a8a8f8e84613f7e565b85809294508193503d8311614061575b6140508183613193565b810103126103675751879183613e93565b503d614046565b50505050505050565b60018201929183106102dc57620f424082018092116102dc5761409c926140979161457a565b61458d565b90565b91620f424081018091116102dc57600182018092116102dc5761409c92614de5565b908160809103126103675760405190608082019082821067ffffffffffffffff831117610b44576060916040528051835260208101516020840152604081015160408401520151606082015290565b6fffffffffffffffffffffffffffffffff9081811161412d571690565b60046040517f6acc9c8f000000000000000000000000000000000000000000000000000000008152fd5b3d156141af573d9067ffffffffffffffff8211610b4457604051916141a460207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8401160184613193565b82523d5f602084013e565b606090565b90816020910312610367575180151581036103675790565b90919073ffffffffffffffffffffffffffffffffffffffff16803b156142e8576040517fa9059cbb000000000000000000000000000000000000000000000000000000006020820190815273ffffffffffffffffffffffffffffffffffffffff9490941660248201526044808201939093529182525f9283928390614252606482613193565b51925af161425e614157565b90156142be5780519081151591826142a3575b505061427957565b60046040517f2f0470fc000000000000000000000000000000000000000000000000000000008152fd5b6142b692506020809183010191016141b4565b155f80614271565b60046040517face2a47e000000000000000000000000000000000000000000000000000000008152fd5b60046040517ff046a714000000000000000000000000000000000000000000000000000000008152fd5b73ffffffffffffffffffffffffffffffffffffffff5f5416330361433257565b60046040517f30cd7471000000000000000000000000000000000000000000000000000000008152fd5b805f5260036020526fffffffffffffffffffffffffffffffff600260405f2001541615610ee4575f52600760205273ffffffffffffffffffffffffffffffffffffffff600560405f2001541633036143b057565b60046040517f0f7f7bcd000000000000000000000000000000000000000000000000000000008152fd5b906040516143e781613177565b6040819360018154916fffffffffffffffffffffffffffffffff92838116865260801c6020860152015416910152565b9190600181018091116102dc57620f424082018092116102dc5761409c92614de5565b620f424083018093116102dc57600182018092116102dc5761409c926140979161457a565b909273ffffffffffffffffffffffffffffffffffffffff80921691823b156142e857604051938160208601967f23b872dd00000000000000000000000000000000000000000000000000000000885216602486015216604484015260648301526064825260a082019282841067ffffffffffffffff851117610b44575f809493819460405251925af16144f0614157565b9015614550578051908115159182614535575b505061450b57565b60046040517f1eded19c000000000000000000000000000000000000000000000000000000008152fd5b61454892506020809183010191016141b4565b155f80614503565b60046040517fe65b7a77000000000000000000000000000000000000000000000000000000008152fd5b818102929181159184041417156102dc57565b8115614597570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b92909391612710808211614707577f9492bafec7fdce8259c23f7dec34550603e9a6de90e2b2a9b21eb69337896af8936146e991865f5260176020526146ce60409173ffffffffffffffffffffffffffffffffffffffff835f209a16998a5f5260205261463c614635845f206143da565b968561457a565b0494602081016fffffffffffffffffffffffffffffffff80825116156146ee575b87169052885f526017602052825f208a5f52602052825f208151602083015160801b7fffffffffffffffffffffffffffffffff000000000000000000000000000000009081166fffffffffffffffffffffffffffffffff928316178355916040906001019301511690825416179055565b51938493846040919493926060820195825260208201520152565b0390a3565b8089168352806146fd87614110565b168584015261465d565b60046040517f11fff5a0000000000000000000000000000000000000000000000000000000008152fd5b61473b8282614f46565b50815f52601560205260405f2073ffffffffffffffffffffffffffffffffffffffff84165f5260205261477060405f206143da565b906fffffffffffffffffffffffffffffffff6020830151161580614cdf575b614cd957825f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff85165f526020526fffffffffffffffffffffffffffffffff600160405f2001541615614cd9576148ce816148c46148d494865f5260036020526148ba60405f20604051906148018261312b565b80546fffffffffffffffffffffffffffffffff8116835260801c60208301526fffffffffffffffffffffffffffffffff60036001830154928284166040860152606085019360801c84526002810154838116608087015260801c60a086015201541660c0830152895f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff8c165f526020526fffffffffffffffffffffffffffffffff806040816001825f200154169401511691511691614417565b9485918989615910565b9283918787615a9f565b90613468565b60018110614cd457815f52600360205260405f206fffffffffffffffffffffffffffffffff6149e26149d66149626040519461490f8661312b565b8054858116875260801c602087015284600360018301549282841660408a01528360801c60608a0152600281015483811660808b015260801c60a08a015201541660c0870152848160801c91168761409f565b61496b81614110565b875f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff8a165f52602052600160405f2001907fffffffffffffffffffffffffffffffff00000000000000000000000000000000866149cb845493828516613444565b169116179055614110565b82606085015116613444565b1660608201526fffffffffffffffffffffffffffffffff614a11614a0584614110565b82604085015116613444565b1660408201526fffffffffffffffffffffffffffffffff614a3d614a3484614110565b82845116613444565b1681525f906fffffffffffffffffffffffffffffffff60a08201511680614c2f575b505f84815260036020818152604090922083519284015160801b7fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff93841617815560c09190604085015160608601517fffffffffffffffffffffffffffffffff0000000000000000000000000000000090861660801b169085166fffffffffffffffffffffffffffffffff1617600182015560808581015160a08701516fffffffffffffffffffffffffffffffff9187169190911690861690911b7fffffffffffffffffffffffffffffffff000000000000000000000000000000001617600282015501920151167fffffffffffffffffffffffffffffffff000000000000000000000000000000008254161790556040519182526020820152817f090eee6ac5af73cf4534c51b1be6693f7fae2db8acd16126d8ad373dc78188c6604073ffffffffffffffffffffffffffffffffffffffff861693a35f52601560205273ffffffffffffffffffffffffffffffffffffffff60405f2091165f5260205260405f206fffffffffffffffffffffffffffffffff42167fffffffffffffffffffffffffffffffff00000000000000000000000000000000825416179055565b670de0b6b3a7640000919250614c45908461457a565b04906fffffffffffffffffffffffffffffffff614cc8614cbc614c7c614c6e86858751166134e2565b84602087015116908761443a565b875f52600260205260405f2073ffffffffffffffffffffffffffffffffffffffff600154165f5260205260405f20614cb5828254613468565b9055614110565b82602085015116613444565b1660208201525f614a5f565b505050565b50505050565b50600481101561306757801561478f565b81810392915f1380158285131691841216176102dc57565b7f800000000000000000000000000000000000000000000000000000000000000081146102dc575f0390565b73ffffffffffffffffffffffffffffffffffffffff80601454163314614da3578060015416908133149283614d97575b505050614d955760046040517f2e29d74a000000000000000000000000000000000000000000000000000000008152fd5b565b161490505f8080614d64565b5050565b61409c91614db49161457a565b612f80671bc16d674ec80000614dca838061457a565b046729a2241af62c0000614dde848361457a565b0492613468565b90614def9161457a565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101918183116102dc5761409c9261409791613468565b805f5260206016815260405f205491604051917fbd5da9ac000000000000000000000000000000000000000000000000000000008352808360048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e165afa928315610858575f93614f17575b5083158015614f0f575b614f06576016915f525260405f207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83019283116102dc57614f0092614ef991613333565b5054613468565b42101590565b50505050600190565b508215614eb4565b9080935081813d8311614f3f575b614f2f8183613193565b810103126103675751915f614eaa565b503d614f25565b90815f5260209060178252604092835f2073ffffffffffffffffffffffffffffffffffffffff8093165f528352614f7e845f206143da565b906fffffffffffffffffffffffffffffffff90818584015116156150cf5781835116815f5260168652865f205411156150a657600492608092614fcd925f5260168752875f2091511690613333565b5054928551928380927f614bd9440000000000000000000000000000000000000000000000000000000082527f0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e165afa93841561509d57505f9361507c575b50615038835182613468565b42111561507257825161504a91613468565b9101615057815183613468565b421061506c575161506791613468565b600391565b50600291565b9291505060019190565b61509691935060803d6080116120695761205b8183613193565b915f61502c565b513d5f823e3d90fd5b600486517f11baffb2000000000000000000000000000000000000000000000000000000008152fd5b5050505050505f905f90565b90815f52600260205260409073ffffffffffffffffffffffffffffffffffffffff825f2091165f52602052805f2091600182519361511885613177565b805485520154926fffffffffffffffffffffffffffffffff92838516816020840193828552019560801c8652156151b9576151b1925f52600360205283815f209282516151648161312b565b8454838116825260801c602082015260c08360036001880154828116809886015260801c978860608601526002810154838116608087015260801c60a08601520154169101525116614417565b915116101590565b5050505050600190565b614d9591815f526020906015825260409173ffffffffffffffffffffffffffffffffffffffff835f20921691825f5281526151ff835f206143da565b93805f5260038252835f206152b161529c86519261521c8461312b565b8054936fffffffffffffffffffffffffffffffff94858116825260801c8782015260018201549060c08660038c8401958286168752606085019560801c86526002810154838116608087015260801c60a0860152015416910152855f5260028752885f20885f52875284808060018c5f2001541693511691511691614417565b82885116158015615328575b61531e57614110565b16848601525f5260158152825f20915f52525f208151602083015160801b7fffffffffffffffffffffffffffffffff000000000000000000000000000000009081166fffffffffffffffffffffffffffffffff928316178355916040906001019301511690825416179055565b8242168852614110565b508287890151161580156152a857508015156152a8565b5f815f526020926007845273ffffffffffffffffffffffffffffffffffffffff9380604092866005855f200154168451938480927fe90eaa5100000000000000000000000000000000000000000000000000000000825260049687915afa90811561583a579088915f9161581d575b50169283156154b057865f5260188352845f2097821697885f5283526fffffffffffffffffffffffffffffffff9182865f205416946153ed828a614f46565b90848110156157f157600314959493929190888a8c8e8a6157e7575b8b158b806157e0575b15615794575050505050813b156103675788517fcb6b88550000000000000000000000000000000000000000000000000000000081528c858201525f8160248183875af1801561578a57918d918d9361576b575b5091818c938c969593837f28bb2b50e85ab8cb3028aa7ee85d6a0e4f8ae610956f2d4d09b62c7450f11df88c8a51858152a35b849a615540575b50505050505050508383036154ba575b5050505050505050565b8486887fdfc0c058da6e22e40bf226987ffd5316a213e4ad1ec60802bc07aef3f75a76a198526018845220885f528252845f209083167fffffffffffffffffffffffffffffffff0000000000000000000000000000000082541617905561552a6155248484614cf0565b87615c35565b8351928352820152a35f808080808080806154b0565b879a50966156446155ea8b948b899a9b958c9a968042115f146157615761556790426134e2565b9c8d9a5b84815260038a528181209482516155818161312b565b8654868116825260801c8c82015260c0600188015496600386840199828a168b52606085019960801c8a526002810154838116608087015260801c60a0860152015416910152815260028a5220905f5287528c808060018d5f2001541693511691511691614417565b9889975197889485947f49190203000000000000000000000000000000000000000000000000000000008652850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0381845afa92831561575757908792918c94615723575b5083948c6156ba959a8d51968795869485937f852be02900000000000000000000000000000000000000000000000000000000855284016020909392919373ffffffffffffffffffffffffffffffffffffffff60408201951681520152565b03925af180156157195783929186916156ea575b5050116156e2575b858188818b8d826154a0565b92505f6156d6565b90809293503d8311615712575b6157018183613193565b81010312610367578190845f6156ce565b503d6156f7565b88513d8b823e3d90fd5b8381949295503d8311615750575b61573b8183613193565b81010312610367576156ba928792519361565b565b503d615731565b8a513d8d823e3d90fd5b50899c8d9a61556b565b8b9594929c5061577c919350613163565b8b5f9b919394929092615466565b8a513d5f823e3d90fd5b8b9796949795919293951590816157d7575b50156154995781837ffcba921102de188664e72818df26311ac84b9f31348028598cbaaf8801d422e55f80a3615499565b9050155f6157a6565b5080615412565b8415159a50615409565b6021857f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b6158349150843d8611613a0e57613a008183613193565b5f6153ae565b85513d5f823e3d90fd5b9091815f52601760205260409073ffffffffffffffffffffffffffffffffffffffff825f20941693845f52602052815f205460801c80156159095781106158e057907f9f3566c9415b4b8515c473fc1ef06cb3271e69346db61e985f9a223f1f81844b91835f526017602052815f20855f52602052815f206fffffffffffffffffffffffffffffffff815416905581519081525f6020820152a3565b600482517f9efe3019000000000000000000000000000000000000000000000000000000008152fd5b5050505050565b939092916fffffffffffffffffffffffffffffffff9061593382825116426134e2565b948515615a94576301e13380808711615a8c575b5082602083015116946004811015613067578015159081615a80575b50615979575b5061409c95506040015116615e2c565b60806159cc886004995f52601760205260405f2073ffffffffffffffffffffffffffffffffffffffff8095165f526020526159b660405f206143da565b905f5260166020528560405f2091511690613333565b505491604051988980927f614bd9440000000000000000000000000000000000000000000000000000000082527f0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e165afa9081156108585761409c975f92615a5f575b50615a408484511691835190613468565b101561596957604091946060615a5892015190613468565b9390615969565b615a7991925060803d6080116120695761205b8183613193565b905f615a2f565b6001915014155f615963565b95505f615947565b505050505050505f90565b929193909360048110156130675760028114159081615c29575b50615c2157600490835f5260156020526040805f209073ffffffffffffffffffffffffffffffffffffffff80971691825f52602052615af9815f206143da565b91865f526017602052815f20905f52602052615b16815f206143da565b955f526016602052805f20916080615b436fffffffffffffffffffffffffffffffff94858a511690613333565b5054988351968780927f614bd9440000000000000000000000000000000000000000000000000000000082527f0000000000000000000000006b276a2a7dd8b629adba8a06ad6573d01c84f34e165afa948515615c17575f95615bf4575b5082905116615bb1855189613468565b10615a9457615bc361409c97426134e2565b956301e13380808811615beb575b5001511692606091615be291613468565b91015191615e2c565b96506060615bd1565b83919550615c109060803d6080116120695761205b8183613193565b9490615ba1565b82513d5f823e3d90fd5b505050505f90565b6003915014155f615ab9565b908015614da357815f52600360205260405f209060405191615c568361312b565b8054926fffffffffffffffffffffffffffffffff9283928386168352602083019560801c865283600182015484604081018383168152606082019260801c835283600286015493816080850197818716895260a086019660801c875260030154169c60c085019d8e528d5f8a135f149b615dcc9a615d7b9760039e615de1578161382c9184615d05949281835116809111615dd9575b61382c84615cf9926134e2565b16905283855116613468565b1690525b5f90815260208b90526040902098519b516fffffffffffffffffffffffffffffffff9c83168d16908316608090811b7fffffffffffffffffffffffffffffffff00000000000000000000000000000000908116929092178b5593519151918316909c16911690911b8a16176001870155565b81600286019351168884541617835551166fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b0192511690825416179055565b925082615cec565b61382c90615df1615e1c93614d08565b9084865116808311615e24575b5084615e1061382c8483855116613468565b169052838551166134e2565b169052615d09565b91505f615dfe565b909181158015615fcc575b615c21575f925f90838111615e82575b50670de0b6b3a76400009394615e64615e699493613ee993613468565b614da7565b049080821115615e7c5761409c916134e2565b50505f90565b93505090615e9081846134e2565b93670de0b6b3a764000093848102908082048614901517156102dc577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83018381116102dc576140978491615ee493613468565b90848210615f6e577ffffffffffffffffffffffffffffffffffffffffffffffffff21f494c589c000082019182116102dc57615e64615e6994615f6183614097896003615f5989670de0b6b3a76400009d615f4282613ee99d61457a565b0493615f4e828661457a565b049360011c906134e2565b910490613468565b9350939450509493615e47565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f6c6e20756e646566696e656400000000000000000000000000000000000000006044820152fd5b508315615e3756","source_code":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity 0.8.22;\n\nimport {\n    Id,\n    MarketParams,\n    Position,\n    Market,\n    BorrowerPremium,\n    RepaymentStatus,\n    PaymentCycle,\n    RepaymentObligation,\n    MarkdownState,\n    IMorphoCredit\n} from \"./interfaces/IMorpho.sol\";\nimport {IMarkdownController} from \"./interfaces/IMarkdownController.sol\";\nimport {IERC20} from \"./interfaces/IERC20.sol\";\nimport {IProtocolConfig, MarketConfig} from \"./interfaces/IProtocolConfig.sol\";\nimport {ProtocolConfigLib} from \"./libraries/ProtocolConfigLib.sol\";\nimport {ICreditLine} from \"./interfaces/ICreditLine.sol\";\nimport {Morpho} from \"./Morpho.sol\";\n\nimport {UtilsLib} from \"./libraries/UtilsLib.sol\";\nimport {EventsLib} from \"./libraries/EventsLib.sol\";\nimport {ErrorsLib} from \"./libraries/ErrorsLib.sol\";\nimport {MathLib} from \"./libraries/MathLib.sol\";\nimport {MarketParamsLib} from \"./libraries/MarketParamsLib.sol\";\nimport {SharesMathLib} from \"./libraries/SharesMathLib.sol\";\nimport {SafeTransferLib} from \"./libraries/SafeTransferLib.sol\";\n\n/// @title Morpho Credit\n/// @author 3Jane\n/// @custom:contact support@3jane.xyz\n/// @notice The Morpho Credit contract extends Morpho with credit-based lending and per-borrower risk premiums.\n/// @dev This contract implements a three-tier interest accrual system:\n///\n/// **Interest Rate Components:**\n/// 1. Base Rate: Market-wide rate from the IRM, applied to all borrowers\n/// 2. Premium Rate: Per-borrower risk premium based on creditworthiness\n/// 3. Penalty Rate: Additional rate when borrower is delinquent (past grace period)\n///\n/// **Accrual Process Flow:**\n/// ```\n/// Market Interest (continuous) → Base Rate Growth\n///                                      ↓\n/// Borrower Premium Accrual → Premium on top of base\n///                                      ↓\n/// Delinquency Check → If delinquent, add penalty rate\n/// ```\n/// - Using ending balance for penalty calculations\ncontract MorphoCredit is Morpho, IMorphoCredit {\n    using UtilsLib for uint256;\n    using MarketParamsLib for MarketParams;\n    using SharesMathLib for uint256;\n    using MathLib for uint256;\n    using SafeTransferLib for IERC20;\n\n    /* STATE VARIABLES */\n\n    /// @inheritdoc IMorphoCredit\n    address public helper;\n\n    /// @notice Immutable protocol configuration contract\n    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable\n    address public immutable protocolConfig;\n\n    /// @inheritdoc IMorphoCredit\n    address public usd3;\n\n    /// @inheritdoc IMorphoCredit\n    mapping(Id => mapping(address => BorrowerPremium)) public borrowerPremium;\n\n    /// @notice Payment cycles for each market\n    mapping(Id => PaymentCycle[]) public paymentCycle;\n\n    /// @notice Repayment obligations for each borrower in each market\n    mapping(Id => mapping(address => RepaymentObligation)) public repaymentObligation;\n\n    /// @notice Markdown state for tracking defaulted debt value reduction\n    mapping(Id => mapping(address => MarkdownState)) public markdownState;\n\n    /// @dev Storage gap for future upgrades (14 slots).\n    uint256[14] private __gap;\n\n    /* CONSTANTS */\n\n    uint256 internal constant MIN_PREMIUM_THRESHOLD = 1;\n\n    /// @notice Maximum elapsed time for premium accrual (365 days)\n    uint256 internal constant MAX_ELAPSED_TIME = 365 days;\n\n    /// @notice Maximum basis points (100%)\n    uint256 internal constant MAX_BPS = 10000;\n\n    /* INITIALIZER */\n\n    /// @custom:oz-upgrades-unsafe-allow constructor\n    constructor(address _protocolConfig) {\n        if (_protocolConfig == address(0)) revert ErrorsLib.ZeroAddress();\n        protocolConfig = _protocolConfig;\n        _disableInitializers();\n    }\n\n    /// @dev Initializes the MorphoCredit contract.\n    /// @param newOwner The initial owner of the contract.\n    function initialize(address newOwner) external initializer {\n        __Morpho_init(newOwner);\n    }\n\n    /* ADMIN FUNCTIONS */\n\n    /// @inheritdoc IMorphoCredit\n    function setHelper(address newHelper) external onlyOwner {\n        helper = newHelper;\n    }\n\n    /// @inheritdoc IMorphoCredit\n    function setUsd3(address newUsd3) external onlyOwner {\n        usd3 = newUsd3;\n    }\n\n    /* EXTERNAL FUNCTIONS - PREMIUM MANAGEMENT */\n\n    /// @inheritdoc IMorphoCredit\n    function accruePremiumsForBorrowers(Id id, address[] calldata borrowers) external {\n        if (market[id].lastUpdate == 0) revert ErrorsLib.MarketNotCreated();\n        MarketParams memory marketParams = idToMarketParams[id];\n        _accrueInterest(marketParams, id);\n        for (uint256 i = 0; i < borrowers.length; i++) {\n            _accrueBorrowerPremiumAndUpdate(id, borrowers[i]);\n        }\n    }\n\n    /// @dev Internal helper to accrue premium and update borrower state\n    function _accrueBorrowerPremiumAndUpdate(Id id, address borrower) internal {\n        _accrueBorrowerPremium(id, borrower);\n        _updateBorrowerMarkdown(id, borrower);\n        _snapshotBorrowerPosition(id, borrower);\n    }\n\n    /* INTERNAL FUNCTIONS - PREMIUM CALCULATIONS */\n\n    /// @dev Calculates the premium amount to be added based on observed base rate growth\n    /// @param borrowAssetsAtLastAccrual The borrower's assets at last premium accrual\n    /// @param borrowAssetsCurrent The borrower's current assets (including base interest)\n    /// @param premiumRate The borrower's premium rate per second (scaled by WAD)\n    /// @param elapsed Time elapsed since last accrual\n    /// @return premiumAmount The premium amount to add\n    function _calculateBorrowerPremiumAmount(\n        uint256 borrowAssetsAtLastAccrual,\n        uint256 borrowAssetsCurrent,\n        uint256 premiumRate,\n        uint256 elapsed\n    ) internal pure returns (uint256 premiumAmount) {\n        // Prevent division by zero\n        if (borrowAssetsAtLastAccrual == 0 || elapsed == 0) return 0;\n\n        // Calculate the actual base growth\n        uint256 baseGrowthActual;\n        uint256 baseRatePerSecond;\n        if (borrowAssetsCurrent > borrowAssetsAtLastAccrual) {\n            baseGrowthActual = borrowAssetsCurrent - borrowAssetsAtLastAccrual;\n            baseRatePerSecond = borrowAssetsCurrent.wDivUp(borrowAssetsAtLastAccrual).wInverseTaylorCompounded(elapsed);\n        }\n\n        // Combine base rate with premium rate (both per-second)\n        uint256 combinedRate = baseRatePerSecond + premiumRate;\n\n        // Calculate compound growth using wTaylorCompounded\n        uint256 totalGrowth = combinedRate.wTaylorCompounded(elapsed);\n        uint256 totalGrowthAmount = borrowAssetsAtLastAccrual.wMulDown(totalGrowth);\n\n        // Premium amount is the difference between total growth and actual base growth\n        premiumAmount = totalGrowthAmount > baseGrowthActual ? totalGrowthAmount - baseGrowthActual : 0;\n    }\n\n    /// @dev Calculate ongoing premium and penalty rate if already past grace period\n    /// @return premiumAmount The calculated premium amount (including penalty if applicable)\n    function _calculateOngoingPremiumAndPenalty(\n        Id id,\n        address borrower,\n        BorrowerPremium memory premium,\n        RepaymentStatus status,\n        uint256 borrowAssetsCurrent\n    ) internal view returns (uint256 premiumAmount) {\n        uint256 elapsed = block.timestamp - premium.lastAccrualTime;\n        if (elapsed == 0) return 0;\n\n        if (elapsed > MAX_ELAPSED_TIME) {\n            elapsed = MAX_ELAPSED_TIME;\n        }\n\n        uint256 totalPremiumRate = premium.rate;\n\n        // Add penalty rate if already in penalty period (after grace period)\n        if (status != RepaymentStatus.Current && status != RepaymentStatus.GracePeriod) {\n            RepaymentObligation memory obligation = repaymentObligation[id][borrower];\n            uint256 cycleEndDate = paymentCycle[id][obligation.paymentCycleId].endDate;\n            MarketConfig memory terms = IProtocolConfig(protocolConfig).getMarketConfig();\n\n            if (premium.lastAccrualTime > cycleEndDate + terms.gracePeriod) {\n                totalPremiumRate += terms.irp;\n            }\n        }\n\n        premiumAmount = _calculateBorrowerPremiumAmount(\n            premium.borrowAssetsAtLastAccrual, borrowAssetsCurrent, totalPremiumRate, elapsed\n        );\n    }\n\n    /// @dev Calculate initial penalty when first transitioning into penalty period\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @param status Current repayment status\n    /// @param borrowAssetsCurrent Current borrow assets after base accrual\n    /// @param basePremiumAmount Premium amount already calculated\n    /// @return penaltyAmount The calculated penalty amount\n    /// @dev Penalty calculation logic:\n    /// 1. Only applies if status is Delinquent or Default\n    /// 2. Only for first accrual after grace period ends (lastAccrualTime <= cycleEndDate + gracePeriod)\n    /// 3. Uses ending balance from obligation as the principal\n    /// 4. Calculates penalty from cycle end date to now\n    /// 5. Adds basePremiumAmount to current assets for accurate compounding\n    function _calculateInitialPenalty(\n        Id id,\n        address borrower,\n        RepaymentStatus status,\n        uint256 borrowAssetsCurrent,\n        uint256 basePremiumAmount\n    ) internal view returns (uint256 penaltyAmount) {\n        if (status != RepaymentStatus.Delinquent && status != RepaymentStatus.Default) {\n            return 0;\n        }\n\n        BorrowerPremium memory premium = borrowerPremium[id][borrower];\n        RepaymentObligation memory obligation = repaymentObligation[id][borrower];\n        uint256 cycleEndDate = paymentCycle[id][obligation.paymentCycleId].endDate;\n        MarketConfig memory terms = IProtocolConfig(protocolConfig).getMarketConfig();\n\n        if (premium.lastAccrualTime > cycleEndDate + terms.gracePeriod) {\n            return 0; // Already handled in premium calculation\n        }\n\n        uint256 elapsed = block.timestamp - cycleEndDate;\n        if (elapsed > MAX_ELAPSED_TIME) {\n            elapsed = MAX_ELAPSED_TIME;\n        }\n        penaltyAmount = _calculateBorrowerPremiumAmount(\n            obligation.endingBalance, borrowAssetsCurrent + basePremiumAmount, terms.irp, elapsed\n        );\n    }\n\n    /// @dev Update position and market with premium shares\n    function _updatePositionWithPremium(Id id, address borrower, uint256 premiumAmount) internal {\n        Market memory targetMarket = market[id];\n\n        uint256 premiumShares = premiumAmount.toSharesUp(targetMarket.totalBorrowAssets, targetMarket.totalBorrowShares);\n\n        // Update borrower position\n        position[id][borrower].borrowShares += premiumShares.toUint128();\n\n        // Update market totals\n        targetMarket.totalBorrowShares += premiumShares.toUint128();\n        targetMarket.totalBorrowAssets += premiumAmount.toUint128();\n        targetMarket.totalSupplyAssets += premiumAmount.toUint128();\n\n        // Handle fees\n        uint256 feeAmount;\n        if (targetMarket.fee != 0) {\n            feeAmount = premiumAmount.wMulDown(targetMarket.fee);\n            uint256 feeShares =\n                feeAmount.toSharesDown(targetMarket.totalSupplyAssets - feeAmount, targetMarket.totalSupplyShares);\n            position[id][feeRecipient].supplyShares += feeShares;\n            targetMarket.totalSupplyShares += feeShares.toUint128();\n        }\n\n        // Write back to storage\n        market[id] = targetMarket;\n\n        emit EventsLib.PremiumAccrued(id, borrower, premiumAmount, feeAmount);\n    }\n\n    /// @notice Accrue premium for a specific borrower\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @dev Core accrual function that orchestrates the premium and penalty calculation process:\n    /// 1. Check repayment status\n    /// 2. Calculate premium based on elapsed time and rates\n    /// 3. Calculate penalty if borrower is delinquent/default (not during grace period)\n    /// 4. Apply combined premium+penalty as new borrow shares\n    /// 5. Update timestamp to prevent double accrual\n    /// @dev MUST be called after _accrueInterest to ensure base rate is current\n    function _accrueBorrowerPremium(Id id, address borrower) internal {\n        (RepaymentStatus status,) = getRepaymentStatus(id, borrower);\n\n        BorrowerPremium memory premium = borrowerPremium[id][borrower];\n        if (premium.rate == 0 && status == RepaymentStatus.Current) return;\n\n        if (position[id][borrower].borrowShares == 0) return;\n\n        // Calculate current borrow assets\n        Market memory targetMarket = market[id];\n        uint256 borrowAssetsCurrent = uint256(position[id][borrower].borrowShares)\n            .toAssetsUp(targetMarket.totalBorrowAssets, targetMarket.totalBorrowShares);\n\n        // Calculate premium and penalty accruals\n        uint256 premiumAmount = _calculateOngoingPremiumAndPenalty(id, borrower, premium, status, borrowAssetsCurrent);\n\n        // Calculate penalty if needed (handles first penalty accrual)\n        uint256 penaltyAmount = _calculateInitialPenalty(id, borrower, status, borrowAssetsCurrent, premiumAmount);\n\n        uint256 totalPremium = premiumAmount + penaltyAmount;\n\n        // Skip if below threshold\n        if (totalPremium < MIN_PREMIUM_THRESHOLD) {\n            return;\n        }\n\n        // Apply the premium\n        _updatePositionWithPremium(id, borrower, totalPremium);\n\n        // Update timestamp\n        borrowerPremium[id][borrower].lastAccrualTime = uint128(block.timestamp);\n    }\n\n    /// @notice Snapshot borrower's position for premium tracking\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @dev Snapshots are critical for accurate premium calculation:\n    /// - Captures the current borrow amount after all accruals\n    /// - Updates borrowAssetsAtLastAccrual to this new value\n    /// - Ensures next premium calculation starts from correct base\n    /// - Only updates if borrower has a premium rate set\n    /// @dev Called after every borrow, repay, or liquidation to maintain accuracy\n    function _snapshotBorrowerPosition(Id id, address borrower) internal {\n        BorrowerPremium memory premium = borrowerPremium[id][borrower];\n\n        Market memory targetMarket = market[id];\n\n        uint256 currentBorrowAssets = uint256(position[id][borrower].borrowShares)\n            .toAssetsUp(targetMarket.totalBorrowAssets, targetMarket.totalBorrowShares);\n\n        // Update timestamp if:\n        // - Not initialized (safety check), OR\n        // - This is the first actual borrow (transition from 0 debt to positive debt)\n        if (premium.lastAccrualTime == 0 || (premium.borrowAssetsAtLastAccrual == 0 && currentBorrowAssets > 0)) {\n            premium.lastAccrualTime = uint128(block.timestamp);\n        }\n\n        // Update borrow amount snapshot\n        premium.borrowAssetsAtLastAccrual = currentBorrowAssets.toUint128();\n\n        // Write back to storage\n        borrowerPremium[id][borrower] = premium;\n    }\n\n    /* MODIFIERS */\n\n    /// @notice Modifier to restrict access to the market's CreditLine contract\n    modifier onlyCreditLine(Id id) {\n        requireCreditLine(id);\n        _;\n    }\n\n    function requireCreditLine(Id id) internal {\n        if (market[id].lastUpdate == 0) revert ErrorsLib.MarketNotCreated();\n        if (msg.sender != idToMarketParams[id].creditLine) revert ErrorsLib.NotCreditLine();\n    }\n\n    /* EXTERNAL FUNCTIONS - CREDIT LINE MANAGEMENT */\n\n    /// @inheritdoc IMorphoCredit\n    function setCreditLine(Id id, address borrower, uint256 credit, uint128 premiumRate) external onlyCreditLine(id) {\n        if (borrower == address(0)) revert ErrorsLib.ZeroAddress();\n\n        position[id][borrower].collateral = credit.toUint128();\n\n        emit EventsLib.SetCreditLine(id, borrower, credit);\n\n        _setBorrowerPremiumRate(id, borrower, premiumRate);\n    }\n\n    /// @notice Set or update a borrower's premium rate\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @param newRate New premium rate per second in WAD (e.g., 0.1e18 / 365 days for 10% APR)\n    function _setBorrowerPremiumRate(Id id, address borrower, uint128 newRate) internal {\n        // Accrue base interest first to ensure premium calculations are accurate\n        MarketParams memory marketParams = idToMarketParams[id];\n        _accrueInterest(marketParams, id);\n\n        // If there's an existing position with borrow shares, accrue premium\n        uint256 borrowShares = uint256(position[id][borrower].borrowShares);\n        if (borrowShares > 0) {\n            _accrueBorrowerPremium(id, borrower);\n        }\n\n        // Load premium from storage\n        BorrowerPremium memory premium = borrowerPremium[id][borrower];\n        uint128 oldRate = premium.rate;\n\n        // Set the new rate\n        premium.rate = newRate;\n        borrowerPremium[id][borrower] = premium;\n\n        // Take snapshot after setting the new rate if there are borrow shares\n        if (borrowShares > 0 && newRate > 0) {\n            _snapshotBorrowerPosition(id, borrower);\n        }\n\n        emit EventsLib.BorrowerPremiumRateSet(id, borrower, oldRate, newRate);\n    }\n\n    /* EXTERNAL FUNCTIONS - REPAYMENT MANAGEMENT */\n\n    /// @notice Close a payment cycle and create it on-chain retroactively\n    /// @param id Market ID\n    /// @param endDate Cycle end date\n    /// @param borrowers Array of borrower addresses\n    /// @param repaymentBps Array of repayment basis points (e.g., 500 = 5%)\n    /// @param endingBalances Array of ending balances for penalty calculations\n    /// @dev The ending balance is crucial for penalty calculations - it represents\n    /// the borrower's debt at cycle end and is used to calculate penalty interest\n    /// from that point forward, ensuring path independence\n    function closeCycleAndPostObligations(\n        Id id,\n        uint256 endDate,\n        address[] calldata borrowers,\n        uint256[] calldata repaymentBps,\n        uint256[] calldata endingBalances\n    ) external onlyCreditLine(id) {\n        if (borrowers.length != repaymentBps.length || repaymentBps.length != endingBalances.length) {\n            revert ErrorsLib.InconsistentInput();\n        }\n        if (endDate > block.timestamp) revert ErrorsLib.CannotCloseFutureCycle();\n\n        uint256 cycleLength = paymentCycle[id].length;\n        uint256 startDate;\n\n        if (cycleLength > 0) {\n            PaymentCycle storage prevCycle = paymentCycle[id][cycleLength - 1];\n            startDate = prevCycle.endDate;\n\n            uint256 cycleDuration = IProtocolConfig(protocolConfig).getCycleDuration();\n\n            if (cycleDuration > 0 && endDate < startDate + cycleDuration) {\n                revert ErrorsLib.InvalidCycleDuration();\n            }\n        }\n\n        // Create the payment cycle record\n        paymentCycle[id].push(PaymentCycle({endDate: endDate}));\n\n        uint256 cycleId = paymentCycle[id].length - 1;\n\n        // Post obligations for this cycle\n        for (uint256 i = 0; i < borrowers.length; i++) {\n            _postRepaymentObligation(id, borrowers[i], repaymentBps[i], cycleId, endingBalances[i]);\n        }\n\n        emit EventsLib.PaymentCycleCreated(id, cycleId, startDate, endDate);\n    }\n\n    /// @notice Add more obligations to the most recently closed cycle\n    /// @param id Market ID\n    /// @param borrowers Array of borrower addresses\n    /// @param repaymentBps Array of repayment basis points (e.g., 500 = 5%)\n    /// @param endingBalances Array of ending balances\n    function addObligationsToLatestCycle(\n        Id id,\n        address[] calldata borrowers,\n        uint256[] calldata repaymentBps,\n        uint256[] calldata endingBalances\n    ) external onlyCreditLine(id) {\n        if (borrowers.length != repaymentBps.length || repaymentBps.length != endingBalances.length) {\n            revert ErrorsLib.InconsistentInput();\n        }\n        if (paymentCycle[id].length == 0) revert ErrorsLib.NoCyclesExist();\n\n        uint256 latestCycleId = paymentCycle[id].length - 1;\n\n        for (uint256 i = 0; i < borrowers.length; i++) {\n            _postRepaymentObligation(id, borrowers[i], repaymentBps[i], latestCycleId, endingBalances[i]);\n        }\n    }\n\n    /// @notice Internal function to post individual obligation\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @param repaymentBps Repayment percentage in basis points (e.g., 500 = 5%)\n    /// @param cycleId Payment cycle ID\n    /// @param endingBalance Balance at cycle end for penalty calculations\n    function _postRepaymentObligation(\n        Id id,\n        address borrower,\n        uint256 repaymentBps,\n        uint256 cycleId,\n        uint256 endingBalance\n    ) internal {\n        if (repaymentBps > MAX_BPS) revert ErrorsLib.RepaymentExceedsHundredPercent();\n\n        RepaymentObligation memory obligation = repaymentObligation[id][borrower];\n\n        // Calculate actual amount from basis points\n        uint256 amount = endingBalance * repaymentBps / MAX_BPS;\n\n        // Only set cycleId and endingBalance for new obligations\n        if (obligation.amountDue == 0) {\n            obligation.paymentCycleId = uint128(cycleId);\n            obligation.endingBalance = endingBalance.toUint128();\n        }\n\n        // Update amount due\n        obligation.amountDue = uint128(amount);\n\n        repaymentObligation[id][borrower] = obligation;\n\n        // Emit input parameters to reflect poster's intent\n        emit EventsLib.RepaymentObligationPosted(id, borrower, amount, cycleId, endingBalance);\n    }\n\n    /// @notice Get repayment status for a borrower\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @return _status The borrower's current repayment status\n    /// @return _statusStartTime The timestamp when the current status began\n    function getRepaymentStatus(Id id, address borrower)\n        internal\n        view\n        returns (RepaymentStatus _status, uint256 _statusStartTime)\n    {\n        RepaymentObligation memory obligation = repaymentObligation[id][borrower];\n\n        if (obligation.amountDue == 0) return (RepaymentStatus.Current, 0);\n\n        // Validate cycleId is within bounds\n        if (obligation.paymentCycleId >= paymentCycle[id].length) revert ErrorsLib.InvalidCycleId();\n\n        _statusStartTime = paymentCycle[id][obligation.paymentCycleId].endDate;\n\n        MarketConfig memory terms = IProtocolConfig(protocolConfig).getMarketConfig();\n\n        if (block.timestamp <= _statusStartTime + terms.gracePeriod) {\n            return (RepaymentStatus.GracePeriod, _statusStartTime);\n        }\n        _statusStartTime += terms.gracePeriod;\n        if (block.timestamp < _statusStartTime + terms.delinquencyPeriod) {\n            return (RepaymentStatus.Delinquent, _statusStartTime);\n        }\n\n        return (RepaymentStatus.Default, _statusStartTime + terms.delinquencyPeriod);\n    }\n\n    /* INTERNAL FUNCTIONS - HOOK IMPLEMENTATIONS */\n\n    /// @inheritdoc Morpho\n    function _beforeSupply(MarketParams memory, Id id, address onBehalf, uint256, uint256, bytes calldata)\n        internal\n        virtual\n        override\n    {\n        if (msg.sender != usd3) revert ErrorsLib.NotUsd3();\n        if (IProtocolConfig(protocolConfig).getIsPaused() > 0) revert ErrorsLib.Paused();\n    }\n\n    /// @inheritdoc Morpho\n    function _beforeWithdraw(MarketParams memory, Id id, address onBehalf, uint256, uint256) internal virtual override {\n        // Allow USD3 to withdraw on behalf of anyone\n        if (msg.sender == usd3) return;\n\n        // Allow fee recipient to withdraw their own fees only\n        if (msg.sender == feeRecipient && onBehalf == feeRecipient) return;\n\n        // Reject all other withdrawals\n        revert ErrorsLib.NotUsd3();\n    }\n\n    /// @inheritdoc Morpho\n    function _beforeBorrow(MarketParams memory, Id id, address onBehalf, uint256 assets, uint256)\n        internal\n        virtual\n        override\n    {\n        if (msg.sender != helper) revert ErrorsLib.NotHelper();\n        if (IProtocolConfig(protocolConfig).getIsPaused() > 0) revert ErrorsLib.Paused();\n        if (_isMarketFrozen(id)) revert ErrorsLib.MarketFrozen();\n\n        // Check if borrower can borrow\n        (RepaymentStatus status,) = getRepaymentStatus(id, onBehalf);\n        if (status != RepaymentStatus.Current) revert ErrorsLib.OutstandingRepayment();\n        _accrueBorrowerPremium(id, onBehalf);\n        // No need to update markdown - borrower must be Current to borrow, so markdown is always 0\n\n        // Check debt cap\n        uint256 debtCap = IProtocolConfig(protocolConfig).config(ProtocolConfigLib.DEBT_CAP);\n        if (debtCap == 0 || market[id].totalBorrowAssets + assets > debtCap) {\n            revert ErrorsLib.DebtCapExceeded();\n        }\n\n        // Check minimum borrow requirement\n        uint256 minBorrow = IProtocolConfig(protocolConfig).getMarketConfig().minBorrow;\n        if (minBorrow > 0) {\n            Market memory m = market[id];\n            uint256 currentDebt =\n                uint256(position[id][onBehalf].borrowShares).toAssetsUp(m.totalBorrowAssets, m.totalBorrowShares);\n            uint256 newDebt = currentDebt + assets;\n            if (newDebt < minBorrow) revert ErrorsLib.BelowMinimumBorrow();\n        }\n    }\n\n    /// @inheritdoc Morpho\n    /// @dev Accrues premium before tracking payment. During grace period, only base + premium\n    /// accrue (no penalty), allowing borrowers to clear obligations without penalty.\n    /// During delinquent/default, penalty also accrues before payment is tracked.\n    function _beforeRepay(MarketParams memory, Id id, address onBehalf, uint256 assets, uint256)\n        internal\n        virtual\n        override\n    {\n        if (_isMarketFrozen(id)) revert ErrorsLib.MarketFrozen();\n\n        // Accrue premium (including penalty if past grace period)\n        _accrueBorrowerPremium(id, onBehalf);\n        _updateBorrowerMarkdown(id, onBehalf); // TODO: decide whether to remove\n\n        // Check minimum borrow requirement for remaining debt\n        uint256 minBorrow = IProtocolConfig(protocolConfig).getMarketConfig().minBorrow;\n        if (minBorrow > 0) {\n            Market memory m = market[id];\n            uint256 currentDebt =\n                uint256(position[id][onBehalf].borrowShares).toAssetsUp(m.totalBorrowAssets, m.totalBorrowShares);\n            if (currentDebt > assets) {\n                uint256 remainingDebt = currentDebt - assets;\n                if (remainingDebt < minBorrow) revert ErrorsLib.BelowMinimumBorrow();\n            }\n        }\n\n        // Track payment against obligation\n        _trackObligationPayment(id, onBehalf, assets);\n    }\n\n    /// @inheritdoc Morpho\n    function _afterBorrow(MarketParams memory, Id id, address onBehalf) internal virtual override {\n        _snapshotBorrowerPosition(id, onBehalf);\n    }\n\n    /// @inheritdoc Morpho\n    function _afterRepay(MarketParams memory, Id id, address onBehalf, uint256) internal virtual override {\n        _snapshotBorrowerPosition(id, onBehalf);\n        _updateBorrowerMarkdown(id, onBehalf);\n    }\n\n    /// @dev Track obligation payment and update state\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @param payment Payment amount being made\n    /// @dev Enforces minimum payment requirement - must pay full obligation\n    /// This prevents partial payments that would leave borrowers in limbo\n    function _trackObligationPayment(Id id, address borrower, uint256 payment) internal {\n        uint256 amountDue = repaymentObligation[id][borrower].amountDue;\n\n        if (amountDue == 0) return;\n\n        if (payment < amountDue) revert ErrorsLib.MustPayFullObligation();\n\n        // Clear the obligation\n        repaymentObligation[id][borrower].amountDue = 0;\n\n        emit EventsLib.RepaymentTracked(id, borrower, payment, 0);\n    }\n\n    /* INTERNAL FUNCTIONS - HEALTH CHECK OVERRIDES */\n\n    /// @dev Override health check for credit-based lending (without price)\n    /// @param marketParams The market parameters\n    /// @param id The market id\n    /// @param borrower The borrower address\n    /// @return healthy Whether the position is healthy\n    function _isHealthy(MarketParams memory marketParams, Id id, address borrower)\n        internal\n        view\n        override\n        returns (bool)\n    {\n        // For credit-based lending, price is irrelevant\n        return _isHealthy(marketParams, id, borrower, 0);\n    }\n\n    /// @dev Override health check for credit-based lending (with price)\n    /// @param marketParams The market parameters\n    /// @param id The market id\n    /// @param borrower The borrower address\n    /// @param collateralPrice The collateral price (unused in credit model)\n    /// @return healthy Whether the position is healthy\n    function _isHealthy(MarketParams memory marketParams, Id id, address borrower, uint256 collateralPrice)\n        internal\n        view\n        override\n        returns (bool)\n    {\n        Position memory position = position[id][borrower];\n\n        // Early return if no borrow position\n        if (position.borrowShares == 0) return true;\n\n        Market memory market = market[id];\n        uint256 borrowed = uint256(position.borrowShares).toAssetsUp(market.totalBorrowAssets, market.totalBorrowShares);\n        uint256 creditLimit = position.collateral;\n\n        return creditLimit >= borrowed;\n    }\n\n    /* MARKDOWN FUNCTIONS */\n\n    /// @notice Update a borrower's markdown state and market total\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    function _updateBorrowerMarkdown(Id id, address borrower) internal {\n        address manager = ICreditLine(idToMarketParams[id].creditLine).mm();\n        if (manager == address(0)) return; // No markdown manager set\n\n        uint256 lastMarkdown = markdownState[id][borrower].lastCalculatedMarkdown;\n        (RepaymentStatus status, uint256 statusStartTime) = getRepaymentStatus(id, borrower);\n\n        // Check if in default and emit status change events\n        bool isInDefault = status == RepaymentStatus.Default && statusStartTime > 0;\n        bool wasInDefault = lastMarkdown > 0;\n\n        if (isInDefault && !wasInDefault) {\n            IMarkdownController(manager).resetBorrowerState(borrower);\n            emit EventsLib.DefaultStarted(id, borrower, statusStartTime);\n        } else if (!isInDefault && wasInDefault) {\n            emit EventsLib.DefaultCleared(id, borrower);\n        }\n\n        // Calculate new markdown\n        uint256 newMarkdown = 0;\n        if (isInDefault) {\n            uint256 timeInDefault = block.timestamp > statusStartTime ? block.timestamp - statusStartTime : 0;\n            uint256 borrowerAssets = _getBorrowerAssets(id, borrower);\n\n            newMarkdown = IMarkdownController(manager).calculateMarkdown(borrower, borrowerAssets, timeInDefault);\n\n            // Slash JANE proportionally to markdown\n            IMarkdownController(manager).slashJaneProportional(borrower, timeInDefault);\n\n            // Cap markdown at the borrower's actual outstanding debt\n            // since markdown represents the write-down of the loan value\n            if (newMarkdown > borrowerAssets) {\n                newMarkdown = borrowerAssets;\n            }\n        }\n\n        if (newMarkdown != lastMarkdown) {\n            // Update borrower state\n            markdownState[id][borrower].lastCalculatedMarkdown = uint128(newMarkdown);\n\n            // Update market totals - use a separate function to avoid stack issues\n            _updateMarketMarkdown(id, int256(newMarkdown) - int256(lastMarkdown));\n\n            emit EventsLib.BorrowerMarkdownUpdated(id, borrower, lastMarkdown, newMarkdown);\n        }\n    }\n\n    /// @notice Update market totals for markdown changes\n    /// @param id Market ID\n    /// @param markdownDelta Change in markdown (positive = increase, negative = decrease)\n    function _updateMarketMarkdown(Id id, int256 markdownDelta) internal {\n        if (markdownDelta == 0) return;\n\n        Market memory m = market[id];\n\n        if (markdownDelta > 0) {\n            // Markdown increasing (borrower deeper in default)\n            uint256 increase = uint256(markdownDelta);\n\n            // Cap at available supply to avoid underflow\n            if (increase > m.totalSupplyAssets) {\n                increase = m.totalSupplyAssets;\n            }\n\n            // Apply the reduction to supply and record what was marked down\n            m.totalSupplyAssets = (m.totalSupplyAssets - increase).toUint128();\n            m.totalMarkdownAmount = (m.totalMarkdownAmount + increase).toUint128();\n        } else {\n            // Markdown decreasing (borrower repaying/recovering)\n            uint256 decrease = uint256(-markdownDelta);\n\n            // Cap at previously marked down amount to avoid creating phantom supply\n            if (decrease > m.totalMarkdownAmount) {\n                decrease = m.totalMarkdownAmount;\n            }\n\n            // Restore the supply and reduce the tracked markdown amount\n            m.totalSupplyAssets = (m.totalSupplyAssets + decrease).toUint128();\n            m.totalMarkdownAmount = (m.totalMarkdownAmount - decrease).toUint128();\n        }\n\n        market[id] = m;\n    }\n\n    /// @notice Get borrower's current borrow assets\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    /// @return assets Current borrow amount in assets\n    function _getBorrowerAssets(Id id, address borrower) internal view returns (uint256 assets) {\n        Market memory m = market[id];\n        assets = uint256(position[id][borrower].borrowShares).toAssetsUp(m.totalBorrowAssets, m.totalBorrowShares);\n    }\n\n    /// @notice Check if a market is frozen based on cycle timing\n    /// @param id Market ID\n    /// @return Whether the market is frozen\n    function _isMarketFrozen(Id id) internal view returns (bool) {\n        uint256 cycleCount = paymentCycle[id].length;\n        uint256 cycleDuration = IProtocolConfig(protocolConfig).getCycleDuration();\n\n        if (cycleCount == 0 || cycleDuration == 0) {\n            return true;\n        }\n\n        uint256 lastCycleEnd = paymentCycle[id][cycleCount - 1].endDate;\n        uint256 expectedNextCycleEnd = lastCycleEnd + cycleDuration;\n\n        return block.timestamp >= expectedNextCycleEnd;\n    }\n\n    /// @notice Settle a borrower's account by writing off all remaining debt\n    /// @dev Only callable by credit line contract\n    /// @dev Should be called after any partial repayments have been made\n    /// @param marketParams The market parameters\n    /// @param borrower The borrower whose account to settle\n    /// @return writtenOffAssets Amount of assets written off\n    /// @return writtenOffShares Amount of shares written off\n    function settleAccount(MarketParams memory marketParams, address borrower)\n        external\n        onlyCreditLine(marketParams.id())\n        returns (uint256 writtenOffAssets, uint256 writtenOffShares)\n    {\n        Id id = marketParams.id();\n\n        _accrueInterest(marketParams, id);\n        _accrueBorrowerPremium(id, borrower);\n\n        // Get position\n        writtenOffShares = position[id][borrower].borrowShares;\n\n        // If no debt remains (e.g., insurance fully covered it), still clear all state\n        // This prevents settled borrowers from borrowing again\n        if (writtenOffShares == 0) {\n            // Clear all borrower state to prevent re-borrowing\n            _applySettlement(id, borrower, 0, 0);\n            emit EventsLib.AccountSettled(id, msg.sender, borrower, 0, 0);\n            return (0, 0);\n        }\n\n        Market memory m = market[id];\n\n        // Calculate written off assets\n        writtenOffAssets = writtenOffShares.toAssetsUp(m.totalBorrowAssets, m.totalBorrowShares);\n\n        // Slash all remaining JANE on settlement\n        address manager = ICreditLine(idToMarketParams[id].creditLine).mm();\n        if (manager != address(0)) {\n            IMarkdownController(manager).slashJaneFull(borrower);\n        }\n\n        // Clear position and apply supply adjustment\n        _applySettlement(id, borrower, writtenOffShares, writtenOffAssets);\n\n        emit EventsLib.AccountSettled(id, msg.sender, borrower, writtenOffAssets, writtenOffShares);\n    }\n\n    /// @notice Apply settlement to storage\n    function _applySettlement(Id id, address borrower, uint256 writtenOffShares, uint256 writtenOffAssets) internal {\n        uint256 lastMarkdown = markdownState[id][borrower].lastCalculatedMarkdown;\n\n        // Clear borrower position and related state\n        position[id][borrower].borrowShares = 0;\n        position[id][borrower].collateral = 0;\n        delete markdownState[id][borrower];\n        delete repaymentObligation[id][borrower];\n        delete borrowerPremium[id][borrower];\n\n        // Update borrow totals\n        market[id].totalBorrowShares = (market[id].totalBorrowShares - writtenOffShares).toUint128();\n        market[id].totalBorrowAssets = (market[id].totalBorrowAssets - writtenOffAssets).toUint128();\n\n        // Apply net supply adjustment\n        uint128 totalSupplyAssets = market[id].totalSupplyAssets;\n        int256 netAdjustment = int256(lastMarkdown) - int256(writtenOffAssets);\n        if (netAdjustment > 0) {\n            market[id].totalSupplyAssets = (totalSupplyAssets + uint256(netAdjustment)).toUint128();\n        } else if (netAdjustment < 0) {\n            uint256 loss = uint256(-netAdjustment);\n            if (totalSupplyAssets < loss) revert ErrorsLib.InsufficientLiquidity();\n            market[id].totalSupplyAssets = (totalSupplyAssets - loss).toUint128();\n        }\n\n        // Update markdown total\n        if (lastMarkdown > 0) {\n            uint128 totalMarkdownAmount = market[id].totalMarkdownAmount;\n            market[id].totalMarkdownAmount =\n                totalMarkdownAmount > lastMarkdown ? (totalMarkdownAmount - lastMarkdown).toUint128() : 0;\n        }\n    }\n}\n","creation_status":"success","file_path":"src/MorphoCredit.sol"}