Skip to content

Commit

Permalink
refactor: repo structure
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD committed Oct 4, 2023
1 parent 2ce15dd commit 0007653
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/chainlink/ChainlinkOracle.sol → src/ChainlinkOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ pragma solidity 0.8.19;

import {IOracle} from "morpho-blue/interfaces/IOracle.sol";

import {AggregatorV3Interface, DataFeedLib} from "./libraries/DataFeedLib.sol";
import {AggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/ChainlinkDataFeedLib.sol";

contract ChainlinkOracle is IOracle {
using DataFeedLib for AggregatorV3Interface;
using ChainlinkDataFeedLib for AggregatorV3Interface;

/* CONSTANT */

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import {ErrorsLib} from "./ErrorsLib.sol";
import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol";

library DataFeedLib {
library ChainlinkDataFeedLib {
/// @dev Performs some safety checks and returns the latest price of a feed.
/// @dev When `feed` is the address zero, returns 1.
function getPrice(AggregatorV3Interface feed) internal view returns (uint256) {
Expand Down
File renamed without changes.
13 changes: 5 additions & 8 deletions test/chainlink/ChainlinkOracleTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "src/chainlink/ChainlinkOracle.sol";
import "src/chainlink/libraries/ErrorsLib.sol";
import "src/ChainlinkOracle.sol";
import "src/libraries/ErrorsLib.sol";

AggregatorV3Interface constant feedZero = AggregatorV3Interface(address(0));
// 8 decimals of precision
Expand Down Expand Up @@ -43,8 +43,7 @@ contract ChainlinkOracleTest is Test {
}

function testOracleWbtcUsdc() public {
ChainlinkOracle oracle =
new ChainlinkOracle(wBtcBtcFeed, btcUsdFeed, usdcUsdFeed, feedZero, 8, 6);
ChainlinkOracle oracle = new ChainlinkOracle(wBtcBtcFeed, btcUsdFeed, usdcUsdFeed, feedZero, 8, 6);
(, int256 firstBaseAnswer,,,) = wBtcBtcFeed.latestRoundData();
(, int256 secondBaseAnswer,,,) = btcUsdFeed.latestRoundData();
(, int256 quoteAnswer,,,) = usdcUsdFeed.latestRoundData();
Expand All @@ -56,8 +55,7 @@ contract ChainlinkOracleTest is Test {
}

function testOracleUsdcWbtc() public {
ChainlinkOracle oracle =
new ChainlinkOracle(usdcUsdFeed, feedZero, wBtcBtcFeed, btcUsdFeed, 6, 8);
ChainlinkOracle oracle = new ChainlinkOracle(usdcUsdFeed, feedZero, wBtcBtcFeed, btcUsdFeed, 6, 8);
(, int256 baseAnswer,,,) = usdcUsdFeed.latestRoundData();
(, int256 firstQuoteAnswer,,,) = wBtcBtcFeed.latestRoundData();
(, int256 secondQuoteAnswer,,,) = btcUsdFeed.latestRoundData();
Expand All @@ -69,8 +67,7 @@ contract ChainlinkOracleTest is Test {
}

function testOracleWbtcEth() public {
ChainlinkOracle oracle =
new ChainlinkOracle(wBtcBtcFeed, btcEthFeed, feedZero, feedZero, 8, 18);
ChainlinkOracle oracle = new ChainlinkOracle(wBtcBtcFeed, btcEthFeed, feedZero, feedZero, 8, 18);
(, int256 firstBaseAnswer,,,) = wBtcBtcFeed.latestRoundData();
(, int256 secondBaseAnswer,,,) = btcEthFeed.latestRoundData();
assertEq(oracle.price(), (uint256(firstBaseAnswer) * uint256(secondBaseAnswer) * 10 ** (36 + 18 - 8 - 8 - 18)));
Expand Down

0 comments on commit 0007653

Please sign in to comment.