Skip to content

Commit a58dc16

Browse files
Merge pull request #35 from morpho-labs/fix/vault-conversion-zero
fix(oracle): require vault conversion not zero
2 parents 16f372f + f313350 commit a58dc16

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/ChainlinkOracle.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ contract ChainlinkOracle is IOracle {
6060
require(
6161
address(vault) != address(0) || vaultConversionSample == 1, ErrorsLib.VAULT_CONVERSION_SAMPLE_IS_NOT_ONE
6262
);
63+
require(vaultConversionSample != 0, ErrorsLib.VAULT_CONVERSION_SAMPLE_IS_ZERO);
64+
6365
VAULT = vault;
6466
VAULT_CONVERSION_SAMPLE = vaultConversionSample;
6567
BASE_FEED_1 = baseFeed1;
@@ -87,7 +89,7 @@ contract ChainlinkOracle is IOracle {
8789
** (
8890
36 + quoteTokenDecimals + quoteFeed1.getDecimals() + quoteFeed2.getDecimals() - baseTokenDecimals
8991
- baseFeed1.getDecimals() - baseFeed2.getDecimals()
90-
) / VAULT_CONVERSION_SAMPLE;
92+
) / vaultConversionSample;
9193
}
9294

9395
/* PRICE */

src/libraries/ErrorsLib.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ library ErrorsLib {
99
/// @notice Thrown when the answer returned by a Chainlink feed is negative.
1010
string constant NEGATIVE_ANSWER = "negative answer";
1111

12+
/// @notice Thrown when the vault conversion sample is 0.
13+
string constant VAULT_CONVERSION_SAMPLE_IS_ZERO = "vault conversion sample is zero";
14+
1215
/// @notice Thrown when the vault conversion sample is not 1 while vault = address(0).
1316
string constant VAULT_CONVERSION_SAMPLE_IS_NOT_ONE = "vault conversion sample is not one";
1417
}

test/ChainlinkOracleTest.sol

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ contract ChainlinkOracleTest is Test {
132132
assertApproxEqRel(oracle.price(), expectedPrice, deviation);
133133
}
134134

135+
function testConstructorZeroVaultConversionSample() public {
136+
vm.expectRevert(bytes(ErrorsLib.VAULT_CONVERSION_SAMPLE_IS_ZERO));
137+
new ChainlinkOracle(sDaiVault, daiEthFeed, feedZero, usdcEthFeed, feedZero, 0, 18, 6);
138+
}
139+
135140
function testConstructorVaultZeroNonOneSample(uint256 vaultConversionSample) public {
136-
vm.assume(vaultConversionSample != 1);
141+
vaultConversionSample = bound(vaultConversionSample, 2, type(uint256).max);
142+
137143
vm.expectRevert(bytes(ErrorsLib.VAULT_CONVERSION_SAMPLE_IS_NOT_ONE));
138144
new ChainlinkOracle(vaultZero, daiEthFeed, feedZero, usdcEthFeed, feedZero, vaultConversionSample, 18, 6);
139145
}

0 commit comments

Comments
 (0)