@@ -28,6 +28,8 @@ IERC4626 constant vaultZero = IERC4626(address(0));
28
28
IERC4626 constant sDaiVault = IERC4626 (0x83F20F44975D03b1b09e64809B757c47f942BEeA );
29
29
30
30
contract ChainlinkOracleTest is Test {
31
+ using Math for uint256 ;
32
+
31
33
function setUp () public {
32
34
vm.createSelectFork (vm.envString ("ETH_RPC_URL " ));
33
35
}
@@ -141,6 +143,35 @@ contract ChainlinkOracleTest is Test {
141
143
assertApproxEqRel (oracle.price (), expectedPrice, deviation);
142
144
}
143
145
146
+ function testEthSDaiOracle () public {
147
+ ChainlinkOracle oracle =
148
+ new ChainlinkOracle (vaultZero, 1 , sDaiVault, 1e18 , feedZero, feedZero, daiEthFeed, feedZero, 18 , 18 );
149
+ (, int256 expectedPrice ,,,) = daiEthFeed.latestRoundData ();
150
+ assertEq (
151
+ oracle.price (),
152
+ // 1e(36 + dQ1 + fpQ1 + fpQ2 - dB1 - fpB1 - fpB2) * qCS / bCS
153
+ 10 ** (36 + 18 + 18 + 0 - 18 - 0 - 0 ) * 1e18 / (sDaiVault.convertToAssets (1e18 ) * uint256 (expectedPrice))
154
+ );
155
+ }
156
+
157
+ function testUsdcSDaiOracle () public {
158
+ ChainlinkOracle oracle =
159
+ new ChainlinkOracle (vaultZero, 1 , sDaiVault, 1e18 , usdcEthFeed, feedZero, daiEthFeed, feedZero, 6 , 18 );
160
+ (, int256 baseAnswer ,,,) = usdcEthFeed.latestRoundData ();
161
+ (, int256 quoteAnswer ,,,) = daiEthFeed.latestRoundData ();
162
+ // 1e(36 + dQ1 + fpQ1 + fpQ2 - dB1 - fpB1 - fpB2) * qCS / bCS
163
+ uint256 scaleFactor = 10 ** (36 + 18 + 18 + 0 - 6 - 18 - 0 ) * 1e18 ;
164
+ assertEq (
165
+ oracle.price (),
166
+ scaleFactor.mulDiv (uint256 (baseAnswer), (sDaiVault.convertToAssets (1e18 ) * uint256 (quoteAnswer)))
167
+ );
168
+ // DAI has 12 more decimals than USDC.
169
+ uint256 expectedPrice = 10 ** (36 + 12 );
170
+ // Admit a 50% interest gain before breaking this test.
171
+ uint256 deviation = 0.66 ether ;
172
+ assertApproxEqRel (oracle.price (), expectedPrice, deviation);
173
+ }
174
+
144
175
function testConstructorZeroVaultConversionSample () public {
145
176
vm.expectRevert (bytes (ErrorsLib.VAULT_CONVERSION_SAMPLE_IS_ZERO));
146
177
new ChainlinkOracle (sDaiVault, 0 , vaultZero, 1 , daiEthFeed, feedZero, usdcEthFeed, feedZero, 18 , 6 );
0 commit comments