Skip to content

Commit

Permalink
feat: dapt chainlink oracles with v3
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinEgalite committed Aug 19, 2023
1 parent 0639f2a commit e323705
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 31 deletions.
8 changes: 4 additions & 4 deletions contracts/oracles/ChainlinkOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
21 changes: 8 additions & 13 deletions contracts/oracles/ChainlinkPairOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions contracts/oracles/ChainlinkUniswapV3Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ 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";

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) {
Expand Down
8 changes: 4 additions & 4 deletions contracts/oracles/UniswapV3ChainlinkOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ 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";

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) {
return (OracleFeed.UNISWAP_V3, address(UNI_V3_COLLATERAL_POOL));
}

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) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/oracles/adapters/ChainlinkBorrowableAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 2 additions & 2 deletions contracts/oracles/adapters/ChainlinkCollateralAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion contracts/oracles/libraries/OracleFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit e323705

Please sign in to comment.