Skip to content

Commit

Permalink
update inversion logic (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
daopunk authored Feb 19, 2024
1 parent 5d64891 commit 4730d1d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion script/Registry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ address constant SEPOLIA_WETH = 0x980B62Da83eFf3D4576C647993b0c1D7faf17c73;
uint256 constant ORACLE_INTERVAL_TEST = 1 minutes;
uint256 constant MINT_AMOUNT = 1_000_000 ether;
uint256 constant INIT_WETH_AMOUNT = 1 ether;
uint256 constant INIT_OD_AMOUNT = 2230 ether;
uint256 constant INIT_OD_AMOUNT = 2500 ether;

// Members for governance
address constant H = 0x37c5B029f9c3691B3d47cb024f84E5E257aEb0BB;
Expand Down
10 changes: 8 additions & 2 deletions src/contracts/oracles/DenominatedOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ contract DenominatedOracle {
(uint256 _denominationPriceSourceValue, bool _denominationPriceSourceValidity) =
denominationPriceSource.getResultWithValidity();

_priceSourceValue = inverted ? WAD.wdiv(_priceSourceValue) : _priceSourceValue;
if (inverted) {
if (_priceSourceValue == 0) return (0, false);
_priceSourceValue = WAD.wdiv(_priceSourceValue);
}

_result = _priceSourceValue.wmul(_denominationPriceSourceValue);
_validity = _priceSourceValidity && _denominationPriceSourceValidity;
Expand All @@ -59,7 +62,10 @@ contract DenominatedOracle {
uint256 _priceSourceValue = priceSource.read();
uint256 _denominationPriceSourceValue = denominationPriceSource.read();

_priceSourceValue = inverted ? WAD.wdiv(_priceSourceValue) : _priceSourceValue;
if (inverted) {
if (_priceSourceValue == 0) revert('InvalidPriceFeed');
_priceSourceValue = WAD.wdiv(_priceSourceValue);
}

return _priceSourceValue.wmul(_denominationPriceSourceValue);
}
Expand Down
4 changes: 4 additions & 0 deletions test/QMath.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import {MintableERC20} from '@contracts/for-test/MintableERC20.sol';

// forge test --match-contract QMath -vvvvv

/**
* @dev large price fluctuations in the price of ETH may break these tests
* in the case of large price fluctuation, adjust INIT_OD_AMOUNT in the Registry to set OD / ETH price
*/
contract QMath is Test {
using SafeMath for uint256;

Expand Down

0 comments on commit 4730d1d

Please sign in to comment.