{"sources":{"src/Helper.sol":{"content":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport {IMorpho} from \"./interfaces/IMorpho.sol\";\nimport {MarketParams} from \"./interfaces/IMorpho.sol\";\nimport {IHelper} from \"./interfaces/IHelper.sol\";\nimport {IUSD3} from \"./interfaces/IUSD3.sol\";\nimport {IERC20} from \"./interfaces/IERC20.sol\";\n\nimport {ErrorsLib} from \"./libraries/ErrorsLib.sol\";\nimport {SafeTransferLib} from \"./libraries/SafeTransferLib.sol\";\n\nimport {IERC4626} from \"../lib/forge-std/src/interfaces/IERC4626.sol\";\n\n/// @title Helper\n/// @author 3Jane\n/// @custom:contact support@3jane.xyz\ncontract Helper is IHelper {\n    using SafeTransferLib for IERC20;\n\n    /// @inheritdoc IHelper\n    address public immutable MORPHO;\n    /// @inheritdoc IHelper\n    address public immutable USD3;\n    /// @inheritdoc IHelper\n    address public immutable sUSD3;\n    /// @inheritdoc IHelper\n    address public immutable USDC;\n    /// @inheritdoc IHelper\n    address public immutable WAUSDC;\n\n    /* CONSTRUCTOR */\n\n    constructor(address morpho, address usd3, address susd3, address usdc, address wausdc) {\n        if (morpho == address(0)) revert ErrorsLib.ZeroAddress();\n        if (usd3 == address(0)) revert ErrorsLib.ZeroAddress();\n        if (susd3 == address(0)) revert ErrorsLib.ZeroAddress();\n        if (usdc == address(0)) revert ErrorsLib.ZeroAddress();\n        if (wausdc == address(0)) revert ErrorsLib.ZeroAddress();\n\n        MORPHO = morpho;\n        USD3 = usd3;\n        sUSD3 = susd3;\n        USDC = usdc;\n        WAUSDC = wausdc;\n\n        // Set max approvals\n        IERC20(USDC).approve(WAUSDC, type(uint256).max);\n        IERC20(WAUSDC).approve(USD3, type(uint256).max);\n        IERC20(WAUSDC).approve(MORPHO, type(uint256).max);\n        IERC20(USD3).approve(sUSD3, type(uint256).max);\n    }\n\n    /// @inheritdoc IHelper\n    function deposit(uint256 assets, address receiver, bool hop) external returns (uint256) {\n        uint256 waUsdcAmount = _wrap(msg.sender, assets);\n\n        if (hop) {\n            require(IUSD3(USD3).whitelist(receiver), \"!whitelist\");\n            assets = IUSD3(USD3).deposit(waUsdcAmount, address(this));\n            assets = IERC4626(sUSD3).deposit(assets, receiver);\n        } else {\n            assets = IUSD3(USD3).deposit(waUsdcAmount, receiver);\n        }\n\n        return assets;\n    }\n\n    /// @inheritdoc IHelper\n    function redeem(uint256 shares, address receiver) external returns (uint256) {\n        uint256 waUsdcAssets = IUSD3(USD3).redeem(shares, address(this), msg.sender);\n        return IERC4626(WAUSDC).redeem(waUsdcAssets, receiver, address(this));\n    }\n\n    /// @inheritdoc IHelper\n    function borrow(MarketParams memory marketParams, uint256 assets) external returns (uint256, uint256) {\n        (uint256 waUSDCAmount, uint256 shares) =\n            IMorpho(MORPHO).borrow(marketParams, assets, 0, msg.sender, address(this));\n        uint256 usdcAmount = IERC4626(WAUSDC).redeem(waUSDCAmount, msg.sender, address(this));\n        return (usdcAmount, shares);\n    }\n\n    /// @inheritdoc IHelper\n    function repay(MarketParams memory marketParams, uint256 assets, address onBehalf, bytes calldata data)\n        external\n        returns (uint256, uint256)\n    {\n        uint256 waUSDCAmount = _wrap(msg.sender, assets);\n        (, uint256 shares) = IMorpho(MORPHO).repay(marketParams, waUSDCAmount, 0, onBehalf, data);\n        return (assets, shares);\n    }\n\n    function _wrap(address from, uint256 assets) internal returns (uint256) {\n        IERC20(USDC).safeTransferFrom(from, address(this), assets);\n        return IERC4626(WAUSDC).deposit(assets, address(this));\n    }\n}\n"},"src/interfaces/IMorpho.sol":{"content":"// 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 Manually accrue premium for a borrower\n    /// @param id Market ID\n    /// @param borrower Borrower address\n    function accrueBorrowerPremium(Id id, address borrower) external;\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 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        external\n        view\n        returns (RepaymentStatus status, uint256 statusStartTime);\n\n    /// @notice Get the total number of payment cycles for a market\n    /// @param id Market ID\n    /// @return The number of payment cycles\n    function getPaymentCycleLength(Id id) external view returns (uint256);\n\n    /// @notice Get both start and end dates for a given cycle\n    /// @param id Market ID\n    /// @param cycleId Cycle ID\n    /// @return startDate The cycle start date\n    /// @return endDate The cycle end date\n    function getCycleDates(Id id, uint256 cycleId) external view returns (uint256 startDate, uint256 endDate);\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"},"src/interfaces/IHelper.sol":{"content":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport {IERC4626} from \"../../lib/forge-std/src/interfaces/IERC4626.sol\";\n\nimport {MarketParams} from \"./IMorpho.sol\";\n\n/// @title IHelper\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Helper contract to simplify interactions with 3Jane's token ecosystem and Morpho protocol\n/// @dev This contract handles the token conversions: USDC → waUSDC → USD3 → sUSD3\ninterface IHelper {\n    /// @notice The Morpho protocol contract address\n    /// @return The address of the Morpho contract\n    function MORPHO() external view returns (address);\n\n    /// @notice The USD3 token address (ERC4626 vault for waUSDC)\n    /// @return The address of the USD3 token\n    function USD3() external view returns (address);\n\n    /// @notice The sUSD3 token address (subordinate/staked USD3, also ERC4626)\n    /// @return The address of the sUSD3 token\n    function sUSD3() external view returns (address);\n\n    /// @notice The USDC token address (base stablecoin)\n    /// @return The address of the USDC token\n    function USDC() external view returns (address);\n\n    /// @notice The waUSDC token address (wrapped asset USDC, ERC4626 vault)\n    /// @return The address of the waUSDC token\n    function WAUSDC() external view returns (address);\n\n    /// @notice Deposits USDC and converts through the token hierarchy\n    /// @dev Flow: USDC → waUSDC → USD3 (→ sUSD3 if hop=true)\n    /// @param assets The amount of USDC to deposit\n    /// @param receiver The address that will receive the USD3/sUSD3 shares\n    /// @param hop If true, deposits into sUSD3; if false, stops at USD3\n    /// @return The amount of shares minted (USD3 or sUSD3 depending on hop)\n    function deposit(uint256 assets, address receiver, bool hop) external returns (uint256);\n\n    /// @notice Redeems USD3 shares back to USDC\n    /// @dev Flow: USD3 → waUSDC → USDC. Caller must have approved Helper for USD3 spending\n    /// @param shares The amount of USD3 shares to redeem\n    /// @param receiver The address that will receive the USDC\n    /// @return The amount of USDC received\n    function redeem(uint256 shares, address receiver) external returns (uint256);\n\n    /// @notice Borrows assets from a Morpho market and unwraps to USDC\n    /// @dev The borrowed waUSDC is automatically unwrapped to USDC for the borrower\n    /// @param marketParams The market parameters defining which market to borrow from\n    /// @param assets The amount of assets to borrow (in waUSDC terms)\n    /// @return usdcAmount The amount of USDC received by the borrower\n    /// @return shares The amount of borrow shares created\n    function borrow(MarketParams memory marketParams, uint256 assets) external returns (uint256, uint256);\n\n    /// @notice Repays a loan by wrapping USDC to waUSDC\n    /// @dev Flow: USDC → waUSDC → Morpho repay. Caller must have approved Helper for USDC spending\n    /// @param marketParams The market parameters defining which market to repay\n    /// @param assets The amount of USDC to repay\n    /// @param onBehalf The address whose debt is being repaid\n    /// @param data Additional data for the repay operation (e.g., for callbacks)\n    /// @return usdcAmount The amount of USDC used from the caller\n    /// @return shares The amount of borrow shares repaid\n    function repay(MarketParams memory marketParams, uint256 assets, address onBehalf, bytes calldata data)\n        external\n        returns (uint256, uint256);\n}\n"},"src/interfaces/IUSD3.sol":{"content":"// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport {IERC4626} from \"../../lib/forge-std/src/interfaces/IERC4626.sol\";\n\n/// @title IUSD3\n/// @author Morpho Labs\n/// @custom:contact security@morpho.org\n/// @notice Interface for USD3 token, which is an ERC4626 vault\ninterface IUSD3 is IERC4626 {\n    // USD3 inherits all ERC4626 functions including:\n    // - deposit(uint256 assets, address receiver) returns (uint256 shares)\n    // - redeem(uint256 shares, address receiver, address owner) returns (uint256 assets)\n    // - And all other ERC4626 standard functions\n    function whitelist(address user) external view returns (bool);\n}\n"},"src/interfaces/IERC20.sol":{"content":"// 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"},"src/libraries/ErrorsLib.sol":{"content":"// 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"},"src/libraries/SafeTransferLib.sol":{"content":"// 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"},"lib/forge-std/src/interfaces/IERC4626.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity >=0.6.2;\n\nimport {IERC20} from \"./IERC20.sol\";\n\n/// @dev Interface of the ERC4626 \"Tokenized Vault Standard\", as defined in\n/// https://eips.ethereum.org/EIPS/eip-4626\ninterface IERC4626 is IERC20 {\n    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);\n\n    event Withdraw(\n        address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares\n    );\n\n    /// @notice Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.\n    /// @dev\n    /// - MUST be an ERC-20 token contract.\n    /// - MUST NOT revert.\n    function asset() external view returns (address assetTokenAddress);\n\n    /// @notice Returns the total amount of the underlying asset that is “managed” by Vault.\n    /// @dev\n    /// - SHOULD include any compounding that occurs from yield.\n    /// - MUST be inclusive of any fees that are charged against assets in the Vault.\n    /// - MUST NOT revert.\n    function totalAssets() external view returns (uint256 totalManagedAssets);\n\n    /// @notice Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal\n    /// scenario where all the conditions are met.\n    /// @dev\n    /// - MUST NOT be inclusive of any fees that are charged against assets in the Vault.\n    /// - MUST NOT show any variations depending on the caller.\n    /// - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.\n    /// - MUST NOT revert.\n    ///\n    /// NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the\n    /// “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and\n    /// from.\n    function convertToShares(uint256 assets) external view returns (uint256 shares);\n\n    /// @notice Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal\n    /// scenario where all the conditions are met.\n    /// @dev\n    /// - MUST NOT be inclusive of any fees that are charged against assets in the Vault.\n    /// - MUST NOT show any variations depending on the caller.\n    /// - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.\n    /// - MUST NOT revert.\n    ///\n    /// NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the\n    /// “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and\n    /// from.\n    function convertToAssets(uint256 shares) external view returns (uint256 assets);\n\n    /// @notice Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,\n    /// through a deposit call.\n    /// @dev\n    /// - MUST return a limited value if receiver is subject to some deposit limit.\n    /// - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.\n    /// - MUST NOT revert.\n    function maxDeposit(address receiver) external view returns (uint256 maxAssets);\n\n    /// @notice Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given\n    /// current on-chain conditions.\n    /// @dev\n    /// - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit\n    ///   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called\n    ///   in the same transaction.\n    /// - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the\n    ///   deposit would be accepted, regardless if the user has enough tokens approved, etc.\n    /// - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.\n    /// - MUST NOT revert.\n    ///\n    /// NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in\n    /// share price or some other type of condition, meaning the depositor will lose assets by depositing.\n    function previewDeposit(uint256 assets) external view returns (uint256 shares);\n\n    /// @notice Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.\n    /// @dev\n    /// - MUST emit the Deposit event.\n    /// - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the\n    ///   deposit execution, and are accounted for during deposit.\n    /// - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not\n    ///   approving enough underlying tokens to the Vault contract, etc).\n    ///\n    /// NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.\n    function deposit(uint256 assets, address receiver) external returns (uint256 shares);\n\n    /// @notice Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.\n    /// @dev\n    /// - MUST return a limited value if receiver is subject to some mint limit.\n    /// - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.\n    /// - MUST NOT revert.\n    function maxMint(address receiver) external view returns (uint256 maxShares);\n\n    /// @notice Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given\n    /// current on-chain conditions.\n    /// @dev\n    /// - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call\n    ///   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the\n    ///   same transaction.\n    /// - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint\n    ///   would be accepted, regardless if the user has enough tokens approved, etc.\n    /// - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.\n    /// - MUST NOT revert.\n    ///\n    /// NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in\n    /// share price or some other type of condition, meaning the depositor will lose assets by minting.\n    function previewMint(uint256 shares) external view returns (uint256 assets);\n\n    /// @notice Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.\n    /// @dev\n    /// - MUST emit the Deposit event.\n    /// - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint\n    ///   execution, and are accounted for during mint.\n    /// - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not\n    ///   approving enough underlying tokens to the Vault contract, etc).\n    ///\n    /// NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.\n    function mint(uint256 shares, address receiver) external returns (uint256 assets);\n\n    /// @notice Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the\n    /// Vault, through a withdrawal call.\n    /// @dev\n    /// - MUST return a limited value if owner is subject to some withdrawal limit or timelock.\n    /// - MUST NOT revert.\n    function maxWithdraw(address owner) external view returns (uint256 maxAssets);\n\n    /// @notice Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,\n    /// given current on-chain conditions.\n    /// @dev\n    /// - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw\n    ///   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if\n    ///   called\n    ///   in the same transaction.\n    /// - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though\n    ///   the withdrawal would be accepted, regardless if the user has enough shares, etc.\n    /// - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.\n    /// - MUST NOT revert.\n    ///\n    /// NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in\n    /// share price or some other type of condition, meaning the depositor will lose assets by depositing.\n    function previewWithdraw(uint256 assets) external view returns (uint256 shares);\n\n    /// @notice Burns shares from owner and sends exactly assets of underlying tokens to receiver.\n    /// @dev\n    /// - MUST emit the Withdraw event.\n    /// - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the\n    ///   withdraw execution, and are accounted for during withdrawal.\n    /// - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner\n    ///   not having enough shares, etc).\n    ///\n    /// Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.\n    /// Those methods should be performed separately.\n    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);\n\n    /// @notice Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,\n    /// through a redeem call.\n    /// @dev\n    /// - MUST return a limited value if owner is subject to some withdrawal limit or timelock.\n    /// - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.\n    /// - MUST NOT revert.\n    function maxRedeem(address owner) external view returns (uint256 maxShares);\n\n    /// @notice Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,\n    /// given current on-chain conditions.\n    /// @dev\n    /// - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call\n    ///   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the\n    ///   same transaction.\n    /// - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the\n    ///   redemption would be accepted, regardless if the user has enough shares, etc.\n    /// - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.\n    /// - MUST NOT revert.\n    ///\n    /// NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in\n    /// share price or some other type of condition, meaning the depositor will lose assets by redeeming.\n    function previewRedeem(uint256 shares) external view returns (uint256 assets);\n\n    /// @notice Burns exactly shares from owner and sends assets of underlying tokens to receiver.\n    /// @dev\n    /// - MUST emit the Withdraw event.\n    /// - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the\n    ///   redeem execution, and are accounted for during redeem.\n    /// - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner\n    ///   not having enough shares, etc).\n    ///\n    /// NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.\n    /// Those methods should be performed separately.\n    function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);\n}\n"},"lib/forge-std/src/interfaces/IERC20.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity >=0.6.2;\n\n/// @dev Interface of the ERC20 standard as defined in the EIP.\n/// @dev This includes the optional name, symbol, and decimals metadata.\ninterface IERC20 {\n    /// @dev Emitted when `value` tokens are moved from one account (`from`) to another (`to`).\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /// @dev Emitted when the allowance of a `spender` for an `owner` is set, where `value`\n    /// is the new allowance.\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /// @notice Returns the amount of tokens in existence.\n    function totalSupply() external view returns (uint256);\n\n    /// @notice Returns the amount of tokens owned by `account`.\n    function balanceOf(address account) external view returns (uint256);\n\n    /// @notice Moves `amount` tokens from the caller's account to `to`.\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /// @notice Returns the remaining number of tokens that `spender` is allowed\n    /// to spend on behalf of `owner`\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /// @notice Sets `amount` as the allowance of `spender` over the caller's tokens.\n    /// @dev Be aware of front-running risks: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /// @notice Moves `amount` tokens from `from` to `to` using the allowance mechanism.\n    /// `amount` is then deducted from the caller's allowance.\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n\n    /// @notice Returns the name of the token.\n    function name() external view returns (string memory);\n\n    /// @notice Returns the symbol of the token.\n    function symbol() external view returns (string memory);\n\n    /// @notice Returns the decimals places of the token.\n    function decimals() external view returns (uint8);\n}\n"}},"matchId":"28513720","creationMatch":"match","runtimeMatch":"match","verifiedAt":"2026-05-04T09:48:38Z","match":"match","chainId":"1","address":"0x82736F81A56935c8429ADdbDa4aEBec737444505"}