BERA Price: $3.55 (-3.50%)

Contract

0x54a2538ca9670673073dC391A11297EcD05c50fa

Overview

BERA Balance

Berachain LogoBerachain LogoBerachain Logo0 BERA

BERA Value

$0.00

Multichain Info

No addresses found
Amount:Between 1-10k
Reset Filter

Transaction Hash
Method
Block
From
To

There are no matching entries

Update your filters to view other transactions

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
MainAssetCompoundingInfraredCollVault

Compiler Version
v0.8.26+commit.8a97fa7a

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity)

/**
 *Submitted for verification at berascan.com on 2025-03-10
*/

// SPDX-License-Identifier: MIT
pragma solidity =0.8.26 ^0.8.0 ^0.8.1 ^0.8.20 ^0.8.21;

// lib/openzeppelin-contracts/contracts/utils/Address.sol

// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

// lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol

// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

// lib/openzeppelin-contracts/contracts/proxy/beacon/IBeacon.sol

// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

// lib/openzeppelin-contracts/contracts/interfaces/IERC1967.sol

// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol)

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 */
interface IERC1967 {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}

// lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol

// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

/**
 * @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);
}

// lib/openzeppelin-contracts/contracts/interfaces/IERC3156FlashBorrower.sol

// OpenZeppelin Contracts (last updated v4.7.0) (interfaces/IERC3156FlashBorrower.sol)

/**
 * @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);
}

// src/interfaces/core/IFactory.sol

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
    }

    event NewDeployment(address collateral, address priceFeed, address denManager, address sortedDens);

    function deployNewInstance(
        address collateral,
        address priceFeed,
        address customDenManagerImpl,
        address customSortedDensImpl,
        DeploymentParams calldata params,
        uint64 unlockRatePerSecond,
        bool forceThroughLspBalanceCheck
    ) external;

    function setImplementations(address _denManagerImpl, address _sortedDensImpl) external;

    function BERABORROW_CORE() external view returns (address);

    function borrowerOperations() external view returns (address);

    function debtToken() external view returns (address);

    function guardian() external view returns (address);

    function liquidationManager() external view returns (address);

    function owner() external view returns (address);

    function sortedDensImpl() external view returns (address);

    function liquidStabilityPool() external view returns (address);

    function denManagerCount() external view returns (uint256);

    function denManagerImpl() external view returns (address);

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

// src/interfaces/utils/integrations/IInfraredVault.sol

interface IInfraredVault {
    function stakingToken() external view returns (address);
    function stake(uint256 amount) external;
    function withdraw(uint256 amount) external;
    function getReward() external;
    function getRewardForUser(address account) external;
    function rewardTokens(uint) external view returns (address);
    function getAllRewardTokens() external view returns (address[] memory);
    function earned(address account, address _rewardsToken) external view returns (uint256);
    function registerVault(address stakingToken) external returns (address);
}

// src/interfaces/core/IMetaBeraborrowCore.sol

interface IMetaBeraborrowCore {
    // ---------------------------------
    // Structures
    // ---------------------------------
    struct FeeInfo {
        bool existsForNect;
        uint16 nectFee;
    }

    struct RebalancerFeeInfo {
        bool exists;
        uint16 entryFee;
        uint16 exitFee;
    }

    // ---------------------------------
    // Public constants
    // ---------------------------------
    function OWNERSHIP_TRANSFER_DELAY() external view returns (uint256);
    function DEFAULT_FLASH_LOAN_FEE() external view returns (uint16);

    // ---------------------------------
    // Public state variables
    // ---------------------------------
    function nect() external view returns (address);
    function lspEntryFee() external view returns (uint16);
    function lspExitFee() external view returns (uint16);

    function feeReceiver() external view returns (address);
    function priceFeed() external view returns (address);
    function owner() external view returns (address);
    function pendingOwner() external view returns (address);
    function ownershipTransferDeadline() external view returns (uint256);
    function manager() external view returns (address);
    function guardian() external view returns (address);
    function paused() external view returns (bool);
    function lspBootstrapPeriod() external view returns (uint64);

    // ---------------------------------
    // External functions
    // ---------------------------------
    function setFeeReceiver(address _feeReceiver) external;
    function setPriceFeed(address _priceFeed) external;
    function setGuardian(address _guardian) external;
    function setManager(address _manager) external;

    /**
     * @notice Global pause/unpause
     *         Pausing halts new deposits/borrowing across the protocol
     */
    function setPaused(bool _paused) external;

    /**
     * @notice Extend or change the LSP bootstrap period,
     *         after which certain protocol mechanics change
     */
    function setLspBootstrapPeriod(uint64 _bootstrapPeriod) external;

    /**
     * @notice Set a custom flash-loan fee for a given periphery contract
     * @param _periphery Target contract that will get this custom fee
     * @param _nectFee Fee in basis points (bp)
     * @param _existsForNect Whether this custom fee is used when the caller = `nect`
     */
    function setPeripheryFlashLoanFee(address _periphery, uint16 _nectFee, bool _existsForNect) external;

    /**
     * @notice Begin the ownership transfer process
     * @param newOwner The address proposed to be the new owner
     */
    function commitTransferOwnership(address newOwner) external;

    /**
     * @notice Finish the ownership transfer, after the mandatory delay
     */
    function acceptTransferOwnership() external;

    /**
     * @notice Revoke a pending ownership transfer
     */
    function revokeTransferOwnership() external;

    /**
     * @notice Look up a custom flash-loan fee for a specific periphery contract
     * @param peripheryContract The contract that might have a custom fee
     * @return The flash-loan fee in basis points
     */
    function getPeripheryFlashLoanFee(address peripheryContract) external view returns (uint16);

    /**
     * @notice Set / override entry & exit fees for a special rebalancer contract
     */
    function setRebalancerFee(address _rebalancer, uint16 _entryFee, uint16 _exitFee) external;

    /**
     * @notice Set the LSP entry fee globally
     * @param _fee Fee in basis points
     */
    function setEntryFee(uint16 _fee) external;

    /**
     * @notice Set the LSP exit fee globally
     * @param _fee Fee in basis points
     */
    function setExitFee(uint16 _fee) external;

    /**
     * @notice Look up the LSP entry fee for a rebalancer
     * @param rebalancer Possibly has a special fee
     * @return The entry fee in basis points
     */
    function getLspEntryFee(address rebalancer) external view returns (uint16);

    /**
     * @notice Look up the LSP exit fee for a rebalancer
     * @param rebalancer Possibly has a special fee
     * @return The exit fee in basis points
     */
    function getLspExitFee(address rebalancer) external view returns (uint16);

    // ---------------------------------
    // Events
    // ---------------------------------
    event NewOwnerCommitted(address indexed owner, address indexed pendingOwner, uint256 deadline);
    event NewOwnerAccepted(address indexed oldOwner, address indexed newOwner);
    event NewOwnerRevoked(address indexed owner, address indexed revokedOwner);

    event FeeReceiverSet(address indexed feeReceiver);
    event PriceFeedSet(address indexed priceFeed);
    event GuardianSet(address indexed guardian);
    event ManagerSet(address indexed manager);
    event PeripheryFlashLoanFee(address indexed periphery, uint16 nectFee);
    event LSPBootstrapPeriodSet(uint64 bootstrapPeriod);
    event RebalancerFees(address indexed rebalancer, uint16 entryFee, uint16 exitFee);
    event EntryFeeSet(uint16 fee);
    event ExitFeeSet(uint16 fee);
    event Paused();
    event Unpaused();
}

// src/interfaces/core/IPriceFeed.sol

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 BERABORROW_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);
}

// src/interfaces/utils/integrations/IRebalancer.sol

interface IRebalancer {
    function swap(
        address sentCurrency,
        uint sentAmount,
        address receivedCurrency,
        bytes calldata payload
    ) external;
}

// lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol

// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// lib/openzeppelin-contracts/contracts/utils/math/Math.sol

// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)

/**
 * @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);
        }
    }
}

// lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol

// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

/**
 * @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);
    }
}

// lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol

// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }
}

// lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol

// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

// lib/openzeppelin-contracts/contracts/token/ERC20/extensions/draft-IERC20Permit.sol

// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

// lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol

// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)

/**
 * @dev Standard ERC-20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC-721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC-1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

// lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol

// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

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

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

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

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

// src/libraries/FeeLib.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);
    }
}

// src/interfaces/core/IBeraborrowCore.sol

interface IBeraborrowCore {

    // --- Public variables ---
    function metaBeraborrowCore() external view returns (IMetaBeraborrowCore);
    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 setDMBootstrapPeriod(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 manager() 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 getPeripheryFlashLoanFee(address peripheryContract) external view returns (uint16);

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

// lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol

// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)

// lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol

// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.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);
}

// src/libraries/PriceLib.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;
    }

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

        if (collPrice != 0) {
            return assetsUsdValue.mulDiv(10 ** collDecimals, collPrice, rounding);
        } else {
            return 0;
        }
    }

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

// src/interfaces/utils/tokens/IAsset.sol

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

// lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol

// OpenZeppelin Contracts (last updated v4.8.0) (interfaces/IERC4626.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);
}

// src/interfaces/core/vaults/IInfraredWrapper.sol

interface IInfraredWrapper is IERC20 {
    function metaBeraborrowCore() external view returns (address);
    function infraredCollVault() external view returns (address);
    function decimals() external view returns (uint8);
    function depositFor(address account, uint256 amount) external returns (bool);
    function withdrawTo(address account, uint256 amount) external returns (bool);
    function recover(address account) external returns (uint256);
}

// src/interfaces/core/IDenManager.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 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);
}

// lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol

// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

// lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol

// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
 */
library ERC1967Utils {
    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit IERC1967.Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit IERC1967.AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the ERC-1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit IERC1967.BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}

// src/interfaces/core/IDebtToken.sol

 

interface IDebtToken is IERC20 {
    // --- Events ---
    event FlashLoanFeeUpdated(uint256 newFee);

    // --- Public constants ---
    function version() external view returns (string memory);
    function permitTypeHash() external view returns (bytes32);

    // --- Public immutables ---
    function gasPool() external view returns (address);
    function DEBT_GAS_COMPENSATION() external view returns (uint256);
    function PSMBond() external view returns (address);

    // --- Public mappings ---
    function liquidStabilityPools(address) external view returns (bool);
    function borrowerOperations(address) external view returns (bool);
    function factories(address) external view returns (bool);
    function peripheries(address) external view returns (bool);
    function denManagers(address) external view returns (bool);

    // --- External functions ---

    function enableDenManager(address _denManager) external;
    function mintWithGasCompensation(address _account, uint256 _amount) external returns (bool);
    function burnWithGasCompensation(address _account, uint256 _amount) external returns (bool);
    function mint(address _account, uint256 _amount) external;
    function burn(address _account, uint256 _amount) external;
    function decimals() external view returns (uint8);
    function sendToPeriphery(address _sender, uint256 _amount) external;
    function sendToSP(address _sender, uint256 _amount) external;
    function returnFromPool(address _poolAddress, address _receiver, uint256 _amount) external;
    function transfer(address recipient, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    function maxFlashLoan(address token) external view returns (uint256);
    function flashFee(address token, uint256 amount) external view returns (uint256);
    function flashLoan(
        IERC3156FlashBorrower receiver,
        address token,
        uint256 amount,
        bytes calldata data
    ) external returns (bool);
    function whitelistLiquidStabilityPoolAddress(address _liquidStabilityPool, bool active) external;
    function whitelistBorrowerOperationsAddress(address _borrowerOperations, bool active) external;
    function whitelistFactoryAddress(address _factory, bool active) external;
    function whitelistPeripheryAddress(address _periphery, bool active) external;
    function whitelistPSMBond(address, bool) external;
    function setDebtGasCompensation(uint256 _gasCompensation, bool _isFinalValue) external;
    function setFlashLoanFee(uint256 _fee) external;
    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function permit(
        address owner,
        address spender,
        uint256 amount,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
    function nonces(address owner) external view returns (uint256);
}

// lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol

// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC-20
 * applications.
 */
abstract contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20, IERC20Metadata, IERC20Errors {
    /// @custom:storage-location erc7201:openzeppelin.storage.ERC20
    struct ERC20Storage {
        mapping(address account => uint256) _balances;

        mapping(address account => mapping(address spender => uint256)) _allowances;

        uint256 _totalSupply;

        string _name;
        string _symbol;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC20")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ERC20StorageLocation = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00;

    function _getERC20Storage() private pure returns (ERC20Storage storage $) {
        assembly {
            $.slot := ERC20StorageLocation
        }
    }

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
        __ERC20_init_unchained(name_, symbol_);
    }

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
        ERC20Storage storage $ = _getERC20Storage();
        $._name = name_;
        $._symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        ERC20Storage storage $ = _getERC20Storage();
        return $._name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        ERC20Storage storage $ = _getERC20Storage();
        return $._symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual returns (uint256) {
        ERC20Storage storage $ = _getERC20Storage();
        return $._totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual returns (uint256) {
        ERC20Storage storage $ = _getERC20Storage();
        return $._balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `value`.
     */
    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual returns (uint256) {
        ERC20Storage storage $ = _getERC20Storage();
        return $._allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Skips emitting an {Approval} event indicating an allowance update. This is not
     * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        ERC20Storage storage $ = _getERC20Storage();
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            $._totalSupply += value;
        } else {
            uint256 fromBalance = $._balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                $._balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                $._totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                $._balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     *
     * ```solidity
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        ERC20Storage storage $ = _getERC20Storage();
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        $._allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}

// lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol

// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
     * See {_onlyProxy}.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC-1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}

// lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/ERC4626Upgradeable.sol

// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC4626.sol)

/**
 * @dev Implementation of the ERC-4626 "Tokenized Vault Standard" as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 *
 * This extension allows the minting and burning of "shares" (represented using the ERC-20 inheritance) in exchange for
 * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
 * the ERC-20 standard. Any additional extensions included along it would affect the "shares" token represented by this
 * contract and not the "assets" token which is an independent contract.
 *
 * [CAUTION]
 * ====
 * In empty (or nearly empty) ERC-4626 vaults, deposits are at high risk of being stolen through frontrunning
 * with a "donation" to the vault that inflates the price of a share. This is variously known as a donation or inflation
 * attack and is essentially a problem of slippage. Vault deployers can protect against this attack by making an initial
 * deposit of a non-trivial amount of the asset, such that price manipulation becomes infeasible. Withdrawals may
 * similarly be affected by slippage. Users can protect against this attack as well as unexpected slippage in general by
 * verifying the amount received is as expected, using a wrapper that performs these checks such as
 * https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router].
 *
 * Since v4.9, this implementation introduces configurable virtual assets and shares to help developers mitigate that risk.
 * The `_decimalsOffset()` corresponds to an offset in the decimal representation between the underlying asset's decimals
 * and the vault decimals. This offset also determines the rate of virtual shares to virtual assets in the vault, which
 * itself determines the initial exchange rate. While not fully preventing the attack, analysis shows that the default
 * offset (0) makes it non-profitable even if an attacker is able to capture value from multiple user deposits, as a result
 * of the value being captured by the virtual shares (out of the attacker's donation) matching the attacker's expected gains.
 * With a larger offset, the attack becomes orders of magnitude more expensive than it is profitable. More details about the
 * underlying math can be found xref:erc4626.adoc#inflation-attack[here].
 *
 * The drawback of this approach is that the virtual shares do capture (a very small) part of the value being accrued
 * to the vault. Also, if the vault experiences losses, the users try to exit the vault, the virtual shares and assets
 * will cause the first user to exit to experience reduced losses in detriment to the last users that will experience
 * bigger losses. Developers willing to revert back to the pre-v4.9 behavior just need to override the
 * `_convertToShares` and `_convertToAssets` functions.
 *
 * To learn more, check out our xref:ROOT:erc4626.adoc[ERC-4626 guide].
 * ====
 */
abstract contract ERC4626Upgradeable is Initializable, ERC20Upgradeable, IERC4626 {
    using Math for uint256;

    /// @custom:storage-location erc7201:openzeppelin.storage.ERC4626
    struct ERC4626Storage {
        IERC20 _asset;
        uint8 _underlyingDecimals;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC4626")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ERC4626StorageLocation = 0x0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00;

    function _getERC4626Storage() private pure returns (ERC4626Storage storage $) {
        assembly {
            $.slot := ERC4626StorageLocation
        }
    }

    /**
     * @dev Attempted to deposit more assets than the max amount for `receiver`.
     */
    error ERC4626ExceededMaxDeposit(address receiver, uint256 assets, uint256 max);

    /**
     * @dev Attempted to mint more shares than the max amount for `receiver`.
     */
    error ERC4626ExceededMaxMint(address receiver, uint256 shares, uint256 max);

    /**
     * @dev Attempted to withdraw more assets than the max amount for `receiver`.
     */
    error ERC4626ExceededMaxWithdraw(address owner, uint256 assets, uint256 max);

    /**
     * @dev Attempted to redeem more shares than the max amount for `receiver`.
     */
    error ERC4626ExceededMaxRedeem(address owner, uint256 shares, uint256 max);

    /**
     * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC-20 or ERC-777).
     */
    function __ERC4626_init(IERC20 asset_) internal onlyInitializing {
        __ERC4626_init_unchained(asset_);
    }

    function __ERC4626_init_unchained(IERC20 asset_) internal onlyInitializing {
        ERC4626Storage storage $ = _getERC4626Storage();
        (bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
        $._underlyingDecimals = success ? assetDecimals : 18;
        $._asset = asset_;
    }

    /**
     * @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
     */
    function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool, uint8) {
        (bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
            abi.encodeCall(IERC20Metadata.decimals, ())
        );
        if (success && encodedDecimals.length >= 32) {
            uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256));
            if (returnedDecimals <= type(uint8).max) {
                return (true, uint8(returnedDecimals));
            }
        }
        return (false, 0);
    }

    /**
     * @dev Decimals are computed by adding the decimal offset on top of the underlying asset's decimals. This
     * "original" value is cached during construction of the vault contract. If this read operation fails (e.g., the
     * asset has not been created yet), a default of 18 is used to represent the underlying asset's decimals.
     *
     * See {IERC20Metadata-decimals}.
     */
    function decimals() public view virtual override(IERC20Metadata, ERC20Upgradeable) returns (uint8) {
        ERC4626Storage storage $ = _getERC4626Storage();
        return $._underlyingDecimals + _decimalsOffset();
    }

    /** @dev See {IERC4626-asset}. */
    function asset() public view virtual returns (address) {
        ERC4626Storage storage $ = _getERC4626Storage();
        return address($._asset);
    }

    /** @dev See {IERC4626-totalAssets}. */
    function totalAssets() public view virtual returns (uint256) {
        ERC4626Storage storage $ = _getERC4626Storage();
        return $._asset.balanceOf(address(this));
    }

    /** @dev See {IERC4626-convertToShares}. */
    function convertToShares(uint256 assets) public view virtual returns (uint256) {
        return _convertToShares(assets, Math.Rounding.Down);
    }

    /** @dev See {IERC4626-convertToAssets}. */
    function convertToAssets(uint256 shares) public view virtual returns (uint256) {
        return _convertToAssets(shares, Math.Rounding.Down);
    }

    /** @dev See {IERC4626-maxDeposit}. */
    function maxDeposit(address) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    /** @dev See {IERC4626-maxMint}. */
    function maxMint(address) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    /** @dev See {IERC4626-maxWithdraw}. */
    function maxWithdraw(address owner) public view virtual returns (uint256) {
        return _convertToAssets(balanceOf(owner), Math.Rounding.Down);
    }

    /** @dev See {IERC4626-maxRedeem}. */
    function maxRedeem(address owner) public view virtual returns (uint256) {
        return balanceOf(owner);
    }

    /** @dev See {IERC4626-previewDeposit}. */
    function previewDeposit(uint256 assets) public view virtual returns (uint256) {
        return _convertToShares(assets, Math.Rounding.Down);
    }

    /** @dev See {IERC4626-previewMint}. */
    function previewMint(uint256 shares) public view virtual returns (uint256) {
        return _convertToAssets(shares, Math.Rounding.Up);
    }

    /** @dev See {IERC4626-previewWithdraw}. */
    function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
        return _convertToShares(assets, Math.Rounding.Up);
    }

    /** @dev See {IERC4626-previewRedeem}. */
    function previewRedeem(uint256 shares) public view virtual returns (uint256) {
        return _convertToAssets(shares, Math.Rounding.Down);
    }

    /** @dev See {IERC4626-deposit}. */
    function deposit(uint256 assets, address receiver) public virtual returns (uint256) {
        uint256 maxAssets = maxDeposit(receiver);
        if (assets > maxAssets) {
            revert ERC4626ExceededMaxDeposit(receiver, assets, maxAssets);
        }

        uint256 shares = previewDeposit(assets);
        _deposit(_msgSender(), receiver, assets, shares);

        return shares;
    }

    /** @dev See {IERC4626-mint}. */
    function mint(uint256 shares, address receiver) public virtual returns (uint256) {
        uint256 maxShares = maxMint(receiver);
        if (shares > maxShares) {
            revert ERC4626ExceededMaxMint(receiver, shares, maxShares);
        }

        uint256 assets = previewMint(shares);
        _deposit(_msgSender(), receiver, assets, shares);

        return assets;
    }

    /** @dev See {IERC4626-withdraw}. */
    function withdraw(uint256 assets, address receiver, address owner) public virtual returns (uint256) {
        uint256 maxAssets = maxWithdraw(owner);
        if (assets > maxAssets) {
            revert ERC4626ExceededMaxWithdraw(owner, assets, maxAssets);
        }

        uint256 shares = previewWithdraw(assets);
        _withdraw(_msgSender(), receiver, owner, assets, shares);

        return shares;
    }

    /** @dev See {IERC4626-redeem}. */
    function redeem(uint256 shares, address receiver, address owner) public virtual returns (uint256) {
        uint256 maxShares = maxRedeem(owner);
        if (shares > maxShares) {
            revert ERC4626ExceededMaxRedeem(owner, shares, maxShares);
        }

        uint256 assets = previewRedeem(shares);
        _withdraw(_msgSender(), receiver, owner, assets, shares);

        return assets;
    }

    /**
     * @dev Internal conversion function (from assets to shares) with support for rounding direction.
     */
    // Deposit 1 USDC
    // 1e6 * 1e12 / 1 -> 1e18 shares minted
    // Deposit 1 USDC after first mint
    // 1e6 * 1e18 / 1e18 -> 1e6 shares minted

    // After first mint, BaseCollVault correctly does:
    // 1e6 * 1e18 / 1e6 -> 1e18 shares minted

    // Problem is usdValue in `totalAssets will have to be multiplied in 10 ** decimal precision, instead of WAD:
    // Currently: `amountInAsset = usdValue.mulDiv(WAD, assetPrice) + assetBalanceWad;`
    // Fix: `amountInAsset = usdValue.mulDiv(assetDecimals(), assetPrice) + assetBalance;`
    // Which reduces precision in totalAsset.
    // We could fix it by overriding deposit/mint/withdraw/redeem to scale internally assets to WAD, but leads to higher complexity

    // 8 decimals
    // 1e8 * 1e10 / 1 = 1e18 minted shares
    // 1e8 * 1e18 / 1e8 = 1e18 minted shares

    function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) {
        return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding);
    }

    /**
     * @dev Internal conversion function (from shares to assets) with support for rounding direction.
     */
    function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256) {
        return shares.mulDiv(totalAssets() + 1, totalSupply() + 10 ** _decimalsOffset(), rounding);
    }

    /**
     * @dev Deposit/mint common workflow.
     */
    function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual {
        ERC4626Storage storage $ = _getERC4626Storage();
        // If _asset is ERC-777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the
        // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
        // calls the vault, which is assumed not malicious.
        //
        // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
        // assets are transferred and before the shares are minted, which is a valid state.
        // slither-disable-next-line reentrancy-no-eth
        SafeERC20.safeTransferFrom($._asset, caller, address(this), assets);
        _mint(receiver, shares);

        emit Deposit(caller, receiver, assets, shares);
    }

    /**
     * @dev Withdraw/redeem common workflow.
     */
    function _withdraw(
        address caller,
        address receiver,
        address owner,
        uint256 assets,
        uint256 shares
    ) internal virtual {
        ERC4626Storage storage $ = _getERC4626Storage();
        if (caller != owner) {
            _spendAllowance(owner, caller, shares);
        }

        // If _asset is ERC-777, `transfer` can trigger a reentrancy AFTER the transfer happens through the
        // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
        // calls the vault, which is assumed not malicious.
        //
        // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
        // shares are burned and after the assets are transferred, which is a valid state.
        _burn(owner, shares);
        SafeERC20.safeTransfer($._asset, receiver, assets);

        emit Withdraw(caller, receiver, owner, assets, shares);
    }

    function _decimalsOffset() internal view virtual returns (uint8) {
        return 0;
    }
}

// src/libraries/EmissionsLib.sol

library EmissionsLib {
    using SafeCast for uint256;
    uint64 constant internal DEFAULT_UNLOCK_RATE = 1e11; // 10% per second
    uint64 constant internal MAX_UNLOCK_RATE = 1e12; // 100%

    struct BalanceData {
        mapping(address token => uint) balance;
        mapping(address token => EmissionSchedule) emissionSchedule;
    }

    struct EmissionSchedule {
        uint128 emissions;
        uint64 lockTimestamp;
        uint64 _unlockRatePerSecond; // rate points
    }

    error AmountCannotBeZero();
    error EmissionRateExceedsMax();
    // error UnsupportedEmissionConfig();

    event EmissionsAdded(address indexed token, uint128 amount);
    event EmissionsSub(address indexed token, uint128 amount);
    event NewUnlockRatePerSecond(address indexed token, uint64 unlockRatePerSecond);

    /// @dev zero _unlockRatePerSecond parameter resets rate back to DEFAULT_UNLOCK_RATE
    function setUnlockRatePerSecond(BalanceData storage $, address token, uint64 _unlockRatePerSecond) internal {
        if (_unlockRatePerSecond > MAX_UNLOCK_RATE) revert EmissionRateExceedsMax();
        _addEmissions($, token, 0); // update lockTimestamp and emissions
        $.emissionSchedule[token]._unlockRatePerSecond = _unlockRatePerSecond;

        emit NewUnlockRatePerSecond(token, _unlockRatePerSecond);
    }

    function addEmissions(BalanceData storage $, address token, uint128 amount) internal {
        if (amount == 0) revert AmountCannotBeZero();
        _addEmissions($, token, amount);

        emit EmissionsAdded(token, amount);
    }

    function _addEmissions(BalanceData storage $, address token, uint128 amount) private {        
        EmissionSchedule memory schedule = $.emissionSchedule[token];

        uint256 _unlockTimestamp = unlockTimestamp(schedule);
        uint128 nextEmissions = (lockedEmissions(schedule, _unlockTimestamp) + amount).toUint128();

        schedule.emissions = nextEmissions;
        schedule.lockTimestamp = block.timestamp.toUint64();
        $.balance[token] += amount;

        $.emissionSchedule[token] = schedule;
    }

    function subEmissions(BalanceData storage $, address token, uint128 amount) internal {
        if (amount == 0) revert AmountCannotBeZero();
        _subEmissions($, token, amount);

        emit EmissionsSub(token, amount);
    }

    function _subEmissions(BalanceData storage $, address token, uint128 amount) private {
        EmissionSchedule memory schedule = $.emissionSchedule[token];

        uint256 _unlockTimestamp = unlockTimestamp(schedule);
        uint128 nextEmissions = (lockedEmissions(schedule, _unlockTimestamp) - amount).toUint128();

        schedule.emissions = nextEmissions;
        schedule.lockTimestamp = block.timestamp.toUint64();
        $.balance[token] -= amount;

        $.emissionSchedule[token] = schedule;
    }

    /// @dev Doesn't include locked emissions
    function unlockedEmissions(EmissionSchedule memory schedule) internal view returns (uint256) {
        return schedule.emissions - lockedEmissions(schedule, unlockTimestamp(schedule));
    }

    function balanceOfWithFutureEmissions(BalanceData storage $, address token) internal view returns (uint256) {
        return $.balance[token];
    }

    /**
     * @notice Returns the unlocked token emissions
     */
    function balanceOf(BalanceData storage $, address token) internal view returns (uint256) {
        EmissionSchedule memory schedule = $.emissionSchedule[token];
        return $.balance[token] - lockedEmissions(schedule, unlockTimestamp(schedule));
    }

    /**
     * @notice Returns locked emissions
     */
    function lockedEmissions(EmissionSchedule memory schedule, uint256 _unlockTimestamp) internal view returns (uint256) {
        if (block.timestamp >= _unlockTimestamp) {
            // all emissions were unlocked 
            return 0;
        } else {
            // emissions are still unlocking, calculate the amount of already unlocked emissions
            uint256 secondsSinceLockup = block.timestamp - schedule.lockTimestamp;
            // design decision - use dimensionless 'unlock rate units' to unlock emissions over a fixed time window 
            uint256 ratePointsUnlocked = unlockRatePerSecond(schedule) * secondsSinceLockup;
            // emissions remainder is designed to be added to balance in unlockTimestamp
            return schedule.emissions - ratePointsUnlocked * schedule.emissions / MAX_UNLOCK_RATE;
        }
    } 

    // timestamp at which all emissions are fully unlocked
    function unlockTimestamp(EmissionSchedule memory schedule) internal pure returns (uint256) {
        // ceil to account for remainder seconds left after integer division
        return divRoundUp(MAX_UNLOCK_RATE, unlockRatePerSecond(schedule)) + schedule.lockTimestamp; 
    }

    function unlockRatePerSecond(EmissionSchedule memory schedule) internal pure returns (uint256) {
        return schedule._unlockRatePerSecond == 0 ? DEFAULT_UNLOCK_RATE : schedule._unlockRatePerSecond;
    }

    function divRoundUp(uint256 dividend, uint256 divisor) internal pure returns (uint256) {
        return (dividend + divisor - 1) / divisor;
    }
}

// src/interfaces/core/ILiquidStabilityPool.sol

interface ILiquidStabilityPool is IERC4626, IERC1822Proxiable {
    struct LSPStorage {
        IMetaBeraborrowCore metaBeraborrowCore;
        address feeReceiver;
        /// @notice Array of tokens that have been emitted to the LiquidStabilityPool
        /// @notice Used to track which tokens can be withdrawn to LSP share holders
        /// @dev Doesn't include tokens that are already BeraBorrow's collaterals
        EnumerableSet.AddressSet extraAssets;
        Queue queue;
        address[] collateralTokens;
        mapping(uint16 => SunsetIndex) _sunsetIndexes;
        mapping(address collateral => uint256 index) indexByCollateral;
        mapping(bytes32 => uint) threshold;
        EmissionsLib.BalanceData balanceData;
        mapping(address => bool) factoryProtocol;
        mapping(address => bool) liquidationManagerProtocol;
        // Allowed to withdraw their positions during bootstrap period
        mapping(address => bool) boycoVault;
    }

    struct InitParams {
        IERC20 _asset;
        string _sharesName;
        string _sharesSymbol;
        IMetaBeraborrowCore _metaBeraborrowCore;
        address _liquidationManager;
        address _factory;
        address _feeReceiver;
    }

    struct RebalanceParams {
        address sentCurrency;
        uint sentAmount;
        address receivedCurrency;
        address swapper;
        bytes payload;
    }

    struct SunsetIndex {
        uint128 idx;
        uint128 expiry;
    }

    struct Queue {
        uint16 firstSunsetIndexKey;
        uint16 nextSunsetIndexKey;
    }

    event CollAndEmissionsWithdraw(
        address indexed receiver,
        uint shares,
        uint[] amounts
    );

    struct Arrays {
        uint length;
        address[] collaterals;
        uint collateralsLength;
        uint[] amounts;
    }

    event EmissionTokenAdded(address token);
    event EmissionTokenRemoved(address token);
    event StabilityPoolDebtBalanceUpdated(uint256 newBalance);
    event UserDepositChanged(address indexed depositor, uint256 newDeposit);
    event CollateralOverwritten(address oldCollateral, address newCollateral);

    // PROXY
    function upgradeToAndCall(address newImplementation, bytes calldata data) external;
    function getCurrentImplementation() external view returns (address);

    function SUNSET_DURATION() external view returns (uint128);
    function totalDebtTokenDeposits() external view returns (uint256);
    function enableCollateral(address _collateral, uint64 _unlockRatePerSecond, bool forceThroughBalanceCheck) external;
    function startCollateralSunset(address collateral) external;
    function getTotalDebtTokenDeposits() external view returns (uint256);
    function getCollateralTokens() external view returns (address[] memory);
    function offset(address collateral, uint256 _debtToOffset, uint256 _collToAdd) external;
    function initialize(InitParams calldata params) external;
    function rebalance(RebalanceParams calldata p) external;
    function linearVestingExtraAssets(address token, int amount, address recipient) external;
    function withdraw(
        uint assets,
        address[] calldata preferredUnderlyingTokens,
        address receiver,
        address _owner
    ) external returns (uint shares);
    function redeem(
        uint shares,
        address[] calldata preferredUnderlyingTokens,
        address receiver,
        address _owner
    ) external returns (uint assets);
    function updateProtocol(
        address _liquidationManager, 
        address _factory,
        bool _register
    ) external;
    function addNewExtraAsset(address token, uint64 _unlockRatePerSecond) external;
    function removeEmitedTokens(address token) external;
    function setPairThreshold(address tokenIn, address tokenOut, uint thresholdInBP) external;
    function setUnlockRatePerSecond(address token, uint64 _unlockRatePerSecond) external;
    function getPrice(address token) external view returns (uint);
    function getLockedEmissions(address token) external view returns (uint);
    function extSloads(bytes32[] calldata slots) external view returns (bytes32[] memory res);
    function unlockRatePerSecond(address token) external view returns (uint);
    function removeExtraAsset(address token) external;
}

// src/interfaces/core/vaults/IBaseCollateralVault.sol

interface IBaseCollateralVault is IERC4626, IERC1822Proxiable {
    struct BaseInitParams {
        uint16 _minWithdrawFee;
        uint16 _maxWithdrawFee;
        uint16 _withdrawFee;
        IMetaBeraborrowCore _metaBeraborrowCore;
        // ERC4626
        IERC20 _asset;
        // ERC20
        string _sharesName;
        string _sharesSymbol;
    }

    struct BaseCollVaultStorage {
        uint16 minWithdrawFee;
        uint16 maxWithdrawFee;
        uint16 withdrawFee; // over rewarded tokens, in basis points
        uint8 assetDecimals;

        IMetaBeraborrowCore _metaBeraborrowCore;

        // Second mapping of this struct is usless, but it's for retrocompatibility with InfraredCollateralVault
        EmissionsLib.BalanceData balanceData;
    }

    function totalAssets() external view returns (uint);

    function fetchPrice() external view returns (uint);

    function getPrice(address token) external view returns (uint);

    function receiveDonations(address[] memory tokens, uint[] memory amounts, address receiver) external;

    function setWithdrawFee(uint16 _withdrawFee) external;

    function getBalance(address token) external view returns (uint);

    function getWithdrawFee() external view returns (uint16);

    function getMetaBeraborrowCore() external view returns (IMetaBeraborrowCore);

    function getPriceFeed() external view returns (IPriceFeed);

    function assetDecimals() external view returns (uint8);
}

// src/interfaces/core/vaults/IInfraredCollateralVault.sol

interface IInfraredCollateralVault is IBaseCollateralVault {
    struct InfraredCollVaultStorage {
        uint16 minPerformanceFee;
        uint16 maxPerformanceFee;
        uint16 performanceFee; // over yield, in basis points
        address iRedToken;
        /// @dev We currently don't know the infraredVault implementation, but if it were to be possible for them to remove tokens from the rewardTokens
        /// There would be no need to remove it from here since the amounts should continue being accounted for in the virtual balance
        EnumerableSet.AddressSet rewardedTokens;

        IInfraredVault _infraredVault;
        address ibgtVault;
        address ibgt;
        IInfraredWrapper infraredWrapper;
        uint96 lastUpdate;

        mapping(address tokenIn => uint) threshold;
    }

    struct InfraredInitParams {
        BaseInitParams _baseParams;
        uint16 _minPerformanceFee;
        uint16 _maxPerformanceFee;
        uint16 _performanceFee; // over yield, in basis points
        address _iRedToken;
        IInfraredVault _infraredVault;
        address _ibgtVault;
        address _infraredWrapper;
    }

    struct RebalanceParams {
        address sentCurrency; 
        uint sentAmount; 
        address swapper;
        bytes payload;
    }

    function rebalance(RebalanceParams calldata p) external;

    function setUnlockRatePerSecond(address token, uint64 _unlockRatePerSecond) external;

    function internalizeDonations(address[] memory tokens, uint128[] memory amounts) external;

    function setPairThreshold(address tokenIn, uint thresholdInBP) external;

    function setPerformanceFee(uint16 _performanceFee) external;
    function setWithdrawFee(uint16 _withdrawFee) external;

    function getBalance(address token) external view returns (uint);

    function getBalanceOfWithFutureEmissions(address token) external view returns (uint);

    function getFullProfitUnlockTimestamp(address token) external view returns (uint);

    function unlockRatePerSecond(address token) external view returns (uint);

    function getLockedEmissions(address token) external view returns (uint);

    function getPerformanceFee() external view returns (uint16);

    function rewardedTokens() external view returns (address[] memory);

    function iRedToken() external view returns (address);

    function infraredVault() external view returns (IInfraredVault);

    function ibgt() external view returns (address);

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

// src/interfaces/core/vaults/IIBGTVault.sol

interface IIBGTVault is IInfraredCollateralVault {
    /*
    struct IBGTVaultStorage {
        IInfraredVault infraredIBGTVault;
    }

    struct InitParams {
        IInfraredVault _infraredIBGTVault;
    }
    */

    function initialize(IInfraredCollateralVault.InfraredInitParams calldata baseParams /*, InitParams calldata ibgtParams */) external;
    function setInfraredVault(address _infraredVault) external;
    function upgradeToAndCall(address newImplementation, bytes calldata data) external;
}

// src/interfaces/core/vaults/IMainAssetCompoundingInfraredCollVault.sol

interface IMainAssetCompoundingInfraredCollVault {
    struct MainAssetCompoundingInfraredInitParams {
        address _keeper;
    }

    struct IMainAssetCompoundingInfraredCollVaultStorage {
        address keeper;
    }

    function initialize(IMainAssetCompoundingInfraredCollVault.MainAssetCompoundingInfraredInitParams calldata params, IInfraredCollateralVault.InfraredInitParams calldata baseParams) external;
    function setKeeper(address _keeper) external;
    function previewHarvestRewards() external view returns (address[] memory tokens, uint[] memory amounts);
}

// src/core/vaults/BaseCollateralVault.sol

 

abstract contract BaseCollateralVault is ERC4626Upgradeable, UUPSUpgradeable, IBaseCollateralVault {
    using Math for uint;
    using SafeERC20 for IERC20;
    using FeeLib for uint;

    uint internal constant BP = 1e4;

    // keccak256(abi.encode(uint(keccak256("openzeppelin.storage.BaseCollateralVault")) - 1)) & ~bytes32(uint(0xff))
    bytes32 private constant BaseCollateralVaultStorageLocation = 0x19001df2d131e9aa1479f4ce661ae121445caf0662dea1e41907028a6da6fe00;

    function _getBaseCollVaultStorage() internal pure returns (BaseCollVaultStorage storage store) {
        assembly {
            store.slot := BaseCollateralVaultStorageLocation
        }
    }

    constructor() {
        _disableInitializers();
    }

    function __BaseCollateralVault_init(BaseInitParams calldata params) internal onlyInitializing {
        __BaseCollateralVault_init_unchained(params);
    }

    function __BaseCollateralVault_init_unchained(BaseInitParams calldata params) internal onlyInitializing {
        BaseCollVaultStorage storage $ = _getBaseCollVaultStorage();

        if (address(params._metaBeraborrowCore) == address(0) || address(params._asset) == address(0)) {
            revert("CollVault: 0 address");
        }

        _requireAssetFeed(params._metaBeraborrowCore, address(params._asset));
        require(params._withdrawFee >= params._minWithdrawFee && params._withdrawFee <= params._maxWithdrawFee, "CollVault: withdraw fee out of bounds");

        $.minWithdrawFee = params._minWithdrawFee;
        $.maxWithdrawFee = params._maxWithdrawFee;

        $.withdrawFee = params._withdrawFee;

        uint8 _assetDecimals = IAsset(address(params._asset)).decimals();
        if (_assetDecimals > 18) {
            revert("CollVault: asset decimals > 18");
        }
        $.assetDecimals = _assetDecimals;

        $._metaBeraborrowCore = params._metaBeraborrowCore;

        __ERC20_init(params._sharesName, params._sharesSymbol);
        __ERC4626_init(params._asset);
    }

    function _requireAssetFeed(IMetaBeraborrowCore _metaBeraborrowCore, address asset) internal virtual {
        IPriceFeed priceFeed = IPriceFeed(_metaBeraborrowCore.priceFeed());
        require(priceFeed.fetchPrice(asset) != 0, "CollVault: asset price feed not set up");
    }

    modifier onlyOwner {
        _onlyOwner();
        _;
    }

    modifier harvestRewards() {
        _harvestRewards();
        _;
    }

    function _onlyOwner() private view {
        // Owner is beacon variable MetaBeraborrowCore::owner()
        require(msg.sender == getMetaBeraborrowCore().owner(), "CollVault: caller is not the owner");
    }

    function _authorizeUpgrade(address newImplementation) internal override virtual onlyOwner {}

    /** @dev See {IERC4626-totalAssets}. */
    /// @notice Returns the total assets in the vault, denominated in the asset of the vault
    /// @dev Virtual accounting to avoid donations, asset valued denomination, returned in asset decimals
    function totalAssets() public view override(ERC4626Upgradeable, IBaseCollateralVault) virtual returns (uint) {
        return getBalance(asset());
    }

    /// @dev Called by DenManager, returns the share usd value in WAD
    /// @dev Fees are not accounted to downprice the share value for redeemCollateral,
    ///     for borrowing, MCR will account for this downprice 
    function fetchPrice() public view virtual returns (uint) {
        uint _totalSupply = totalSupply();
        if (_totalSupply == 0) return 0;
        return (totalAssets() * 10 ** _decimalsOffset()).mulDiv(getPrice(asset()), _totalSupply);
    }

    /// @dev Note, validate this implementation if inherited by multi asset vault (InfraredCollateralVault)
    function _decimalsOffset() internal view override virtual returns (uint8) {
        return 18 - assetDecimals();
    }

    function deposit(
        uint assets,
        address receiver
    ) public override(ERC4626Upgradeable, IERC4626) harvestRewards returns (uint shares) {
        shares = super.deposit(assets, receiver);

        _stake(assets);

        _increaseBalance(asset(), assets);
    }

    function mint(
        uint shares,
        address receiver
    ) public override(ERC4626Upgradeable, IERC4626) harvestRewards returns (uint assets) {
        assets = super.mint(shares, receiver);

        _stake(assets);

        _increaseBalance(asset(), assets);
    }

    function withdraw(
        uint assets,
        address receiver,
        address _owner
    ) public override(ERC4626Upgradeable, IERC4626) harvestRewards returns (uint shares) {
        uint _totalSupply = totalSupply(); // cached to don't account for the burn

        { // scope to avoid stack too deep error
            uint256 maxAssets = maxWithdraw(_owner);
            if (assets > maxAssets) {
                revert ERC4626ExceededMaxWithdraw(_owner, assets, maxAssets);
            }
        }
        uint shareFee;
        (shares, shareFee) = _previewWithdraw(assets);

        (uint assetAmount, uint netShares) = _applyShareFee(shares, _totalSupply, shareFee);

        if (assetAmount != 0) {
            _unstake(assetAmount);
            _decreaseBalance(asset(), assetAmount);
        }

        _withdraw(msg.sender, receiver, _owner, assetAmount, shares);
        _withdrawExtraRewardedTokens(receiver, netShares, _totalSupply);
    }

    /// @dev Decompounded redeem() function to reuse `previewRedeem()` on `infrared.withdraw`
    function redeem(
        uint shares,
        address receiver,
        address _owner
    ) public override(ERC4626Upgradeable, IERC4626) harvestRewards returns (uint assets) {
        uint _totalSupply = totalSupply(); // cached to don't account for the burn

        { // scope to avoid stack too deep error
            uint256 maxShares = maxRedeem(_owner);
            if (shares > maxShares) {
                revert ERC4626ExceededMaxRedeem(_owner, shares, maxShares);
            }
        }

        uint shareFee;
        (assets, shareFee) = _previewRedeem(shares);

        (uint assetAmount, uint netShares) = _applyShareFee(shares, _totalSupply, shareFee);

        if (assetAmount != 0) {
            _unstake(assetAmount);
            _decreaseBalance(asset(), assetAmount);
        }

        _withdraw(msg.sender, receiver, _owner, assetAmount, shares);
        _withdrawExtraRewardedTokens(receiver, netShares, _totalSupply);
    }

    function _applyShareFee(uint shares, uint _totalSupply, uint fee) internal virtual returns (uint, uint) {
        BaseCollVaultStorage storage $ = _getBaseCollVaultStorage();

        uint netShares = shares - fee;

        uint assetAmount = netShares.mulDiv(getBalance(asset()), _totalSupply, Math.Rounding.Down);

        address feeReceiver = $._metaBeraborrowCore.feeReceiver();
        if (fee != 0) {
            _mint(feeReceiver, fee);
        }

        return (assetAmount, netShares);
    }

    /// @dev Preview adding an exit fee on withdraw. See {IERC4626-previewWithdraw}.
    function previewWithdraw(
        uint assets
    ) public view virtual override(ERC4626Upgradeable, IERC4626) returns (uint) {
        (uint totalShares,) = _previewWithdraw(assets);
        return totalShares;
    }

    function _previewWithdraw(uint assets) internal view virtual returns (uint, uint) {
        BaseCollVaultStorage storage $ = _getBaseCollVaultStorage();

        uint netShares = super.previewWithdraw(assets);
        uint totalShares = netShares.mulDiv(BP, BP - $.withdrawFee, Math.Rounding.Up);
        uint shareFee = totalShares - netShares;
        return (totalShares, shareFee);
    }

    /// @dev Preview taking an exit fee on redeem. See {IERC4626-previewRedeem}.
    function previewRedeem(
        uint shares
    ) public view virtual override(ERC4626Upgradeable, IERC4626) returns (uint) {
        (uint assets,) = _previewRedeem(shares);
        return assets;
    }

    function _previewRedeem(uint shares) internal view virtual returns (uint, uint) {
        BaseCollVaultStorage storage $ = _getBaseCollVaultStorage();

        uint shareFee = shares.feeOnRaw($.withdrawFee);
        uint assets = super.previewRedeem(shares - shareFee);
        return (assets, shareFee);
    }

    /** @dev See {IERC4626-maxWithdraw}. */
    function maxWithdraw(address _owner) public view override(ERC4626Upgradeable, IERC4626) returns (uint) {
        return previewRedeem(balanceOf(_owner));
    }

    /// @dev `receiver` automatically receives `asset()` donations, and `tokens` and `amounts` donations as desired by the owner `amounts`
    function receiveDonations(address[] memory tokens, uint[] memory amounts, address receiver) external virtual onlyOwner {
        BaseCollVaultStorage storage $ = _getBaseCollVaultStorage();

        uint tokensLength = tokens.length;

        require(tokensLength == amounts.length, "CollVault: tokens and amounts length mismatch");

        uint assetBalance = IERC20(asset()).balanceOf(address(this));
        uint virtualBalance = $.balanceData.balance[asset()];

        if (assetBalance > virtualBalance) {
            IERC20(asset()).safeTransfer(receiver, assetBalance - virtualBalance);
        }

        for (uint i; i < tokensLength; i++) {
            if (tokens[i] == asset()) {
                continue;
            }
            uint256 tokenBalance = IERC20(tokens[i]).balanceOf(address(this));
            uint256 virtualTokenBalance = $.balanceData.balance[tokens[i]];
            uint256 transferAmount = Math.min(amounts[i], tokenBalance - virtualTokenBalance);
            if (transferAmount > 0) {
                IERC20(tokens[i]).safeTransfer(receiver, transferAmount);
            }
        }
    }

    function setWithdrawFee(uint16 _withdrawFee) external virtual onlyOwner {
        BaseCollVaultStorage storage $ = _getBaseCollVaultStorage();

        require(_withdrawFee >= $.minWithdrawFee && _withdrawFee <= $.maxWithdrawFee, "CollVault: Withdraw fee out of bounds");

        $.withdrawFee = _withdrawFee;
    }

    function _increaseBalance(address token, uint amount) internal virtual {
        BaseCollVaultStorage storage $ = _getBaseCollVaultStorage();
        $.balanceData.balance[token] += amount;
    }

    function _decreaseBalance(address token, uint amount) internal virtual {
        BaseCollVaultStorage storage $ = _getBaseCollVaultStorage();
        $.balanceData.balance[token] -= amount;
    }

    function _getBalanceData() internal view virtual returns (EmissionsLib.BalanceData storage) {
        return _getBaseCollVaultStorage().balanceData;
    }

    function getPrice(
        address token
    ) public view virtual returns (uint) {
        return getPriceFeed().fetchPrice(token);
    }

    function getBalance(address token) public view virtual returns (uint) {
        return _getBaseCollVaultStorage().balanceData.balance[token];
    }

    function getWithdrawFee() public view virtual returns (uint16) {
        return _getBaseCollVaultStorage().withdrawFee;
    }

    function getMetaBeraborrowCore() public view virtual returns (IMetaBeraborrowCore) {
        return _getBaseCollVaultStorage()._metaBeraborrowCore;
    }

    function getPriceFeed() public view virtual returns (IPriceFeed) {
        return IPriceFeed(_getBaseCollVaultStorage()._metaBeraborrowCore.priceFeed());
    }

    function assetDecimals() public view virtual returns (uint8) {
        return _getBaseCollVaultStorage().assetDecimals;
    }

    function _harvestRewards() internal virtual {}
    function _stake(uint amount) internal virtual {}
    function _unstake(uint amount) internal virtual {}
    function _withdrawExtraRewardedTokens(address receiver, uint netShares, uint _totalSupply) internal virtual {}
}

// src/core/vaults/InfraredCollateralVault.sol

/**
 * @title Beraborrow Infrared Collateral Vault
 * @notice Supercharges DenManager with PoL
 */
abstract contract InfraredCollateralVault is BaseCollateralVault {
    using Math for uint;
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;
    using EmissionsLib for EmissionsLib.BalanceData;
    using EmissionsLib for EmissionsLib.EmissionSchedule;
    using PriceLib for uint;
    using FeeLib for uint;

    uint internal constant WAD = 1e18;

    error WithdrawingLockedEmissions();

    // keccak256(abi.encode(uint(keccak256("openzeppelin.storage.InfraredCollateralVault")) - 1)) & ~bytes32(uint(0xff))
    bytes32 private constant InfraredCollateralVaultStorageLocation = 0xf6a35052099d23fafed8c58b549933969c057c5a9a13ac5133024adc8dd4f200;

    event Rebalance(address indexed sentCurrency, uint sent, uint received, uint sentValue, uint receivedValue);
    event PerformanceFee(address indexed token, uint amount);

    function _getInfraredCollVaultStorage() internal pure returns (IInfraredCollateralVault.InfraredCollVaultStorage storage store) {
        assembly {
            store.slot := InfraredCollateralVaultStorageLocation
        }
    }

    function __InfraredCollateralVault_init(IInfraredCollateralVault.InfraredInitParams calldata params) internal onlyInitializing {
        __InfraredCollateralVault_init_unchained(params);
    }

    function __InfraredCollateralVault_init_unchained(IInfraredCollateralVault.InfraredInitParams calldata params) internal onlyInitializing {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();

        if (params._iRedToken == address(0) ||  address(params._infraredVault) == address(0) || params._ibgtVault == address(0)) {
            revert("CollVault: 0 address");
        }

        IERC20 _asset = params._baseParams._asset;

        require(params._minPerformanceFee <= params._maxPerformanceFee && params._maxPerformanceFee <= BP, "CollVault: Incorrect min/max performance fee");
        require(params._performanceFee >= params._minPerformanceFee && params._performanceFee <= params._maxPerformanceFee, "CollVault: performance fee out of bounds");
        bool infraredWrapped = params._infraredWrapper != address(0);
        address stakingToken = params._infraredVault.stakingToken();
        require(infraredWrapped ? stakingToken == params._infraredWrapper : stakingToken == address(_asset), "CollVault: stakingToken mismatch");
        require(!infraredWrapped || IInfraredWrapper(params._infraredWrapper).infraredCollVault() == address(this), "CollVault: InfraredWrapper mismatch");

        $.minPerformanceFee = params._minPerformanceFee;
        $.maxPerformanceFee = params._maxPerformanceFee;
        $.performanceFee = params._performanceFee;

        $.iRedToken = params._iRedToken; // this set assumes that the iRedToken is a reward token in all InfraredVaults, which may not be the case
        $._infraredVault = params._infraredVault;
        $.ibgtVault = params._ibgtVault;
        $.infraredWrapper = IInfraredWrapper(params._infraredWrapper);

        __BaseCollateralVault_init(params._baseParams);

        $.ibgt = address(this) == params._ibgtVault ? address(_asset) : IIBGTVault(params._ibgtVault).asset();
    }

    // Compound iBGT rewards
    /// @dev Since we are not accepting donations, we won't `stake` ibgt.balanceOf(this)
    function _harvestRewards() internal override {
        if (block.timestamp == _getInfraredCollVaultStorage().lastUpdate) return;

        IInfraredVault iVault = infraredVault();
        address[] memory tokens = iVault.getAllRewardTokens();
        uint[] memory prevBalances = new uint[](tokens.length);

        for (uint i; i < tokens.length; i++) {
            prevBalances[i] = IERC20(tokens[i]).balanceOf(address(this));
        }

        // harvest rewards
        iVault.getReward();

        uint _performanceFee = getPerformanceFee();
        address _iRedToken = iRedToken();
        address _ibgt = ibgt();
        IIBGTVault _ibgtVault = IIBGTVault(ibgtVault());
        // re-stake iBGT, take performance fee and update accounting
        for (uint i; i < tokens.length; i++) {
            address _token = tokens[i];
            uint newBalance = IERC20(_token).balanceOf(address(this));

            uint rewards = newBalance - prevBalances[i];
            if (rewards == 0) continue; /// @dev Skip if no rewards, saves from iVault revert 'Cannot stake 0'

            (rewards, _token) = _autoCompoundHook(_token, _ibgt, _ibgtVault, rewards);

            // Meanwhile the token doesn't has an oracle mapped, it will be processed as a donation
            // This will avoid returns meanwhile a newly Infrared pushed reward token is not mapped
            if (_hasPriceFeed(_token) && _token != _iRedToken && !_isCollVault(_token)) {
                uint fee = rewards * _performanceFee / BP;
                uint netRewards = rewards - fee;

                if (_token == asset()) {
                    _stake(netRewards);
                }

                _increaseBalance(_token, netRewards);

                // First time the oracle happens to be mapped, we add the token to the rewardedTokens
                // If token has no oracle map this won't be called, hence not DOS the vault at `totalAssets`
                _addRewardedToken(_token); // won't add duplicates

                if (fee != 0) {
                    IERC20(_token).safeTransfer(getMetaBeraborrowCore().feeReceiver(), fee);

                    emit PerformanceFee(_token, fee);
                }
            }
        }
        _getInfraredCollVaultStorage().lastUpdate = uint96(block.timestamp);
    }

    /** @dev See {IERC4626-totalAssets}. */
    /// @notice Returns the total assets in the vault, denominated in the asset of the vault
    /// @dev Virtual accounting to avoid donations, asset valued denomination, returned in WAD
    /// @dev Not yet harvested rewards not yet added due to possible temporal overestimation due to rewards being donated through `getRewardForUser`
    function totalAssets() public view override virtual returns (uint amountInAsset) {
        // UsdValue is scaled to 1e18, since `getPrice` returns a WAD scaled price
        uint usdValue;
        address[] memory _rewardedTokens = rewardedTokens();
        uint rewardedTokensLength = _rewardedTokens.length;

        uint assetPrice = getPrice(asset());
        uint assetBalance = _isRewardedToken(asset()) ? 0 : getBalance(asset());

        for (uint i; i < rewardedTokensLength; i++) {
            usdValue += _convertToValue(_rewardedTokens[i]);
        }

        amountInAsset = usdValue.mulDiv(10 ** assetDecimals(), assetPrice) + assetBalance;
    }

    function _previewRedeem(uint shares) internal view override returns (uint, uint) {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();

        bool isInternalRedemption = address(this) == $.ibgtVault && getPriceFeed().isCollVault(msg.sender);
        uint shareFee = isInternalRedemption ? 0 : shares.feeOnRaw(getWithdrawFee());
        uint assets = ERC4626Upgradeable.previewRedeem(shares - shareFee);
        return (assets, shareFee);
    }

    /// @dev Token out or received currency will always be the asset of the vault
    function rebalance(IInfraredCollateralVault.RebalanceParams calldata p) external virtual onlyOwner {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();

        uint sentPrice = getPrice(p.sentCurrency);
        uint receivedPrice = getPrice(asset());
        uint8 sentDecimals = IAsset(p.sentCurrency).decimals();
        uint sentCurrencyBalance = IAsset(p.sentCurrency).balanceOf(address(this));
        uint receivedCurrencyBalance = IAsset(asset()).balanceOf(address(this));

        // Perform the swap using the swapper contract
        IERC20(p.sentCurrency).safeTransfer(p.swapper, p.sentAmount);
        IRebalancer(p.swapper).swap(
            p.sentCurrency,
            p.sentAmount,
            asset(),
            p.payload
        );

        uint received = IAsset(asset()).balanceOf(address(this)) - receivedCurrencyBalance;
        uint sent = sentCurrencyBalance - IAsset(p.sentCurrency).balanceOf(address(this));

        // if we were to rebalance locked emissions, a possible revert on subsequent `$.balanceOf` calls would occur
        if (sent > getBalance(p.sentCurrency)) revert WithdrawingLockedEmissions();

        uint receivedValue = received.convertToValue(receivedPrice, assetDecimals());
        uint sentValue = sent.convertToValue(sentPrice, sentDecimals);

        // if threshold isn't set, it will be 0, not tolerating any slippage
        require(receivedValue >= sentValue * (BP - $.threshold[p.sentCurrency]) / BP, "CollVault: received amount is below threshold");

        _decreaseBalance(p.sentCurrency, sent);
        _increaseBalance(asset(), received);

        _afterVaultRebalance(received);

        emit Rebalance(p.sentCurrency, sent, received, sentValue, receivedValue);
    }

    function setUnlockRatePerSecond(address token, uint64 _unlockRatePerSecond) external onlyOwner {
        _getBalanceData().setUnlockRatePerSecond(token, _unlockRatePerSecond);
    }

    /// @notice Creates a linear vesting for certain tokens donated to this vault
    /// @dev Make sure to call `setUnlockRatePerSecond` before calling this function for each token, default one is too low for this purpose
    function internalizeDonations(address[] memory tokens, uint128[] memory amounts) external virtual onlyOwner {
        uint tokensLength = tokens.length;

        require(tokensLength == amounts.length, "CollVault: tokens and amounts length mismatch");

        address _ibgt = ibgt();
        IIBGTVault _ibgtVault = IIBGTVault(ibgtVault());
        uint _performanceFee = getPerformanceFee();

        for (uint i; i < tokensLength; i++) {
            address token = tokens[i];
            uint amount = amounts[i];

            if (amount == 0) continue;

            // asset is staked in infraredVault, not in address(this)
            uint donatedAmount = token != asset()
                ? IERC20(token).balanceOf(address(this)) - getBalanceOfWithFutureEmissions(token)
                : IAsset(asset()).balanceOf(address(this));
            require(donatedAmount >= amount, "CollVault: insufficient balance");

            (amount, token) = _autoCompoundHook(token, _ibgt, _ibgtVault, amount);

            require(_isRewardedToken(token), "CollVault: token not rewarded");

            uint fee = amount * _performanceFee / BP;
            uint netAmounts = amount - fee;

            if (token == asset()) {
                _stake(netAmounts);
            }

            if (fee != 0) {
                IERC20(token).safeTransfer(getMetaBeraborrowCore().feeReceiver(), fee);
            }

            _getBalanceData().addEmissions(token, uint128(netAmounts));
        }
    }

    /// @dev Harvests rewards to don't have previously accrued but still not harvested rewards processed with the new fee
    function setPerformanceFee(uint16 _performanceFee) external virtual onlyOwner harvestRewards {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();

        require(_performanceFee >= $.minPerformanceFee && _performanceFee <= $.maxPerformanceFee, "CollVault: performance fee out of bounds");

        $.performanceFee = _performanceFee;
    }

    function setPairThreshold(address tokenIn, uint thresholdInBP) external virtual onlyOwner {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();

        require(thresholdInBP <= BP, "CollVault: threshold > BP");

        $.threshold[tokenIn] = thresholdInBP;
    }

    function setIRED(address _iRedToken) external virtual onlyOwner {
        _getInfraredCollVaultStorage().iRedToken = _iRedToken;
    }

    function _increaseBalance(address token, uint amount) internal override {
        _getBalanceData().balance[token] += amount;
    }

    function _decreaseBalance(address token, uint amount) internal override {
        _getBalanceData().balance[token] -= amount;
    }

    /* Getters */

    /// @dev Doesn't include vesting amount, same as `getTokenVirtualBalance` in LSPGetters
    function getBalance(address token) public view override returns (uint) {
        return _getBalanceData().balanceOf(token);
    }

    /// @dev Includes vesting amount
    function getBalanceOfWithFutureEmissions(address token) public view virtual returns (uint) {
        return _getBalanceData().balance[token];
    }

    /// @dev Returns the locked emissions
    function getLockedEmissions(address token) public view returns (uint) {
        EmissionsLib.EmissionSchedule memory schedule = _getBalanceData().emissionSchedule[token];
        uint fullUnlockTimestamp = schedule.unlockTimestamp();

        return schedule.lockedEmissions(fullUnlockTimestamp);
    }

    function unlockRatePerSecond(address token) external view virtual returns (uint) {
        EmissionsLib.EmissionSchedule memory schedule = _getBalanceData().emissionSchedule[token];

        return schedule.unlockRatePerSecond();
    }

    function getFullProfitUnlockTimestamp(address token) external view returns (uint) {
        EmissionsLib.EmissionSchedule memory schedule = _getBalanceData().emissionSchedule[token];

        return schedule.unlockTimestamp();
    }

    function getPerformanceFee() public view virtual returns (uint16) {
        return _getInfraredCollVaultStorage().performanceFee;
    }

    /// @dev Returns tokens that has been rewarded at some point by the infrared vault
    function rewardedTokens() public view virtual returns (address[] memory) {
        return _getInfraredCollVaultStorage().rewardedTokens.values();
    }

    function _isRewardedToken(address token) internal view virtual returns (bool) {
        return _getInfraredCollVaultStorage().rewardedTokens.contains(token);
    }

    function _addRewardedToken(address token) internal virtual {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();
        $.rewardedTokens.add(token);
    }

    function iRedToken() public view virtual returns (address) {
        return _getInfraredCollVaultStorage().iRedToken;
    }

    function infraredVault() public view virtual returns (IInfraredVault) {
        return _getInfraredCollVaultStorage()._infraredVault;
    }

    function ibgt() public view virtual returns (address) {
        return _getInfraredCollVaultStorage().ibgt;
    }

    function ibgtVault() public view virtual returns (address) {
        return _getInfraredCollVaultStorage().ibgtVault;
    }

    function _stake(uint amount) internal override {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();
        IInfraredVault iVault = $._infraredVault;
        IInfraredWrapper infraredWrapper = $.infraredWrapper;
        address stakingToken;

        if (address(infraredWrapper) != address(0)) {
            IERC20(asset()).safeApprove(address(infraredWrapper), amount);
            infraredWrapper.depositFor(address(this), amount);
            stakingToken = address(infraredWrapper);
        } else {
            stakingToken = asset();
        }
        IERC20(stakingToken).safeIncreaseAllowance(address(iVault), amount); 
        iVault.stake(amount);
    }

    function _unstake(uint amount) internal override {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();
        IInfraredWrapper infraredWrapper = $.infraredWrapper;

        $._infraredVault.withdraw(amount);

        if (address(infraredWrapper) != address(0)) {
            infraredWrapper.withdrawTo(address(this), amount);
        }
    }

    /// @dev Rewards the rest of the rewarded tokens (not the asset) to the receiver
    function _withdrawExtraRewardedTokens(
        address receiver,
        uint shares,
        uint _totalSupply
    ) internal override virtual {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();

        address[] memory tokens = rewardedTokens();
        uint tokensLength = tokens.length;
        address _ibgtVault = $.ibgtVault;

        for (uint i; i < tokensLength; i++) {
            address token = tokens[i];
            // if token is the asset, go next token since has already been transferred
            if (token == asset()) {
                continue;
            }

            uint amount = shares.mulDiv(getBalance(token), _totalSupply, Math.Rounding.Down);

            if (amount == 0) continue;
            _decreaseBalance(token, amount);

            if (token == _ibgtVault && _ibgtVault != address(this)) {
                IInfraredCollateralVault(token).redeem(amount, receiver, address(this));
            } else {
                IERC20(token).safeTransfer(receiver, amount);
            }
        }
    }

    function _hasPriceFeed(address token) internal view virtual returns (bool) {
        IPriceFeed priceFeed = getPriceFeed();

        (address oracle,,,,) = priceFeed.oracleRecords(token);

        IPriceFeed.FeedType memory feedInfo = priceFeed.feedType(token);

        return oracle != address(0) || feedInfo.isCollVault || feedInfo.spotOracle != address(0);
    }

    function _convertToValue(address token) public view virtual returns (uint) {
        uint currentBalance = getBalance(token);
        uint price = getPrice(token);
        uint8 _decimals = IAsset(token).decimals();
        return currentBalance.convertToValue(price, _decimals);
    }

    /**
     * @dev Hook that is called to check if the token is a collateral vault
     * @dev Prevents recursion DOS attacks by preventing the vault from being a reward token
     * Only collateral vault permitted is iBGTVault
     */
    function _isCollVault(address token) internal view virtual returns (bool) {
        IInfraredCollateralVault.InfraredCollVaultStorage storage $ = _getInfraredCollVaultStorage();

        // iBGTVault is the only collateral vault permitted, unless it is the current vault
        if (token == $.ibgtVault && $.ibgtVault != address(this)) {
            return false;
        }
        return getPriceFeed().isCollVault(token);
    }

    function _autoCompoundHook(address _token, address /*_ibgt*/, IIBGTVault /*_ibgtVault*/, uint _rewards) internal virtual returns (uint, address) {
        return (_rewards, _token);
    }

    /**
     * @dev Hook that is called after the vault has been rebalanced
     * Meant to be used by the child contract to stake the `asset()` in the infrared vault
     */
    function _afterVaultRebalance(uint amount) internal virtual {
        _stake(amount);
    }
}

// src/core/vaults/MainAssetCompoundingInfraredCollVault.sol

/**
 * @title MainAssetCompoundingInfraredCollVault
 * @author Beraborrow Team
 * @notice CollateralVault depositable as collateral to mint NECT, autocompounds reward tokens to main asset
 * @dev Not usable as collateral in Beraborrow until BPT pricing solution is in place (fetchPrice reverts)
 */
contract MainAssetCompoundingInfraredCollVault is InfraredCollateralVault {
    using SafeERC20 for IERC20;
    using PriceLib for uint;
    using EmissionsLib for EmissionsLib.BalanceData;

    // keccak256(abi.encode(uint(keccak256("openzeppelin.storage.MainAssetCompoundingInfraredCollVault")) - 1)) & ~bytes32(uint(0xff))
    bytes32 private constant MainAssetCompoundingInfraredCollVaultStorageLocation = 0x11107a1f81311054281ce199600e6bde1fc6abe70b0d42e6392b22b9c1234700;

    function initialize(IMainAssetCompoundingInfraredCollVault.MainAssetCompoundingInfraredInitParams calldata params, IInfraredCollateralVault.InfraredInitParams calldata baseParams) public initializer {
        __InfraredCollateralVault_init(baseParams);
        __MainAssetCompoundingInfraredCollVault_init(params);
    }

    function _getMainAssetCompoundingInfraredCollVaultStorage() internal pure returns (IMainAssetCompoundingInfraredCollVault.IMainAssetCompoundingInfraredCollVaultStorage storage store) {
        assembly {
            store.slot := MainAssetCompoundingInfraredCollVaultStorageLocation
        }
    }

    function __MainAssetCompoundingInfraredCollVault_init(IMainAssetCompoundingInfraredCollVault.MainAssetCompoundingInfraredInitParams calldata params) internal onlyInitializing {
        __MainAssetCompoundingInfraredCollVault_init_unchained(params);
    }

    function __MainAssetCompoundingInfraredCollVault_init_unchained(IMainAssetCompoundingInfraredCollVault.MainAssetCompoundingInfraredInitParams calldata params) internal onlyInitializing {
        _getMainAssetCompoundingInfraredCollVaultStorage().keeper = params._keeper;
    }

    /// @dev Returns virtual balance, without accounting locked vest
    function totalAssets() public view override virtual returns (uint) {
        return BaseCollateralVault.totalAssets();
    }

    modifier onlyKeeperOrOwner() {
        require(
            _getMainAssetCompoundingInfraredCollVaultStorage().keeper == msg.sender
            || getMetaBeraborrowCore().owner() == msg.sender,
            "MainAssetCompoundingInfraredCollVault: Not owner nor keeper"
        );
        _;
    }

    /// @dev Version with also keeper access and linear emission of asset() rebalance
    /// @dev Requires asset() to have a defined unlockRatePerSecond, default of 10%/s is too high
    /// @dev Keeper will be configured to rebalance as fast as possible to main asset
    /// if it turns malicious, it's impact will be limited to new rewards until it's address is revoked
    function rebalance(IInfraredCollateralVault.RebalanceParams calldata p) external override virtual onlyKeeperOrOwner harvestRewards {
        require(p.sentCurrency != asset(), "CollVault: asset can't be sent");

        uint sentCurrencyBalance = IAsset(p.sentCurrency).balanceOf(address(this));
        uint receivedCurrencyBalance = IAsset(asset()).balanceOf(address(this));

        // Perform the swap using the swapper contract
        IERC20(p.sentCurrency).safeTransfer(p.swapper, p.sentAmount);
        IRebalancer(p.swapper).swap(
            p.sentCurrency,
            p.sentAmount,
            asset(),
            p.payload
        );

        uint received = IAsset(asset()).balanceOf(address(this)) - receivedCurrencyBalance;
        uint sent = sentCurrencyBalance - IAsset(p.sentCurrency).balanceOf(address(this));

        // if we were to rebalance locked emissions, a possible revert on subsequent `$.balanceOf` calls would occur
        if (sent > getBalance(p.sentCurrency)) revert WithdrawingLockedEmissions();
        // if threshold isn't set, it will be 0, not tolerating any slippage
        require(_getBalanceData().emissionSchedule[asset()]._unlockRatePerSecond != 0, "CollVault: asset needs a defined unlockRatePerSecond");

        _decreaseBalance(p.sentCurrency, sent);
        _getBalanceData().addEmissions(asset(), uint128(received));

        _afterVaultRebalance(received);

        emit Rebalance(p.sentCurrency, sent, received, 0, 0);
    }

    /**
     * @return tokens Only includes tokens that are virtually accounted as rewardedTokens
     * @return amounts Array of amounts per token after performance fee
     */
    function previewHarvestRewards() external view returns (address[] memory tokens, uint[] memory amounts) {
        IInfraredVault iVault = infraredVault();
        
        tokens = iVault.getAllRewardTokens();
        amounts = new uint[](tokens.length);

        uint _performanceFee = getPerformanceFee();
        address _iRedToken = iRedToken();
        address _ibgt = ibgt();
        IIBGTVault _ibgtVault = IIBGTVault(ibgtVault());

        for (uint i; i < tokens.length; i++) {
            address _token = tokens[i];
            uint rewards = iVault.earned(address(this), tokens[i]);
            if (rewards == 0) continue;

            bool isIBGT = _token == _ibgt;
            if (isIBGT && _hasPriceFeed(_ibgt)) {
                rewards = _ibgtVault.previewDeposit(rewards);
                _token = isIBGT ? address(_ibgtVault) : _token;
            }

            if (_hasPriceFeed(_token) && _token != _iRedToken && !_isCollVault(_token)) {
                uint fee = rewards * _performanceFee / BP;
                uint netRewards = rewards - fee;

                amounts[i] = netRewards;
            }
        }
    }

    function _autoCompoundHook(address _token, address _ibgt, IIBGTVault _ibgtVault, uint _rewards) internal override returns (uint, address) {
        uint bbIbgtMinted;
        bool isIBGT = _token == _ibgt;
        if (isIBGT && _hasPriceFeed(_token)) {
            IERC20(_ibgt).safeIncreaseAllowance(address(_ibgtVault), _rewards);
            bbIbgtMinted = _ibgtVault.deposit(_rewards, address(this));
            _rewards = bbIbgtMinted;
            _token = isIBGT ? address(_ibgtVault) : _token;
        }

        return (_rewards, _token);
    }

    function _requireAssetFeed(IMetaBeraborrowCore _metaBeraborrowCore, address asset) internal override {}

    /// @dev Since they're not accounted in totalAssets(), they are no longer withdrawable
    function _withdrawExtraRewardedTokens(
        address receiver,
        uint shares,
        uint _totalSupply
    ) internal override virtual {}

    function setKeeper(address _keeper) external onlyOwner {
        _getMainAssetCompoundingInfraredCollVaultStorage().keeper = _keeper;
    }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"name":"AmountCannotBeZero","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxDeposit","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxMint","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxRedeem","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxWithdraw","type":"error"},{"inputs":[],"name":"EmissionRateExceedsMax","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"inputs":[],"name":"WithdrawingLockedEmissions","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"}],"name":"EmissionsAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint64","name":"unlockRatePerSecond","type":"uint64"}],"name":"NewUnlockRatePerSecond","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"PerformanceFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sentCurrency","type":"address"},{"indexed":false,"internalType":"uint256","name":"sent","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"received","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sentValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"receivedValue","type":"uint256"}],"name":"Rebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"_convertToValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"assetDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"fetchPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getBalanceOfWithFutureEmissions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getFullProfitUnlockTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getLockedEmissions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMetaBeraborrowCore","outputs":[{"internalType":"contract IMetaBeraborrowCore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPerformanceFee","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"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":"getPriceFeed","outputs":[{"internalType":"contract IPriceFeed","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getWithdrawFee","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"iRedToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ibgt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ibgtVault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"infraredVault","outputs":[{"internalType":"contract IInfraredVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"_keeper","type":"address"}],"internalType":"struct IMainAssetCompoundingInfraredCollVault.MainAssetCompoundingInfraredInitParams","name":"params","type":"tuple"},{"components":[{"components":[{"internalType":"uint16","name":"_minWithdrawFee","type":"uint16"},{"internalType":"uint16","name":"_maxWithdrawFee","type":"uint16"},{"internalType":"uint16","name":"_withdrawFee","type":"uint16"},{"internalType":"contract IMetaBeraborrowCore","name":"_metaBeraborrowCore","type":"address"},{"internalType":"contract IERC20","name":"_asset","type":"address"},{"internalType":"string","name":"_sharesName","type":"string"},{"internalType":"string","name":"_sharesSymbol","type":"string"}],"internalType":"struct IBaseCollateralVault.BaseInitParams","name":"_baseParams","type":"tuple"},{"internalType":"uint16","name":"_minPerformanceFee","type":"uint16"},{"internalType":"uint16","name":"_maxPerformanceFee","type":"uint16"},{"internalType":"uint16","name":"_performanceFee","type":"uint16"},{"internalType":"address","name":"_iRedToken","type":"address"},{"internalType":"contract IInfraredVault","name":"_infraredVault","type":"address"},{"internalType":"address","name":"_ibgtVault","type":"address"},{"internalType":"address","name":"_infraredWrapper","type":"address"}],"internalType":"struct IInfraredCollateralVault.InfraredInitParams","name":"baseParams","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint128[]","name":"amounts","type":"uint128[]"}],"name":"internalizeDonations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"previewHarvestRewards","outputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"sentCurrency","type":"address"},{"internalType":"uint256","name":"sentAmount","type":"uint256"},{"internalType":"address","name":"swapper","type":"address"},{"internalType":"bytes","name":"payload","type":"bytes"}],"internalType":"struct IInfraredCollateralVault.RebalanceParams","name":"p","type":"tuple"}],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address","name":"receiver","type":"address"}],"name":"receiveDonations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardedTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_iRedToken","type":"address"}],"name":"setIRED","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_keeper","type":"address"}],"name":"setKeeper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"thresholdInBP","type":"uint256"}],"name":"setPairThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_performanceFee","type":"uint16"}],"name":"setPerformanceFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint64","name":"_unlockRatePerSecond","type":"uint64"}],"name":"setUnlockRatePerSecond","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_withdrawFee","type":"uint16"}],"name":"setWithdrawFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"unlockRatePerSecond","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

60a060405230608052348015610013575f80fd5b5061001c610021565b6100d3565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff16156100715760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146100d05780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b608051615f946100f95f395f8181612d5801528181612d810152612ec30152615f945ff3fe608060405260043610610366575f3560e01c806370a08231116101c8578063ba087652116100fd578063d9c001971161009d578063ef8b30f71161006d578063ef8b30f7146108b5578063f57d959c146109a2578063f8b2cb4f146109c1578063fd64c377146109e0575f80fd5b8063d9c0019714610931578063dd62ed3e14610950578063e993e7ed1461096f578063ec05c34114610983575f80fd5b8063c6e6f592116100d8578063c6e6f592146108b5578063ce96cb77146108d4578063d5c16d79146108f3578063d905777e14610912575f80fd5b8063ba0876521461086c578063c2d416011461088b578063c63d75b6146105c4575f80fd5b8063aa290e6d11610168578063b009c92c11610143578063b009c92c146107ed578063b2c06ba01461080f578063b3d7f6b91461082e578063b460af941461084d575f80fd5b8063aa290e6d1461077d578063aaffe0761461079c578063ad3cb1cc146107bd575f80fd5b806395d89b41116101a357806395d89b41146107175780639a400b0f1461072b5780639e87a5cd1461074a578063a9059cbb1461075e575f80fd5b806370a08231146106ba578063748747e6146106d957806394bf804d146106f8575f80fd5b8063322ce8f01161029e57806341519a651161023e5780634f1ef286116102195780634f1ef2861461066057806352d1902d146106735780636ab3b0e5146106875780636e553f651461069b575f80fd5b806341519a651461060357806341976e09146106225780634cdad50614610641575f80fd5b80633dafa4f3116102795780633dafa4f3146105915780633e92f95b146105a5578063402d267d146105c4578063403dd3bc146105e4575f80fd5b8063322ce8f01461053f57806332e1fef21461055e57806338d52e0f1461057d575f80fd5b80631540aa8911610309578063235c3603116102e4578063235c3603146104c757806323b872dd146104db57806329d78c88146104fa578063313ce56714610519575f80fd5b80631540aa891461045457806318160ddd1461047b578063221085d71461049b575f80fd5b8063095ea7b311610344578063095ea7b3146103d15780630a28a477146104005780630b983a741461041f5780630fdb11cf14610440575f80fd5b806301e1d1141461036a57806306fdde031461039157806307a2d13a146103b2575b5f80fd5b348015610375575f80fd5b5061037e6109f4565b6040519081526020015b60405180910390f35b34801561039c575f80fd5b506103a5610a02565b60405161038891906151bf565b3480156103bd575f80fd5b5061037e6103cc3660046151f4565b610ac2565b3480156103dc575f80fd5b506103f06103eb36600461522f565b610ad3565b6040519015158152602001610388565b34801561040b575f80fd5b5061037e61041a3660046151f4565b610aea565b34801561042a575f80fd5b5061043e610439366004615259565b610afd565b005b34801561044b575f80fd5b5061037e610b21565b34801561045f575f80fd5b50610468610b89565b60405161ffff9091168152602001610388565b348015610486575f80fd5b505f80516020615e988339815191525461037e565b3480156104a6575f80fd5b506104af610bab565b6040516001600160a01b039091168152602001610388565b3480156104d2575f80fd5b50610468610bcd565b3480156104e6575f80fd5b506103f06104f536600461529b565b610bd6565b348015610505575f80fd5b5061037e6105143660046152d9565b610bfb565b348015610524575f80fd5b5061052d610c21565b60405160ff9091168152602001610388565b34801561054a575f80fd5b5061043e610559366004615303565b610c4e565b348015610569575f80fd5b5061043e6105783660046153f7565b610d0d565b348015610588575f80fd5b506104af610fab565b34801561059c575f80fd5b506104af610fc6565b3480156105b0575f80fd5b5061043e6105bf3660046154c1565b610fe1565b3480156105cf575f80fd5b5061037e6105de3660046152d9565b505f1990565b3480156105ef575f80fd5b5061037e6105fe3660046152d9565b611354565b34801561060e575f80fd5b5061043e61061d3660046152d9565b6113d4565b34801561062d575f80fd5b5061037e61063c3660046152d9565b611414565b34801561064c575f80fd5b5061037e61065b3660046151f4565b611487565b61043e61066e366004615591565b611492565b34801561067e575f80fd5b5061037e6114ad565b348015610692575f80fd5b506104af6114c8565b3480156106a6575f80fd5b5061037e6106b5366004615636565b6114e3565b3480156106c5575f80fd5b5061037e6106d43660046152d9565b611512565b3480156106e4575f80fd5b5061043e6106f33660046152d9565b611538565b348015610703575f80fd5b5061037e610712366004615636565b611584565b348015610722575f80fd5b506103a56115b3565b348015610736575f80fd5b5061043e61074536600461522f565b6115f1565b348015610755575f80fd5b506104af611675565b348015610769575f80fd5b506103f061077836600461522f565b6116f9565b348015610788575f80fd5b5061043e610797366004615303565b611706565b3480156107a7575f80fd5b506107b0611766565b604051610388919061569c565b3480156107c8575f80fd5b506103a5604051806040016040528060058152602001640352e302e360dc1b81525081565b3480156107f8575f80fd5b5061080161177b565b6040516103889291906156ae565b34801561081a575f80fd5b5061043e610829366004615706565b611a71565b348015610839575f80fd5b5061037e6108483660046151f4565b612031565b348015610858575f80fd5b5061037e61086736600461573c565b61203d565b348015610877575f80fd5b5061037e61088636600461573c565b6120eb565b348015610896575f80fd5b505f80516020615f3f83398151915254600160301b900460ff1661052d565b3480156108c0575f80fd5b5061037e6108cf3660046151f4565b612188565b3480156108df575f80fd5b5061037e6108ee3660046152d9565b612193565b3480156108fe575f80fd5b5061037e61090d3660046152d9565b6121a0565b34801561091d575f80fd5b5061037e61092c3660046152d9565b61220b565b34801561093c575f80fd5b5061037e61094b3660046152d9565b612215565b34801561095b575f80fd5b5061037e61096a36600461577b565b612280565b34801561097a575f80fd5b506104af6122c9565b34801561098e575f80fd5b5061037e61099d3660046152d9565b6122e8565b3480156109ad575f80fd5b5061043e6109bc3660046157a7565b612378565b3480156109cc575f80fd5b5061037e6109db3660046152d9565b61248d565b3480156109eb575f80fd5b506104af6124a5565b5f6109fd6124c0565b905090565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0380546060915f80516020615e7883398151915291610a40906157f4565b80601f0160208091040260200160405190810160405280929190818152602001828054610a6c906157f4565b8015610ab75780601f10610a8e57610100808354040283529160200191610ab7565b820191905f5260205f20905b815481529060010190602001808311610a9a57829003601f168201915b505050505091505090565b5f610acd825f6124cc565b92915050565b5f33610ae0818585612518565b5060019392505050565b5f80610af58361252a565b509392505050565b610b0561258e565b610b1d5f80516020615eb88339815191528383612662565b5050565b5f80610b385f80516020615e988339815191525490565b9050805f03610b48575f91505090565b610b83610b5661063c610fab565b82610b5f612713565b610b6a90600a61591b565b610b726109f4565b610b7c9190615929565b9190612739565b91505090565b5f5f80516020615f3f8339815191525b54640100000000900461ffff16919050565b5f80516020615f3f83398151915254600160381b90046001600160a01b031690565b5f610b996127e2565b5f33610be3858285612806565b610bee858585612856565b60019150505b9392505050565b6001600160a01b03165f9081525f80516020615eb8833981519152602052604090205490565b5f5f80516020615f1f833981519152610c38612713565b8154610b839190600160a01b900460ff16615940565b610c5661258e565b5f80516020615f3f833981519152805461ffff90811690831610801590610c8c5750805461ffff62010000909104811690831611155b610ceb5760405162461bcd60e51b815260206004820152602560248201527f436f6c6c5661756c743a20576974686472617720666565206f7574206f6620626044820152646f756e647360d81b60648201526084015b60405180910390fd5b805461ffff9092166401000000000265ffff0000000019909216919091179055565b610d1561258e565b825182515f80516020615f3f83398151915291908114610d475760405162461bcd60e51b8152600401610ce290615959565b5f610d50610fab565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015610d94573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610db891906159a6565b90505f6001840181610dc8610fab565b6001600160a01b03166001600160a01b031681526020019081526020015f2054905080821115610e1857610e1885610e0083856159bd565b610e08610fab565b6001600160a01b031691906128b3565b5f5b83811015610fa157610e2a610fab565b6001600160a01b0316888281518110610e4557610e456159d0565b60200260200101516001600160a01b03160315610f99575f888281518110610e6f57610e6f6159d0565b60209081029190910101516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610ebd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ee191906159a6565b90505f866001015f015f8b8581518110610efd57610efd6159d0565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205490505f610f568a8581518110610f3d57610f3d6159d0565b60200260200101518385610f5191906159bd565b612916565b90508015610f9557610f9589828d8781518110610f7557610f756159d0565b60200260200101516001600160a01b03166128b39092919063ffffffff16565b5050505b600101610e1a565b5050505050505050565b5f80516020615f1f833981519152546001600160a01b031690565b5f610fcf6127e2565b600501546001600160a01b0316919050565b610fe961258e565b81518151811461100b5760405162461bcd60e51b8152600401610ce290615959565b5f611014610fc6565b90505f61101f6124a5565b90505f61102a610bcd565b61ffff1690505f5b8481101561134b575f87828151811061104d5761104d6159d0565b602002602001015190505f87838151811061106a5761106a6159d0565b60200260200101516001600160801b03169050805f0361108b575050611343565b5f611094610fab565b6001600160a01b0316836001600160a01b031603611121576110b4610fab565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156110f8573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061111c91906159a6565b61119a565b61112a83610bfb565b6040516370a0823160e01b81523060048201526001600160a01b038516906370a0823190602401602060405180830381865afa15801561116c573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061119091906159a6565b61119a91906159bd565b9050818110156111ec5760405162461bcd60e51b815260206004820152601f60248201527f436f6c6c5661756c743a20696e73756666696369656e742062616c616e6365006044820152606401610ce2565b6111f88388888561292b565b93509150611205836129f5565b6112515760405162461bcd60e51b815260206004820152601d60248201527f436f6c6c5661756c743a20746f6b656e206e6f742072657761726465640000006044820152606401610ce2565b5f61271061125f8785615929565b61126991906159f8565b90505f61127682856159bd565b9050611280610fab565b6001600160a01b0316856001600160a01b0316036112a1576112a181612a0b565b8115611322576113226112b2610bab565b6001600160a01b031663b3f006746040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112ed573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113119190615a17565b6001600160a01b03871690846128b3565b61133d85825f80516020615eb88339815191525b9190612b44565b50505050505b600101611032565b50505050505050565b6001600160a01b0381165f9081525f80516020615e5883398151915260209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b900490921690820152816113c082612bbc565b90506113cc8282612bed565b949350505050565b6113dc61258e565b806113e56127e2565b80546001600160a01b0392909216600160301b026601000000000000600160d01b031990921691909117905550565b5f61141d611675565b604051635670bcc760e11b81526001600160a01b038481166004830152919091169063ace1798e90602401602060405180830381865afa158015611463573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610acd91906159a6565b5f80610af583612c74565b61149a612d4d565b6114a382612df1565b610b1d8282612dfc565b5f6114b6612eb8565b505f80516020615ed883398151915290565b5f6114d16127e2565b600301546001600160a01b0316919050565b5f6114ec612f01565b6114f6838361332a565b905061150183612a0b565b610acd61150c610fab565b84613345565b6001600160a01b03165f9081525f80516020615e78833981519152602052604090205490565b61154061258e565b807f11107a1f81311054281ce199600e6bde1fc6abe70b0d42e6392b22b9c12347005b80546001600160a01b0319166001600160a01b039290921691909117905550565b5f61158d612f01565b6115978383613381565b90506115a281612a0b565b610acd6115ad610fab565b82613345565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0480546060915f80516020615e7883398151915291610a40906157f4565b6115f961258e565b5f6116026127e2565b90506127108211156116565760405162461bcd60e51b815260206004820152601960248201527f436f6c6c5661756c743a207468726573686f6c64203e204250000000000000006044820152606401610ce2565b6001600160a01b039092165f9081526007909201602052604090912055565b5f5f80516020615f3f8339815191525f0160079054906101000a90046001600160a01b03166001600160a01b031663741bef1a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116d5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109fd9190615a17565b5f33610ae0818585612856565b61170e61258e565b611716612f01565b5f61171f6127e2565b805490915061ffff9081169083161080159061174a5750805461ffff62010000909104811690831611155b610ceb5760405162461bcd60e51b8152600401610ce290615a32565b60606109fd6117736127e2565b60010161339c565b6060805f6117876114c8565b9050806001600160a01b03166312edb24c6040518163ffffffff1660e01b81526004015f60405180830381865afa1580156117c4573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526117eb9190810190615a7a565b925082516001600160401b038111156118065761180661531e565b60405190808252806020026020018201604052801561182f578160200160208202803683370190505b5091505f61183b610bcd565b61ffff1690505f61184a6122c9565b90505f611855610fc6565b90505f6118606124a5565b90505f5b8751811015611a67575f888281518110611880576118806159d0565b602002602001015190505f876001600160a01b031663211dc32d308c86815181106118ad576118ad6159d0565b60200260200101516040518363ffffffff1660e01b81526004016118e79291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa158015611902573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061192691906159a6565b9050805f03611936575050611a5f565b6001600160a01b03828116908616148080156119565750611956866133a8565b156119d45760405163ef8b30f760e01b8152600481018390526001600160a01b0386169063ef8b30f790602401602060405180830381865afa15801561199e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119c291906159a6565b9150806119cf57826119d1565b845b92505b6119dd836133a8565b80156119fb5750866001600160a01b0316836001600160a01b031614155b8015611a0d5750611a0b836134c3565b155b15611a5b575f612710611a208a85615929565b611a2a91906159f8565b90505f611a3782856159bd565b9050808c8781518110611a4c57611a4c6159d0565b60200260200101818152505050505b5050505b600101611864565b5050505050509091565b337f11107a1f81311054281ce199600e6bde1fc6abe70b0d42e6392b22b9c1234700546001600160a01b03161480611b17575033611aad610bab565b6001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae8573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b0c9190615a17565b6001600160a01b0316145b611b895760405162461bcd60e51b815260206004820152603b60248201527f4d61696e4173736574436f6d706f756e64696e67496e667261726564436f6c6c60448201527f5661756c743a204e6f74206f776e6572206e6f72206b656570657200000000006064820152608401610ce2565b611b91612f01565b611b99610fab565b6001600160a01b0316611baf60208301836152d9565b6001600160a01b031603611c055760405162461bcd60e51b815260206004820152601e60248201527f436f6c6c5661756c743a2061737365742063616e27742062652073656e7400006044820152606401610ce2565b5f611c1360208301836152d9565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611c57573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c7b91906159a6565b90505f611c86610fab565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611cca573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cee91906159a6565b9050611d14611d0360608501604086016152d9565b60208501803590610e0890876152d9565b611d2460608401604085016152d9565b6001600160a01b0316637f0f41d7611d3f60208601866152d9565b8560200135611d4c610fab565b611d596060890189615b09565b6040518663ffffffff1660e01b8152600401611d79959493929190615b52565b5f604051808303815f87803b158015611d90575f80fd5b505af1158015611da2573d5f803e3d5ffd5b505050505f81611db0610fab565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611df4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e1891906159a6565b611e2291906159bd565b90505f611e3260208601866152d9565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611e76573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e9a91906159a6565b611ea490856159bd565b9050611eb66109db60208701876152d9565b811115611ed657604051630301465d60e11b815260040160405180910390fd5b5f80516020615e588339815191525f611eed610fab565b6001600160a01b0316815260208101919091526040015f90812054600160c01b90046001600160401b03169003611f835760405162461bcd60e51b815260206004820152603460248201527f436f6c6c5661756c743a206173736574206e65656473206120646566696e6564604482015273081d5b9b1bd8dad4985d1954195c94d958dbdb9960621b6064820152608401610ce2565b611f99611f9360208701876152d9565b8261357b565b611fb8611fa4610fab565b835f80516020615eb8833981519152611336565b611fc1826135ae565b611fce60208601866152d9565b6001600160a01b03167f90fea00fe6e24ccfd7c40b40e07486e8b69ada2a3ad693dd908b6479cac36b6b82845f80604051612022949392919093845260208401929092526040830152606082015260800190565b60405180910390a25050505050565b5f610acd8260016124cc565b5f612046612f01565b5f61205c5f80516020615e988339815191525490565b90505f61206884612193565b90508086111561209157838682604051633fa733bb60e21b8152600401610ce293929190615ba2565b505f61209c8661252a565b90935090505f806120ae8585856135b7565b91509150815f146120d3576120c282613686565b6120d36120cd610fab565b8361357b565b6120e03388888589613772565b505050509392505050565b5f6120f4612f01565b5f61210a5f80516020615e988339815191525490565b90505f6121168461220b565b90508086111561213f57838682604051632e52afbb60e21b8152600401610ce293929190615ba2565b505f61214a86612c74565b90935090505f8061215c8885856135b7565b91509150815f1461217b5761217082613686565b61217b6120cd610fab565b6120e0338888858c613772565b5f610acd825f613826565b5f610acd61065b83611512565b6001600160a01b0381165f9081525f80516020615e5883398151915260209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b900490921690820152610bf481612bbc565b5f610acd82611512565b6001600160a01b0381165f9081525f80516020615e5883398151915260209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b900490921690820152610bf481613869565b6001600160a01b039182165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020908152604080832093909416825291909152205490565b5f6122d26127e2565b54600160301b90046001600160a01b0316919050565b5f806122f38361248d565b90505f6122ff84611414565b90505f846001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561233e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123629190615bd3565b905061236f83838361389e565b95945050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f811580156123bc5750825b90505f826001600160401b031660011480156123d75750303b155b9050811580156123e5575080155b156124035760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561242d57845460ff60401b1916600160401b1785555b612436866138be565b61243f876138cf565b831561134b57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a150505050505050565b5f610acd5f80516020615eb8833981519152836138e0565b5f6124ae6127e2565b600401546001600160a01b0316919050565b5f6109fd6109db610fab565b5f610bf46124d86109f4565b6124e3906001615bec565b6124eb612713565b6124f690600a61591b565b5f80516020615e988339815191525461250f9190615bec565b8591908561396c565b61252583838360016139c5565b505050565b5f805f80516020615f3f8339815191528161254485613aa9565b82549091505f90612573906127109061256990640100000000900461ffff16826159bd565b849190600161396c565b90505f61258083836159bd565b919791965090945050505050565b612596610bab565b6001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156125d1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125f59190615a17565b6001600160a01b0316336001600160a01b0316146126605760405162461bcd60e51b815260206004820152602260248201527f436f6c6c5661756c743a2063616c6c6572206973206e6f7420746865206f776e60448201526132b960f11b6064820152608401610ce2565b565b64e8d4a510006001600160401b0382161115612691576040516304bba2fb60e51b815260040160405180910390fd5b61269c83835f613ab5565b6001600160a01b0382165f81815260018501602090815260409182902080546001600160c01b0316600160c01b6001600160401b0387169081029190911790915591519182527f5577d4c8f6e5397effa5c71df8fe221e1162e18aaa0aabe87026cfb0c676215091015b60405180910390a2505050565b5f80516020615f3f833981519152545f90600160301b900460ff166109fd906012615bff565b5f80805f19858709858702925082811083820303915050805f0361277057838281612766576127666159e4565b0492505050610bf4565b80841161277b575f80fd5b5f8486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091025f889003889004909101858311909403939093029303949094049190911702949350505050565b7ff6a35052099d23fafed8c58b549933969c057c5a9a13ac5133024adc8dd4f20090565b5f6128118484612280565b90505f198114612850578181101561284257828183604051637dc7a0d960e11b8152600401610ce293929190615ba2565b61285084848484035f6139c5565b50505050565b6001600160a01b03831661287f57604051634b637e8f60e11b81525f6004820152602401610ce2565b6001600160a01b0382166128a85760405163ec442f0560e01b81525f6004820152602401610ce2565b612525838383613c19565b6040516001600160a01b03831660248201526044810182905261252590849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613d3f565b5f8183106129245781610bf4565b5090919050565b5f80806001600160a01b038781169087161480801561294e575061294e886133a8565b156129ea576129676001600160a01b0388168787613e10565b604051636e553f6560e01b8152600481018690523060248201526001600160a01b03871690636e553f65906044016020604051808303815f875af11580156129b1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129d591906159a6565b9150819450806129e557876129e7565b855b97505b509296945050505050565b5f610acd82612a026127e2565b60010190613ebf565b5f612a146127e2565b600381015460068201549192506001600160a01b0390811691165f8115612ac957612a528286612a42610fab565b6001600160a01b03169190613ee0565b6040516317a790f160e11b8152306004820152602481018690526001600160a01b03831690632f4f21e2906044016020604051808303815f875af1158015612a9c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ac09190615c27565b50819050612ad4565b612ad1610fab565b90505b612ae86001600160a01b0382168487613e10565b60405163534a7e1d60e11b8152600481018690526001600160a01b0384169063a694fc3a906024015f604051808303815f87803b158015612b27575f80fd5b505af1158015612b39573d5f803e3d5ffd5b505050505050505050565b806001600160801b03165f03612b6d5760405163d11b25af60e01b815260040160405180910390fd5b612b78838383613ab5565b6040516001600160801b03821681526001600160a01b038316907f693ffe037fd29f4846b006bd3ada57d4fd4c3622277227342f0e4fed9011dc2090602001612706565b60208101515f906001600160401b0316612be364e8d4a51000612bde85613869565b613ff3565b610acd9190615bec565b5f814210612bfc57505f610acd565b5f83602001516001600160401b031642612c1691906159bd565b90505f81612c2386613869565b612c2d9190615929565b855190915064e8d4a5100090612c4c906001600160801b031683615929565b612c5691906159f8565b8551612c6b91906001600160801b03166159bd565b92505050610acd565b5f805f612c7f6127e2565b60048101549091505f906001600160a01b031630148015612d0b5750612ca3611675565b6040516370dee85360e11b81523360048201526001600160a01b03919091169063e1bdd0a690602401602060405180830381865afa158015612ce7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d0b9190615c27565b90505f81612d2e57612d29612d1e610b89565b879061ffff16614015565b612d30565b5f5b90505f612d406103cc83896159bd565b9791965090945050505050565b306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161480612dd357507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316612dc75f80516020615ed8833981519152546001600160a01b031690565b6001600160a01b031614155b156126605760405163703e46dd60e11b815260040160405180910390fd5b612df961258e565b50565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612e56575060408051601f3d908101601f19168201909252612e53918101906159a6565b60015b612e7e57604051634c9c8ce360e01b81526001600160a01b0383166004820152602401610ce2565b5f80516020615ed88339815191528114612eae57604051632a87526960e21b815260048101829052602401610ce2565b6125258383614025565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146126605760405163703e46dd60e11b815260040160405180910390fd5b612f096127e2565b60060154600160a01b90046001600160601b03164203612f2557565b5f612f2e6114c8565b90505f816001600160a01b03166312edb24c6040518163ffffffff1660e01b81526004015f60405180830381865afa158015612f6c573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612f939190810190615a7a565b90505f81516001600160401b03811115612faf57612faf61531e565b604051908082528060200260200182016040528015612fd8578160200160208202803683370190505b5090505f5b825181101561308f57828181518110612ff857612ff86159d0565b60209081029190910101516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613046573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061306a91906159a6565b82828151811061307c5761307c6159d0565b6020908102919091010152600101612fdd565b50826001600160a01b0316633d18b9126040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156130c8575f80fd5b505af11580156130da573d5f803e3d5ffd5b505050505f6130e7610bcd565b61ffff1690505f6130f66122c9565b90505f613101610fc6565b90505f61310c6124a5565b90505f5b86518110156132f0575f87828151811061312c5761312c6159d0565b60209081029190910101516040516370a0823160e01b81523060048201529091505f906001600160a01b038316906370a0823190602401602060405180830381865afa15801561317e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131a291906159a6565b90505f8884815181106131b7576131b76159d0565b6020026020010151826131ca91906159bd565b9050805f036131db575050506132e8565b6131e78387878461292b565b935090506131f4836133a8565b80156132125750866001600160a01b0316836001600160a01b031614155b80156132245750613222836134c3565b155b156132e4575f6127106132378a84615929565b61324191906159f8565b90505f61324e82846159bd565b9050613258610fab565b6001600160a01b0316856001600160a01b0316036132795761327981612a0b565b6132838582613345565b61328c8561407a565b81156132e15761329d6112b2610bab565b846001600160a01b03167f620154c7367c3805aa5a57be3421bcd8ae0de705b07bb7880c7ebdd1eff84237836040516132d891815260200190565b60405180910390a25b50505b5050505b600101613110565b50426132fa6127e2565b60060160146101000a8154816001600160601b0302191690836001600160601b0316021790555050505050505050565b5f5f195f61333785612188565b90506113cc33858784614092565b6001600160a01b0382165f9081525f80516020615eb8833981519152602052604081208054839290613378908490615bec565b90915550505050565b5f5f195f61338e85612031565b90506113cc33858388614092565b60605f610bf48361410f565b5f806133b2611675565b604051633e6ef28360e11b81526001600160a01b0385811660048301529192505f91831690637cdde5069060240160a060405180830381865afa1580156133fb573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061341f9190615c40565b505060405163771bc57760e01b81526001600160a01b0388811660048301529394505f938616925063771bc57791506024016040805180830381865afa15801561346b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061348f9190615cb5565b90506001600160a01b0382161515806134a9575080602001515b8061236f5750516001600160a01b03161515949350505050565b5f806134cd6127e2565b60048101549091506001600160a01b0384811691161480156134fc575060048101546001600160a01b03163014155b1561350957505f92915050565b613511611675565b6040516370dee85360e11b81526001600160a01b038581166004830152919091169063e1bdd0a690602401602060405180830381865afa158015613557573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bf49190615c27565b6001600160a01b0382165f9081525f80516020615eb88339815191526020526040812080548392906133789084906159bd565b612df981612a0b565b5f805f80516020615f3f833981519152816135d285886159bd565b90505f6135ec6135e36109db610fab565b8390895f61396c565b90505f835f0160079054906101000a90046001600160a01b03166001600160a01b031663b3f006746040518163ffffffff1660e01b8152600401602060405180830381865afa158015613641573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906136659190615a17565b90508615613677576136778188614168565b5093509150505b935093915050565b5f61368f6127e2565b60068101546003820154604051632e1a7d4d60e01b8152600481018690529293506001600160a01b0391821692911690632e1a7d4d906024015f604051808303815f87803b1580156136df575f80fd5b505af11580156136f1573d5f803e3d5ffd5b505050506001600160a01b038116156125255760405163040b850f60e31b8152306004820152602481018490526001600160a01b0382169063205c2878906044016020604051808303815f875af115801561374e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128509190615c27565b5f80516020615f1f8339815191526001600160a01b038681169085161461379e5761379e848784612806565b6137a8848361419c565b80546137be906001600160a01b031686856128b3565b836001600160a01b0316856001600160a01b0316876001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8686604051613816929190918252602082015260400190565b60405180910390a4505050505050565b5f610bf4613832612713565b61383d90600a61591b565b5f80516020615e98833981519152546138569190615bec565b61385e6109f4565b61250f906001615bec565b5f81604001516001600160401b03165f1461388857816040015161388f565b64174876e8005b6001600160401b031692915050565b5f6138aa82600a61591b565b6138b48486615929565b6113cc91906159f8565b6138c66141d0565b612df981614219565b6138d76141d0565b612df981614833565b6001600160a01b0381165f9081526001830160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b90049092169082015261394a8161394581612bbc565b612bed565b6001600160a01b0384165f908152602086905260409020546113cc91906159bd565b5f80613979868686612739565b9050600183600281111561398f5761398f615d11565b1480156139ab57505f84806139a6576139a66159e4565b868809115b1561236f576139bb600182615bec565b9695505050505050565b5f80516020615e788339815191526001600160a01b0385166139fc5760405163e602df0560e01b81525f6004820152602401610ce2565b6001600160a01b038416613a2557604051634a1406b160e11b81525f6004820152602401610ce2565b6001600160a01b038086165f90815260018301602090815260408083209388168352929052208390558115613aa257836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92585604051613a9991815260200190565b60405180910390a35b5050505050565b5f610acd826001613826565b6001600160a01b0382165f9081526001840160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b90049092169082015290613b1782612bbc565b90505f613b40846001600160801b0316613b318585612bed565b613b3b9190615bec565b61486e565b6001600160801b03811684529050613b57426148da565b6001600160401b03166020808501919091526001600160a01b0386165f908152908790526040812080546001600160801b0387169290613b98908490615bec565b909155505050506001600160a01b03929092165f9081526001939093016020908152604093849020835181549285015194909501516001600160801b039095166001600160c01b031990921691909117600160801b6001600160401b0394851602176001600160c01b0316600160c01b939094169290920292909217905550565b5f80516020615e788339815191526001600160a01b038416613c535781816002015f828254613c489190615bec565b90915550613cb09050565b6001600160a01b0384165f9081526020829052604090205482811015613c925784818460405163391434e360e21b8152600401610ce293929190615ba2565b6001600160a01b0385165f9081526020839052604090209083900390555b6001600160a01b038316613cce576002810180548390039055613cec565b6001600160a01b0383165f9081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051613d3191815260200190565b60405180910390a350505050565b5f613d93826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166149419092919063ffffffff16565b8051909150156125255780806020019051810190613db19190615c27565b6125255760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610ce2565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301525f91839186169063dd62ed3e90604401602060405180830381865afa158015613e5e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613e8291906159a6565b613e8c9190615bec565b6040516001600160a01b03851660248201526044810182905290915061285090859063095ea7b360e01b906064016128df565b6001600160a01b0381165f9081526001830160205260408120541515610bf4565b801580613f585750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015613f32573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613f5691906159a6565b155b613fc35760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610ce2565b6040516001600160a01b03831660248201526044810182905261252590849063095ea7b360e01b906064016128df565b5f8160016140018286615bec565b61400b91906159bd565b610bf491906159f8565b5f610bf48383612710600161396c565b61402e8261494f565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2805115614072576125258282614998565b610b1d6149bd565b5f6140836127e2565b905061252560018201836149dc565b5f80516020615f1f83398151915280546140b7906001600160a01b03168630866149f0565b6140c18483614168565b836001600160a01b0316856001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78585604051613a99929190918252602082015260400190565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561415c57602002820191905f5260205f20905b815481526020019060010190808311614148575b50505050509050919050565b6001600160a01b0382166141915760405163ec442f0560e01b81525f6004820152602401610ce2565b610b1d5f8383613c19565b6001600160a01b0382166141c557604051634b637e8f60e11b81525f6004820152602401610ce2565b610b1d825f83613c19565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661266057604051631afcd79f60e31b815260040160405180910390fd5b6142216141d0565b5f61422a6127e2565b90505f61423d60a08401608085016152d9565b6001600160a01b0316148061426957505f61425e60c0840160a085016152d9565b6001600160a01b0316145b8061428b57505f61428060e0840160c085016152d9565b6001600160a01b0316145b156142cf5760405162461bcd60e51b8152602060048201526014602482015273436f6c6c5661756c743a2030206164647265737360601b6044820152606401610ce2565b5f6142da8380615d25565b6142eb9060a08101906080016152d9565b90506142fd6060840160408501615303565b61ffff166143116040850160208601615303565b61ffff161115801561433857506127106143316060850160408601615303565b61ffff1611155b6143995760405162461bcd60e51b815260206004820152602c60248201527f436f6c6c5661756c743a20496e636f7272656374206d696e2f6d61782070657260448201526b666f726d616e63652066656560a01b6064820152608401610ce2565b6143a96040840160208501615303565b61ffff166143bd6080850160608601615303565b61ffff16101580156143f557506143da6060840160408501615303565b61ffff166143ee6080850160608601615303565b61ffff1611155b6144115760405162461bcd60e51b8152600401610ce290615a32565b5f80614424610100860160e087016152d9565b6001600160a01b0316141590505f61444260c0860160a087016152d9565b6001600160a01b03166372f702f36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561447d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906144a19190615a17565b9050816144c257826001600160a01b0316816001600160a01b0316146144e8565b6144d3610100860160e087016152d9565b6001600160a01b0316816001600160a01b0316145b6145345760405162461bcd60e51b815260206004820181905260248201527f436f6c6c5661756c743a207374616b696e67546f6b656e206d69736d617463686044820152606401610ce2565b8115806145b857503061454e610100870160e088016152d9565b6001600160a01b031663ac22c86d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614589573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906145ad9190615a17565b6001600160a01b0316145b6146105760405162461bcd60e51b815260206004820152602360248201527f436f6c6c5661756c743a20496e66726172656457726170706572206d69736d616044820152620e8c6d60eb1b6064820152608401610ce2565b6146206040860160208701615303565b845461ffff191661ffff919091161784556146416060860160408701615303565b845461ffff91909116620100000263ffff00001990911617845561466b6080860160608701615303565b845461ffff919091166401000000000265ffff000000001990911617845561469960a08601608087016152d9565b84546001600160a01b0391909116600160301b026601000000000000600160d01b03199091161784556146d260c0860160a087016152d9565b6003850180546001600160a01b0319166001600160a01b039290921691909117905561470460e0860160c087016152d9565b6004850180546001600160a01b0319166001600160a01b0392909216919091179055614737610100860160e087016152d9565b6006850180546001600160a01b0319166001600160a01b039290921691909117905561476b6147668680615d25565b614a28565b61477b60e0860160c087016152d9565b6001600160a01b0316306001600160a01b031614614807576147a360e0860160c087016152d9565b6001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156147de573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906148029190615a17565b614809565b825b60059490940180546001600160a01b0319166001600160a01b039095169490941790935550505050565b61483b6141d0565b61484860208201826152d9565b7f11107a1f81311054281ce199600e6bde1fc6abe70b0d42e6392b22b9c1234700611563565b5f6001600160801b038211156148d65760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608401610ce2565b5090565b5f6001600160401b038211156148d65760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203660448201526534206269747360d01b6064820152608401610ce2565b60606113cc84845f85614a39565b806001600160a01b03163b5f0361498457604051634c9c8ce360e01b81526001600160a01b0382166004820152602401610ce2565b805f80516020615ed8833981519152611563565b6060610bf48383604051806060016040528060278152602001615ef860279139614b10565b34156126605760405163b398979f60e01b815260040160405180910390fd5b5f610bf4836001600160a01b038416614b7a565b6040516001600160a01b03808516602483015283166044820152606481018290526128509085906323b872dd60e01b906084016128df565b614a306141d0565b612df981614bc6565b606082471015614a9a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610ce2565b5f80866001600160a01b03168587604051614ab59190615d43565b5f6040518083038185875af1925050503d805f8114614aef576040519150601f19603f3d011682016040523d82523d5f602084013e614af4565b606091505b5091509150614b0587838387614f64565b979650505050505050565b60605f80856001600160a01b031685604051614b2c9190615d43565b5f60405180830381855af49150503d805f8114614b64576040519150601f19603f3d011682016040523d82523d5f602084013e614b69565b606091505b50915091506139bb86838387614f64565b5f818152600183016020526040812054614bbf57508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610acd565b505f610acd565b614bce6141d0565b5f80516020615f3f8339815191525f614bed60808401606085016152d9565b6001600160a01b03161480614c1957505f614c0e60a08401608085016152d9565b6001600160a01b0316145b15614c5d5760405162461bcd60e51b8152602060048201526014602482015273436f6c6c5661756c743a2030206164647265737360601b6044820152606401610ce2565b614c80614c7060808401606085016152d9565b610b1d60a08501608086016152d9565b614c8d6020830183615303565b61ffff16614ca16060840160408501615303565b61ffff1610158015614cd95750614cbe6040830160208401615303565b61ffff16614cd26060840160408501615303565b61ffff1611155b614d335760405162461bcd60e51b815260206004820152602560248201527f436f6c6c5661756c743a20776974686472617720666565206f7574206f6620626044820152646f756e647360d81b6064820152608401610ce2565b614d406020830183615303565b815461ffff191661ffff91909116178155614d616040830160208401615303565b815461ffff91909116620100000263ffff000019909116178155614d8b6060830160408401615303565b815461ffff919091166401000000000265ffff00000000199091161781555f614dba60a08401608085016152d9565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614df5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614e199190615bd3565b905060128160ff161115614e6f5760405162461bcd60e51b815260206004820152601e60248201527f436f6c6c5661756c743a20617373657420646563696d616c73203e20313800006044820152606401610ce2565b815466ff0000000000001916600160301b60ff831602178255614e9860808401606085016152d9565b82546001600160a01b0391909116600160381b02670100000000000000600160d81b0319909116178255614f4c614ed260a0850185615b09565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250614f139250505060c0860186615b09565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250614fdc92505050565b612525614f5f60a08501608086016152d9565b614fee565b60608315614fd25782515f03614fcb576001600160a01b0385163b614fcb5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610ce2565b50816113cc565b6113cc8383614fff565b614fe46141d0565b610b1d8282615029565b614ff66141d0565b612df981615079565b81511561500f5781518083602001fd5b8060405162461bcd60e51b8152600401610ce291906151bf565b6150316141d0565b5f80516020615e788339815191527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0361506a8482615d9d565b50600481016128508382615d9d565b6150816141d0565b5f80516020615f1f8339815191525f8061509a846150e9565b91509150816150aa5760126150ac565b805b83546001600160a81b031916600160a01b60ff92909216919091026001600160a01b031916176001600160a01b0394909416939093179091555050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290515f918291829182916001600160a01b0387169161512f91615d43565b5f60405180830381855afa9150503d805f8114615167576040519150601f19603f3d011682016040523d82523d5f602084013e61516c565b606091505b509150915081801561518057506020815110155b156151b3575f8180602001905181019061519a91906159a6565b905060ff81116151b1576001969095509350505050565b505b505f9485945092505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f60208284031215615204575f80fd5b5035919050565b6001600160a01b0381168114612df9575f80fd5b803561522a8161520b565b919050565b5f8060408385031215615240575f80fd5b823561524b8161520b565b946020939093013593505050565b5f806040838503121561526a575f80fd5b82356152758161520b565b915060208301356001600160401b0381168114615290575f80fd5b809150509250929050565b5f805f606084860312156152ad575f80fd5b83356152b88161520b565b925060208401356152c88161520b565b929592945050506040919091013590565b5f602082840312156152e9575f80fd5b8135610bf48161520b565b61ffff81168114612df9575f80fd5b5f60208284031215615313575f80fd5b8135610bf4816152f4565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b038111828210171561535a5761535a61531e565b604052919050565b5f6001600160401b0382111561537a5761537a61531e565b5060051b60200190565b5f82601f830112615393575f80fd5b81356153a66153a182615362565b615332565b8082825260208201915060208360051b8601019250858311156153c7575f80fd5b602085015b838110156153ed5780356153df8161520b565b8352602092830192016153cc565b5095945050505050565b5f805f60608486031215615409575f80fd5b83356001600160401b0381111561541e575f80fd5b61542a86828701615384565b93505060208401356001600160401b03811115615445575f80fd5b8401601f81018613615455575f80fd5b80356154636153a182615362565b8082825260208201915060208360051b850101925088831115615484575f80fd5b6020840193505b828410156154a657833582526020938401939091019061548b565b94506154b8925050506040850161521f565b90509250925092565b5f80604083850312156154d2575f80fd5b82356001600160401b038111156154e7575f80fd5b6154f385828601615384565b92505060208301356001600160401b0381111561550e575f80fd5b8301601f8101851361551e575f80fd5b803561552c6153a182615362565b8082825260208201915060208360051b85010192508783111561554d575f80fd5b6020840193505b828410156155835783356001600160801b0381168114615572575f80fd5b825260209384019390910190615554565b809450505050509250929050565b5f80604083850312156155a2575f80fd5b82356155ad8161520b565b915060208301356001600160401b038111156155c7575f80fd5b8301601f810185136155d7575f80fd5b80356001600160401b038111156155f0576155f061531e565b615603601f8201601f1916602001615332565b818152866020838501011115615617575f80fd5b816020840160208301375f602083830101528093505050509250929050565b5f8060408385031215615647575f80fd5b8235915060208301356152908161520b565b5f8151808452602084019350602083015f5b828110156156925781516001600160a01b031686526020958601959091019060010161566b565b5093949350505050565b602081525f610bf46020830184615659565b604081525f6156c06040830185615659565b82810360208401528084518083526020830191506020860192505f5b818110156156fa5783518352602093840193909201916001016156dc565b50909695505050505050565b5f60208284031215615716575f80fd5b81356001600160401b0381111561572b575f80fd5b820160808185031215610bf4575f80fd5b5f805f6060848603121561574e575f80fd5b8335925060208401356157608161520b565b915060408401356157708161520b565b809150509250925092565b5f806040838503121561578c575f80fd5b82356157978161520b565b915060208301356152908161520b565b5f8082840360408112156157b9575f80fd5b60208112156157c6575f80fd5b5082915060208301356001600160401b038111156157e2575f80fd5b83016101008186031215615290575f80fd5b600181811c9082168061580857607f821691505b60208210810361582657634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b6001815b600184111561367e5780850481111561585f5761585f61582c565b600184161561586d57908102905b60019390931c928002615844565b5f8261588957506001610acd565b8161589557505f610acd565b81600181146158ab57600281146158b5576158d1565b6001915050610acd565b60ff8411156158c6576158c661582c565b50506001821b610acd565b5060208310610133831016604e8410600b84101617156158f4575081810a610acd565b6159005f198484615840565b805f19048211156159135761591361582c565b029392505050565b5f610bf460ff84168361587b565b8082028115828204841417610acd57610acd61582c565b60ff8181168382160190811115610acd57610acd61582c565b6020808252602d908201527f436f6c6c5661756c743a20746f6b656e7320616e6420616d6f756e7473206c6560408201526c0dccee8d040dad2e6dac2e8c6d609b1b606082015260800190565b5f602082840312156159b6575f80fd5b5051919050565b81810381811115610acd57610acd61582c565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601260045260245ffd5b5f82615a1257634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215615a27575f80fd5b8151610bf48161520b565b60208082526028908201527f436f6c6c5661756c743a20706572666f726d616e636520666565206f7574206f6040820152676620626f756e647360c01b606082015260800190565b5f60208284031215615a8a575f80fd5b81516001600160401b03811115615a9f575f80fd5b8201601f81018413615aaf575f80fd5b8051615abd6153a182615362565b8082825260208201915060208360051b850101925086831115615ade575f80fd5b6020840193505b828410156139bb578351615af88161520b565b825260209384019390910190615ae5565b5f808335601e19843603018112615b1e575f80fd5b8301803591506001600160401b03821115615b37575f80fd5b602001915036819003821315615b4b575f80fd5b9250929050565b6001600160a01b03868116825260208201869052841660408201526080606082018190528101829052818360a08301375f81830160a090810191909152601f909201601f19160101949350505050565b6001600160a01b039390931683526020830191909152604082015260600190565b805160ff8116811461522a575f80fd5b5f60208284031215615be3575f80fd5b610bf482615bc3565b80820180821115610acd57610acd61582c565b60ff8281168282160390811115610acd57610acd61582c565b8051801515811461522a575f80fd5b5f60208284031215615c37575f80fd5b610bf482615c18565b5f805f805f60a08688031215615c54575f80fd5b8551615c5f8161520b565b9450615c6d60208701615bc3565b9350604086015163ffffffff81168114615c85575f80fd5b6060870151909350615c96816152f4565b6080870151909250615ca78161520b565b809150509295509295909350565b5f6040828403128015615cc6575f80fd5b50604080519081016001600160401b0381118282101715615ce957615ce961531e565b6040528251615cf78161520b565b8152615d0560208401615c18565b60208201529392505050565b634e487b7160e01b5f52602160045260245ffd5b5f823560de19833603018112615d39575f80fd5b9190910192915050565b5f82518060208501845e5f920191825250919050565b601f82111561252557805f5260205f20601f840160051c81016020851015615d7e5750805b601f840160051c820191505b81811015613aa2575f8155600101615d8a565b81516001600160401b03811115615db657615db661531e565b615dca81615dc484546157f4565b84615d59565b6020601f821160018114615dfc575f8315615de55750848201515b5f19600385901b1c1916600184901b178455613aa2565b5f84815260208120601f198516915b82811015615e2b5787850151825560209485019460019092019101615e0b565b5084821015615e4857868401515f19600387901b60f8161c191681555b50505050600190811b0190555056fe19001df2d131e9aa1479f4ce661ae121445caf0662dea1e41907028a6da6fe0252c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0219001df2d131e9aa1479f4ce661ae121445caf0662dea1e41907028a6da6fe01360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c65640773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e0019001df2d131e9aa1479f4ce661ae121445caf0662dea1e41907028a6da6fe00a2646970667358221220b9c080a4633dce0eccda1b7515168e926ddb08f485f341def0cb19e0b3f0802d64736f6c634300081a0033

Deployed Bytecode

0x608060405260043610610366575f3560e01c806370a08231116101c8578063ba087652116100fd578063d9c001971161009d578063ef8b30f71161006d578063ef8b30f7146108b5578063f57d959c146109a2578063f8b2cb4f146109c1578063fd64c377146109e0575f80fd5b8063d9c0019714610931578063dd62ed3e14610950578063e993e7ed1461096f578063ec05c34114610983575f80fd5b8063c6e6f592116100d8578063c6e6f592146108b5578063ce96cb77146108d4578063d5c16d79146108f3578063d905777e14610912575f80fd5b8063ba0876521461086c578063c2d416011461088b578063c63d75b6146105c4575f80fd5b8063aa290e6d11610168578063b009c92c11610143578063b009c92c146107ed578063b2c06ba01461080f578063b3d7f6b91461082e578063b460af941461084d575f80fd5b8063aa290e6d1461077d578063aaffe0761461079c578063ad3cb1cc146107bd575f80fd5b806395d89b41116101a357806395d89b41146107175780639a400b0f1461072b5780639e87a5cd1461074a578063a9059cbb1461075e575f80fd5b806370a08231146106ba578063748747e6146106d957806394bf804d146106f8575f80fd5b8063322ce8f01161029e57806341519a651161023e5780634f1ef286116102195780634f1ef2861461066057806352d1902d146106735780636ab3b0e5146106875780636e553f651461069b575f80fd5b806341519a651461060357806341976e09146106225780634cdad50614610641575f80fd5b80633dafa4f3116102795780633dafa4f3146105915780633e92f95b146105a5578063402d267d146105c4578063403dd3bc146105e4575f80fd5b8063322ce8f01461053f57806332e1fef21461055e57806338d52e0f1461057d575f80fd5b80631540aa8911610309578063235c3603116102e4578063235c3603146104c757806323b872dd146104db57806329d78c88146104fa578063313ce56714610519575f80fd5b80631540aa891461045457806318160ddd1461047b578063221085d71461049b575f80fd5b8063095ea7b311610344578063095ea7b3146103d15780630a28a477146104005780630b983a741461041f5780630fdb11cf14610440575f80fd5b806301e1d1141461036a57806306fdde031461039157806307a2d13a146103b2575b5f80fd5b348015610375575f80fd5b5061037e6109f4565b6040519081526020015b60405180910390f35b34801561039c575f80fd5b506103a5610a02565b60405161038891906151bf565b3480156103bd575f80fd5b5061037e6103cc3660046151f4565b610ac2565b3480156103dc575f80fd5b506103f06103eb36600461522f565b610ad3565b6040519015158152602001610388565b34801561040b575f80fd5b5061037e61041a3660046151f4565b610aea565b34801561042a575f80fd5b5061043e610439366004615259565b610afd565b005b34801561044b575f80fd5b5061037e610b21565b34801561045f575f80fd5b50610468610b89565b60405161ffff9091168152602001610388565b348015610486575f80fd5b505f80516020615e988339815191525461037e565b3480156104a6575f80fd5b506104af610bab565b6040516001600160a01b039091168152602001610388565b3480156104d2575f80fd5b50610468610bcd565b3480156104e6575f80fd5b506103f06104f536600461529b565b610bd6565b348015610505575f80fd5b5061037e6105143660046152d9565b610bfb565b348015610524575f80fd5b5061052d610c21565b60405160ff9091168152602001610388565b34801561054a575f80fd5b5061043e610559366004615303565b610c4e565b348015610569575f80fd5b5061043e6105783660046153f7565b610d0d565b348015610588575f80fd5b506104af610fab565b34801561059c575f80fd5b506104af610fc6565b3480156105b0575f80fd5b5061043e6105bf3660046154c1565b610fe1565b3480156105cf575f80fd5b5061037e6105de3660046152d9565b505f1990565b3480156105ef575f80fd5b5061037e6105fe3660046152d9565b611354565b34801561060e575f80fd5b5061043e61061d3660046152d9565b6113d4565b34801561062d575f80fd5b5061037e61063c3660046152d9565b611414565b34801561064c575f80fd5b5061037e61065b3660046151f4565b611487565b61043e61066e366004615591565b611492565b34801561067e575f80fd5b5061037e6114ad565b348015610692575f80fd5b506104af6114c8565b3480156106a6575f80fd5b5061037e6106b5366004615636565b6114e3565b3480156106c5575f80fd5b5061037e6106d43660046152d9565b611512565b3480156106e4575f80fd5b5061043e6106f33660046152d9565b611538565b348015610703575f80fd5b5061037e610712366004615636565b611584565b348015610722575f80fd5b506103a56115b3565b348015610736575f80fd5b5061043e61074536600461522f565b6115f1565b348015610755575f80fd5b506104af611675565b348015610769575f80fd5b506103f061077836600461522f565b6116f9565b348015610788575f80fd5b5061043e610797366004615303565b611706565b3480156107a7575f80fd5b506107b0611766565b604051610388919061569c565b3480156107c8575f80fd5b506103a5604051806040016040528060058152602001640352e302e360dc1b81525081565b3480156107f8575f80fd5b5061080161177b565b6040516103889291906156ae565b34801561081a575f80fd5b5061043e610829366004615706565b611a71565b348015610839575f80fd5b5061037e6108483660046151f4565b612031565b348015610858575f80fd5b5061037e61086736600461573c565b61203d565b348015610877575f80fd5b5061037e61088636600461573c565b6120eb565b348015610896575f80fd5b505f80516020615f3f83398151915254600160301b900460ff1661052d565b3480156108c0575f80fd5b5061037e6108cf3660046151f4565b612188565b3480156108df575f80fd5b5061037e6108ee3660046152d9565b612193565b3480156108fe575f80fd5b5061037e61090d3660046152d9565b6121a0565b34801561091d575f80fd5b5061037e61092c3660046152d9565b61220b565b34801561093c575f80fd5b5061037e61094b3660046152d9565b612215565b34801561095b575f80fd5b5061037e61096a36600461577b565b612280565b34801561097a575f80fd5b506104af6122c9565b34801561098e575f80fd5b5061037e61099d3660046152d9565b6122e8565b3480156109ad575f80fd5b5061043e6109bc3660046157a7565b612378565b3480156109cc575f80fd5b5061037e6109db3660046152d9565b61248d565b3480156109eb575f80fd5b506104af6124a5565b5f6109fd6124c0565b905090565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0380546060915f80516020615e7883398151915291610a40906157f4565b80601f0160208091040260200160405190810160405280929190818152602001828054610a6c906157f4565b8015610ab75780601f10610a8e57610100808354040283529160200191610ab7565b820191905f5260205f20905b815481529060010190602001808311610a9a57829003601f168201915b505050505091505090565b5f610acd825f6124cc565b92915050565b5f33610ae0818585612518565b5060019392505050565b5f80610af58361252a565b509392505050565b610b0561258e565b610b1d5f80516020615eb88339815191528383612662565b5050565b5f80610b385f80516020615e988339815191525490565b9050805f03610b48575f91505090565b610b83610b5661063c610fab565b82610b5f612713565b610b6a90600a61591b565b610b726109f4565b610b7c9190615929565b9190612739565b91505090565b5f5f80516020615f3f8339815191525b54640100000000900461ffff16919050565b5f80516020615f3f83398151915254600160381b90046001600160a01b031690565b5f610b996127e2565b5f33610be3858285612806565b610bee858585612856565b60019150505b9392505050565b6001600160a01b03165f9081525f80516020615eb8833981519152602052604090205490565b5f5f80516020615f1f833981519152610c38612713565b8154610b839190600160a01b900460ff16615940565b610c5661258e565b5f80516020615f3f833981519152805461ffff90811690831610801590610c8c5750805461ffff62010000909104811690831611155b610ceb5760405162461bcd60e51b815260206004820152602560248201527f436f6c6c5661756c743a20576974686472617720666565206f7574206f6620626044820152646f756e647360d81b60648201526084015b60405180910390fd5b805461ffff9092166401000000000265ffff0000000019909216919091179055565b610d1561258e565b825182515f80516020615f3f83398151915291908114610d475760405162461bcd60e51b8152600401610ce290615959565b5f610d50610fab565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015610d94573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610db891906159a6565b90505f6001840181610dc8610fab565b6001600160a01b03166001600160a01b031681526020019081526020015f2054905080821115610e1857610e1885610e0083856159bd565b610e08610fab565b6001600160a01b031691906128b3565b5f5b83811015610fa157610e2a610fab565b6001600160a01b0316888281518110610e4557610e456159d0565b60200260200101516001600160a01b03160315610f99575f888281518110610e6f57610e6f6159d0565b60209081029190910101516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610ebd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ee191906159a6565b90505f866001015f015f8b8581518110610efd57610efd6159d0565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205490505f610f568a8581518110610f3d57610f3d6159d0565b60200260200101518385610f5191906159bd565b612916565b90508015610f9557610f9589828d8781518110610f7557610f756159d0565b60200260200101516001600160a01b03166128b39092919063ffffffff16565b5050505b600101610e1a565b5050505050505050565b5f80516020615f1f833981519152546001600160a01b031690565b5f610fcf6127e2565b600501546001600160a01b0316919050565b610fe961258e565b81518151811461100b5760405162461bcd60e51b8152600401610ce290615959565b5f611014610fc6565b90505f61101f6124a5565b90505f61102a610bcd565b61ffff1690505f5b8481101561134b575f87828151811061104d5761104d6159d0565b602002602001015190505f87838151811061106a5761106a6159d0565b60200260200101516001600160801b03169050805f0361108b575050611343565b5f611094610fab565b6001600160a01b0316836001600160a01b031603611121576110b4610fab565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156110f8573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061111c91906159a6565b61119a565b61112a83610bfb565b6040516370a0823160e01b81523060048201526001600160a01b038516906370a0823190602401602060405180830381865afa15801561116c573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061119091906159a6565b61119a91906159bd565b9050818110156111ec5760405162461bcd60e51b815260206004820152601f60248201527f436f6c6c5661756c743a20696e73756666696369656e742062616c616e6365006044820152606401610ce2565b6111f88388888561292b565b93509150611205836129f5565b6112515760405162461bcd60e51b815260206004820152601d60248201527f436f6c6c5661756c743a20746f6b656e206e6f742072657761726465640000006044820152606401610ce2565b5f61271061125f8785615929565b61126991906159f8565b90505f61127682856159bd565b9050611280610fab565b6001600160a01b0316856001600160a01b0316036112a1576112a181612a0b565b8115611322576113226112b2610bab565b6001600160a01b031663b3f006746040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112ed573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113119190615a17565b6001600160a01b03871690846128b3565b61133d85825f80516020615eb88339815191525b9190612b44565b50505050505b600101611032565b50505050505050565b6001600160a01b0381165f9081525f80516020615e5883398151915260209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b900490921690820152816113c082612bbc565b90506113cc8282612bed565b949350505050565b6113dc61258e565b806113e56127e2565b80546001600160a01b0392909216600160301b026601000000000000600160d01b031990921691909117905550565b5f61141d611675565b604051635670bcc760e11b81526001600160a01b038481166004830152919091169063ace1798e90602401602060405180830381865afa158015611463573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610acd91906159a6565b5f80610af583612c74565b61149a612d4d565b6114a382612df1565b610b1d8282612dfc565b5f6114b6612eb8565b505f80516020615ed883398151915290565b5f6114d16127e2565b600301546001600160a01b0316919050565b5f6114ec612f01565b6114f6838361332a565b905061150183612a0b565b610acd61150c610fab565b84613345565b6001600160a01b03165f9081525f80516020615e78833981519152602052604090205490565b61154061258e565b807f11107a1f81311054281ce199600e6bde1fc6abe70b0d42e6392b22b9c12347005b80546001600160a01b0319166001600160a01b039290921691909117905550565b5f61158d612f01565b6115978383613381565b90506115a281612a0b565b610acd6115ad610fab565b82613345565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0480546060915f80516020615e7883398151915291610a40906157f4565b6115f961258e565b5f6116026127e2565b90506127108211156116565760405162461bcd60e51b815260206004820152601960248201527f436f6c6c5661756c743a207468726573686f6c64203e204250000000000000006044820152606401610ce2565b6001600160a01b039092165f9081526007909201602052604090912055565b5f5f80516020615f3f8339815191525f0160079054906101000a90046001600160a01b03166001600160a01b031663741bef1a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116d5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109fd9190615a17565b5f33610ae0818585612856565b61170e61258e565b611716612f01565b5f61171f6127e2565b805490915061ffff9081169083161080159061174a5750805461ffff62010000909104811690831611155b610ceb5760405162461bcd60e51b8152600401610ce290615a32565b60606109fd6117736127e2565b60010161339c565b6060805f6117876114c8565b9050806001600160a01b03166312edb24c6040518163ffffffff1660e01b81526004015f60405180830381865afa1580156117c4573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526117eb9190810190615a7a565b925082516001600160401b038111156118065761180661531e565b60405190808252806020026020018201604052801561182f578160200160208202803683370190505b5091505f61183b610bcd565b61ffff1690505f61184a6122c9565b90505f611855610fc6565b90505f6118606124a5565b90505f5b8751811015611a67575f888281518110611880576118806159d0565b602002602001015190505f876001600160a01b031663211dc32d308c86815181106118ad576118ad6159d0565b60200260200101516040518363ffffffff1660e01b81526004016118e79291906001600160a01b0392831681529116602082015260400190565b602060405180830381865afa158015611902573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061192691906159a6565b9050805f03611936575050611a5f565b6001600160a01b03828116908616148080156119565750611956866133a8565b156119d45760405163ef8b30f760e01b8152600481018390526001600160a01b0386169063ef8b30f790602401602060405180830381865afa15801561199e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119c291906159a6565b9150806119cf57826119d1565b845b92505b6119dd836133a8565b80156119fb5750866001600160a01b0316836001600160a01b031614155b8015611a0d5750611a0b836134c3565b155b15611a5b575f612710611a208a85615929565b611a2a91906159f8565b90505f611a3782856159bd565b9050808c8781518110611a4c57611a4c6159d0565b60200260200101818152505050505b5050505b600101611864565b5050505050509091565b337f11107a1f81311054281ce199600e6bde1fc6abe70b0d42e6392b22b9c1234700546001600160a01b03161480611b17575033611aad610bab565b6001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae8573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b0c9190615a17565b6001600160a01b0316145b611b895760405162461bcd60e51b815260206004820152603b60248201527f4d61696e4173736574436f6d706f756e64696e67496e667261726564436f6c6c60448201527f5661756c743a204e6f74206f776e6572206e6f72206b656570657200000000006064820152608401610ce2565b611b91612f01565b611b99610fab565b6001600160a01b0316611baf60208301836152d9565b6001600160a01b031603611c055760405162461bcd60e51b815260206004820152601e60248201527f436f6c6c5661756c743a2061737365742063616e27742062652073656e7400006044820152606401610ce2565b5f611c1360208301836152d9565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611c57573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c7b91906159a6565b90505f611c86610fab565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611cca573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cee91906159a6565b9050611d14611d0360608501604086016152d9565b60208501803590610e0890876152d9565b611d2460608401604085016152d9565b6001600160a01b0316637f0f41d7611d3f60208601866152d9565b8560200135611d4c610fab565b611d596060890189615b09565b6040518663ffffffff1660e01b8152600401611d79959493929190615b52565b5f604051808303815f87803b158015611d90575f80fd5b505af1158015611da2573d5f803e3d5ffd5b505050505f81611db0610fab565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611df4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e1891906159a6565b611e2291906159bd565b90505f611e3260208601866152d9565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611e76573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e9a91906159a6565b611ea490856159bd565b9050611eb66109db60208701876152d9565b811115611ed657604051630301465d60e11b815260040160405180910390fd5b5f80516020615e588339815191525f611eed610fab565b6001600160a01b0316815260208101919091526040015f90812054600160c01b90046001600160401b03169003611f835760405162461bcd60e51b815260206004820152603460248201527f436f6c6c5661756c743a206173736574206e65656473206120646566696e6564604482015273081d5b9b1bd8dad4985d1954195c94d958dbdb9960621b6064820152608401610ce2565b611f99611f9360208701876152d9565b8261357b565b611fb8611fa4610fab565b835f80516020615eb8833981519152611336565b611fc1826135ae565b611fce60208601866152d9565b6001600160a01b03167f90fea00fe6e24ccfd7c40b40e07486e8b69ada2a3ad693dd908b6479cac36b6b82845f80604051612022949392919093845260208401929092526040830152606082015260800190565b60405180910390a25050505050565b5f610acd8260016124cc565b5f612046612f01565b5f61205c5f80516020615e988339815191525490565b90505f61206884612193565b90508086111561209157838682604051633fa733bb60e21b8152600401610ce293929190615ba2565b505f61209c8661252a565b90935090505f806120ae8585856135b7565b91509150815f146120d3576120c282613686565b6120d36120cd610fab565b8361357b565b6120e03388888589613772565b505050509392505050565b5f6120f4612f01565b5f61210a5f80516020615e988339815191525490565b90505f6121168461220b565b90508086111561213f57838682604051632e52afbb60e21b8152600401610ce293929190615ba2565b505f61214a86612c74565b90935090505f8061215c8885856135b7565b91509150815f1461217b5761217082613686565b61217b6120cd610fab565b6120e0338888858c613772565b5f610acd825f613826565b5f610acd61065b83611512565b6001600160a01b0381165f9081525f80516020615e5883398151915260209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b900490921690820152610bf481612bbc565b5f610acd82611512565b6001600160a01b0381165f9081525f80516020615e5883398151915260209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b900490921690820152610bf481613869565b6001600160a01b039182165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020908152604080832093909416825291909152205490565b5f6122d26127e2565b54600160301b90046001600160a01b0316919050565b5f806122f38361248d565b90505f6122ff84611414565b90505f846001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561233e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123629190615bd3565b905061236f83838361389e565b95945050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f811580156123bc5750825b90505f826001600160401b031660011480156123d75750303b155b9050811580156123e5575080155b156124035760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561242d57845460ff60401b1916600160401b1785555b612436866138be565b61243f876138cf565b831561134b57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a150505050505050565b5f610acd5f80516020615eb8833981519152836138e0565b5f6124ae6127e2565b600401546001600160a01b0316919050565b5f6109fd6109db610fab565b5f610bf46124d86109f4565b6124e3906001615bec565b6124eb612713565b6124f690600a61591b565b5f80516020615e988339815191525461250f9190615bec565b8591908561396c565b61252583838360016139c5565b505050565b5f805f80516020615f3f8339815191528161254485613aa9565b82549091505f90612573906127109061256990640100000000900461ffff16826159bd565b849190600161396c565b90505f61258083836159bd565b919791965090945050505050565b612596610bab565b6001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156125d1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125f59190615a17565b6001600160a01b0316336001600160a01b0316146126605760405162461bcd60e51b815260206004820152602260248201527f436f6c6c5661756c743a2063616c6c6572206973206e6f7420746865206f776e60448201526132b960f11b6064820152608401610ce2565b565b64e8d4a510006001600160401b0382161115612691576040516304bba2fb60e51b815260040160405180910390fd5b61269c83835f613ab5565b6001600160a01b0382165f81815260018501602090815260409182902080546001600160c01b0316600160c01b6001600160401b0387169081029190911790915591519182527f5577d4c8f6e5397effa5c71df8fe221e1162e18aaa0aabe87026cfb0c676215091015b60405180910390a2505050565b5f80516020615f3f833981519152545f90600160301b900460ff166109fd906012615bff565b5f80805f19858709858702925082811083820303915050805f0361277057838281612766576127666159e4565b0492505050610bf4565b80841161277b575f80fd5b5f8486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091025f889003889004909101858311909403939093029303949094049190911702949350505050565b7ff6a35052099d23fafed8c58b549933969c057c5a9a13ac5133024adc8dd4f20090565b5f6128118484612280565b90505f198114612850578181101561284257828183604051637dc7a0d960e11b8152600401610ce293929190615ba2565b61285084848484035f6139c5565b50505050565b6001600160a01b03831661287f57604051634b637e8f60e11b81525f6004820152602401610ce2565b6001600160a01b0382166128a85760405163ec442f0560e01b81525f6004820152602401610ce2565b612525838383613c19565b6040516001600160a01b03831660248201526044810182905261252590849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613d3f565b5f8183106129245781610bf4565b5090919050565b5f80806001600160a01b038781169087161480801561294e575061294e886133a8565b156129ea576129676001600160a01b0388168787613e10565b604051636e553f6560e01b8152600481018690523060248201526001600160a01b03871690636e553f65906044016020604051808303815f875af11580156129b1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129d591906159a6565b9150819450806129e557876129e7565b855b97505b509296945050505050565b5f610acd82612a026127e2565b60010190613ebf565b5f612a146127e2565b600381015460068201549192506001600160a01b0390811691165f8115612ac957612a528286612a42610fab565b6001600160a01b03169190613ee0565b6040516317a790f160e11b8152306004820152602481018690526001600160a01b03831690632f4f21e2906044016020604051808303815f875af1158015612a9c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ac09190615c27565b50819050612ad4565b612ad1610fab565b90505b612ae86001600160a01b0382168487613e10565b60405163534a7e1d60e11b8152600481018690526001600160a01b0384169063a694fc3a906024015f604051808303815f87803b158015612b27575f80fd5b505af1158015612b39573d5f803e3d5ffd5b505050505050505050565b806001600160801b03165f03612b6d5760405163d11b25af60e01b815260040160405180910390fd5b612b78838383613ab5565b6040516001600160801b03821681526001600160a01b038316907f693ffe037fd29f4846b006bd3ada57d4fd4c3622277227342f0e4fed9011dc2090602001612706565b60208101515f906001600160401b0316612be364e8d4a51000612bde85613869565b613ff3565b610acd9190615bec565b5f814210612bfc57505f610acd565b5f83602001516001600160401b031642612c1691906159bd565b90505f81612c2386613869565b612c2d9190615929565b855190915064e8d4a5100090612c4c906001600160801b031683615929565b612c5691906159f8565b8551612c6b91906001600160801b03166159bd565b92505050610acd565b5f805f612c7f6127e2565b60048101549091505f906001600160a01b031630148015612d0b5750612ca3611675565b6040516370dee85360e11b81523360048201526001600160a01b03919091169063e1bdd0a690602401602060405180830381865afa158015612ce7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d0b9190615c27565b90505f81612d2e57612d29612d1e610b89565b879061ffff16614015565b612d30565b5f5b90505f612d406103cc83896159bd565b9791965090945050505050565b306001600160a01b037f00000000000000000000000054a2538ca9670673073dc391a11297ecd05c50fa161480612dd357507f00000000000000000000000054a2538ca9670673073dc391a11297ecd05c50fa6001600160a01b0316612dc75f80516020615ed8833981519152546001600160a01b031690565b6001600160a01b031614155b156126605760405163703e46dd60e11b815260040160405180910390fd5b612df961258e565b50565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612e56575060408051601f3d908101601f19168201909252612e53918101906159a6565b60015b612e7e57604051634c9c8ce360e01b81526001600160a01b0383166004820152602401610ce2565b5f80516020615ed88339815191528114612eae57604051632a87526960e21b815260048101829052602401610ce2565b6125258383614025565b306001600160a01b037f00000000000000000000000054a2538ca9670673073dc391a11297ecd05c50fa16146126605760405163703e46dd60e11b815260040160405180910390fd5b612f096127e2565b60060154600160a01b90046001600160601b03164203612f2557565b5f612f2e6114c8565b90505f816001600160a01b03166312edb24c6040518163ffffffff1660e01b81526004015f60405180830381865afa158015612f6c573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612f939190810190615a7a565b90505f81516001600160401b03811115612faf57612faf61531e565b604051908082528060200260200182016040528015612fd8578160200160208202803683370190505b5090505f5b825181101561308f57828181518110612ff857612ff86159d0565b60209081029190910101516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613046573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061306a91906159a6565b82828151811061307c5761307c6159d0565b6020908102919091010152600101612fdd565b50826001600160a01b0316633d18b9126040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156130c8575f80fd5b505af11580156130da573d5f803e3d5ffd5b505050505f6130e7610bcd565b61ffff1690505f6130f66122c9565b90505f613101610fc6565b90505f61310c6124a5565b90505f5b86518110156132f0575f87828151811061312c5761312c6159d0565b60209081029190910101516040516370a0823160e01b81523060048201529091505f906001600160a01b038316906370a0823190602401602060405180830381865afa15801561317e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131a291906159a6565b90505f8884815181106131b7576131b76159d0565b6020026020010151826131ca91906159bd565b9050805f036131db575050506132e8565b6131e78387878461292b565b935090506131f4836133a8565b80156132125750866001600160a01b0316836001600160a01b031614155b80156132245750613222836134c3565b155b156132e4575f6127106132378a84615929565b61324191906159f8565b90505f61324e82846159bd565b9050613258610fab565b6001600160a01b0316856001600160a01b0316036132795761327981612a0b565b6132838582613345565b61328c8561407a565b81156132e15761329d6112b2610bab565b846001600160a01b03167f620154c7367c3805aa5a57be3421bcd8ae0de705b07bb7880c7ebdd1eff84237836040516132d891815260200190565b60405180910390a25b50505b5050505b600101613110565b50426132fa6127e2565b60060160146101000a8154816001600160601b0302191690836001600160601b0316021790555050505050505050565b5f5f195f61333785612188565b90506113cc33858784614092565b6001600160a01b0382165f9081525f80516020615eb8833981519152602052604081208054839290613378908490615bec565b90915550505050565b5f5f195f61338e85612031565b90506113cc33858388614092565b60605f610bf48361410f565b5f806133b2611675565b604051633e6ef28360e11b81526001600160a01b0385811660048301529192505f91831690637cdde5069060240160a060405180830381865afa1580156133fb573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061341f9190615c40565b505060405163771bc57760e01b81526001600160a01b0388811660048301529394505f938616925063771bc57791506024016040805180830381865afa15801561346b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061348f9190615cb5565b90506001600160a01b0382161515806134a9575080602001515b8061236f5750516001600160a01b03161515949350505050565b5f806134cd6127e2565b60048101549091506001600160a01b0384811691161480156134fc575060048101546001600160a01b03163014155b1561350957505f92915050565b613511611675565b6040516370dee85360e11b81526001600160a01b038581166004830152919091169063e1bdd0a690602401602060405180830381865afa158015613557573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bf49190615c27565b6001600160a01b0382165f9081525f80516020615eb88339815191526020526040812080548392906133789084906159bd565b612df981612a0b565b5f805f80516020615f3f833981519152816135d285886159bd565b90505f6135ec6135e36109db610fab565b8390895f61396c565b90505f835f0160079054906101000a90046001600160a01b03166001600160a01b031663b3f006746040518163ffffffff1660e01b8152600401602060405180830381865afa158015613641573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906136659190615a17565b90508615613677576136778188614168565b5093509150505b935093915050565b5f61368f6127e2565b60068101546003820154604051632e1a7d4d60e01b8152600481018690529293506001600160a01b0391821692911690632e1a7d4d906024015f604051808303815f87803b1580156136df575f80fd5b505af11580156136f1573d5f803e3d5ffd5b505050506001600160a01b038116156125255760405163040b850f60e31b8152306004820152602481018490526001600160a01b0382169063205c2878906044016020604051808303815f875af115801561374e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128509190615c27565b5f80516020615f1f8339815191526001600160a01b038681169085161461379e5761379e848784612806565b6137a8848361419c565b80546137be906001600160a01b031686856128b3565b836001600160a01b0316856001600160a01b0316876001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8686604051613816929190918252602082015260400190565b60405180910390a4505050505050565b5f610bf4613832612713565b61383d90600a61591b565b5f80516020615e98833981519152546138569190615bec565b61385e6109f4565b61250f906001615bec565b5f81604001516001600160401b03165f1461388857816040015161388f565b64174876e8005b6001600160401b031692915050565b5f6138aa82600a61591b565b6138b48486615929565b6113cc91906159f8565b6138c66141d0565b612df981614219565b6138d76141d0565b612df981614833565b6001600160a01b0381165f9081526001830160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b90049092169082015261394a8161394581612bbc565b612bed565b6001600160a01b0384165f908152602086905260409020546113cc91906159bd565b5f80613979868686612739565b9050600183600281111561398f5761398f615d11565b1480156139ab57505f84806139a6576139a66159e4565b868809115b1561236f576139bb600182615bec565b9695505050505050565b5f80516020615e788339815191526001600160a01b0385166139fc5760405163e602df0560e01b81525f6004820152602401610ce2565b6001600160a01b038416613a2557604051634a1406b160e11b81525f6004820152602401610ce2565b6001600160a01b038086165f90815260018301602090815260408083209388168352929052208390558115613aa257836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92585604051613a9991815260200190565b60405180910390a35b5050505050565b5f610acd826001613826565b6001600160a01b0382165f9081526001840160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b90049092169082015290613b1782612bbc565b90505f613b40846001600160801b0316613b318585612bed565b613b3b9190615bec565b61486e565b6001600160801b03811684529050613b57426148da565b6001600160401b03166020808501919091526001600160a01b0386165f908152908790526040812080546001600160801b0387169290613b98908490615bec565b909155505050506001600160a01b03929092165f9081526001939093016020908152604093849020835181549285015194909501516001600160801b039095166001600160c01b031990921691909117600160801b6001600160401b0394851602176001600160c01b0316600160c01b939094169290920292909217905550565b5f80516020615e788339815191526001600160a01b038416613c535781816002015f828254613c489190615bec565b90915550613cb09050565b6001600160a01b0384165f9081526020829052604090205482811015613c925784818460405163391434e360e21b8152600401610ce293929190615ba2565b6001600160a01b0385165f9081526020839052604090209083900390555b6001600160a01b038316613cce576002810180548390039055613cec565b6001600160a01b0383165f9081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051613d3191815260200190565b60405180910390a350505050565b5f613d93826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166149419092919063ffffffff16565b8051909150156125255780806020019051810190613db19190615c27565b6125255760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610ce2565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301525f91839186169063dd62ed3e90604401602060405180830381865afa158015613e5e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613e8291906159a6565b613e8c9190615bec565b6040516001600160a01b03851660248201526044810182905290915061285090859063095ea7b360e01b906064016128df565b6001600160a01b0381165f9081526001830160205260408120541515610bf4565b801580613f585750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015613f32573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613f5691906159a6565b155b613fc35760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610ce2565b6040516001600160a01b03831660248201526044810182905261252590849063095ea7b360e01b906064016128df565b5f8160016140018286615bec565b61400b91906159bd565b610bf491906159f8565b5f610bf48383612710600161396c565b61402e8261494f565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2805115614072576125258282614998565b610b1d6149bd565b5f6140836127e2565b905061252560018201836149dc565b5f80516020615f1f83398151915280546140b7906001600160a01b03168630866149f0565b6140c18483614168565b836001600160a01b0316856001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78585604051613a99929190918252602082015260400190565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561415c57602002820191905f5260205f20905b815481526020019060010190808311614148575b50505050509050919050565b6001600160a01b0382166141915760405163ec442f0560e01b81525f6004820152602401610ce2565b610b1d5f8383613c19565b6001600160a01b0382166141c557604051634b637e8f60e11b81525f6004820152602401610ce2565b610b1d825f83613c19565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661266057604051631afcd79f60e31b815260040160405180910390fd5b6142216141d0565b5f61422a6127e2565b90505f61423d60a08401608085016152d9565b6001600160a01b0316148061426957505f61425e60c0840160a085016152d9565b6001600160a01b0316145b8061428b57505f61428060e0840160c085016152d9565b6001600160a01b0316145b156142cf5760405162461bcd60e51b8152602060048201526014602482015273436f6c6c5661756c743a2030206164647265737360601b6044820152606401610ce2565b5f6142da8380615d25565b6142eb9060a08101906080016152d9565b90506142fd6060840160408501615303565b61ffff166143116040850160208601615303565b61ffff161115801561433857506127106143316060850160408601615303565b61ffff1611155b6143995760405162461bcd60e51b815260206004820152602c60248201527f436f6c6c5661756c743a20496e636f7272656374206d696e2f6d61782070657260448201526b666f726d616e63652066656560a01b6064820152608401610ce2565b6143a96040840160208501615303565b61ffff166143bd6080850160608601615303565b61ffff16101580156143f557506143da6060840160408501615303565b61ffff166143ee6080850160608601615303565b61ffff1611155b6144115760405162461bcd60e51b8152600401610ce290615a32565b5f80614424610100860160e087016152d9565b6001600160a01b0316141590505f61444260c0860160a087016152d9565b6001600160a01b03166372f702f36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561447d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906144a19190615a17565b9050816144c257826001600160a01b0316816001600160a01b0316146144e8565b6144d3610100860160e087016152d9565b6001600160a01b0316816001600160a01b0316145b6145345760405162461bcd60e51b815260206004820181905260248201527f436f6c6c5661756c743a207374616b696e67546f6b656e206d69736d617463686044820152606401610ce2565b8115806145b857503061454e610100870160e088016152d9565b6001600160a01b031663ac22c86d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614589573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906145ad9190615a17565b6001600160a01b0316145b6146105760405162461bcd60e51b815260206004820152602360248201527f436f6c6c5661756c743a20496e66726172656457726170706572206d69736d616044820152620e8c6d60eb1b6064820152608401610ce2565b6146206040860160208701615303565b845461ffff191661ffff919091161784556146416060860160408701615303565b845461ffff91909116620100000263ffff00001990911617845561466b6080860160608701615303565b845461ffff919091166401000000000265ffff000000001990911617845561469960a08601608087016152d9565b84546001600160a01b0391909116600160301b026601000000000000600160d01b03199091161784556146d260c0860160a087016152d9565b6003850180546001600160a01b0319166001600160a01b039290921691909117905561470460e0860160c087016152d9565b6004850180546001600160a01b0319166001600160a01b0392909216919091179055614737610100860160e087016152d9565b6006850180546001600160a01b0319166001600160a01b039290921691909117905561476b6147668680615d25565b614a28565b61477b60e0860160c087016152d9565b6001600160a01b0316306001600160a01b031614614807576147a360e0860160c087016152d9565b6001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156147de573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906148029190615a17565b614809565b825b60059490940180546001600160a01b0319166001600160a01b039095169490941790935550505050565b61483b6141d0565b61484860208201826152d9565b7f11107a1f81311054281ce199600e6bde1fc6abe70b0d42e6392b22b9c1234700611563565b5f6001600160801b038211156148d65760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608401610ce2565b5090565b5f6001600160401b038211156148d65760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203660448201526534206269747360d01b6064820152608401610ce2565b60606113cc84845f85614a39565b806001600160a01b03163b5f0361498457604051634c9c8ce360e01b81526001600160a01b0382166004820152602401610ce2565b805f80516020615ed8833981519152611563565b6060610bf48383604051806060016040528060278152602001615ef860279139614b10565b34156126605760405163b398979f60e01b815260040160405180910390fd5b5f610bf4836001600160a01b038416614b7a565b6040516001600160a01b03808516602483015283166044820152606481018290526128509085906323b872dd60e01b906084016128df565b614a306141d0565b612df981614bc6565b606082471015614a9a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610ce2565b5f80866001600160a01b03168587604051614ab59190615d43565b5f6040518083038185875af1925050503d805f8114614aef576040519150601f19603f3d011682016040523d82523d5f602084013e614af4565b606091505b5091509150614b0587838387614f64565b979650505050505050565b60605f80856001600160a01b031685604051614b2c9190615d43565b5f60405180830381855af49150503d805f8114614b64576040519150601f19603f3d011682016040523d82523d5f602084013e614b69565b606091505b50915091506139bb86838387614f64565b5f818152600183016020526040812054614bbf57508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610acd565b505f610acd565b614bce6141d0565b5f80516020615f3f8339815191525f614bed60808401606085016152d9565b6001600160a01b03161480614c1957505f614c0e60a08401608085016152d9565b6001600160a01b0316145b15614c5d5760405162461bcd60e51b8152602060048201526014602482015273436f6c6c5661756c743a2030206164647265737360601b6044820152606401610ce2565b614c80614c7060808401606085016152d9565b610b1d60a08501608086016152d9565b614c8d6020830183615303565b61ffff16614ca16060840160408501615303565b61ffff1610158015614cd95750614cbe6040830160208401615303565b61ffff16614cd26060840160408501615303565b61ffff1611155b614d335760405162461bcd60e51b815260206004820152602560248201527f436f6c6c5661756c743a20776974686472617720666565206f7574206f6620626044820152646f756e647360d81b6064820152608401610ce2565b614d406020830183615303565b815461ffff191661ffff91909116178155614d616040830160208401615303565b815461ffff91909116620100000263ffff000019909116178155614d8b6060830160408401615303565b815461ffff919091166401000000000265ffff00000000199091161781555f614dba60a08401608085016152d9565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614df5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614e199190615bd3565b905060128160ff161115614e6f5760405162461bcd60e51b815260206004820152601e60248201527f436f6c6c5661756c743a20617373657420646563696d616c73203e20313800006044820152606401610ce2565b815466ff0000000000001916600160301b60ff831602178255614e9860808401606085016152d9565b82546001600160a01b0391909116600160381b02670100000000000000600160d81b0319909116178255614f4c614ed260a0850185615b09565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250614f139250505060c0860186615b09565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250614fdc92505050565b612525614f5f60a08501608086016152d9565b614fee565b60608315614fd25782515f03614fcb576001600160a01b0385163b614fcb5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610ce2565b50816113cc565b6113cc8383614fff565b614fe46141d0565b610b1d8282615029565b614ff66141d0565b612df981615079565b81511561500f5781518083602001fd5b8060405162461bcd60e51b8152600401610ce291906151bf565b6150316141d0565b5f80516020615e788339815191527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0361506a8482615d9d565b50600481016128508382615d9d565b6150816141d0565b5f80516020615f1f8339815191525f8061509a846150e9565b91509150816150aa5760126150ac565b805b83546001600160a81b031916600160a01b60ff92909216919091026001600160a01b031916176001600160a01b0394909416939093179091555050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290515f918291829182916001600160a01b0387169161512f91615d43565b5f60405180830381855afa9150503d805f8114615167576040519150601f19603f3d011682016040523d82523d5f602084013e61516c565b606091505b509150915081801561518057506020815110155b156151b3575f8180602001905181019061519a91906159a6565b905060ff81116151b1576001969095509350505050565b505b505f9485945092505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f60208284031215615204575f80fd5b5035919050565b6001600160a01b0381168114612df9575f80fd5b803561522a8161520b565b919050565b5f8060408385031215615240575f80fd5b823561524b8161520b565b946020939093013593505050565b5f806040838503121561526a575f80fd5b82356152758161520b565b915060208301356001600160401b0381168114615290575f80fd5b809150509250929050565b5f805f606084860312156152ad575f80fd5b83356152b88161520b565b925060208401356152c88161520b565b929592945050506040919091013590565b5f602082840312156152e9575f80fd5b8135610bf48161520b565b61ffff81168114612df9575f80fd5b5f60208284031215615313575f80fd5b8135610bf4816152f4565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b038111828210171561535a5761535a61531e565b604052919050565b5f6001600160401b0382111561537a5761537a61531e565b5060051b60200190565b5f82601f830112615393575f80fd5b81356153a66153a182615362565b615332565b8082825260208201915060208360051b8601019250858311156153c7575f80fd5b602085015b838110156153ed5780356153df8161520b565b8352602092830192016153cc565b5095945050505050565b5f805f60608486031215615409575f80fd5b83356001600160401b0381111561541e575f80fd5b61542a86828701615384565b93505060208401356001600160401b03811115615445575f80fd5b8401601f81018613615455575f80fd5b80356154636153a182615362565b8082825260208201915060208360051b850101925088831115615484575f80fd5b6020840193505b828410156154a657833582526020938401939091019061548b565b94506154b8925050506040850161521f565b90509250925092565b5f80604083850312156154d2575f80fd5b82356001600160401b038111156154e7575f80fd5b6154f385828601615384565b92505060208301356001600160401b0381111561550e575f80fd5b8301601f8101851361551e575f80fd5b803561552c6153a182615362565b8082825260208201915060208360051b85010192508783111561554d575f80fd5b6020840193505b828410156155835783356001600160801b0381168114615572575f80fd5b825260209384019390910190615554565b809450505050509250929050565b5f80604083850312156155a2575f80fd5b82356155ad8161520b565b915060208301356001600160401b038111156155c7575f80fd5b8301601f810185136155d7575f80fd5b80356001600160401b038111156155f0576155f061531e565b615603601f8201601f1916602001615332565b818152866020838501011115615617575f80fd5b816020840160208301375f602083830101528093505050509250929050565b5f8060408385031215615647575f80fd5b8235915060208301356152908161520b565b5f8151808452602084019350602083015f5b828110156156925781516001600160a01b031686526020958601959091019060010161566b565b5093949350505050565b602081525f610bf46020830184615659565b604081525f6156c06040830185615659565b82810360208401528084518083526020830191506020860192505f5b818110156156fa5783518352602093840193909201916001016156dc565b50909695505050505050565b5f60208284031215615716575f80fd5b81356001600160401b0381111561572b575f80fd5b820160808185031215610bf4575f80fd5b5f805f6060848603121561574e575f80fd5b8335925060208401356157608161520b565b915060408401356157708161520b565b809150509250925092565b5f806040838503121561578c575f80fd5b82356157978161520b565b915060208301356152908161520b565b5f8082840360408112156157b9575f80fd5b60208112156157c6575f80fd5b5082915060208301356001600160401b038111156157e2575f80fd5b83016101008186031215615290575f80fd5b600181811c9082168061580857607f821691505b60208210810361582657634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b6001815b600184111561367e5780850481111561585f5761585f61582c565b600184161561586d57908102905b60019390931c928002615844565b5f8261588957506001610acd565b8161589557505f610acd565b81600181146158ab57600281146158b5576158d1565b6001915050610acd565b60ff8411156158c6576158c661582c565b50506001821b610acd565b5060208310610133831016604e8410600b84101617156158f4575081810a610acd565b6159005f198484615840565b805f19048211156159135761591361582c565b029392505050565b5f610bf460ff84168361587b565b8082028115828204841417610acd57610acd61582c565b60ff8181168382160190811115610acd57610acd61582c565b6020808252602d908201527f436f6c6c5661756c743a20746f6b656e7320616e6420616d6f756e7473206c6560408201526c0dccee8d040dad2e6dac2e8c6d609b1b606082015260800190565b5f602082840312156159b6575f80fd5b5051919050565b81810381811115610acd57610acd61582c565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601260045260245ffd5b5f82615a1257634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215615a27575f80fd5b8151610bf48161520b565b60208082526028908201527f436f6c6c5661756c743a20706572666f726d616e636520666565206f7574206f6040820152676620626f756e647360c01b606082015260800190565b5f60208284031215615a8a575f80fd5b81516001600160401b03811115615a9f575f80fd5b8201601f81018413615aaf575f80fd5b8051615abd6153a182615362565b8082825260208201915060208360051b850101925086831115615ade575f80fd5b6020840193505b828410156139bb578351615af88161520b565b825260209384019390910190615ae5565b5f808335601e19843603018112615b1e575f80fd5b8301803591506001600160401b03821115615b37575f80fd5b602001915036819003821315615b4b575f80fd5b9250929050565b6001600160a01b03868116825260208201869052841660408201526080606082018190528101829052818360a08301375f81830160a090810191909152601f909201601f19160101949350505050565b6001600160a01b039390931683526020830191909152604082015260600190565b805160ff8116811461522a575f80fd5b5f60208284031215615be3575f80fd5b610bf482615bc3565b80820180821115610acd57610acd61582c565b60ff8281168282160390811115610acd57610acd61582c565b8051801515811461522a575f80fd5b5f60208284031215615c37575f80fd5b610bf482615c18565b5f805f805f60a08688031215615c54575f80fd5b8551615c5f8161520b565b9450615c6d60208701615bc3565b9350604086015163ffffffff81168114615c85575f80fd5b6060870151909350615c96816152f4565b6080870151909250615ca78161520b565b809150509295509295909350565b5f6040828403128015615cc6575f80fd5b50604080519081016001600160401b0381118282101715615ce957615ce961531e565b6040528251615cf78161520b565b8152615d0560208401615c18565b60208201529392505050565b634e487b7160e01b5f52602160045260245ffd5b5f823560de19833603018112615d39575f80fd5b9190910192915050565b5f82518060208501845e5f920191825250919050565b601f82111561252557805f5260205f20601f840160051c81016020851015615d7e5750805b601f840160051c820191505b81811015613aa2575f8155600101615d8a565b81516001600160401b03811115615db657615db661531e565b615dca81615dc484546157f4565b84615d59565b6020601f821160018114615dfc575f8315615de55750848201515b5f19600385901b1c1916600184901b178455613aa2565b5f84815260208120601f198516915b82811015615e2b5787850151825560209485019460019092019101615e0b565b5084821015615e4857868401515f19600387901b60f8161c191681555b50505050600190811b0190555056fe19001df2d131e9aa1479f4ce661ae121445caf0662dea1e41907028a6da6fe0252c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0219001df2d131e9aa1479f4ce661ae121445caf0662dea1e41907028a6da6fe01360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c65640773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e0019001df2d131e9aa1479f4ce661ae121445caf0662dea1e41907028a6da6fe00a2646970667358221220b9c080a4633dce0eccda1b7515168e926ddb08f485f341def0cb19e0b3f0802d64736f6c634300081a0033

Block Transaction 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

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.