{
  "sources": [
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/MidnightAdapter.sol",
      "quote": "/// DURATION CAPS\n/// @dev Durations can be used to cap the amount of credit above specific TTMs.\n/// @dev The caps of a duration are the vault's caps of the id keccak256(abi.encode(\"this/duration\", adapter, duration)).\n/// @dev A position counts toward every duration <= its current remaining time to maturity.\n/// @dev The vault does not store the allocations of duration ids. The adapter stores them instead and enforces the caps as well."
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/VaultV2.sol",
      "quote": "/// SHARE PRICE\n/// @dev The share price can go down if the vault incurs some losses.\n/// @dev To get some additional bounds on the share price upon interactions, a check must be performed on top.\n/// @dev Interest/loss are accounted only once per transaction (at the first interaction with the vault)."
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/MorphoMarketV1AdapterV2.sol",
      "quote": "function ids(MarketParams memory marketParams) public view returns (bytes32[] memory) {\n        bytes32[] memory ids_ = new bytes32[](3);\n        ids_[0] = adapterId;\n        ids_[1] = keccak256(abi.encode(\"collateralToken\", marketParams.collateralToken));\n        ids_[2] = keccak256(abi.encode(\"this/marketParams\", address(this), marketParams));\n        return ids_;\n    }"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/README.md",
      "quote": "The vault caps the stored net credit of the adapter, not its amortized net credit.\nThe granularity of the caps is the following:\n\n- Adapter-wide\n- Market \"family\": collateral parameters, RCF threshold, liquidator gate, and enter gate, regardless of maturity\n- Each collateral token"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/MidnightAdapterFactory.sol",
      "quote": ") external returns (address) {\n        bytes32 salt = keccak256(abi.encode(preSalt, msg.sender));\n        address _midnightAdapter =\n            address(new MidnightAdapter{salt: salt}(parentVault, midnight, durations, enterGateFactory));\n        isCreated[_midnightAdapter] = true;"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/libraries/PackedDurationsLib.sol",
      "quote": "}\n\n    /// @dev Assumes durations.length <= 8 and that each duration fits in 32 bits.\n    function pack(uint256[] memory durations) internal pure returns (bytes32) {\n        bytes32 packedDurations;\n        for (uint256 i = 0; i < durations.length; i++) {\n            packedDurations |= bytes32(durations[i] << (32 * i));\n        }"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/gates/IKRCompatibleEnterGate.sol",
      "quote": "function admit(address user, address adapterFactory) external {\n        require(admitEnabled, AdmitDisabled());\n        require(\n            admitterFactory[adapterFactory] && IMidnightAdapterFactory(adapterFactory).isCreated(msg.sender),\n            Unauthorized()\n        );\n        admitted = user;\n        emit Admit(msg.sender, user, adapterFactory);"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/gates/IKRCompatibleEnterGateFactory.sol",
      "quote": "bytes32 salt = keccak256(abi.encode(preSalt, msg.sender));\n        address gate = address(new IKRCompatibleEnterGate{salt: salt}(subGate, admitEnabled));\n        isCreated[gate] = true;\n        emit CreateIKRCompatibleEnterGate(msg.sender, gate, subGate, admitEnabled, preSalt);\n        return gate;"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/gates/WhitelistEnterSubGateFactory.sol",
      "quote": "bytes32 salt = keccak256(abi.encode(preSalt, msg.sender));\n        address subGate =\n            address(new WhitelistEnterSubGate{salt: salt}(creditRoleSetter, debtRoleSetter, creditOpen, debtOpen));\n        isCreated[subGate] = true;"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/gates/WhitelistEnterSubGate.sol",
      "quote": "function setIsWhitelisted(bool creditSide, address account, bool newIsWhitelisted) external {\n        require(isWhitelister[creditSide][msg.sender], NotWhitelister());\n        isWhitelisted[creditSide][account] = newIsWhitelisted;\n        emit SetIsWhitelisted(msg.sender, creditSide, account, newIsWhitelisted);\n    }"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/gates/interfaces/IWhitelistEnterSubGate.sol",
      "quote": "/// @dev keccak256(\"EIP712Domain(uint256 chainId,address verifyingContract)\").\nbytes32 constant EIP712_DOMAIN_TYPEHASH = 0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218;"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol",
      "quote": "ratification[maker][root].isRootRatified = newIsRootRatified;\n        emit SetIsRootRatified(msg.sender, onBehalf, maker, root, newIsRootRatified);\n        return SET_IS_ROOT_RATIFIED_SUCCESS;"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/ratifiers/MidnightAdapterRateRatifierV1.sol",
      "quote": "uint256 timeToMaturity = UtilsLib.zeroFloorSub(offer.market.maturity, block.timestamp);\n        uint256 offerPrice = TickLib.tickToPrice(offer.tick);\n        if (offer.buy) require(offerPrice <= WAD.mulDivDown(WAD, WAD + rate * timeToMaturity), WorsePrice());\n        else require(offerPrice >= WAD.mulDivUp(WAD, WAD + rate * timeToMaturity), WorsePrice());"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/midnight/4e2570e51171d09228645b2d5bdf84ef24b1720b/src/Midnight.sol",
      "quote": "uint256 sellerPrice = offer.buy ? offerPrice - _settlementFee : offerPrice;\n        uint256 buyerPrice = sellerPrice + _settlementFee;\n        uint256 buyerAssets = offer.buy ? units.mulDivDown(buyerPrice, WAD) : units.mulDivUp(buyerPrice, WAD);\n        uint256 sellerAssets = offer.buy ? units.mulDivDown(sellerPrice, WAD) : units.mulDivUp(sellerPrice, WAD);"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/midnight/4e2570e51171d09228645b2d5bdf84ef24b1720b/test/TickLibTest.sol",
      "quote": "assertEq(TickLib.tickToPrice(0), 0, \"tick 0\");"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/foundry.toml",
      "quote": "# The adapter's initcode is embedded in its factory. 833 is the highest optimizer_runs value for which the factory fits under EIP-170.\n[[profile.default.compilation_restrictions]]\npaths = \"src/adapters/midnight/MidnightAdapter.sol\"\noptimizer_runs = 833\nevm_version = \"osaka\""
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/MidnightAdapter.sol",
      "quote": "/// VALUATION\n/// @dev Approximates held assets by discounting the net credit of each market at a constant simple net rate until maturity.\n/// @dev Amortized values of held net credit are rounded down, as in realAssets.\n/// @dev Rates are rounded down on buys and sales, which can accrue some interest earlier.\n/// @dev On sales with a shortfall, each market's target amortized value is rounded up so that the rate reductions cover the whole shortfall, which can also accrue some interest earlier."
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/MidnightAdapter.sol",
      "quote": "/// @dev Withdraws `withdrawnAssets` of matured or repaid credit from `market` to this adapter, updates stored market state, and returns the market's ids and net credit change for the vault to pull `withdrawnAssets`.\n    /// @dev Can be called with `withdrawnAssets == 0` to synchronize `marketData` after a loss."
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/midnight/4e2570e51171d09228645b2d5bdf84ef24b1720b/src/Midnight.sol",
      "quote": "function touchMarket(Market memory market) public returns (bytes32) {\n        bytes32 id = IdLib.toId(market);\n        if (marketState[id].tickSpacing == 0) {\n            require(market.chainId == block.chainid, InvalidChainId());\n            require(market.midnight == address(this), InvalidMidnight());\n            require(market.maturity <= block.timestamp + 100 * 365 days, MaturityTooFar());"
    },
    {
      "url": "https://raw.githubusercontent.com/morpho-org/vault-v2/bbeda7b27ae80abcf070e0158cb8a31e87bb2286/src/adapters/midnight/MidnightAdapter.sol",
      "quote": "/// @dev Fillable with dust takes.\n    uint256 public constant MAX_MARKETS = 250;"
    }
  ]
}
