diff --git a/contracts/oracles/ChainlinkOracle.sol b/contracts/oracles/ChainlinkOracle.sol index 3af81cb8..8edd546a 100644 --- a/contracts/oracles/ChainlinkOracle.sol +++ b/contracts/oracles/ChainlinkOracle.sol @@ -5,17 +5,17 @@ import {IOracle} from "./interfaces/IOracle.sol"; import {IChainlinkAggregatorV3} from "./adapters/interfaces/IChainlinkAggregatorV3.sol"; import {OracleFeed} from "./libraries/OracleFeed.sol"; -import {ChainlinkAggregatorLib} from "./libraries/ChainlinkAggregatorLib.sol"; +import {ChainlinkAggregatorV3Lib} from "./libraries/ChainlinkAggregatorV3Lib.sol"; import {ChainlinkCollateralAdapter} from "./adapters/ChainlinkCollateralAdapter.sol"; contract ChainlinkOracle is ChainlinkCollateralAdapter, IOracle { - using ChainlinkAggregatorLib for IChainlinkAggregatorV3; + using ChainlinkAggregatorV3Lib for IChainlinkAggregatorV3; - constructor(address feed, uint256 scale) ChainlinkCollateralAdapter(feed, scale) {} + constructor(address feed) ChainlinkCollateralAdapter(feed) {} function FEED_COLLATERAL() external view returns (string memory, address) { - return (OracleFeed.CHAINLINK, address(CHAINLINK_COLLATERAL_FEED)); + return (OracleFeed.CHAINLINK_V3, address(CHAINLINK_COLLATERAL_FEED)); } function FEED_BORROWABLE() external view returns (string memory, address) {} diff --git a/contracts/oracles/ChainlinkPairOracle.sol b/contracts/oracles/ChainlinkPairOracle.sol index a5ff7d4a..c972bb1c 100644 --- a/contracts/oracles/ChainlinkPairOracle.sol +++ b/contracts/oracles/ChainlinkPairOracle.sol @@ -5,36 +5,31 @@ import {IOracle} from "./interfaces/IOracle.sol"; import {IChainlinkAggregatorV3} from "./adapters/interfaces/IChainlinkAggregatorV3.sol"; import {OracleFeed} from "./libraries/OracleFeed.sol"; -import {ChainlinkAggregatorLib} from "./libraries/ChainlinkAggregatorLib.sol"; import {FullMath} from "@uniswap/v3-core/libraries/FullMath.sol"; +import {ChainlinkAggregatorV3Lib} from "./libraries/ChainlinkAggregatorV3Lib.sol"; import {ChainlinkCollateralAdapter} from "./adapters/ChainlinkCollateralAdapter.sol"; import {ChainlinkBorrowableAdapter} from "./adapters/ChainlinkBorrowableAdapter.sol"; contract ChainlinkOracle is ChainlinkCollateralAdapter, ChainlinkBorrowableAdapter, IOracle { - using ChainlinkAggregatorLib for IChainlinkAggregatorV3; + using ChainlinkAggregatorV3Lib for IChainlinkAggregatorV3; + /// @dev The scale must be 1e36 * 10^(decimals of borrowable token - decimals of collateral token). uint256 public immutable PRICE_SCALE; - constructor( - address collateralFeed, - address borrowableFeed, - uint256 collateralPriceScale, - uint256 borrowablePriceScale, - uint256 scale - ) - ChainlinkCollateralAdapter(collateralFeed, collateralPriceScale) - ChainlinkBorrowableAdapter(borrowableFeed, borrowablePriceScale) + constructor(address collateralFeed, address borrowableFeed, uint256 scale) + ChainlinkCollateralAdapter(collateralFeed) + ChainlinkBorrowableAdapter(borrowableFeed) { PRICE_SCALE = scale; } function FEED_COLLATERAL() external view returns (string memory, address) { - return (OracleFeed.CHAINLINK, address(CHAINLINK_COLLATERAL_FEED)); + return (OracleFeed.CHAINLINK_V3, address(CHAINLINK_COLLATERAL_FEED)); } function FEED_BORROWABLE() external view returns (string memory, address) { - return (OracleFeed.CHAINLINK, address(CHAINLINK_BORROWABLE_FEED)); + return (OracleFeed.CHAINLINK_V3, address(CHAINLINK_BORROWABLE_FEED)); } function price() external view returns (uint256) { diff --git a/contracts/oracles/ChainlinkUniswapV3Oracle.sol b/contracts/oracles/ChainlinkUniswapV3Oracle.sol index b3b45fd6..5163bae6 100644 --- a/contracts/oracles/ChainlinkUniswapV3Oracle.sol +++ b/contracts/oracles/ChainlinkUniswapV3Oracle.sol @@ -8,7 +8,7 @@ import {IChainlinkAggregatorV3} from "./adapters/interfaces/IChainlinkAggregator import {OracleFeed} from "./libraries/OracleFeed.sol"; import {MathLib} from "@morpho-blue/libraries/MathLib.sol"; import {UniswapV3PoolLib} from "./libraries/UniswapV3PoolLib.sol"; -import {ChainlinkAggregatorLib} from "./libraries/ChainlinkAggregatorLib.sol"; +import {ChainlinkAggregatorV3Lib} from "./libraries/ChainlinkAggregatorV3Lib.sol"; import {ChainlinkCollateralAdapter} from "./adapters/ChainlinkCollateralAdapter.sol"; import {UniswapV3BorrowableAdapter} from "./adapters/UniswapV3BorrowableAdapter.sol"; @@ -16,15 +16,15 @@ import {UniswapV3BorrowableAdapter} from "./adapters/UniswapV3BorrowableAdapter. contract ChainlinkUniswapV3Oracle is ChainlinkCollateralAdapter, UniswapV3BorrowableAdapter, IOracle { using MathLib for uint256; using UniswapV3PoolLib for IUniswapV3Pool; - using ChainlinkAggregatorLib for IChainlinkAggregatorV3; + using ChainlinkAggregatorV3Lib for IChainlinkAggregatorV3; constructor(address feed, address pool, uint256 collateralPriceScale, uint32 borrowablePriceDelay) - ChainlinkCollateralAdapter(feed, collateralPriceScale) + ChainlinkCollateralAdapter(feed) UniswapV3BorrowableAdapter(pool, borrowablePriceDelay) {} function FEED_COLLATERAL() external view returns (string memory, address) { - return (OracleFeed.CHAINLINK, address(CHAINLINK_COLLATERAL_FEED)); + return (OracleFeed.CHAINLINK_V3, address(CHAINLINK_COLLATERAL_FEED)); } function FEED_BORROWABLE() external view returns (string memory, address) { diff --git a/contracts/oracles/UniswapV3ChainlinkOracle.sol b/contracts/oracles/UniswapV3ChainlinkOracle.sol index 46cfc7b4..d0a26db5 100644 --- a/contracts/oracles/UniswapV3ChainlinkOracle.sol +++ b/contracts/oracles/UniswapV3ChainlinkOracle.sol @@ -8,7 +8,7 @@ import {IChainlinkAggregatorV3} from "./adapters/interfaces/IChainlinkAggregator import {OracleFeed} from "./libraries/OracleFeed.sol"; import {MathLib} from "@morpho-blue/libraries/MathLib.sol"; import {UniswapV3PoolLib} from "./libraries/UniswapV3PoolLib.sol"; -import {ChainlinkAggregatorLib} from "./libraries/ChainlinkAggregatorLib.sol"; +import {ChainlinkAggregatorV3Lib} from "./libraries/ChainlinkAggregatorV3Lib.sol"; import {UniswapV3CollateralAdapter} from "./adapters/UniswapV3CollateralAdapter.sol"; import {ChainlinkBorrowableAdapter} from "./adapters/ChainlinkBorrowableAdapter.sol"; @@ -16,11 +16,11 @@ import {ChainlinkBorrowableAdapter} from "./adapters/ChainlinkBorrowableAdapter. contract UniswapV3ChainlinkOracle is UniswapV3CollateralAdapter, ChainlinkBorrowableAdapter, IOracle { using MathLib for uint256; using UniswapV3PoolLib for IUniswapV3Pool; - using ChainlinkAggregatorLib for IChainlinkAggregatorV3; + using ChainlinkAggregatorV3Lib for IChainlinkAggregatorV3; constructor(address pool, address feed, uint32 collateralPriceDelay, uint256 borrowablePriceScale) UniswapV3CollateralAdapter(pool, collateralPriceDelay) - ChainlinkBorrowableAdapter(feed, borrowablePriceScale) + ChainlinkBorrowableAdapter(feed) {} function FEED_COLLATERAL() external view returns (string memory, address) { @@ -28,7 +28,7 @@ contract UniswapV3ChainlinkOracle is UniswapV3CollateralAdapter, ChainlinkBorrow } function FEED_BORROWABLE() external view returns (string memory, address) { - return (OracleFeed.CHAINLINK, address(CHAINLINK_BORROWABLE_FEED)); + return (OracleFeed.CHAINLINK_V3, address(CHAINLINK_BORROWABLE_FEED)); } function price() external view returns (uint256) { diff --git a/contracts/oracles/adapters/ChainlinkBorrowableAdapter.sol b/contracts/oracles/adapters/ChainlinkBorrowableAdapter.sol index 32a70257..dafe2c3b 100644 --- a/contracts/oracles/adapters/ChainlinkBorrowableAdapter.sol +++ b/contracts/oracles/adapters/ChainlinkBorrowableAdapter.sol @@ -7,8 +7,8 @@ abstract contract ChainlinkBorrowableAdapter { IChainlinkAggregatorV3 public immutable CHAINLINK_BORROWABLE_FEED; uint256 public immutable CHAINLINK_BORROWABLE_PRICE_SCALE; - constructor(address feed, uint256 scale) { + constructor(address feed) { CHAINLINK_BORROWABLE_FEED = IChainlinkAggregatorV3(feed); - CHAINLINK_BORROWABLE_PRICE_SCALE = scale; + CHAINLINK_BORROWABLE_PRICE_SCALE = CHAINLINK_BORROWABLE_FEED.decimals(); } } diff --git a/contracts/oracles/adapters/ChainlinkCollateralAdapter.sol b/contracts/oracles/adapters/ChainlinkCollateralAdapter.sol index fc5ff569..7c8b7bbd 100644 --- a/contracts/oracles/adapters/ChainlinkCollateralAdapter.sol +++ b/contracts/oracles/adapters/ChainlinkCollateralAdapter.sol @@ -7,8 +7,8 @@ abstract contract ChainlinkCollateralAdapter { IChainlinkAggregatorV3 public immutable CHAINLINK_COLLATERAL_FEED; uint256 public immutable CHAINLINK_COLLATERAL_PRICE_SCALE; - constructor(address feed, uint256 scale) { + constructor(address feed) { CHAINLINK_COLLATERAL_FEED = IChainlinkAggregatorV3(feed); - CHAINLINK_COLLATERAL_PRICE_SCALE = scale; + CHAINLINK_COLLATERAL_PRICE_SCALE = CHAINLINK_COLLATERAL_FEED.decimals(); } } diff --git a/contracts/oracles/libraries/ChainlinkAggregatorLib.sol b/contracts/oracles/libraries/ChainlinkAggregatorV3Lib.sol similarity index 90% rename from contracts/oracles/libraries/ChainlinkAggregatorLib.sol rename to contracts/oracles/libraries/ChainlinkAggregatorV3Lib.sol index f852098e..55d8765a 100644 --- a/contracts/oracles/libraries/ChainlinkAggregatorLib.sol +++ b/contracts/oracles/libraries/ChainlinkAggregatorV3Lib.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {IChainlinkAggregatorV3} from "../adapters/interfaces/IChainlinkAggregatorV3.sol"; -library ChainlinkAggregatorLib { +library ChainlinkAggregatorV3Lib { function price(IChainlinkAggregatorV3 aggregator) internal view returns (uint256) { (, int256 answer,,,) = aggregator.latestRoundData(); return uint256(answer); diff --git a/contracts/oracles/libraries/OracleFeed.sol b/contracts/oracles/libraries/OracleFeed.sol index a8be71a5..3d341a6f 100644 --- a/contracts/oracles/libraries/OracleFeed.sol +++ b/contracts/oracles/libraries/OracleFeed.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; library OracleFeed { string internal constant UNISWAP_V3 = "uniswapV3"; - string internal constant CHAINLINK = "chainlink"; + string internal constant CHAINLINK_V3 = "chainlinkV3"; string internal constant REDSTONE = "redstone";