Skip to content

Commit

Permalink
Merge pull request #35 from morpho-labs/fix/vault-conversion-zero
Browse files Browse the repository at this point in the history
fix(oracle): require vault conversion not zero
  • Loading branch information
MerlinEgalite authored Nov 8, 2023
2 parents 16f372f + f313350 commit a58dc16
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ChainlinkOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ contract ChainlinkOracle is IOracle {
require(
address(vault) != address(0) || vaultConversionSample == 1, ErrorsLib.VAULT_CONVERSION_SAMPLE_IS_NOT_ONE
);
require(vaultConversionSample != 0, ErrorsLib.VAULT_CONVERSION_SAMPLE_IS_ZERO);

VAULT = vault;
VAULT_CONVERSION_SAMPLE = vaultConversionSample;
BASE_FEED_1 = baseFeed1;
Expand Down Expand Up @@ -87,7 +89,7 @@ contract ChainlinkOracle is IOracle {
** (
36 + quoteTokenDecimals + quoteFeed1.getDecimals() + quoteFeed2.getDecimals() - baseTokenDecimals
- baseFeed1.getDecimals() - baseFeed2.getDecimals()
) / VAULT_CONVERSION_SAMPLE;
) / vaultConversionSample;
}

/* PRICE */
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ library ErrorsLib {
/// @notice Thrown when the answer returned by a Chainlink feed is negative.
string constant NEGATIVE_ANSWER = "negative answer";

/// @notice Thrown when the vault conversion sample is 0.
string constant VAULT_CONVERSION_SAMPLE_IS_ZERO = "vault conversion sample is zero";

/// @notice Thrown when the vault conversion sample is not 1 while vault = address(0).
string constant VAULT_CONVERSION_SAMPLE_IS_NOT_ONE = "vault conversion sample is not one";
}
8 changes: 7 additions & 1 deletion test/ChainlinkOracleTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ contract ChainlinkOracleTest is Test {
assertApproxEqRel(oracle.price(), expectedPrice, deviation);
}

function testConstructorZeroVaultConversionSample() public {
vm.expectRevert(bytes(ErrorsLib.VAULT_CONVERSION_SAMPLE_IS_ZERO));
new ChainlinkOracle(sDaiVault, daiEthFeed, feedZero, usdcEthFeed, feedZero, 0, 18, 6);
}

function testConstructorVaultZeroNonOneSample(uint256 vaultConversionSample) public {
vm.assume(vaultConversionSample != 1);
vaultConversionSample = bound(vaultConversionSample, 2, type(uint256).max);

vm.expectRevert(bytes(ErrorsLib.VAULT_CONVERSION_SAMPLE_IS_NOT_ONE));
new ChainlinkOracle(vaultZero, daiEthFeed, feedZero, usdcEthFeed, feedZero, vaultConversionSample, 18, 6);
}
Expand Down

0 comments on commit a58dc16

Please sign in to comment.