@@ -20,6 +20,11 @@ AggregatorV3Interface constant stEthEthFeed = AggregatorV3Interface(0x86392dC19c
20
20
AggregatorV3Interface constant usdcEthFeed = AggregatorV3Interface (0x986b5E1e1755e3C2440e960477f25201B0a8bbD4 );
21
21
// 8 decimals of precision
22
22
AggregatorV3Interface constant ethUsdFeed = AggregatorV3Interface (0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 );
23
+ // 18 decimals of precision
24
+ AggregatorV3Interface constant daiEthFeed = AggregatorV3Interface (0x773616E4d11A78F511299002da57A0a94577F1f4 );
25
+
26
+ ERC4626 constant vaultZero = ERC4626 (address (0 ));
27
+ ERC4626 constant sDaiVault = ERC4626 (0x83F20F44975D03b1b09e64809B757c47f942BEeA );
23
28
24
29
contract FakeAggregator {
25
30
int256 public answer;
@@ -43,7 +48,7 @@ contract ChainlinkOracleTest is Test {
43
48
}
44
49
45
50
function testOracleWbtcUsdc () public {
46
- ChainlinkOracle oracle = new ChainlinkOracle (wBtcBtcFeed, btcUsdFeed, usdcUsdFeed, feedZero, 8 , 6 );
51
+ ChainlinkOracle oracle = new ChainlinkOracle (vaultZero, wBtcBtcFeed, btcUsdFeed, usdcUsdFeed, feedZero, 8 , 6 );
47
52
(, int256 firstBaseAnswer ,,,) = wBtcBtcFeed.latestRoundData ();
48
53
(, int256 secondBaseAnswer ,,,) = btcUsdFeed.latestRoundData ();
49
54
(, int256 quoteAnswer ,,,) = usdcUsdFeed.latestRoundData ();
@@ -55,7 +60,7 @@ contract ChainlinkOracleTest is Test {
55
60
}
56
61
57
62
function testOracleUsdcWbtc () public {
58
- ChainlinkOracle oracle = new ChainlinkOracle (usdcUsdFeed, feedZero, wBtcBtcFeed, btcUsdFeed, 6 , 8 );
63
+ ChainlinkOracle oracle = new ChainlinkOracle (vaultZero, usdcUsdFeed, feedZero, wBtcBtcFeed, btcUsdFeed, 6 , 8 );
59
64
(, int256 baseAnswer ,,,) = usdcUsdFeed.latestRoundData ();
60
65
(, int256 firstQuoteAnswer ,,,) = wBtcBtcFeed.latestRoundData ();
61
66
(, int256 secondQuoteAnswer ,,,) = btcUsdFeed.latestRoundData ();
@@ -67,51 +72,76 @@ contract ChainlinkOracleTest is Test {
67
72
}
68
73
69
74
function testOracleWbtcEth () public {
70
- ChainlinkOracle oracle = new ChainlinkOracle (wBtcBtcFeed, btcEthFeed, feedZero, feedZero, 8 , 18 );
75
+ ChainlinkOracle oracle = new ChainlinkOracle (vaultZero, wBtcBtcFeed, btcEthFeed, feedZero, feedZero, 8 , 18 );
71
76
(, int256 firstBaseAnswer ,,,) = wBtcBtcFeed.latestRoundData ();
72
77
(, int256 secondBaseAnswer ,,,) = btcEthFeed.latestRoundData ();
73
78
assertEq (oracle.price (), (uint256 (firstBaseAnswer) * uint256 (secondBaseAnswer) * 10 ** (36 + 18 - 8 - 8 - 18 )));
74
79
}
75
80
76
81
function testOracleStEthUsdc () public {
77
- ChainlinkOracle oracle = new ChainlinkOracle (stEthEthFeed, feedZero, usdcEthFeed, feedZero, 18 , 6 );
82
+ ChainlinkOracle oracle = new ChainlinkOracle (vaultZero, stEthEthFeed, feedZero, usdcEthFeed, feedZero, 18 , 6 );
78
83
(, int256 baseAnswer ,,,) = stEthEthFeed.latestRoundData ();
79
84
(, int256 quoteAnswer ,,,) = usdcEthFeed.latestRoundData ();
80
85
assertEq (oracle.price (), uint256 (baseAnswer) * 10 ** (36 + 18 + 6 - 18 - 18 ) / uint256 (quoteAnswer));
81
86
}
82
87
83
88
function testOracleEthUsd () public {
84
- ChainlinkOracle oracle = new ChainlinkOracle (ethUsdFeed, feedZero, feedZero, feedZero, 18 , 0 );
89
+ ChainlinkOracle oracle = new ChainlinkOracle (vaultZero, ethUsdFeed, feedZero, feedZero, feedZero, 18 , 0 );
85
90
(, int256 expectedPrice ,,,) = ethUsdFeed.latestRoundData ();
86
91
assertEq (oracle.price (), uint256 (expectedPrice) * 10 ** (36 - 18 - 8 ));
87
92
}
88
93
89
94
function testOracleStEthEth () public {
90
- ChainlinkOracle oracle = new ChainlinkOracle (stEthEthFeed, feedZero, feedZero, feedZero, 18 , 18 );
95
+ ChainlinkOracle oracle = new ChainlinkOracle (vaultZero, stEthEthFeed, feedZero, feedZero, feedZero, 18 , 18 );
91
96
(, int256 expectedPrice ,,,) = stEthEthFeed.latestRoundData ();
92
97
assertEq (oracle.price (), uint256 (expectedPrice) * 10 ** (36 + 18 - 18 - 18 ));
93
98
assertApproxEqRel (oracle.price (), 1e36 , 0.01 ether);
94
99
}
95
100
96
101
function testOracleEthStEth () public {
97
- ChainlinkOracle oracle = new ChainlinkOracle (feedZero, feedZero, stEthEthFeed, feedZero, 18 , 18 );
102
+ ChainlinkOracle oracle = new ChainlinkOracle (vaultZero, feedZero, feedZero, stEthEthFeed, feedZero, 18 , 18 );
98
103
(, int256 expectedPrice ,,,) = stEthEthFeed.latestRoundData ();
99
104
assertEq (oracle.price (), 10 ** (36 + 18 + 18 - 18 ) / uint256 (expectedPrice));
100
105
assertApproxEqRel (oracle.price (), 1e36 , 0.01 ether);
101
106
}
102
107
103
108
function testOracleUsdcUsd () public {
104
- ChainlinkOracle oracle = new ChainlinkOracle (usdcUsdFeed, feedZero, feedZero, feedZero, 6 , 0 );
109
+ ChainlinkOracle oracle = new ChainlinkOracle (vaultZero, usdcUsdFeed, feedZero, feedZero, feedZero, 6 , 0 );
105
110
assertApproxEqRel (oracle.price (), 1e36 / 1e6 , 0.01 ether);
106
111
}
107
112
108
113
function testNegativeAnswer (int256 price ) public {
109
114
price = bound (price, type (int256 ).min, - 1 );
110
115
FakeAggregator aggregator = new FakeAggregator ();
111
116
ChainlinkOracle oracle =
112
- new ChainlinkOracle (AggregatorV3Interface (address (aggregator)), feedZero, feedZero, feedZero, 18 , 0 );
117
+ new ChainlinkOracle (vaultZero, AggregatorV3Interface (address (aggregator)), feedZero, feedZero, feedZero, 18 , 0 );
113
118
aggregator.setAnwser (price);
114
119
vm.expectRevert (bytes (ErrorsLib.NEGATIVE_ANSWER));
115
120
oracle.price ();
116
121
}
122
+
123
+ function testSDaiEthOracle () public {
124
+ ChainlinkOracle oracle = new ChainlinkOracle (sDaiVault, daiEthFeed, feedZero, feedZero, feedZero, 18 , 18 );
125
+ (, int256 expectedPrice ,,,) = daiEthFeed.latestRoundData ();
126
+ assertEq (
127
+ oracle.price (),
128
+ sDaiVault.convertToAssets (1e18 ) * uint256 (expectedPrice) * 10 ** (36 + 18 + 0 - 18 - 18 - 18 )
129
+ );
130
+ }
131
+
132
+ function testSDaiUsdcOracle () public {
133
+ ChainlinkOracle oracle = new ChainlinkOracle (sDaiVault, daiEthFeed, feedZero, usdcEthFeed, feedZero, 18 , 6 );
134
+ (, int256 baseAnswer ,,,) = daiEthFeed.latestRoundData ();
135
+ (, int256 quoteAnswer ,,,) = usdcEthFeed.latestRoundData ();
136
+ assertEq (
137
+ oracle.price (),
138
+ sDaiVault.convertToAssets (1e18 ) * uint256 (baseAnswer) * 10 ** (36 + 6 + 18 - 18 - 18 - 18 )
139
+ / uint256 (quoteAnswer)
140
+ );
141
+ // DAI has 12 more decimals than USDC.
142
+ uint256 expectedPrice = 10 ** (36 - 12 );
143
+ // Admit a 50% interest gain before breaking this test.
144
+ uint256 deviation = 0.5 ether ;
145
+ assertApproxEqRel (oracle.price (), expectedPrice, deviation);
146
+ }
117
147
}
0 commit comments