ETH Price: $3,185.99 (-0.77%)

Contract

0x4A229a3C5b59AE7231C07A972a62E29566Bf521d

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

1 Internal Transaction found.

Latest 1 internal transaction

Advanced mode:
Parent Transaction Hash Block From To
181528732025-12-05 0:48:042 hrs ago1764895684
0x4A229a3C...566Bf521d
0 ETH

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
EverlongManagedLeveragedVaultGettersV1

Compiler Version
v0.8.26+commit.8a97fa7a

Optimization Enabled:
Yes with 1 runs

Other Settings:
cancun EvmVersion
// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IAsset} from "src/interfaces/utils/tokens/IAsset.sol";
import {IBaseManagedLeveragedVault} from "src/interfaces/core/mlv/base/IBaseManagedLeveragedVault.sol";
import {PropManagedLeveragedVaultGetters, ManagedLeveragedVaultStorageLib} from "src/core/mlv/helpers/protocol/v1/prop/PropManagedLeveragedVaultGetters.sol";

/// @dev Handles the asset of the MLV not being the same as the asset of the collateral
contract EverlongManagedLeveragedVaultGettersV1 is PropManagedLeveragedVaultGetters {
    using SafeCast for int256;

    constructor(IBaseManagedLeveragedVault _vault) PropManagedLeveragedVaultGetters(_vault) {}

    function computeNetColl(
        uint256 debtTokenSurplusInAssets,
        uint256 collToReceive,
        uint256 prevTotalAssets
    ) external view override returns (uint256 netColl) {
        uint256 currTotalAssets = vault.totalAssets();

        uint256 totalAssetsDelta = prevTotalAssets - currTotalAssets - debtTokenSurplusInAssets;
        uint256 totalAssetsDeltaInCollVaultAsset = _assetToCollVaultAsset(totalAssetsDelta);

        int256 operationProfit = int256(collToReceive) - int256(IERC4626(collateral()).convertToShares(totalAssetsDeltaInCollVaultAsset));

        netColl = (int256(collToReceive) + operationProfit).toUint256();
    }

    function _assetToCollVaultAsset(uint256 assets) internal view returns (uint256 collVaultAssetAmount) {
        address collVaultAsset = IERC4626(collateral()).asset();

        uint256 collVaultAssetPrice = getPrice(collVaultAsset);
        uint256 assetPrice = getPrice(_asset());
        uint256 collVaultAssetScaling = 10 ** uint256(IAsset(collVaultAsset).decimals());
        uint256 assetDecimalsScaling = 10 ** uint256(IAsset(_asset()).decimals());

        // An overflow would require a very high decimal coll vault asset, or really high price
        collVaultAssetAmount = assets * assetPrice * collVaultAssetScaling / (collVaultAssetPrice * assetDecimalsScaling);
    }

    function _asset() internal view returns (address) {
        bytes32[] memory slots = new bytes32[](1);
        slots[0] = ManagedLeveragedVaultStorageLib.assetSlot();

        bytes32[] memory r = vault.extSloads(slots);

        return address(uint160(uint256(r[0])));
    }
}

File 2 of 29 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (interfaces/IERC4626.sol)

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20.sol";
import "../token/ERC20/extensions/IERC20Metadata.sol";

/**
 * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 *
 * _Available since v4.7._
 */
interface IERC4626 is IERC20, IERC20Metadata {
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed sender,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /**
     * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
     *
     * - MUST be an ERC-20 token contract.
     * - MUST NOT revert.
     */
    function asset() external view returns (address assetTokenAddress);

    /**
     * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
     *
     * - SHOULD include any compounding that occurs from yield.
     * - MUST be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT revert.
     */
    function totalAssets() external view returns (uint256 totalManagedAssets);

    /**
     * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
     * through a deposit call.
     *
     * - MUST return a limited value if receiver is subject to some deposit limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
     * - MUST NOT revert.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
     *   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
     *   in the same transaction.
     * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
     *   deposit would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   deposit execution, and are accounted for during deposit.
     * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
     * - MUST return a limited value if receiver is subject to some mint limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
     * - MUST NOT revert.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
     *   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
     *   same transaction.
     * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
     *   would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by minting.
     */
    function previewMint(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
     *   execution, and are accounted for during mint.
     * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function mint(uint256 shares, address receiver) external returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
     * Vault, through a withdraw call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
     *   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
     *   called
     *   in the same transaction.
     * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
     *   the withdrawal would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewWithdraw(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   withdraw execution, and are accounted for during withdraw.
     * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function withdraw(
        uint256 assets,
        address receiver,
        address owner
    ) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
     * through a redeem call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
     *   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
     *   same transaction.
     * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
     *   redemption would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
     */
    function previewRedeem(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   redeem execution, and are accounted for during redeem.
     * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function redeem(
        uint256 shares,
        address receiver,
        address owner
    ) external returns (uint256 assets);
}

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

import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";

interface IAsset is IERC20 {
    function decimals() external view returns (uint8);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IBaseManagedLeveragedVault {
    // --- Enums ------------------------------------------------
    enum Tolerance { ABOVE, BOTH }
    enum Operation { LEVERAGE, DELEVERAGE}

    struct BaseInitParams {
        IERC20 asset;
        string name;
        string symbol;
        address everlongCore;
        address debtToken;
        address collateral;
        uint16 maxDeviationICRinBP;
        uint16 maxDeviationTotalAssetsInBP;
        uint16 maxSlippageSwapInBP;
        address keeper;
        address targetICRHook;
        address feeHook;
        address getters;
    }

    // --- Errors ------------------------------------------------
    error ZeroAmount();
    error ZeroAddress();
    error SurpassedPrecision(uint256 precision);
    error AlreadyOpened();
    error NotOwner(address caller);
    error NotSupportedMethod();
    error VaultSlippage(uint256 expected, uint256 actual);

    // --- Events -----------------------------------------------
    event NewTargetICRHook(address targetICRHook);
    event NewKeeper(address keeper);
    event NewMaxDeviationICRInBP(uint16 maxDeviationICRInBP);
    event NewMaxDeviationTotalAssetsInBP(uint16 maxDeviationTotalAssetsInBP);
    event NewMaxSlippageSwapInBP(uint16 maxSlippageSwapInBP);
    event NewFeeHook(address feeHook);
    event NewGetters(address getters);

    // --- Functions ---------------------------------------------
    function totalAssets() external view returns (uint256);
    function setMaxDeviationICRinBP(uint16 _maxDeviationICRinBP) external;
    function setMaxDeviationTotalAssetsInBP(uint16 _maxDeviationTotalAssetsInBP) external;
    function setMaxSlippageSwapInBP(uint16 _maxSlippageSwapInBP) external;
    function setKeeper(address _keeper) external;
    function setTargetICRHook(address _targetICRHook) external;
    function setFeeHook(address _feeHook) external;
    function setGetters(address _getters) external;
    function getPrice(address token) external view returns (uint256 scaledPriceInUsdWad);
    function extSloads(bytes32[] memory slots) external view returns (bytes32[] memory values);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {BaseManagedLeveragedVaultGetters, IBaseManagedLeveragedVaultGetters} from "src/core/mlv/helpers/base/BaseManagedLeveragedVaultGetters.sol";
import {ManagedLeveragedVaultGettersV1, IBaseManagedLeveragedVault, ManagedLeveragedVaultStorageLib} from "src/core/mlv/helpers/base/v1/ManagedLeveragedVaultGettersV1.sol";
import {IPropManagedLeveragedVaultGetters} from "src/interfaces/core/mlv/helpers/protocol/v1/prop/IPropManagedLeveragedVaultGetters.sol";
import {PropGettersLib} from "src/core/mlv/helpers/base/lib/PropGettersLib.sol";
import {IPositionManager} from "src/interfaces/utils/IPositionManager.sol";
import {IBorrowerOperations} from "src/interfaces/utils/IBorrowerOperations.sol";
import {IEverlongCore} from "src/interfaces/core/IEverlongCore.sol";
import {ITargetICRHook} from "src/interfaces/utils/ITargetICRHook.sol";
import {IFeeHook} from "src/interfaces/utils/IFeeHook.sol";

contract PropManagedLeveragedVaultGetters is ManagedLeveragedVaultGettersV1, IPropManagedLeveragedVaultGetters {
    using PropGettersLib for PropGettersLib.Context;

    uint256 internal constant _BORROWER_OPERATIONS_SLOT = 7;
    uint256 internal constant _POSITION_MANAGER_SLOT = 8;
    uint256 internal constant _LEVERAGE_ROUTER_SLOT = 9;
    uint256 internal constant _DELEVERAGE_ROUTER_SLOT = 10;

    function borrowerOperationsSlot() internal pure returns (bytes32) {
        return bytes32(uint256(ManagedLeveragedVaultStorageLib.MLV_VAULT_LOC) + _BORROWER_OPERATIONS_SLOT);
    }

    function positionManagerSlot() internal pure returns (bytes32) {
        return bytes32(uint256(ManagedLeveragedVaultStorageLib.MLV_VAULT_LOC) + _POSITION_MANAGER_SLOT);
    }

    function leverageRouterSlot() internal pure returns (bytes32) {
        return bytes32(uint256(ManagedLeveragedVaultStorageLib.MLV_VAULT_LOC) + _LEVERAGE_ROUTER_SLOT);
    }

    function deleverageRouterSlot() internal pure returns (bytes32) {
        return bytes32(uint256(ManagedLeveragedVaultStorageLib.MLV_VAULT_LOC) + _DELEVERAGE_ROUTER_SLOT);
    }

    constructor(IBaseManagedLeveragedVault _vault) ManagedLeveragedVaultGettersV1(_vault) {}

    function borrowerOperations() public view returns (address) {
        bytes32[] memory slot = _array(borrowerOperationsSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function positionManager() public view returns (address) {
        bytes32[] memory slot = _array(positionManagerSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function leverageRouter() public view returns (address) {
        bytes32[] memory slot = _array(leverageRouterSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function deleverageRouter() public view returns (address) {
        bytes32[] memory slot = _array(deleverageRouterSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function getCollateralBalance() public view override returns (uint256) {
        return _getPropGettersContext().getCollateralBalance();
    }

    function getDebtBalance() public view override returns (uint256) {
        return _getPropGettersContext().getDebtBalance();
    }

    function checkMaxOperationCost(address inputToken, uint256 amountToSwap, uint256 prevTotalAssets) external view override {
        _getPropGettersContext().checkMaxOperationCost(inputToken, amountToSwap, prevTotalAssets);
    }

    function getPrice(address token) public view override returns (uint256) {
        return _getPropGettersContext().getPrice(token);
    }

    function getCurrentPositionICR() public view override returns (uint256) {
        return _getPropGettersContext().getCurrentPositionICR();
    }

    function _getPropGettersContext()
        private
        view
        returns (PropGettersLib.Context memory ctx)
    {
        // Use _array() as a base, then resize in assembly to avoid a second allocation.
        // We only need 6 sloads because maxDeviationTotalAssetsInBP & maxSlippageSwapInBP share the same slot (#2).
        bytes32[] memory slots = new bytes32[](8);
        slots[0] = ManagedLeveragedVaultStorageLib.assetSlot();
        slots[1] = ManagedLeveragedVaultStorageLib.everlongCoreSlot();
        slots[2] = ManagedLeveragedVaultStorageLib.debtTokenSlot();
        slots[3] = ManagedLeveragedVaultStorageLib.targetICRHookSlot();
        slots[4] = ManagedLeveragedVaultStorageLib.feeHookSlot();
        // packed: ICR bp, totalAssets bp, slippage bp, collateral
        slots[5] = ManagedLeveragedVaultStorageLib.maxDeviationICRInBPSlot();
        slots[6] = positionManagerSlot();
        slots[7] = borrowerOperationsSlot();

        bytes32[] memory r = vault.extSloads(slots);

        address asset_ = address(uint160(uint256(r[0])));
        address core_  = address(uint160(uint256(r[1])));
        address debt_  = address(uint160(uint256(r[2])));
        address target_= address(uint160(uint256(r[3])));
        address fee_   = address(uint160(uint256(r[4])));
        uint256 packed = uint256(r[5]);
        address positionManager_ = address(uint160(uint256(r[6])));
        address bo_    = address(uint160(uint256(r[7])));

        uint16 maxDevTotalAssetsBp = uint16(packed >> ManagedLeveragedVaultStorageLib.MAX_DEVIATION_TOTAL_ASSETS_IN_BP_BITS);
        uint16 maxSlippageSwapBp   = uint16(packed >> ManagedLeveragedVaultStorageLib.MAX_SLIPPAGE_SWAP_IN_BP_BITS);

        ctx = PropGettersLib.Context({
            asset: asset_,
            vault: address(vault),
            everlongCore: IEverlongCore(core_),
            positionManager: IPositionManager(positionManager_),
            borrowerOperations: IBorrowerOperations(bo_),
            debtToken: debt_,
            targetICRHook: ITargetICRHook(target_),
            feeHook: IFeeHook(fee_),
            maxDeviationTotalAssetsInBP: maxDevTotalAssetsBp,
            maxSlippageSwapInBP: maxSlippageSwapBp
        });
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 9 of 29 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20.sol";

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IDenManager} from "src/interfaces/periphery/beraborrow/IDenManager.sol";
import {IAsset} from "src/interfaces/utils/tokens/IAsset.sol";
import {PropMath} from "src/libraries/PropMath.sol";
import {FeeLib} from "src/libraries/FeeLib.sol";
import {PriceLib} from "src/libraries/PriceLib.sol";
import {IFeeHook} from "src/interfaces/utils/IFeeHook.sol";
import {ITargetICRHook} from "src/interfaces/utils/ITargetICRHook.sol";
import {IBaseManagedLeveragedVault} from "src/interfaces/core/mlv/base/IBaseManagedLeveragedVault.sol";
import {IBaseManagedLeveragedVaultGetters} from "src/interfaces/core/mlv/helpers/base/IBaseManagedLeveragedVaultGetters.sol";
import {IEverlongCore} from "src/interfaces/core/IEverlongCore.sol";
import {IPriceFeed} from "src/interfaces/core/oracles/IPriceFeed.sol";
import {IBorrowerOperations} from "src/interfaces/periphery/beraborrow/IBorrowerOperations.sol";

library ManagedLeveragedVaultStorageLib {
    // storage-location constant
    bytes32 private constant ERC4626_LOC = 0x0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00;
    bytes32 internal constant MLV_VAULT_LOC = 0x12ca37b393c412d053690654fb6d504d2a16c55c2bd10941af581f2221d9c100;

    // ERC4626 storage slots
    uint256 internal constant _ASSET_SLOT = 0;

    // MLV storage slots
    uint256 internal constant _BEACON_OWNER_SLOT = 0;
    uint256 internal constant _DEBT_TOKEN_SLOT = 1;
    uint256 internal constant _COLLATERAL_SLOT = 2;
    uint256 internal constant _MAX_DEVIATION_ICR_IN_BP_SLOT = 2;
    uint256 internal constant _MAX_DEVIATION_TOTAL_ASSETS_IN_BP_SLOT = 2;
    uint256 internal constant _MAX_SLIPPAGE_SWAP_IN_BP_SLOT = 2;
    uint256 internal constant _KEEPER_SLOT = 3;
    uint256 internal constant _TARGET_ICR_HOOK_SLOT = 4;
    uint256 internal constant _FEE_HOOK_SLOT = 5;
    uint256 internal constant _GETTERS_SLOT = 6;

    // bit offsets within slot 2
    uint256 internal constant MAX_DEVIATION_ICR_IN_BP_BITS = 160;
    uint256 internal constant MAX_DEVIATION_TOTAL_ASSETS_IN_BP_BITS = 176;
    uint256 internal constant MAX_SLIPPAGE_SWAP_IN_BP_BITS = 192;

    // ERC4626 simple-slot getters
    function assetSlot() internal pure returns (bytes32) {
        return bytes32(uint256(ERC4626_LOC) + _ASSET_SLOT);
    }

    // MLV simple-slot getters
    function everlongCoreSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _BEACON_OWNER_SLOT);
    }

    function debtTokenSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _DEBT_TOKEN_SLOT);
    }

    function collateralSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _COLLATERAL_SLOT);
    }

    function maxDeviationICRInBPSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _MAX_DEVIATION_ICR_IN_BP_SLOT);
    }

    function maxDeviationTotalAssetsInBPSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _MAX_DEVIATION_TOTAL_ASSETS_IN_BP_SLOT);
    }

    function maxSlippageSwapInBPSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _MAX_SLIPPAGE_SWAP_IN_BP_SLOT);
    }

    function keeperSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _KEEPER_SLOT);
    }

    function targetICRHookSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _TARGET_ICR_HOOK_SLOT);
    }

    function feeHookSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _FEE_HOOK_SLOT);
    }

    function gettersSlot() internal pure returns (bytes32) {
        return bytes32(uint256(MLV_VAULT_LOC) + _GETTERS_SLOT);
    }
}

abstract contract BaseManagedLeveragedVaultGetters is IBaseManagedLeveragedVaultGetters {
    using Math for uint256;
    using FeeLib for uint256;
    using PriceLib for uint256;
    using SafeCast for int256;

    IBaseManagedLeveragedVault public immutable vault;
    
    uint256 constant WAD = 1e18;
    uint256 constant BP = 1e4;

    constructor(IBaseManagedLeveragedVault _vault) {
        vault = _vault;
    }

    // ─── ERC4626 getters ──────────────────────────────────────────────
    function asset() public view returns (address) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.assetSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    // ─── ManagedLeveragedVault getters ──────────────────────────────
    function everlongCore() public view returns (address) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.everlongCoreSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function debtToken() public view returns (address) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.debtTokenSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function collateral() public view returns (address) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.collateralSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function maxDeviationICRbp() public view returns (uint16) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.maxDeviationICRInBPSlot());
        return uint16(uint256(vault.extSloads(slot)[0]) >> ManagedLeveragedVaultStorageLib.MAX_DEVIATION_ICR_IN_BP_BITS);
    }

    function maxDeviationTotalAssetsInBP() public view returns (uint16) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.maxDeviationTotalAssetsInBPSlot());
        return uint16(uint256(vault.extSloads(slot)[0]) >> ManagedLeveragedVaultStorageLib.MAX_DEVIATION_TOTAL_ASSETS_IN_BP_BITS);
    }

    function maxSlippageSwapInBP() public view returns (uint16) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.maxSlippageSwapInBPSlot());
        return uint16(uint256(vault.extSloads(slot)[0]) >> ManagedLeveragedVaultStorageLib.MAX_SLIPPAGE_SWAP_IN_BP_BITS);
    }

    function keeper() public view returns (address) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.keeperSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function feeHook() public view returns (address) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.feeHookSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function targetICRHook() public view returns (address) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.targetICRHookSlot());
        return address(uint160(uint256(vault.extSloads(slot)[0])));
    }

    function getters() public view returns (IBaseManagedLeveragedVaultGetters) {
        bytes32[] memory slot = _array(ManagedLeveragedVaultStorageLib.gettersSlot());
        return IBaseManagedLeveragedVaultGetters(address(uint160(uint256(vault.extSloads(slot)[0]))));
    }

    // ─── internal helper ────────────────────────────────────────────
    function _array(bytes32 x) internal pure returns (bytes32[] memory) {
        bytes32[] memory res = new bytes32[](1);
        res[0] = x;
        return res;
    }

    function getCollateralBalance() public view virtual returns (uint256) {}
    function getDebtBalance() public view virtual returns (uint256) {}
    function checkMaxOperationCost(address inputToken, uint256 amountToSwap, uint256 prevTotalAssets) external view virtual {}
    function getPrice(address token) public view virtual returns (uint256) {}
    function getCurrentPositionICR() public view virtual returns (uint256) {}

    function getCollateralValue() public view returns (uint256) {
        uint256 amount = getCollateralBalance();

        return getCollateralValue(amount);
    }

    function getCollateralValue(uint256 amount) public view returns (uint256) {
        address _collateral = collateral();
        uint256 price = getPrice(_collateral);

        return amount.convertToValue(price, IAsset(_collateral).decimals());
    }

    function getDebtValue() public view returns (uint256) {
        uint256 debtBalance = getDebtBalance();

        return getDebtValue(debtBalance);
    }

    function getDebtValue(uint256 amount) public view returns (uint256) {
        address _debtToken = debtToken();
        uint256 price = getPrice(_debtToken);

        return amount.convertToValue(price, IAsset(_debtToken).decimals());
    }

    function getTargetICR() public view returns (uint256) {
        ITargetICRHook _targetICRHook = ITargetICRHook(targetICRHook());

        return _targetICRHook.calcTargetICR();
    }

    function entryFeeInBP(uint256 amount, address caller) external view returns (uint256) {
        IFeeHook _feeHook = IFeeHook(feeHook());
        return _feeHook.calcFee(caller, asset(), amount, IFeeHook.Action.DEPOSIT);
    }

    function exitFeeInBP(uint256 amount, address caller) external view returns (uint256) {
        IFeeHook _feeHook = IFeeHook(feeHook());
        return _feeHook.calcFee(caller, asset(), amount, IFeeHook.Action.WITHDRAW);
    }

    function checkInvariantICR(uint256 currentICR, uint256 targetICR, IBaseManagedLeveragedVault.Tolerance tolerance) external view {
        uint256 maxDelta = Math.min(currentICR, targetICR).mulDiv(maxDeviationICRbp(), BP);

        if (IBaseManagedLeveragedVault.Tolerance.ABOVE == tolerance) {
            if (!PropMath._isWithinToleranceAbove(currentICR, targetICR, maxDelta)) revert PositionOutOfTargetCR(currentICR, targetICR, maxDelta);
        } else {
            if (!PropMath._isApproxEqAbs(currentICR, targetICR, maxDelta)) revert PositionOutOfTargetCR(currentICR, targetICR, maxDelta);
        }
    }

    function computeNetColl(
        uint256 nectSurplusInAssets,
        uint256 collToReceive,
        uint256 prevTotalAssets
    ) external view virtual returns (uint256 netColl) {
        uint256 currTotalAssets = vault.totalAssets();
        uint256 totalAssetsDelta = prevTotalAssets - currTotalAssets - nectSurplusInAssets;
        int256 operationProfit = int256(collToReceive) - int256(IERC4626(collateral()).convertToShares(totalAssetsDelta));
        netColl = (int256(collToReceive) + operationProfit).toUint256();
    }
}

File 11 of 29 : ManagedLeveragedVaultGettersV1.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {IBaseManagedLeveragedVault} from "src/interfaces/core/mlv/base/IBaseManagedLeveragedVault.sol";
import {ManagedLeveragedVaultStorageLib, BaseManagedLeveragedVaultGetters} from "src/core/mlv/helpers/base/BaseManagedLeveragedVaultGetters.sol";

abstract contract ManagedLeveragedVaultGettersV1 is BaseManagedLeveragedVaultGetters {
    constructor(IBaseManagedLeveragedVault _vault) BaseManagedLeveragedVaultGetters(_vault) {}
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

interface IPropManagedLeveragedVaultGetters {
    function borrowerOperations() external view returns (address);
    function positionManager() external view returns (address);
    function leverageRouter() external view returns (address);
    function deleverageRouter() external view returns (address);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {IPositionManager} from "src/interfaces/utils/IPositionManager.sol";
import {IBorrowerOperations} from "src/interfaces/utils/IBorrowerOperations.sol";
import {IEverlongCore} from "src/interfaces/core/IEverlongCore.sol";
import {IBaseManagedLeveragedVault} from "src/interfaces/core/mlv/base/IBaseManagedLeveragedVault.sol";
import {IAsset} from "src/interfaces/utils/tokens/IAsset.sol";
import {ITargetICRHook} from "src/interfaces/utils/ITargetICRHook.sol";
import {IFeeHook} from "src/interfaces/utils/IFeeHook.sol";
import {IPriceFeed} from "src/interfaces/core/oracles/IPriceFeed.sol";
import {PriceLib} from "src/libraries/PriceLib.sol";

library PropGettersLib {
    using Math for uint256;
    using PriceLib for uint256;

    uint256 constant BP = 1e4;

    error TotalAssetsDeviation(uint256 prevTotalAssets, uint256 newTotalAssets, uint256 maxDelta);
    error VaultSlippage(uint256 expected, uint256 actual);

    struct Context {
        address asset;
        address vault;
        IEverlongCore everlongCore;
        IPositionManager positionManager;
        IBorrowerOperations borrowerOperations;
        address debtToken;
        ITargetICRHook targetICRHook;
        IFeeHook feeHook;
        uint16 maxDeviationTotalAssetsInBP;
        uint16 maxSlippageSwapInBP;
    }

    function getCollateralBalance(Context memory $) internal view returns (uint256) {
        IPositionManager _positionManager = IPositionManager($.positionManager);

        (uint256 collVaultShares,) = _positionManager.getPositionCollAndDebt(address($.vault));
        collVaultShares += _positionManager.surplusBalances(address($.vault));
        return collVaultShares;
    }

    function getDebtBalance(Context memory $) internal view returns (uint256) {
        (, uint256 debt) = IPositionManager($.positionManager).getPositionCollAndDebt(address($.vault));
        return debt;
    }

    function getCurrentPositionICR(Context memory $) internal view returns (uint256) {
        IPositionManager _positionManager = IPositionManager($.positionManager);

        uint256 collPrice = _positionManager.fetchPrice();

        return _positionManager.getCurrentICR(address($.vault), collPrice);
    }

    function getPrice(Context memory $, address token) internal view returns (uint256 scaledPriceInUsdWad) {
        return IPriceFeed(IEverlongCore($.everlongCore).priceFeed()).fetchPrice(token);
    }

    function checkMaxOperationCost(Context memory $, address inputToken, uint256 amountToSwap, uint256 prevTotalAssets) internal view {
        uint256 currTotalAssets = IBaseManagedLeveragedVault($.vault).totalAssets();

        uint256 maxDelta = Math.min(prevTotalAssets, currTotalAssets).mulDiv($.maxDeviationTotalAssetsInBP, BP);
        if (currTotalAssets < prevTotalAssets - maxDelta) revert TotalAssetsDeviation(prevTotalAssets, currTotalAssets, maxDelta);

        int256 totalAssetsDelta = int256(prevTotalAssets) - int256(currTotalAssets);
        uint256 assetPrice = getPrice($, $.asset);
        uint256 debtFeeInAssets;

        if (inputToken == $.debtToken) {
            // Convert from NECT to assets
            IBorrowerOperations borrowerOps = IBorrowerOperations($.borrowerOperations);
            bool isRecoveryMode = borrowerOps.checkRecoveryMode(borrowerOps.getTCR());
            uint256 debtFee = isRecoveryMode ? 0 : IPositionManager($.positionManager).getBorrowingFeeWithDecay(amountToSwap);
            uint256 nectPrice = getPrice($, $.debtToken);

            debtFeeInAssets = debtFee.mulDiv(nectPrice, assetPrice);
            amountToSwap = amountToSwap.mulDiv(nectPrice, assetPrice);
        } else {
            uint256 exposurePrice = getPrice($, inputToken);
            // Convert from exposure to assets
            amountToSwap = amountToSwap.mulDiv(exposurePrice, assetPrice);
        }

        int256 totalAssetsDeltaFromSwap = totalAssetsDelta - int256(debtFeeInAssets);

        // Early return if positive swap slippage
        if (totalAssetsDeltaFromSwap <= 0) return;

        uint256 swapDelta = uint256(totalAssetsDeltaFromSwap);
        uint256 maxSwapDelta = amountToSwap.mulDiv($.maxSlippageSwapInBP, BP);
        if (swapDelta > maxSwapDelta) revert VaultSlippage(swapDelta, maxSwapDelta);
    }
}

File 14 of 29 : IPositionManager.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {IERC3156FlashBorrower} from "@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IFactory} from "src/interfaces/utils/IFactory.sol";

interface IPositionManager {
    event BaseRateUpdated(uint256 _baseRate);
    event CollateralSent(address _to, uint256 _amount);
    event LTermsUpdated(uint256 _L_collateral, uint256 _L_debt);
    event LastFeeOpTimeUpdated(uint256 _lastFeeOpTime);
    event Redemption(
        address indexed _redeemer,
        uint256 _attemptedDebtAmount,
        uint256 _actualDebtAmount,
        uint256 _collateralSent,
        uint256 _collateralFee
    );
    event SystemSnapshotsUpdated(uint256 _totalStakesSnapshot, uint256 _totalCollateralSnapshot);
    event TotalStakesUpdated(uint256 _newTotalStakes);
    event PositionIndexUpdated(address _borrower, uint256 _newIndex);
    event PositionSnapshotsUpdated(uint256 _L_collateral, uint256 _L_debt);
    event PositionUpdated(address indexed _borrower, uint256 _debt, uint256 _coll, uint256 _stake, uint8 _operation);

    function addCollateralSurplus(address borrower, uint256 collSurplus) external;

    function applyPendingRewards(address _borrower) external returns (uint256 coll, uint256 debt);

    function claimCollateral(address borrower, address _receiver) external;

    function closePosition(address _borrower, address _receiver, uint256 collAmount, uint256 debtAmount) external;

    function closePositionByLiquidation(address _borrower) external;

    function setCollVaultRouter(address _collVaultRouter) external;

    function collectInterests() external;

    function decayBaseRateAndGetBorrowingFee(uint256 _debt) external returns (uint256);

    function decreaseDebtAndSendCollateral(address account, uint256 debt, uint256 coll) external;

    function fetchPrice() external view returns (uint256);

    function finalizeLiquidation(
        address _liquidator,
        uint256 _debt,
        uint256 _coll,
        uint256 _collSurplus,
        uint256 _debtGasComp,
        uint256 _collGasComp
    ) external;

    function getEntireSystemBalances() external view returns (uint256, uint256, uint256);

    function movePendingPositionRewardsToActiveBalances(uint256 _debt, uint256 _collateral) external;

    function openPosition(
        address _borrower,
        uint256 _collateralAmount,
        uint256 _compositeDebt,
        uint256 NICR,
        address _upperHint,
        address _lowerHint
    ) external returns (uint256 stake, uint256 arrayIndex);

    function redeemCollateral(
        uint256 _debtAmount,
        address _firstRedemptionHint,
        address _upperPartialRedemptionHint,
        address _lowerPartialRedemptionHint,
        uint256 _partialRedemptionHintNICR,
        uint256 _maxIterations,
        uint256 _maxFeePercentage
    ) external;

    function setAddresses(address _priceFeedAddress, address _sortedPositionsAddress, address _collateralToken) external;

    function setParameters(
        IFactory.DeploymentParams calldata _params
    ) external;

    function setPaused(bool _paused) external;

    function setPriceFeed(address _priceFeedAddress) external;

    function startSunset() external;

    function updateBalances() external;

    function updatePositionFromAdjustment(
        bool _isDebtIncrease,
        uint256 _debtChange,
        uint256 _netDebtChange,
        bool _isCollIncrease,
        uint256 _collChange,
        address _upperHint,
        address _lowerHint,
        address _borrower,
        address _receiver
    ) external returns (uint256, uint256, uint256);

    function DEBT_GAS_COMPENSATION() external view returns (uint256);

    function DECIMAL_PRECISION() external view returns (uint256);

    function L_collateral() external view returns (uint256);

    function L_debt() external view returns (uint256);

    function MCR() external view returns (uint256);

    function PERCENT_DIVISOR() external view returns (uint256);

    function CORE() external view returns (address);

    function SUNSETTING_INTEREST_RATE() external view returns (uint256);

    function Positions(
        address
    )
        external
        view
        returns (
            uint256 debt,
            uint256 coll,
            uint256 stake,
            uint8 status,
            uint128 arrayIndex,
            uint256 activeInterestIndex
        );

    function activeInterestIndex() external view returns (uint256);

    function baseRate() external view returns (uint256);

    function borrowerOperations() external view returns (address);

    function borrowingFeeFloor() external view returns (uint256);

    function collateralToken() external view returns (address);

    function debtToken() external view returns (address);

    function collVaultRouter() external view returns (address);

    function defaultedCollateral() external view returns (uint256);

    function defaultedDebt() external view returns (uint256);

    function getBorrowingFee(uint256 _debt) external view returns (uint256);

    function getBorrowingFeeWithDecay(uint256 _debt) external view returns (uint256);

    function getBorrowingRate() external view returns (uint256);

    function getBorrowingRateWithDecay() external view returns (uint256);

    function getCurrentICR(address _borrower, uint256 _price) external view returns (uint256);

    function getEntireDebtAndColl(
        address _borrower
    ) external view returns (uint256 debt, uint256 coll, uint256 pendingDebtReward, uint256 pendingCollateralReward);

    function getEntireSystemColl() external view returns (uint256);

    function getEntireSystemDebt() external view returns (uint256);

    function getNominalICR(address _borrower) external view returns (uint256);

    function getPendingCollAndDebtRewards(address _borrower) external view returns (uint256, uint256);

    function getRedemptionFeeWithDecay(uint256 _collateralDrawn) external view returns (uint256);

    function getRedemptionRate() external view returns (uint256);

    function getRedemptionRateWithDecay() external view returns (uint256);

    function getTotalActiveCollateral() external view returns (uint256);

    function getTotalActiveDebt() external view returns (uint256);

    function getPositionCollAndDebt(address _borrower) external view returns (uint256 coll, uint256 debt);

    function getPositionFromPositionOwnersArray(uint256 _index) external view returns (address);

    function getPositionOwnersCount() external view returns (uint256);

    function getPositionStake(address _borrower) external view returns (uint256);

    function getPositionStatus(address _borrower) external view returns (uint256);

    function guardian() external view returns (address);

    function hasPendingRewards(address _borrower) external view returns (bool);

    function interestPayable() external view returns (uint256);

    function interestRate() external view returns (uint256);

    function lastActiveIndexUpdate() external view returns (uint256);

    function lastCollateralError_Redistribution() external view returns (uint256);

    function lastDebtError_Redistribution() external view returns (uint256);

    function lastFeeOperationTime() external view returns (uint256);

    function liquidationManager() external view returns (address);

    function maxBorrowingFee() external view returns (uint256);

    function maxRedemptionFee() external view returns (uint256);

    function maxSystemDebt() external view returns (uint256);

    function minuteDecayFactor() external view returns (uint256);

    function owner() external view returns (address);

    function paused() external view returns (bool);

    function priceFeed() external view returns (address);

    function redemptionFeeFloor() external view returns (uint256);

    function rewardSnapshots(address) external view returns (uint256 collateral, uint256 debt);

    function sortedPositions() external view returns (address);

    function sunsetting() external view returns (bool);

    function surplusBalances(address) external view returns (uint256);

    function systemDeploymentTime() external view returns (uint256);

    function totalCollateralSnapshot() external view returns (uint256);

    function totalStakes() external view returns (uint256);

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

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {ICore} from "./ICore.sol";

interface IBorrowerOperations {
    struct Balances {
        uint256[] collaterals;
        uint256[] debts;
        uint256[] prices;
    }

    event BorrowingFeePaid(address indexed borrower, uint256 amount);
    event CollateralConfigured(address positionManager, address collateralToken);
    event PositionCreated(address indexed _borrower, uint256 arrayIndex);
    event PositionManagerRemoved(address positionManager);
    event PositionUpdated(address indexed _borrower, uint256 _debt, uint256 _coll, uint256 stake, uint8 operation);

    function addColl(
        address positionManager,
        address account,
        uint256 _collateralAmount,
        address _upperHint,
        address _lowerHint
    ) external;

    function adjustPosition(
        address positionManager,
        address account,
        uint256 _maxFeePercentage,
        uint256 _collDeposit,
        uint256 _collWithdrawal,
        uint256 _debtChange,
        bool _isDebtIncrease,
        address _upperHint,
        address _lowerHint
    ) external;

    function closePosition(address positionManager, address account) external;

    function configureCollateral(address positionManager, address collateralToken) external;

    function fetchBalances() external view returns (Balances memory balances);

    function getGlobalSystemBalances() external view returns (uint256 totalPricedCollateral, uint256 totalDebt);

    function getTCR() external view returns (uint256 globalTotalCollateralRatio);

    function openPosition(
        address positionManager,
        address account,
        uint256 _maxFeePercentage,
        uint256 _collateralAmount,
        uint256 _debtAmount,
        address _upperHint,
        address _lowerHint
    ) external;

    function removePositionManager(address positionManager) external;

    function repayDebt(
        address positionManager,
        address account,
        uint256 _debtAmount,
        address _upperHint,
        address _lowerHint
    ) external;

    function setDelegateApproval(address _delegate, bool _isApproved) external;

    function setMinNetDebt(uint256 _minNetDebt) external;

    function withdrawColl(
        address positionManager,
        address account,
        uint256 _collWithdrawal,
        address _upperHint,
        address _lowerHint
    ) external;

    function withdrawDebt(
        address positionManager,
        address account,
        uint256 _maxFeePercentage,
        uint256 _debtAmount,
        address _upperHint,
        address _lowerHint
    ) external;

    function positionManagers(uint256) external view returns (address);

    function checkRecoveryMode(uint256 TCR) external view returns (bool);

    function DEBT_GAS_COMPENSATION() external view returns (uint256);

    function DECIMAL_PRECISION() external view returns (uint256);

    function PERCENT_DIVISOR() external view returns (uint256);

    function CORE() external view returns (ICore);

    function debtToken() external view returns (address);

    function factory() external view returns (address);

    function getCompositeDebt(uint256 _debt) external view returns (uint256);

    function guardian() external view returns (address);

    function isApprovedDelegate(address owner, address caller) external view returns (bool isApproved);

    function minNetDebt() external view returns (uint256);

    function owner() external view returns (address);

    function positionManagersData(address) external view returns (address collateralToken, uint16 index);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

/**
 * @title EverlongCore
 * @author Everlong Labs
 * @notice Single source of truth across all Everlong contracts for key administrative data
 */
interface IEverlongCore {
    function owner() external view returns (address);
    function feeReceiver() external view returns (address);
    function priceFeed() external view returns (address);

    function setFeeReceiver(address _feeReceiver) external;
}

File 17 of 29 : ITargetICRHook.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

interface ITargetICRHook {
    function calcTargetICR()
        external
        view
        returns (uint256 targetICR);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

interface IFeeHook {
    enum Action {
        DEPOSIT,
        MINT,
        WITHDRAW,
        REDEEM
    }

    function calcFee(address caller, address token, uint amount, Action action) external view returns (uint feeInBP);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10**64) {
                value /= 10**64;
                result += 64;
            }
            if (value >= 10**32) {
                value /= 10**32;
                result += 32;
            }
            if (value >= 10**16) {
                value /= 10**16;
                result += 16;
            }
            if (value >= 10**8) {
                value /= 10**8;
                result += 8;
            }
            if (value >= 10**4) {
                value /= 10**4;
                result += 4;
            }
            if (value >= 10**2) {
                value /= 10**2;
                result += 2;
            }
            if (value >= 10**1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}

File 20 of 29 : IDenManager.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {IERC3156FlashBorrower} from "@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IFactory} from "src/interfaces/utils/IFactory.sol";

interface IDenManager {
    event BaseRateUpdated(uint256 _baseRate);
    event CollateralSent(address _to, uint256 _amount);
    event LTermsUpdated(uint256 _L_collateral, uint256 _L_debt);
    event LastFeeOpTimeUpdated(uint256 _lastFeeOpTime);
    event Redemption(
        address indexed _redeemer,
        uint256 _attemptedDebtAmount,
        uint256 _actualDebtAmount,
        uint256 _collateralSent,
        uint256 _collateralFee
    );
    event SystemSnapshotsUpdated(uint256 _totalStakesSnapshot, uint256 _totalCollateralSnapshot);
    event TotalStakesUpdated(uint256 _newTotalStakes);
    event DenIndexUpdated(address _borrower, uint256 _newIndex);
    event DenSnapshotsUpdated(uint256 _L_collateral, uint256 _L_debt);
    event DenUpdated(address indexed _borrower, uint256 _debt, uint256 _coll, uint256 _stake, uint8 _operation);

    function addCollateralSurplus(address borrower, uint256 collSurplus) external;

    function applyPendingRewards(address _borrower) external returns (uint256 coll, uint256 debt);

    function claimCollateral(address borrower, address _receiver) external;

    function closeDen(address _borrower, address _receiver, uint256 collAmount, uint256 debtAmount) external;

    function closeDenByLiquidation(address _borrower) external;

    function setCollVaultRouter(address _collVaultRouter) external;

    function collectInterests() external;

    function decayBaseRateAndGetBorrowingFee(uint256 _debt) external returns (uint256);

    function decreaseDebtAndSendCollateral(address account, uint256 debt, uint256 coll) external;

    function fetchPrice() external view returns (uint256);

    function finalizeLiquidation(
        address _liquidator,
        uint256 _debt,
        uint256 _coll,
        uint256 _collSurplus,
        uint256 _debtGasComp,
        uint256 _collGasComp
    ) external;

    function getEntireSystemBalances() external view returns (uint256, uint256, uint256);

    function movePendingDenRewardsToActiveBalances(uint256 _debt, uint256 _collateral) external;

    function openDen(
        address _borrower,
        uint256 _collateralAmount,
        uint256 _compositeDebt,
        uint256 NICR,
        address _upperHint,
        address _lowerHint
    ) external returns (uint256 stake, uint256 arrayIndex);

    function redeemCollateral(
        uint256 _debtAmount,
        address _firstRedemptionHint,
        address _upperPartialRedemptionHint,
        address _lowerPartialRedemptionHint,
        uint256 _partialRedemptionHintNICR,
        uint256 _maxIterations,
        uint256 _maxFeePercentage
    ) external;

    function setAddresses(address _priceFeedAddress, address _sortedDensAddress, address _collateralToken) external;

    function setParameters(
        IFactory.DeploymentParams calldata _params
    ) external;

    function setPaused(bool _paused) external;

    function setPriceFeed(address _priceFeedAddress) external;

    function startSunset() external;

    function updateBalances() external;

    function updateDenFromAdjustment(
        bool _isDebtIncrease,
        uint256 _debtChange,
        uint256 _netDebtChange,
        bool _isCollIncrease,
        uint256 _collChange,
        address _upperHint,
        address _lowerHint,
        address _borrower,
        address _receiver
    ) external returns (uint256, uint256, uint256);

    function DEBT_GAS_COMPENSATION() external view returns (uint256);

    function DECIMAL_PRECISION() external view returns (uint256);

    function L_collateral() external view returns (uint256);

    function L_debt() external view returns (uint256);

    function MCR() external view returns (uint256);

    function PERCENT_DIVISOR() external view returns (uint256);

    function BERABORROW_CORE() external view returns (address);

    function SUNSETTING_INTEREST_RATE() external view returns (uint256);

    function Dens(
        address
    )
        external
        view
        returns (
            uint256 debt,
            uint256 coll,
            uint256 stake,
            uint8 status,
            uint128 arrayIndex,
            uint256 activeInterestIndex
        );

    function activeInterestIndex() external view returns (uint256);

    function baseRate() external view returns (uint256);

    function borrowerOperations() external view returns (address);

    function borrowingFeeFloor() external view returns (uint256);

    function collateralToken() external view returns (address);

    function debtToken() external view returns (address);

    function collVaultRouter() external view returns (address);

    function defaultedCollateral() external view returns (uint256);

    function defaultedDebt() external view returns (uint256);

    function getBorrowingFee(uint256 _debt) external view returns (uint256);

    function getBorrowingFeeWithDecay(uint256 _debt) external view returns (uint256);

    function getBorrowingRate() external view returns (uint256);

    function getBorrowingRateWithDecay() external view returns (uint256);

    function getCurrentICR(address _borrower, uint256 _price) external view returns (uint256);

    function getEntireDebtAndColl(
        address _borrower
    ) external view returns (uint256 debt, uint256 coll, uint256 pendingDebtReward, uint256 pendingCollateralReward);

    function getEntireSystemColl() external view returns (uint256);

    function getEntireSystemDebt() external view returns (uint256);

    function getNominalICR(address _borrower) external view returns (uint256);

    function getPendingCollAndDebtRewards(address _borrower) external view returns (uint256, uint256);

    function getRedemptionFeeWithDecay(uint256 _collateralDrawn) external view returns (uint256);

    function getRedemptionRate() external view returns (uint256);

    function getRedemptionRateWithDecay() external view returns (uint256);

    function getTotalActiveCollateral() external view returns (uint256);

    function getTotalActiveDebt() external view returns (uint256);

    function getDenCollAndDebt(address _borrower) external view returns (uint256 coll, uint256 debt);

    function getDenFromDenOwnersArray(uint256 _index) external view returns (address);

    function getDenOwnersCount() external view returns (uint256);

    function getDenStake(address _borrower) external view returns (uint256);

    function getDenStatus(address _borrower) external view returns (uint256);

    function guardian() external view returns (address);

    function hasPendingRewards(address _borrower) external view returns (bool);

    function interestPayable() external view returns (uint256);

    function interestRate() external view returns (uint256);

    function lastActiveIndexUpdate() external view returns (uint256);

    function lastCollateralError_Redistribution() external view returns (uint256);

    function lastDebtError_Redistribution() external view returns (uint256);

    function lastFeeOperationTime() external view returns (uint256);

    function liquidationManager() external view returns (address);

    function maxBorrowingFee() external view returns (uint256);

    function maxRedemptionFee() external view returns (uint256);

    function maxSystemDebt() external view returns (uint256);

    function minuteDecayFactor() external view returns (uint256);

    function owner() external view returns (address);

    function paused() external view returns (bool);

    function priceFeed() external view returns (address);

    function redemptionFeeFloor() external view returns (uint256);

    function rewardSnapshots(address) external view returns (uint256 collateral, uint256 debt);

    function sortedDens() external view returns (address);

    function sunsetting() external view returns (bool);

    function surplusBalances(address) external view returns (uint256);

    function systemDeploymentTime() external view returns (uint256);

    function totalCollateralSnapshot() external view returns (uint256);

    function totalStakes() external view returns (uint256);

    function totalStakesSnapshot() external view returns (uint256);

    function brimeDen() external view returns (address);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

library PropMath {
    uint256 internal constant DECIMAL_PRECISION = 1e18;

    /* Precision for Nominal ICR (independent of price). Rationale for the value:
     *
     * - Making it “too high” could lead to overflows.
     * - Making it “too low” could lead to an ICR equal to zero, due to truncation from Solidity floor division.
     *
     * This value of 1e20 is chosen for safety: the NICR will only overflow for numerator > ~1e39,
     * and will only truncate to 0 if the denominator is at least 1e20 times greater than the numerator.
     *
     */
    uint256 internal constant NICR_PRECISION = 1e20;

    function _min(uint256 _a, uint256 _b) internal pure returns (uint256) {
        return (_a < _b) ? _a : _b;
    }

    function _max(uint256 _a, uint256 _b) internal pure returns (uint256) {
        return (_a >= _b) ? _a : _b;
    }

    /*
     * Multiply two decimal numbers and use normal rounding rules:
     * -round product up if 19'th mantissa digit >= 5
     * -round product down if 19'th mantissa digit < 5
     *
     * Used only inside the exponentiation, _decPow().
     */
    function decMul(uint256 x, uint256 y) internal pure returns (uint256 decProd) {
        uint256 prod_xy = x * y;

        decProd = (prod_xy + (DECIMAL_PRECISION / 2)) / DECIMAL_PRECISION;
    }

    /*
     * _decPow: Exponentiation function for 18-digit decimal base, and integer exponent n.
     *
     * Uses the efficient "exponentiation by squaring" algorithm. O(log(n)) complexity.
     *
     * Called by two functions that represent time in units of minutes:
     * 1) PositionManager._calcDecayedBaseRate
     * 2) CommunityIssuance._getCumulativeIssuanceFraction
     *
     * The exponent is capped to avoid reverting due to overflow. The cap 525600000 equals
     * "minutes in 1000 years": 60 * 24 * 365 * 1000
     *
     * If a period of > 1000 years is ever used as an exponent in either of the above functions, the result will be
     * negligibly different from just passing the cap, since:
     *
     * In function 1), the decayed base rate will be 0 for 1000 years or > 1000 years
     * In function 2), the difference in tokens issued at 1000 years and any time > 1000 years, will be negligible
     */
    function _decPow(uint256 _base, uint256 _minutes) internal pure returns (uint256) {
        if (_minutes > 525600000) {
            _minutes = 525600000;
        } // cap to avoid overflow

        if (_minutes == 0) {
            return DECIMAL_PRECISION;
        }

        uint256 y = DECIMAL_PRECISION;
        uint256 x = _base;
        uint256 n = _minutes;

        // Exponentiation-by-squaring
        while (n > 1) {
            if (n % 2 == 0) {
                x = decMul(x, x);
                n = n / 2;
            } else {
                // if (n % 2 != 0)
                y = decMul(x, y);
                x = decMul(x, x);
                n = (n - 1) / 2;
            }
        }

        return decMul(x, y);
    }

    function _getAbsoluteDifference(uint256 _a, uint256 _b) internal pure returns (uint256) {
        return (_a >= _b) ? _a - _b : _b - _a;
    }

    function _computeNominalCR(uint256 _coll, uint256 _debt) internal pure returns (uint256) {
        if (_debt > 0) {
            return (_coll * NICR_PRECISION) / _debt;
        }
        // Return the maximal value for uint256 if the Position has a debt of 0. Represents "infinite" CR.
        else {
            // if (_debt == 0)
            return 2 ** 256 - 1;
        }
    }

    function _computeCR(uint256 _coll, uint256 _debt, uint256 _price) internal pure returns (uint256) {
        if (_debt > 0) {
            uint256 newCollRatio = (_coll * _price) / _debt;

            return newCollRatio;
        }
        // Return the maximal value for uint256 if the Position has a debt of 0. Represents "infinite" CR.
        else {
            // if (_debt == 0)
            return 2 ** 256 - 1;
        }
    }

    function _computeCR(uint256 _coll, uint256 _debt) internal pure returns (uint256) {
        if (_debt > 0) {
            uint256 newCollRatio = (_coll) / _debt;

            return newCollRatio;
        }
        // Return the maximal value for uint256 if the Position has a debt of 0. Represents "infinite" CR.
        else {
            // if (_debt == 0)
            return 2 ** 256 - 1;
        }
    }

    function _isApproxEqAbs(uint256 a, uint256 b, uint256 tolerance) internal pure returns (bool) {
        return a > b ? (a - b) <= tolerance : (b - a) <= tolerance;
    }

    function _isWithinToleranceAbove(
        uint256 a,
        uint256 b,
        uint256 tolerance
    ) internal pure returns (bool) {
        if (a < b) return false;
        return (a - b) <= tolerance;
    }

    function _isWithinToleranceBelow(
        uint256 a,
        uint256 b,
        uint256 tolerance
    ) internal pure returns (bool) {
        if (a > b) return false;
        return (b - a) <= tolerance;
    }
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

library FeeLib {
    using Math for uint;

    uint private constant BP = 1e4;

    /// @dev Calculates the fees that should be added to an amount `shares` that does already include fees.
    /// Used in {IERC4626-deposit}, {IERC4626-mint}, {IERC4626-withdraw} and {IERC4626-previewRedeem} operations.
    function feeOnRaw(
        uint shares,
        uint feeBP
    ) internal pure returns (uint) {
        return shares.mulDiv(feeBP, BP, Math.Rounding.Up);
    }

    /// @dev Calculates the fee part of an amount `shares` that deoes not includes fees.
    /// Used in {IERC4626-previewDeposit} and {IERC4626-previewRedeem} operations.
    function feeOnTotal(
        uint shares,
        uint feeBP
    ) internal pure returns (uint) {
        return shares.mulDiv(feeBP, feeBP + BP, Math.Rounding.Up);
    }
}

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

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

library PriceLib {
    using Math for uint;

    // WAD adjusted result
    function convertToValue(uint amount, uint price, uint8 decimals) internal pure returns (uint) {
        return amount * price / 10 ** decimals;
    }

    function convertToAmount(uint amountInUsd, uint collPrice, uint8 collDecimals, Math.Rounding rounding) internal pure returns (uint) {
        if (collPrice == 0 || amountInUsd == 0) {
            return 0;
        }

        return amountInUsd.mulDiv(10 ** collDecimals, collPrice, rounding);
    }

    // Coll decimal adjust amount result
    function convertAssetsToCollAmount(uint assets, uint collPrice, uint debtTokenPrice, uint8 vaultDecimals, uint8 collDecimals, Math.Rounding rounding) internal pure returns (uint) {
        uint assetsUsdValue = assets.mulDiv(debtTokenPrice, 10 ** vaultDecimals, rounding);

        if (collPrice != 0) {
            return convertToAmount(assetsUsdValue, collPrice, collDecimals, rounding);
        } else {
            return 0;
        }
    }

    function convertCollAmountToAssets(uint collAmount, uint collPrice, uint debtTokenPrice, uint8 vaultDecimals, uint8 collDecimals) internal pure returns (uint) {
        uint collUsdValue = collAmount * collPrice / 10 ** collDecimals;
        
        if (debtTokenPrice != 0) {
            return collUsdValue * 10 ** vaultDecimals / debtTokenPrice;
        } else {
            return 0;
        }
    }
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {IBaseManagedLeveragedVault} from "src/interfaces/core/mlv/base/IBaseManagedLeveragedVault.sol";

interface IBaseManagedLeveragedVaultGetters {
    error PositionOutOfTargetCR(uint256 currentICR, uint256 targetICR, uint256 maxDelta);
    error TotalAssetsDeviation(uint256 prevTotalAssets, uint256 newTotalAssets, uint256 maxDelta);
    error VaultSlippage(uint256 expected, uint256 actual);

    function getPrice(address token) external view returns (uint256);
    function vault() external view returns (IBaseManagedLeveragedVault);
    function getCollateralBalance() external view returns (uint256);
    function getCollateralValue() external view returns (uint256);
    function getCollateralValue(uint256 amount) external view returns (uint256);
    function getDebtBalance() external view returns (uint256);
    function getDebtValue() external view returns (uint256);
    function getDebtValue(uint256 amount) external view returns (uint256);
    function getCurrentPositionICR() external view returns (uint256);
    function getTargetICR() external view returns (uint256);
    function entryFeeInBP(uint256 amount, address caller) external view returns (uint256);
    function exitFeeInBP(uint256 amount, address caller) external view returns (uint256);
    function checkInvariantICR(uint256 currentICR, uint256 targetICR, IBaseManagedLeveragedVault.Tolerance tolerance) external view;
    function checkMaxOperationCost(address inputToken, uint256 amountToSwap, uint256 prevTotalAssets) external view;
    function computeNetColl(uint256 nectSurplusInAssets, uint256 collToReceive, uint256 prevTotalAssets) external view returns (uint256 netColl);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IPriceFeed {
    struct FeedType {
        address spotOracle;
        bool isCollVault;
    }

    event NewOracleRegistered(address token, address chainlinkAggregator, address underlyingDerivative);
    event PriceFeedStatusUpdated(address token, address oracle, bool isWorking);
    event PriceRecordUpdated(address indexed token, uint256 _price);
    event NewCollVaultRegistered(address collVault, bool enable);
    event NewSpotOracleRegistered(address token, address spotOracle);

    function fetchPrice(address _token) external view returns (uint256);

    function getMultiplePrices(address[] memory _tokens) external view returns (uint256[] memory prices);

    function setOracle(
        address _token,
        address _chainlinkOracle,
        uint32 _heartbeat,
        uint16 _staleThreshold,
        address underlyingDerivative
    ) external;

    function whitelistCollateralVault(address _collateralVaultShareToken, bool enable) external;
    
    function setSpotOracle(address _token, address _spotOracle) external;
    
    function MAX_PRICE_DEVIATION_FROM_PREVIOUS_ROUND() external view returns (uint256);

    function CORE() external view returns (address);

    function RESPONSE_TIMEOUT() external view returns (uint256);

    function TARGET_DIGITS() external view returns (uint256);

    function guardian() external view returns (address);

    function oracleRecords(
        address
    )
        external
        view
        returns (
        address chainLinkOracle,
        uint8 decimals,
        uint32 heartbeat,
        uint16 staleThreshold,
        address underlyingDerivative
    );

    function isCollVault(address _collateralVaultShareToken) external view returns (bool);

    function isStableBPT(address _oracle) external view returns (bool);

    function isWeightedBPT(address _oracle) external view returns (bool);

    function getSpotOracle(address _token) external view returns (address);

    function feedType(address _token) external view returns (FeedType memory);

    function owner() external view returns (address);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

import {ICore} from "src/interfaces/utils/ICore.sol";

interface IBorrowerOperations {
    struct Balances {
        uint256[] collaterals;
        uint256[] debts;
        uint256[] prices;
    }

    event BorrowingFeePaid(address indexed borrower, uint256 amount);
    event CollateralConfigured(address denManager, address collateralToken);
    event DenCreated(address indexed _borrower, uint256 arrayIndex);
    event DenManagerRemoved(address denManager);
    event DenUpdated(address indexed _borrower, uint256 _debt, uint256 _coll, uint256 stake, uint8 operation);

    function addColl(
        address denManager,
        address account,
        uint256 _collateralAmount,
        address _upperHint,
        address _lowerHint
    ) external;

    function adjustDen(
        address denManager,
        address account,
        uint256 _maxFeePercentage,
        uint256 _collDeposit,
        uint256 _collWithdrawal,
        uint256 _debtChange,
        bool _isDebtIncrease,
        address _upperHint,
        address _lowerHint
    ) external;

    function brimeDen() external view returns (address);

    function closeDen(address denManager, address account) external;

    function configureCollateral(address denManager, address collateralToken) external;

    function fetchBalances() external view returns (Balances memory balances);

    function getGlobalSystemBalances() external view returns (uint256 totalPricedCollateral, uint256 totalDebt);

    function getTCR() external view returns (uint256 globalTotalCollateralRatio);

    function openDen(
        address denManager,
        address account,
        uint256 _maxFeePercentage,
        uint256 _collateralAmount,
        uint256 _debtAmount,
        address _upperHint,
        address _lowerHint
    ) external;

    function removeDenManager(address denManager) external;

    function repayDebt(
        address denManager,
        address account,
        uint256 _debtAmount,
        address _upperHint,
        address _lowerHint
    ) external;

    function setDelegateApproval(address _delegate, bool _isApproved) external;

    function setMinNetDebt(uint256 _minNetDebt) external;

    function withdrawColl(
        address denManager,
        address account,
        uint256 _collWithdrawal,
        address _upperHint,
        address _lowerHint
    ) external;

    function withdrawDebt(
        address denManager,
        address account,
        uint256 _maxFeePercentage,
        uint256 _debtAmount,
        address _upperHint,
        address _lowerHint
    ) external;

    function denManagers(uint256) external view returns (address);

    function checkRecoveryMode(uint256 TCR) external view returns (bool);

    function DEBT_GAS_COMPENSATION() external view returns (uint256);

    function DECIMAL_PRECISION() external view returns (uint256);

    function PERCENT_DIVISOR() external view returns (uint256);

    function BERABORROW_CORE() external view returns (ICore);

    function debtToken() external view returns (address);

    function factory() external view returns (address);

    function getCompositeDebt(uint256 _debt) external view returns (uint256);

    function guardian() external view returns (address);

    function isApprovedDelegate(address owner, address caller) external view returns (bool isApproved);

    function minNetDebt() external view returns (uint256);

    function owner() external view returns (address);

    function denManagersData(address) external view returns (address collateralToken, uint16 index);

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

File 27 of 29 : IERC3156FlashBorrower.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (interfaces/IERC3156FlashBorrower.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC3156 FlashBorrower, as defined in
 * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
 *
 * _Available since v4.1._
 */
interface IERC3156FlashBorrower {
    /**
     * @dev Receive a flash loan.
     * @param initiator The initiator of the loan.
     * @param token The loan currency.
     * @param amount The amount of tokens lent.
     * @param fee The additional amount of tokens to repay.
     * @param data Arbitrary data structure, intended to contain user-defined parameters.
     * @return The keccak256 hash of "IERC3156FlashBorrower.onFlashLoan"
     */
    function onFlashLoan(
        address initiator,
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata data
    ) external returns (bytes32);
}

File 28 of 29 : IFactory.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

interface IFactory {
    // commented values are suggested default parameters
    struct DeploymentParams {
        uint256 minuteDecayFactor; // 999037758833783000  (half life of 12 hours)
        uint256 redemptionFeeFloor; // 1e18 / 1000 * 5  (0.5%)
        uint256 maxRedemptionFee; // 1e18  (100%)
        uint256 borrowingFeeFloor; // 1e18 / 1000 * 5  (0.5%)
        uint256 maxBorrowingFee; // 1e18 / 100 * 5  (5%)
        uint256 interestRateInBps; // 100 (1%)
        uint256 maxDebt;
        uint256 MCR; // 12 * 1e17  (120%)
        address collVaultRouter; // set to address(0) if DenManager coll is not CollateralVault
    }
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

interface ICore {

    // --- Public variables ---
    function metaCore() external view returns (address);
    function startTime() external view returns (uint256);
    function CCR() external view returns (uint256);
    function dmBootstrapPeriod() external view returns (uint64);
    function isPeriphery(address peripheryContract) external view returns (bool);

    // --- External functions ---

    function setPeripheryEnabled(address _periphery, bool _enabled) external;
    function setPMBootstrapPeriod(address dm, uint64 _bootstrapPeriod) external;
    function setNewCCR(uint256 _CCR) external;

    function priceFeed() external view returns (address);
    function owner() external view returns (address);
    function pendingOwner() external view returns (address);
    function guardian() external view returns (address);
    function feeReceiver() external view returns (address);
    function paused() external view returns (bool);
    function lspBootstrapPeriod() external view returns (uint64);
    function getLspEntryFee(address rebalancer) external view returns (uint16);
    function getLspExitFee(address rebalancer) external view returns (uint16);
    function interestProtocolShare() external view returns (uint16);
    function defaultInterestReceiver() external view returns (address);

    // --- Events ---
    event CCRSet(uint256 initialCCR);
    event PMBootstrapPeriodSet(address dm, uint64 bootstrapPeriod);
    event PeripheryEnabled(address indexed periphery, bool enabled);
}

Settings
{
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin-upgradeable/contracts/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "forge-std/=lib/forge-std/src/",
    "@uniswap/v3-core/=lib/v3-core/",
    "@uniswap/v3-periphery/=lib/v3-periphery/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "v3-core/=lib/v3-core/contracts/",
    "v3-periphery/=lib/v3-periphery/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 1
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract IBaseManagedLeveragedVault","name":"_vault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"currentICR","type":"uint256"},{"internalType":"uint256","name":"targetICR","type":"uint256"},{"internalType":"uint256","name":"maxDelta","type":"uint256"}],"name":"PositionOutOfTargetCR","type":"error"},{"inputs":[{"internalType":"uint256","name":"prevTotalAssets","type":"uint256"},{"internalType":"uint256","name":"newTotalAssets","type":"uint256"},{"internalType":"uint256","name":"maxDelta","type":"uint256"}],"name":"TotalAssetsDeviation","type":"error"},{"inputs":[{"internalType":"uint256","name":"prevTotalAssets","type":"uint256"},{"internalType":"uint256","name":"newTotalAssets","type":"uint256"},{"internalType":"uint256","name":"maxDelta","type":"uint256"}],"name":"TotalAssetsDeviation","type":"error"},{"inputs":[{"internalType":"uint256","name":"expected","type":"uint256"},{"internalType":"uint256","name":"actual","type":"uint256"}],"name":"VaultSlippage","type":"error"},{"inputs":[{"internalType":"uint256","name":"expected","type":"uint256"},{"internalType":"uint256","name":"actual","type":"uint256"}],"name":"VaultSlippage","type":"error"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowerOperations","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"currentICR","type":"uint256"},{"internalType":"uint256","name":"targetICR","type":"uint256"},{"internalType":"enum IBaseManagedLeveragedVault.Tolerance","name":"tolerance","type":"uint8"}],"name":"checkInvariantICR","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"uint256","name":"amountToSwap","type":"uint256"},{"internalType":"uint256","name":"prevTotalAssets","type":"uint256"}],"name":"checkMaxOperationCost","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collateral","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"debtTokenSurplusInAssets","type":"uint256"},{"internalType":"uint256","name":"collToReceive","type":"uint256"},{"internalType":"uint256","name":"prevTotalAssets","type":"uint256"}],"name":"computeNetColl","outputs":[{"internalType":"uint256","name":"netColl","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"debtToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deleverageRouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"caller","type":"address"}],"name":"entryFeeInBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"everlongCore","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"caller","type":"address"}],"name":"exitFeeInBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeHook","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCollateralBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getCollateralValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCollateralValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentPositionICR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDebtBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDebtValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getDebtValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTargetICR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getters","outputs":[{"internalType":"contract IBaseManagedLeveragedVaultGetters","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"keeper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"leverageRouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxDeviationICRbp","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxDeviationTotalAssetsInBP","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSlippageSwapInBP","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"targetICRHook","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract IBaseManagedLeveragedVault","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60a0604052348015600e575f80fd5b50604051611ffd380380611ffd833981016040819052602b91603b565b6001600160a01b03166080526066565b5f60208284031215604a575f80fd5b81516001600160a01b0381168114605f575f80fd5b9392505050565b608051611f476100b65f395f81816102de015281816103d90152818161048f01528181610658015281816107330152818161090701528181610bf801528181610d8901526119320152611f475ff3fe608060405234801561000f575f80fd5b5060043610610168575f3560e01c80630fc0958e1461016c5780631529a6391461019257806321216ba31461019a57806321a348a1146101af578063293772e5146101c457806338d52e0f146101d75780633d6105d9146101df57806341976e09146101e75780634ad45c84146101fa5780634bb701ad146102025780635ccbbdf11461020a5780636317732e14610212578063685159f81461021a57806377553ad414610235578063791b98bc1461023d5780638152e2601461024557806382fee08f1461024d5780638f3fadf61461026057806391b58ae814610273578063aced16611461027b578063c0177bd514610283578063c047e56314610296578063d3af80d71461029e578063d8dfeb45146102a6578063ebe6e53d146102ae578063ec9d2552146102c1578063f11f4461146102c9578063f8d89898146102d1578063fbfa77cf146102d9578063fcfa3e9414610300575b5f80fd5b61017f61017a3660046119e4565b610308565b6040519081526020015b60405180910390f35b61017f610397565b6101a26103ad565b6040516101899190611a12565b6101c26101bd366004611a26565b610470565b005b61017f6101d2366004611a58565b61048b565b6101a26105d2565b6101a26105df565b61017f6101f5366004611a81565b6105ec565b61017f6105ff565b6101a261061a565b61017f610627565b6101a2610638565b610222610645565b60405161ffff9091168152602001610189565b6101a2610706565b6101a2610713565b610222610720565b61017f61025b366004611a9c565b61077d565b6101c261026e366004611ab3565b610809565b61017f6108b7565b6101a26108c8565b61017f610291366004611a9c565b6108d5565b61017f6108df565b6102226108f4565b6101a2610951565b61017f6102bc3660046119e4565b61095e565b61017f6109a3565b6101a2610a0f565b6101a2610a1c565b6101a27f000000000000000000000000000000000000000000000000000000000000000081565b6101a2610a29565b5f80610312610a0f565b9050806001600160a01b031663385d2ae28461032c6105d2565b8760026040518563ffffffff1660e01b815260040161034e9493929190611b00565b602060405180830381865afa158015610369573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061038d9190611b4a565b9150505b92915050565b5f6103a86103a3610a36565b610e0a565b905090565b5f806103bf6103ba610efe565b610f1b565b604051637784c68560e01b81529091506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690637784c6859061040e908490600401611b61565b5f60405180830381865afa158015610428573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261044f9190810190611bb7565b5f8151811061046057610460611c7e565b60200260200101515f1c91505090565b61048683838361047e610a36565b929190610f64565b505050565b5f807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104e9573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061050d9190611b4a565b90505f8561051b8386611ca6565b6105259190611ca6565b90505f6105318261126c565b90505f61053c610951565b6001600160a01b031663c6e6f592836040518263ffffffff1660e01b815260040161056991815260200190565b602060405180830381865afa158015610584573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105a89190611b4a565b6105b29088611cb9565b90506105c66105c18289611cdf565b61140e565b98975050505050505050565b5f806103bf6103ba611463565b5f806103bf6103ba61148e565b5f610391826105f9610a36565b906114a7565b5f80610609610627565b9050610614816108d5565b91505090565b5f806103bf6103ba61157d565b5f6103a8610633610a36565b611596565b5f806103bf6103ba61160a565b5f806106526103ba611623565b905060b07f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637784c685836040518263ffffffff1660e01b81526004016106a29190611b61565b5f60405180830381865afa1580156106bc573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526106e39190810190611bb7565b5f815181106106f4576106f4611c7e565b60200260200101515f1c901c91505090565b5f806103bf6103ba61163c565b5f806103bf6103ba611655565b5f8061072d6103ba611623565b905060c07f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637784c685836040518263ffffffff1660e01b81526004016106a29190611b61565b5f80610787610951565b90505f610793826105ec565b905061080181836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107d5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107f99190611d06565b86919061166e565b949350505050565b5f61082d6108156108f4565b61ffff16612710610826878761168e565b91906116a3565b905081600181111561084157610841611aec565b5f036108835761085284848361174c565b61087e5783838260405163ed9118ed60e01b815260040161087593929190611d26565b60405180910390fd5b6108b1565b61088e848483611771565b6108b15783838260405163ed9118ed60e01b815260040161087593929190611d26565b50505050565b5f6103a86108c3610a36565b61178b565b5f806103bf6103ba61186c565b5f80610787610a1c565b5f806108e9610397565b90506106148161077d565b5f806109016103ba611623565b905060a07f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637784c685836040518263ffffffff1660e01b81526004016106a29190611b61565b5f806103bf6103ba611623565b5f80610968610a0f565b9050806001600160a01b031663385d2ae2846109826105d2565b875f6040518563ffffffff1660e01b815260040161034e9493929190611b00565b5f806109ad61061a565b9050806001600160a01b031663404adb316040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109eb573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106149190611b4a565b5f806103bf6103ba611885565b5f806103bf6103ba61189e565b5f806103bf6103ba6118b7565b60408051610140810182525f80825260208201819052818301819052606082018190526080820181905260a0820181905260c0820181905260e0820181905261010082018190526101208083018290528351600880825291810190945291929091816020016020820280368337019050509050610ab1611463565b815f81518110610ac357610ac3611c7e565b602002602001018181525050610ad7610efe565b81600181518110610aea57610aea611c7e565b602002602001018181525050610afe61189e565b81600281518110610b1157610b11611c7e565b602002602001018181525050610b2561157d565b81600381518110610b3857610b38611c7e565b602002602001018181525050610b4c611885565b81600481518110610b5f57610b5f611c7e565b602002602001018181525050610b73611623565b81600581518110610b8657610b86611c7e565b602002602001018181525050610b9a611655565b81600681518110610bad57610bad611c7e565b602002602001018181525050610bc161163c565b81600781518110610bd457610bd4611c7e565b6020908102919091010152604051637784c68560e01b81525f906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690637784c68590610c2d908590600401611b61565b5f60405180830381865afa158015610c47573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610c6e9190810190611bb7565b90505f815f81518110610c8357610c83611c7e565b60200260200101515f1c90505f82600181518110610ca357610ca3611c7e565b60200260200101515f1c90505f83600281518110610cc357610cc3611c7e565b60200260200101515f1c90505f84600381518110610ce357610ce3611c7e565b60200260200101515f1c90505f85600481518110610d0357610d03611c7e565b60200260200101515f1c90505f86600581518110610d2357610d23611c7e565b60200260200101515f1c90505f87600681518110610d4357610d43611c7e565b60200260200101515f1c90505f88600781518110610d6357610d63611c7e565b60209081029190910181015160408051610140810182526001600160a01b039b8c1681527f00000000000000000000000000000000000000000000000000000000000000008c1693810193909352988a1698820198909852918816606083015250948616608086015292851660a085015290841660c084810191909152931660e083015261ffff60b082901c8116610100840152921c919091166101208201529392505050565b606081015160208201516040516375bd3fbf60e11b81525f929183916001600160a01b0384169163eb7a7f7e91610e449190600401611a12565b6040805180830381865afa158015610e5e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e829190611d3c565b50602085015160405163ec38a05d60e01b81529192506001600160a01b0384169163ec38a05d91610eb591600401611a12565b602060405180830381865afa158015610ed0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ef49190611b4a565b6108019082611d5e565b5f610f16815f80516020611ef2833981519152611d5e565b919050565b6040805160018082528183019092526060915f91906020808301908036833701905050905082815f81518110610f5357610f53611c7e565b602090810291909101015292915050565b5f84602001516001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fa5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fc99190611b4a565b90505f610fe686610100015161ffff16612710610826868661168e565b9050610ff28184611ca6565b82101561101857828282604051630e54628560e11b815260040161087593929190611d26565b5f6110238385611cb9565b90505f61103388895f01516114a7565b90505f8860a001516001600160a01b0316886001600160a01b0316036111da575f896080015190505f816001600160a01b0316634e443d9e836001600160a01b031663b620115d6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110a7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110cb9190611b4a565b6040518263ffffffff1660e01b81526004016110e991815260200190565b602060405180830381865afa158015611104573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111289190611d71565b90505f816111a25760608c015160405163477d66cf60e01b8152600481018c90526001600160a01b039091169063477d66cf90602401602060405180830381865afa158015611179573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061119d9190611b4a565b6111a4565b5f5b90505f6111b58d8e60a001516114a7565b90506111c28282886116a3565b94506111cf8b82886116a3565b9a50505050506111f6565b5f6111e58a8a6114a7565b90506111f28882856116a3565b9750505b5f6112018285611cb9565b90505f8113611215575050505050506108b1565b6101208a015181905f90611231908b9061ffff166127106116a3565b90508082111561125e576040516327014c6d60e11b81526004810183905260248101829052604401610875565b505050505050505050505050565b5f80611276610951565b6001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112b1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112d59190611d90565b90505f6112e1826105ec565b90505f6112ef6101f56118d0565b90505f836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561132e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113529190611d06565b6113609060ff16600a611e8e565b90505f61136b6118d0565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113a6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113ca9190611d06565b6113d89060ff16600a611e8e565b90506113e48185611e99565b826113ef858a611e99565b6113f99190611e99565b6114039190611ec4565b979650505050505050565b5f8082121561145f5760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152606401610875565b5090565b5f610f16817f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00611d5e565b5f610f16600a5f80516020611ef2833981519152611d5e565b5f82604001516001600160a01b031663741bef1a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114e8573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061150c9190611d90565b6001600160a01b031663ace1798e836040518263ffffffff1660e01b81526004016115379190611a12565b602060405180830381865afa158015611552573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115769190611b4a565b9392505050565b5f610f1660045f80516020611ef2833981519152611d5e565b5f8082606001516001600160a01b031663eb7a7f7e84602001516040518263ffffffff1660e01b81526004016115cc9190611a12565b6040805180830381865afa1580156115e6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108019190611d3c565b5f610f1660065f80516020611ef2833981519152611d5e565b5f610f1660025f80516020611ef2833981519152611d5e565b5f610f1660075f80516020611ef2833981519152611d5e565b5f610f1660085f80516020611ef2833981519152611d5e565b5f61167a82600a611ee3565b6116848486611e99565b6108019190611ec4565b5f81831061169c5781611576565b5090919050565b5f80805f19858709858702925082811083820303915050805f036116da578382816116d0576116d0611eb0565b0492505050611576565b8084116116e5575f80fd5b5f8486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091025f889003889004909101858311909403939093029303949094049190911702949350505050565b5f8284101561175c57505f611576565b816117678486611ca6565b1115949350505050565b5f82841161175c57816117848585611ca6565b1115610801565b5f80826060015190505f816001600160a01b0316630fdb11cf6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117d1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117f59190611b4a565b6020850151604051630d293c7160e41b81526001600160a01b0391821660048201526024810183905291925083169063d293c71090604401602060405180830381865afa158015611848573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108019190611b4a565b5f610f1660035f80516020611ef2833981519152611d5e565b5f610f1660055f80516020611ef2833981519152611d5e565b5f610f1660015f80516020611ef2833981519152611d5e565b5f610f1660095f80516020611ef2833981519152611d5e565b6040805160018082528183019092525f91829190602080830190803683370190505090506118fc611463565b815f8151811061190e5761190e611c7e565b6020908102919091010152604051637784c68560e01b81525f906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690637784c68590611967908590600401611b61565b5f60405180830381865afa158015611981573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526119a89190810190611bb7565b9050805f815181106119bc576119bc611c7e565b60200260200101515f1c9250505090565b6001600160a01b03811681146119e1575f80fd5b50565b5f80604083850312156119f5575f80fd5b823591506020830135611a07816119cd565b809150509250929050565b6001600160a01b0391909116815260200190565b5f805f60608486031215611a38575f80fd5b8335611a43816119cd565b95602085013595506040909401359392505050565b5f805f60608486031215611a6a575f80fd5b505081359360208301359350604090920135919050565b5f60208284031215611a91575f80fd5b8135611576816119cd565b5f60208284031215611aac575f80fd5b5035919050565b5f805f60608486031215611ac5575f80fd5b8335925060208401359150604084013560028110611ae1575f80fd5b809150509250925092565b634e487b7160e01b5f52602160045260245ffd5b6001600160a01b03858116825284166020820152604081018390526080810160048310611b3b57634e487b7160e01b5f52602160045260245ffd5b82606083015295945050505050565b5f60208284031215611b5a575f80fd5b5051919050565b602080825282518282018190525f918401906040840190835b81811015611b98578351835260209384019390920191600101611b7a565b509095945050505050565b634e487b7160e01b5f52604160045260245ffd5b5f60208284031215611bc7575f80fd5b81516001600160401b03811115611bdc575f80fd5b8201601f81018413611bec575f80fd5b80516001600160401b03811115611c0557611c05611ba3565b604051600582901b90603f8201601f191681016001600160401b0381118282101715611c3357611c33611ba3565b604052918252602081840181019290810187841115611c50575f80fd5b6020850194505b83851015611c7357845180825260209586019590935001611c57565b509695505050505050565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8181038181111561039157610391611c92565b8181035f831280158383131683831282161715611cd857611cd8611c92565b5092915050565b8082018281125f831280158216821582161715611cfe57611cfe611c92565b505092915050565b5f60208284031215611d16575f80fd5b815160ff81168114611576575f80fd5b9283526020830191909152604082015260600190565b5f8060408385031215611d4d575f80fd5b505080516020909101519092909150565b8082018082111561039157610391611c92565b5f60208284031215611d81575f80fd5b81518015158114611576575f80fd5b5f60208284031215611da0575f80fd5b8151611576816119cd565b6001815b6001841115611de657808504811115611dca57611dca611c92565b6001841615611dd857908102905b60019390931c928002611daf565b935093915050565b5f82611dfc57506001610391565b81611e0857505f610391565b8160018114611e1e5760028114611e2857611e44565b6001915050610391565b60ff841115611e3957611e39611c92565b50506001821b610391565b5060208310610133831016604e8410600b8410161715611e67575081810a610391565b611e735f198484611dab565b805f1904821115611e8657611e86611c92565b029392505050565b5f6115768383611dee565b808202811582820484141761039157610391611c92565b634e487b7160e01b5f52601260045260245ffd5b5f82611ede57634e487b7160e01b5f52601260045260245ffd5b500490565b5f61157660ff841683611dee56fe12ca37b393c412d053690654fb6d504d2a16c55c2bd10941af581f2221d9c100a26469706673582212202c221574094d628a1c379a45998cbc94ae0473d1b4aefbf1edbd13b55089192d64736f6c634300081a00330000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc

Deployed Bytecode

0x608060405234801561000f575f80fd5b5060043610610168575f3560e01c80630fc0958e1461016c5780631529a6391461019257806321216ba31461019a57806321a348a1146101af578063293772e5146101c457806338d52e0f146101d75780633d6105d9146101df57806341976e09146101e75780634ad45c84146101fa5780634bb701ad146102025780635ccbbdf11461020a5780636317732e14610212578063685159f81461021a57806377553ad414610235578063791b98bc1461023d5780638152e2601461024557806382fee08f1461024d5780638f3fadf61461026057806391b58ae814610273578063aced16611461027b578063c0177bd514610283578063c047e56314610296578063d3af80d71461029e578063d8dfeb45146102a6578063ebe6e53d146102ae578063ec9d2552146102c1578063f11f4461146102c9578063f8d89898146102d1578063fbfa77cf146102d9578063fcfa3e9414610300575b5f80fd5b61017f61017a3660046119e4565b610308565b6040519081526020015b60405180910390f35b61017f610397565b6101a26103ad565b6040516101899190611a12565b6101c26101bd366004611a26565b610470565b005b61017f6101d2366004611a58565b61048b565b6101a26105d2565b6101a26105df565b61017f6101f5366004611a81565b6105ec565b61017f6105ff565b6101a261061a565b61017f610627565b6101a2610638565b610222610645565b60405161ffff9091168152602001610189565b6101a2610706565b6101a2610713565b610222610720565b61017f61025b366004611a9c565b61077d565b6101c261026e366004611ab3565b610809565b61017f6108b7565b6101a26108c8565b61017f610291366004611a9c565b6108d5565b61017f6108df565b6102226108f4565b6101a2610951565b61017f6102bc3660046119e4565b61095e565b61017f6109a3565b6101a2610a0f565b6101a2610a1c565b6101a27f0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc81565b6101a2610a29565b5f80610312610a0f565b9050806001600160a01b031663385d2ae28461032c6105d2565b8760026040518563ffffffff1660e01b815260040161034e9493929190611b00565b602060405180830381865afa158015610369573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061038d9190611b4a565b9150505b92915050565b5f6103a86103a3610a36565b610e0a565b905090565b5f806103bf6103ba610efe565b610f1b565b604051637784c68560e01b81529091506001600160a01b037f0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc1690637784c6859061040e908490600401611b61565b5f60405180830381865afa158015610428573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261044f9190810190611bb7565b5f8151811061046057610460611c7e565b60200260200101515f1c91505090565b61048683838361047e610a36565b929190610f64565b505050565b5f807f0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc6001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104e9573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061050d9190611b4a565b90505f8561051b8386611ca6565b6105259190611ca6565b90505f6105318261126c565b90505f61053c610951565b6001600160a01b031663c6e6f592836040518263ffffffff1660e01b815260040161056991815260200190565b602060405180830381865afa158015610584573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105a89190611b4a565b6105b29088611cb9565b90506105c66105c18289611cdf565b61140e565b98975050505050505050565b5f806103bf6103ba611463565b5f806103bf6103ba61148e565b5f610391826105f9610a36565b906114a7565b5f80610609610627565b9050610614816108d5565b91505090565b5f806103bf6103ba61157d565b5f6103a8610633610a36565b611596565b5f806103bf6103ba61160a565b5f806106526103ba611623565b905060b07f0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc6001600160a01b0316637784c685836040518263ffffffff1660e01b81526004016106a29190611b61565b5f60405180830381865afa1580156106bc573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526106e39190810190611bb7565b5f815181106106f4576106f4611c7e565b60200260200101515f1c901c91505090565b5f806103bf6103ba61163c565b5f806103bf6103ba611655565b5f8061072d6103ba611623565b905060c07f0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc6001600160a01b0316637784c685836040518263ffffffff1660e01b81526004016106a29190611b61565b5f80610787610951565b90505f610793826105ec565b905061080181836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107d5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107f99190611d06565b86919061166e565b949350505050565b5f61082d6108156108f4565b61ffff16612710610826878761168e565b91906116a3565b905081600181111561084157610841611aec565b5f036108835761085284848361174c565b61087e5783838260405163ed9118ed60e01b815260040161087593929190611d26565b60405180910390fd5b6108b1565b61088e848483611771565b6108b15783838260405163ed9118ed60e01b815260040161087593929190611d26565b50505050565b5f6103a86108c3610a36565b61178b565b5f806103bf6103ba61186c565b5f80610787610a1c565b5f806108e9610397565b90506106148161077d565b5f806109016103ba611623565b905060a07f0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc6001600160a01b0316637784c685836040518263ffffffff1660e01b81526004016106a29190611b61565b5f806103bf6103ba611623565b5f80610968610a0f565b9050806001600160a01b031663385d2ae2846109826105d2565b875f6040518563ffffffff1660e01b815260040161034e9493929190611b00565b5f806109ad61061a565b9050806001600160a01b031663404adb316040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109eb573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106149190611b4a565b5f806103bf6103ba611885565b5f806103bf6103ba61189e565b5f806103bf6103ba6118b7565b60408051610140810182525f80825260208201819052818301819052606082018190526080820181905260a0820181905260c0820181905260e0820181905261010082018190526101208083018290528351600880825291810190945291929091816020016020820280368337019050509050610ab1611463565b815f81518110610ac357610ac3611c7e565b602002602001018181525050610ad7610efe565b81600181518110610aea57610aea611c7e565b602002602001018181525050610afe61189e565b81600281518110610b1157610b11611c7e565b602002602001018181525050610b2561157d565b81600381518110610b3857610b38611c7e565b602002602001018181525050610b4c611885565b81600481518110610b5f57610b5f611c7e565b602002602001018181525050610b73611623565b81600581518110610b8657610b86611c7e565b602002602001018181525050610b9a611655565b81600681518110610bad57610bad611c7e565b602002602001018181525050610bc161163c565b81600781518110610bd457610bd4611c7e565b6020908102919091010152604051637784c68560e01b81525f906001600160a01b037f0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc1690637784c68590610c2d908590600401611b61565b5f60405180830381865afa158015610c47573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610c6e9190810190611bb7565b90505f815f81518110610c8357610c83611c7e565b60200260200101515f1c90505f82600181518110610ca357610ca3611c7e565b60200260200101515f1c90505f83600281518110610cc357610cc3611c7e565b60200260200101515f1c90505f84600381518110610ce357610ce3611c7e565b60200260200101515f1c90505f85600481518110610d0357610d03611c7e565b60200260200101515f1c90505f86600581518110610d2357610d23611c7e565b60200260200101515f1c90505f87600681518110610d4357610d43611c7e565b60200260200101515f1c90505f88600781518110610d6357610d63611c7e565b60209081029190910181015160408051610140810182526001600160a01b039b8c1681527f0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc8c1693810193909352988a1698820198909852918816606083015250948616608086015292851660a085015290841660c084810191909152931660e083015261ffff60b082901c8116610100840152921c919091166101208201529392505050565b606081015160208201516040516375bd3fbf60e11b81525f929183916001600160a01b0384169163eb7a7f7e91610e449190600401611a12565b6040805180830381865afa158015610e5e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e829190611d3c565b50602085015160405163ec38a05d60e01b81529192506001600160a01b0384169163ec38a05d91610eb591600401611a12565b602060405180830381865afa158015610ed0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ef49190611b4a565b6108019082611d5e565b5f610f16815f80516020611ef2833981519152611d5e565b919050565b6040805160018082528183019092526060915f91906020808301908036833701905050905082815f81518110610f5357610f53611c7e565b602090810291909101015292915050565b5f84602001516001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fa5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fc99190611b4a565b90505f610fe686610100015161ffff16612710610826868661168e565b9050610ff28184611ca6565b82101561101857828282604051630e54628560e11b815260040161087593929190611d26565b5f6110238385611cb9565b90505f61103388895f01516114a7565b90505f8860a001516001600160a01b0316886001600160a01b0316036111da575f896080015190505f816001600160a01b0316634e443d9e836001600160a01b031663b620115d6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110a7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110cb9190611b4a565b6040518263ffffffff1660e01b81526004016110e991815260200190565b602060405180830381865afa158015611104573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111289190611d71565b90505f816111a25760608c015160405163477d66cf60e01b8152600481018c90526001600160a01b039091169063477d66cf90602401602060405180830381865afa158015611179573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061119d9190611b4a565b6111a4565b5f5b90505f6111b58d8e60a001516114a7565b90506111c28282886116a3565b94506111cf8b82886116a3565b9a50505050506111f6565b5f6111e58a8a6114a7565b90506111f28882856116a3565b9750505b5f6112018285611cb9565b90505f8113611215575050505050506108b1565b6101208a015181905f90611231908b9061ffff166127106116a3565b90508082111561125e576040516327014c6d60e11b81526004810183905260248101829052604401610875565b505050505050505050505050565b5f80611276610951565b6001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112b1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112d59190611d90565b90505f6112e1826105ec565b90505f6112ef6101f56118d0565b90505f836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561132e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113529190611d06565b6113609060ff16600a611e8e565b90505f61136b6118d0565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113a6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113ca9190611d06565b6113d89060ff16600a611e8e565b90506113e48185611e99565b826113ef858a611e99565b6113f99190611e99565b6114039190611ec4565b979650505050505050565b5f8082121561145f5760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152606401610875565b5090565b5f610f16817f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00611d5e565b5f610f16600a5f80516020611ef2833981519152611d5e565b5f82604001516001600160a01b031663741bef1a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114e8573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061150c9190611d90565b6001600160a01b031663ace1798e836040518263ffffffff1660e01b81526004016115379190611a12565b602060405180830381865afa158015611552573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115769190611b4a565b9392505050565b5f610f1660045f80516020611ef2833981519152611d5e565b5f8082606001516001600160a01b031663eb7a7f7e84602001516040518263ffffffff1660e01b81526004016115cc9190611a12565b6040805180830381865afa1580156115e6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108019190611d3c565b5f610f1660065f80516020611ef2833981519152611d5e565b5f610f1660025f80516020611ef2833981519152611d5e565b5f610f1660075f80516020611ef2833981519152611d5e565b5f610f1660085f80516020611ef2833981519152611d5e565b5f61167a82600a611ee3565b6116848486611e99565b6108019190611ec4565b5f81831061169c5781611576565b5090919050565b5f80805f19858709858702925082811083820303915050805f036116da578382816116d0576116d0611eb0565b0492505050611576565b8084116116e5575f80fd5b5f8486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091025f889003889004909101858311909403939093029303949094049190911702949350505050565b5f8284101561175c57505f611576565b816117678486611ca6565b1115949350505050565b5f82841161175c57816117848585611ca6565b1115610801565b5f80826060015190505f816001600160a01b0316630fdb11cf6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117d1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117f59190611b4a565b6020850151604051630d293c7160e41b81526001600160a01b0391821660048201526024810183905291925083169063d293c71090604401602060405180830381865afa158015611848573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108019190611b4a565b5f610f1660035f80516020611ef2833981519152611d5e565b5f610f1660055f80516020611ef2833981519152611d5e565b5f610f1660015f80516020611ef2833981519152611d5e565b5f610f1660095f80516020611ef2833981519152611d5e565b6040805160018082528183019092525f91829190602080830190803683370190505090506118fc611463565b815f8151811061190e5761190e611c7e565b6020908102919091010152604051637784c68560e01b81525f906001600160a01b037f0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc1690637784c68590611967908590600401611b61565b5f60405180830381865afa158015611981573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526119a89190810190611bb7565b9050805f815181106119bc576119bc611c7e565b60200260200101515f1c9250505090565b6001600160a01b03811681146119e1575f80fd5b50565b5f80604083850312156119f5575f80fd5b823591506020830135611a07816119cd565b809150509250929050565b6001600160a01b0391909116815260200190565b5f805f60608486031215611a38575f80fd5b8335611a43816119cd565b95602085013595506040909401359392505050565b5f805f60608486031215611a6a575f80fd5b505081359360208301359350604090920135919050565b5f60208284031215611a91575f80fd5b8135611576816119cd565b5f60208284031215611aac575f80fd5b5035919050565b5f805f60608486031215611ac5575f80fd5b8335925060208401359150604084013560028110611ae1575f80fd5b809150509250925092565b634e487b7160e01b5f52602160045260245ffd5b6001600160a01b03858116825284166020820152604081018390526080810160048310611b3b57634e487b7160e01b5f52602160045260245ffd5b82606083015295945050505050565b5f60208284031215611b5a575f80fd5b5051919050565b602080825282518282018190525f918401906040840190835b81811015611b98578351835260209384019390920191600101611b7a565b509095945050505050565b634e487b7160e01b5f52604160045260245ffd5b5f60208284031215611bc7575f80fd5b81516001600160401b03811115611bdc575f80fd5b8201601f81018413611bec575f80fd5b80516001600160401b03811115611c0557611c05611ba3565b604051600582901b90603f8201601f191681016001600160401b0381118282101715611c3357611c33611ba3565b604052918252602081840181019290810187841115611c50575f80fd5b6020850194505b83851015611c7357845180825260209586019590935001611c57565b509695505050505050565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8181038181111561039157610391611c92565b8181035f831280158383131683831282161715611cd857611cd8611c92565b5092915050565b8082018281125f831280158216821582161715611cfe57611cfe611c92565b505092915050565b5f60208284031215611d16575f80fd5b815160ff81168114611576575f80fd5b9283526020830191909152604082015260600190565b5f8060408385031215611d4d575f80fd5b505080516020909101519092909150565b8082018082111561039157610391611c92565b5f60208284031215611d81575f80fd5b81518015158114611576575f80fd5b5f60208284031215611da0575f80fd5b8151611576816119cd565b6001815b6001841115611de657808504811115611dca57611dca611c92565b6001841615611dd857908102905b60019390931c928002611daf565b935093915050565b5f82611dfc57506001610391565b81611e0857505f610391565b8160018114611e1e5760028114611e2857611e44565b6001915050610391565b60ff841115611e3957611e39611c92565b50506001821b610391565b5060208310610133831016604e8410600b8410161715611e67575081810a610391565b611e735f198484611dab565b805f1904821115611e8657611e86611c92565b029392505050565b5f6115768383611dee565b808202811582820484141761039157610391611c92565b634e487b7160e01b5f52601260045260245ffd5b5f82611ede57634e487b7160e01b5f52601260045260245ffd5b500490565b5f61157660ff841683611dee56fe12ca37b393c412d053690654fb6d504d2a16c55c2bd10941af581f2221d9c100a26469706673582212202c221574094d628a1c379a45998cbc94ae0473d1b4aefbf1edbd13b55089192d64736f6c634300081a0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc

-----Decoded View---------------
Arg [0] : _vault (address): 0x1b1b8fd8eAaA1E31293a3dbc4DfcF8eDBF53CFFC

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000001b1b8fd8eaaa1e31293a3dbc4dfcf8edbf53cffc


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.