creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "src/core/misc/rsETHPriceAdaptor.sol": {
        "content": "pragma solidity 0.8.10;\n\nimport {AggregatorInterface} from \"../dependencies/chainlink/AggregatorInterface.sol\";\nimport {Ownable} from \"../dependencies/openzeppelin/contracts/Ownable.sol\";\n\ninterface IRedStoneFeed {\n    function latestAnswer() external view returns(int256);\n    function latestRoundData() external view returns(\n        uint80 roundId,  int256 answer, uint256 startAt, uint256 updatedAt, uint80 answerInRound\n    );\n    function getRoundData(uint80) external view returns(\n        uint80 roundId,  int256 answer, uint256 startAt, uint256 updatedAt, uint80 answerInRound\n    );\n    function aggregator() external view returns(address);\n}   \n\ninterface ITWAPAggregator {\n    function getTWAP() external view returns (uint256);\n}\n\n\n// make use of redstone ETH/ezETH price feed and chainlink ETH feed\ncontract rsETHPriceAdaptor is Ownable, AggregatorInterface {\n    AggregatorInterface public constant ethOracle = AggregatorInterface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);\n    IRedStoneFeed public constant redstoneOracle = IRedStoneFeed(0xA736eAe8805dDeFFba40cAB8c99bCB309dEaBd9B);\n    int256 public  maxFallbackThreshold = 0;\n    address public twapAggregatorAddress;\n\n    event SetTWAPAggregatorAddress(address twapAggregatorAddress);\n    event SetMaxFallbackThreshold(int256 maxFallbackThreshold);\n\n    constructor() public {\n    }\n    function aggregator() external view returns(address) {\n        return redstoneOracle.aggregator();\n    }\n    function setTWAPAggregatorAddress(address _twapAggregatorAddress) external onlyOwner {\n        twapAggregatorAddress = _twapAggregatorAddress;\n        emit SetTWAPAggregatorAddress(_twapAggregatorAddress);\n    }\n\n    function setMaxFallbackThreshold(int256 _maxFallbackThreshold) external onlyOwner {\n        maxFallbackThreshold = _maxFallbackThreshold;\n        emit SetMaxFallbackThreshold(_maxFallbackThreshold);\n    }\n\n\n\n    function ETH_TO_BASE() internal view returns(int256) {\n        return ethOracle.latestAnswer();\n    }\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        require(value < 2**255, \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n    function getTWAP() public view returns (int256) {\n        return toInt256(ITWAPAggregator(twapAggregatorAddress).getTWAP());\n    }\n\n    // need to gaurantee to return\n    function latestAnswer() external view returns (int256) {\n        int256 ethPrice = ETH_TO_BASE();\n         try redstoneOracle.latestAnswer() returns (int256 ratio) {\n            if (_shouldFallbackToTwap(ratio)) {\n                return getTWAP() * ethPrice / 1e8;\n            }\n            return ratio * ethPrice / 1e8 ;\n        } catch {\n            return getTWAP() * ethPrice / 1e8;\n        }\n    }\n\n    function latestTimestamp() external view returns (uint256) {\n            (,,,uint256 updatedAt,) = redstoneOracle.latestRoundData();\n            return updatedAt;\n    }\n\n    function latestRound() external view returns (uint256) {\n        (,,,,uint80 answeredInRound) = redstoneOracle.latestRoundData();\n        return uint256(answeredInRound);\n    }\n\n    // return the redStone rate * latestETHPrice\n    function getAnswer(uint256 roundId) external view returns (int256) {\n        (,int256 answer,,,) = redstoneOracle.getRoundData(uint80(roundId));\n        int256 ethPrice = ETH_TO_BASE();\n        return ethPrice * answer / 1e8;\n    }\n\n    function getTimestamp(uint256 roundId) external view returns (uint256) {\n        (,,,uint256 updatedAt,) = redstoneOracle.getRoundData(uint80(roundId));\n        return updatedAt;\n    }\n\n    function _shouldFallbackToTwap(int256 price) internal view returns(bool) {\n        int256 threshold;\n        if (maxFallbackThreshold == 0) {\n            // should take multiple years for pufETH to accumulate 50% yield from eth PoS\n            threshold = 1e8 * 110 / 100;\n        } else {\n            threshold = maxFallbackThreshold;\n        }\n        if (price > threshold) {\n            return true;\n        }\n        return false;\n    }\n} "
      },
      "src/core/dependencies/chainlink/AggregatorInterface.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// Chainlink Contracts v0.8\npragma solidity ^0.8.0;\n\ninterface AggregatorInterface {\n  function latestAnswer() external view returns (int256);\n\n  function latestTimestamp() external view returns (uint256);\n\n  function latestRound() external view returns (uint256);\n\n  function getAnswer(uint256 roundId) external view returns (int256);\n\n  function getTimestamp(uint256 roundId) external view returns (uint256);\n\n  event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt);\n\n  event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt);\n}\n"
      },
      "src/core/dependencies/openzeppelin/contracts/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.10;\n\nimport './Context.sol';\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\ncontract Ownable is Context {\n  address private _owner;\n\n  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n  /**\n   * @dev Initializes the contract setting the deployer as the initial owner.\n   */\n  constructor() {\n    address msgSender = _msgSender();\n    _owner = msgSender;\n    emit OwnershipTransferred(address(0), msgSender);\n  }\n\n  /**\n   * @dev Returns the address of the current owner.\n   */\n  function owner() public view returns (address) {\n    return _owner;\n  }\n\n  /**\n   * @dev Throws if called by any account other than the owner.\n   */\n  modifier onlyOwner() {\n    require(_owner == _msgSender(), 'Ownable: caller is not the owner');\n    _;\n  }\n\n  /**\n   * @dev Leaves the contract without owner. It will not be possible to call\n   * `onlyOwner` functions anymore. Can only be called by the current owner.\n   *\n   * NOTE: Renouncing ownership will leave the contract without an owner,\n   * thereby removing any functionality that is only available to the owner.\n   */\n  function renounceOwnership() public virtual onlyOwner {\n    emit OwnershipTransferred(_owner, address(0));\n    _owner = address(0);\n  }\n\n  /**\n   * @dev Transfers ownership of the contract to a new account (`newOwner`).\n   * Can only be called by the current owner.\n   */\n  function transferOwnership(address newOwner) public virtual onlyOwner {\n    require(newOwner != address(0), 'Ownable: new owner is the zero address');\n    emit OwnershipTransferred(_owner, newOwner);\n    _owner = newOwner;\n  }\n}\n"
      },
      "src/core/dependencies/openzeppelin/contracts/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.10;\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n  function _msgSender() internal view virtual returns (address payable) {\n    return payable(msg.sender);\n  }\n\n  function _msgData() internal view virtual returns (bytes memory) {\n    this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n    return msg.data;\n  }\n}\n"
      }
    },
    "settings": {
      "remappings": [
        "forge-std/=lib/forge-std/src/",
        "test/=test/",
        "@openzeppelin/=lib/openzeppelin-contracts/contracts/",
        "@aave/=node_modules/@aave/",
        "eth-gas-reporter/=node_modules/eth-gas-reporter/",
        "hardhat-deploy/=node_modules/hardhat-deploy/",
        "hardhat/=node_modules/hardhat/",
        "src/=src/",
        "@ensdomains/=node_modules/@ensdomains/",
        "@siddomains/=node_modules/@siddomains/",
        "ds-test/=lib/forge-std/lib/ds-test/src/",
        "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
        "openzeppelin-contracts/=lib/openzeppelin-contracts/",
        "openzeppelin/=lib/openzeppelin-contracts/contracts/"
      ],
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "metadata": {
        "useLiteralContent": false,
        "bytecodeHash": "ipfs"
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "evmVersion": "london",
      "libraries": {
        "src/core/protocol/libraries/logic/BorrowLogic.sol": {
          "BorrowLogic": "0xee2585C8f2A1DEBaD9f43eE764E3D0766e2A4273"
        },
        "src/core/protocol/libraries/logic/BridgeLogic.sol": {
          "BridgeLogic": "0xE3Aad8bd71E9Be91A60770159242325E06Af86B4"
        },
        "src/core/protocol/libraries/logic/ConfiguratorLogic.sol": {
          "ConfiguratorLogic": "0x306ca8E36c1DcC1E160f94d1Eb5Fd97CEa889871"
        },
        "src/core/protocol/libraries/logic/EModeLogic.sol": {
          "EModeLogic": "0xC8CB15Bc73B7f5f95Af33AEce738bC9B62Cb28D9"
        },
        "src/core/protocol/libraries/logic/FlashLoanLogic.sol": {
          "FlashLoanLogic": "0x486D682781A960fFb2A1feeDbD3455C6fae608eA"
        },
        "src/core/protocol/libraries/logic/LiquidationLogic.sol": {
          "LiquidationLogic": "0x107a0d2b34fC76F19aD64e9a9d27340A049b4Ac2"
        },
        "src/core/protocol/libraries/logic/PoolLogic.sol": {
          "PoolLogic": "0x30777a478886eCFcA0DC8B023e4Fd19b133D616F"
        },
        "src/core/protocol/libraries/logic/SupplyLogic.sol": {
          "SupplyLogic": "0x6253996626073F9E25D5b49FeAE792A45a9B9451"
        }
      }
    }
  }}