-
Notifications
You must be signed in to change notification settings - Fork 176
Multiplicative Price Feed #757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c93fab7
to
044600f
Compare
constructor(address priceFeedA_, address priceFeedB_, uint8 decimals_, string memory description_) { | ||
priceFeedA = priceFeedA_; | ||
priceFeedB = priceFeedB_; | ||
uint8 priceFeedADecimals = AggregatorV3Interface(priceFeedA_).decimals(); | ||
uint8 priceFeedBDecimals = AggregatorV3Interface(priceFeedB_).decimals(); | ||
combinedScale = signed256(10 ** (priceFeedADecimals + priceFeedBDecimals)); | ||
|
||
if (decimals_ > 18) revert BadDecimals(); | ||
decimals = decimals_; | ||
description = description_; | ||
priceFeedScale = int256(10 ** decimals); | ||
} |
Check notice
Code scanning / Semgrep
Semgrep Finding: rules.solidity.performance.non-payable-constructor
constructor(address priceFeedA_, address priceFeedB_, uint8 decimals_, string memory description_) { | ||
priceFeedA = priceFeedA_; | ||
priceFeedB = priceFeedB_; | ||
uint8 priceFeedADecimals = AggregatorV3Interface(priceFeedA_).decimals(); | ||
uint8 priceFeedBDecimals = AggregatorV3Interface(priceFeedB_).decimals(); | ||
combinedScale = signed256(10 ** (priceFeedADecimals + priceFeedBDecimals)); | ||
|
||
if (decimals_ > 18) revert BadDecimals(); | ||
decimals = decimals_; | ||
description = description_; | ||
priceFeedScale = int256(10 ** decimals); | ||
} |
Check warning
Code scanning / Semgrep
Semgrep Finding: compound.solidity.missing-constructor-sanity-checks
constructor(address priceFeedA_, address priceFeedB_, uint8 decimals_, string memory description_) { | ||
priceFeedA = priceFeedA_; | ||
priceFeedB = priceFeedB_; | ||
uint8 priceFeedADecimals = AggregatorV3Interface(priceFeedA_).decimals(); | ||
uint8 priceFeedBDecimals = AggregatorV3Interface(priceFeedB_).decimals(); | ||
combinedScale = signed256(10 ** (priceFeedADecimals + priceFeedBDecimals)); | ||
|
||
if (decimals_ > 18) revert BadDecimals(); | ||
decimals = decimals_; | ||
description = description_; | ||
priceFeedScale = int256(10 ** decimals); | ||
} |
Check warning
Code scanning / Semgrep
Semgrep Finding: compound.solidity.missing-constructor-sanity-checks
constructor(address priceFeedA_, address priceFeedB_, uint8 decimals_, string memory description_) { | ||
priceFeedA = priceFeedA_; | ||
priceFeedB = priceFeedB_; | ||
uint8 priceFeedADecimals = AggregatorV3Interface(priceFeedA_).decimals(); | ||
uint8 priceFeedBDecimals = AggregatorV3Interface(priceFeedB_).decimals(); | ||
combinedScale = signed256(10 ** (priceFeedADecimals + priceFeedBDecimals)); | ||
|
||
if (decimals_ > 18) revert BadDecimals(); | ||
decimals = decimals_; | ||
description = description_; | ||
priceFeedScale = int256(10 ** decimals); | ||
} |
Check warning
Code scanning / Semgrep
Semgrep Finding: compound.solidity.missing-constructor-sanity-checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! 🙌
Forgot to merge this. Here is the final audit report from OZ: https://gist.github.com/antonleviathan/2938185330642deffe141f682375678b |
This generalizes the logic used in the recently audited
WBTCPriceFeed
to create aMultiplicativePriceFeed
that derives its price from multiplying the prices from two other price feeds together.This is a flexible wrapper price feed that can be used to generate prices for any asset that does not have a price feed that fits Comet's expected price denomination. e.g. if we wanted to add
cbETH
tocUSDCv3
, there is no Chainlink price feed forcbETH / USD
, so we would need to multiply thecbETH / ETH
andETH / USD
price feeds together to getcbETH / USD