Skip to content

Commit 2103045

Browse files
committed
Merge remote-tracking branch 'origin/feat/chainlink' into feat/chainlink-factorized
2 parents fd65d54 + b7e95c3 commit 2103045

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

src/ChainlinkOracle.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ contract ChainlinkOracle is IOracle {
6262
// common quote currency.
6363
// Chainlink feeds return pB1*b1FeedPrecision, pB2*b2FeedPrecision, pQ1*q1FeedPrecision and pQ2*q2FeedPrecision.
6464
// `price()` should return 1e36 * (pB1/1e(b1Decimals) * pB2/1e(b2Decimals)) / (pQ1/1e(q1Decimals) *
65-
// pQ2/1e(q2Decimals)).
65+
// pQ2/1e(q2Decimals))
6666
// Yet `price()` returns (pB1*1e(b1FeedPrecision) * pB2*1e(b2FeedPrecision) * SCALE_FACTOR) /
6767
// (pQ1*1e(q1FeedPrecision) * pQ2*1e(q2FeedPrecision))
6868
// So 1e36 * (pB1/1e(b1Decimals) * pB2/1e(b2Decimals)) / (pQ1/1e(q1Decimals) * pQ2/1e(q2Decimals)) =
@@ -74,8 +74,8 @@ contract ChainlinkOracle is IOracle {
7474
// b2Decimals - b1FeedPrecision - b2FeedPrecision)
7575
SCALE_FACTOR = 10
7676
** (
77-
36 + quoteTokenDecimals + quoteFeed1.getDecimals() + quoteFeed2.getDecimals() - baseFeed1.getDecimals()
78-
- baseFeed2.getDecimals() - baseTokenDecimals - VAULT_DECIMALS
77+
36 + quoteTokenDecimals + quoteFeed1.getDecimals() + quoteFeed2.getDecimals() - baseTokenDecimals
78+
- baseFeed1.getDecimals() - baseFeed2.getDecimals() - VAULT_DECIMALS
7979
);
8080
}
8181

test/ChainlinkOracleTest.sol

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
44
import "forge-std/Test.sol";
55
import "src/ChainlinkOracle.sol";
66
import "src/libraries/ErrorsLib.sol";
7+
import "./mocks/ChainlinkAggregatorMock.sol";
78

89
AggregatorV3Interface constant feedZero = AggregatorV3Interface(address(0));
910
// 8 decimals of precision
@@ -26,22 +27,6 @@ AggregatorV3Interface constant daiEthFeed = AggregatorV3Interface(0x773616E4d11A
2627
IERC4626 constant vaultZero = IERC4626(address(0));
2728
IERC4626 constant sDaiVault = IERC4626(0x83F20F44975D03b1b09e64809B757c47f942BEeA);
2829

29-
contract FakeAggregator {
30-
int256 public answer;
31-
32-
function setAnwser(int256 newAnswer) external {
33-
answer = newAnswer;
34-
}
35-
36-
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
37-
return (0, answer, 0, 0, 0);
38-
}
39-
40-
function decimals() external pure returns (uint256) {
41-
return 8;
42-
}
43-
}
44-
4530
contract ChainlinkOracleTest is Test {
4631
function setUp() public {
4732
vm.createSelectFork(vm.envString("ETH_RPC_URL"));
@@ -112,7 +97,7 @@ contract ChainlinkOracleTest is Test {
11297

11398
function testNegativeAnswer(int256 price) public {
11499
price = bound(price, type(int256).min, -1);
115-
FakeAggregator aggregator = new FakeAggregator();
100+
ChainlinkAggregatorMock aggregator = new ChainlinkAggregatorMock();
116101
ChainlinkOracle oracle =
117102
new ChainlinkOracle(vaultZero, AggregatorV3Interface(address(aggregator)), feedZero, feedZero, feedZero, 18, 0);
118103
aggregator.setAnwser(price);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
contract ChainlinkAggregatorMock {
5+
int256 public answer;
6+
7+
function setAnwser(int256 newAnswer) external {
8+
answer = newAnswer;
9+
}
10+
11+
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
12+
return (0, answer, 0, 0, 0);
13+
}
14+
15+
function decimals() external pure returns (uint256) {
16+
return 8;
17+
}
18+
}

0 commit comments

Comments
 (0)