creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/interfaces/IChainlinkV3Aggregator.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.17;\n\ninterface IChainlinkV3Aggregator {\n    function decimals() external view returns (uint8);\n\n    function latestRoundData()\n        external\n        view\n        returns (\n            uint80 roundId,\n            int256 answer,\n            uint256 startedAt,\n            uint256 updatedAt,\n            uint80 answeredInRound\n        );\n}\n"
      },
      "contracts/interfaces/IOracle.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.17;\n\ninterface IOracle {\n    function viewPriceInUSD() external view returns (uint256);\n}\n"
      },
      "contracts/interfaces/IPriceOracleAggregator.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.17;\n\nimport {IOracle} from './IOracle.sol';\n\ninterface IPriceOracleAggregator {\n    event UpdateOracle(address token, IOracle oracle);\n\n    function updateOracleForAsset(address _asset, IOracle _oracle) external;\n\n    function viewPriceInUSD(address _token) external view returns (uint256);\n}\n"
      },
      "contracts/oracle/ChainlinkUSDAdapter.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.17;\n\nimport '../interfaces/IOracle.sol';\nimport '../interfaces/IPriceOracleAggregator.sol';\nimport '../interfaces/IChainlinkV3Aggregator.sol';\n\ncontract ChainlinkUSDAdapter is IOracle {\n    /// @notice the asset with the price oracle\n    address public immutable asset;\n\n    /// @notice chainlink aggregator with price in base asset\n    IChainlinkV3Aggregator public immutable chainlinkAggregator;\n\n    /// @notice the base asset of chainlink aggregator\n    address public immutable baseAsset;\n\n    /// @notice oracle that returns price in USD\n    IPriceOracleAggregator public immutable aggregator;\n\n    constructor(\n        address _asset,\n        address _aggregator,\n        address _baseAsset,\n        address _priceOracleAggregator\n    ) {\n        require(address(_aggregator) != address(0), 'invalid aggregator');\n\n        asset = _asset;\n        chainlinkAggregator = IChainlinkV3Aggregator(_aggregator);\n        baseAsset = _baseAsset;\n        aggregator = IPriceOracleAggregator(_priceOracleAggregator);\n    }\n\n    function adjustDecimal(\n        uint256 balance,\n        uint8 org,\n        uint8 target\n    ) internal pure returns (uint256 adjustedBalance) {\n        adjustedBalance = balance;\n        if (target < org) {\n            adjustedBalance = adjustedBalance / (10 ** (org - target));\n        } else if (target > org) {\n            adjustedBalance = adjustedBalance * (10 ** (target - org));\n        }\n    }\n\n    /// @dev returns the latest price of asset\n    function viewPriceInUSD() external view override returns (uint256) {\n        (, int256 priceC, , , ) = chainlinkAggregator.latestRoundData();\n\n        uint256 priceInBaseAsset = adjustDecimal(\n            uint256(priceC),\n            chainlinkAggregator.decimals(),\n            8\n        ); // 8 decimals\n\n        if (baseAsset != address(0)) {\n            return\n                (priceInBaseAsset * aggregator.viewPriceInUSD(baseAsset)) /\n                10 ** 8;\n        }\n\n        return priceInBaseAsset;\n    }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "metadata": {
        "useLiteralContent": true
      },
      "libraries": {}
    }
  }}