-
Notifications
You must be signed in to change notification settings - Fork 0
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
Proposal for Mantle USDe market #85
base: main
Are you sure you want to change the base?
Changes from 24 commits
f9bcb26
b6697bc
74b436b
6e4a0d7
9fbe1b2
ed0dde2
6433f55
7fb3137
2205595
45dab4c
4f97f07
4462c80
62d748b
fccd37c
d833496
f2ce5fa
5ec3b62
4a3a857
782522d
c07ada8
15c7f58
d15c67d
ca9253a
fe24058
f9a86e1
197dc91
e862fb9
34e4ab9
739c6df
2f2257a
0129b6c
39b1986
0a13d2f
d70364b
9085b8a
d34ec5f
32be792
86bc48d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.15; | ||
|
||
import "../vendor/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | ||
import "../IPriceFeed.sol"; | ||
|
||
/** | ||
* @title Scaling price feed | ||
* @notice A custom price feed that scales up or down the price received from an underlying price feed and returns the result | ||
* @author Compound | ||
*/ | ||
contract ScalingPriceFeedWithCustomDescription is IPriceFeed { | ||
/** Custom errors **/ | ||
error InvalidInt256(); | ||
|
||
/// @notice Version of the price feed | ||
uint public constant override version = 1; | ||
|
||
/// @notice Description of the price feed | ||
string public description; | ||
|
||
/// @notice Number of decimals for returned prices | ||
uint8 public immutable override decimals; | ||
|
||
/// @notice Underlying price feed where prices are fetched from | ||
address public immutable underlyingPriceFeed; | ||
|
||
/// @notice Whether or not the price should be upscaled | ||
bool internal immutable shouldUpscale; | ||
|
||
/// @notice The amount to upscale or downscale the price by | ||
int256 internal immutable rescaleFactor; | ||
|
||
/** | ||
* @notice Construct a new scaling price feed | ||
* @param underlyingPriceFeed_ The address of the underlying price feed to fetch prices from | ||
* @param decimals_ The number of decimals for the returned prices | ||
**/ | ||
constructor(address underlyingPriceFeed_, uint8 decimals_, string memory description_) { | ||
underlyingPriceFeed = underlyingPriceFeed_; | ||
decimals = decimals_; | ||
description = description_; | ||
|
||
uint8 underlyingPriceFeedDecimals = AggregatorV3Interface(underlyingPriceFeed_).decimals(); | ||
// Note: Solidity does not allow setting immutables in if/else statements | ||
shouldUpscale = underlyingPriceFeedDecimals < decimals_ ? true : false; | ||
rescaleFactor = (shouldUpscale | ||
? signed256(10 ** (decimals_ - underlyingPriceFeedDecimals)) | ||
: signed256(10 ** (underlyingPriceFeedDecimals - decimals_)) | ||
); | ||
} | ||
Comment on lines
+39
to
+51
Check warning Code scanning / Semgrep OSS There're no sanity checks for the constructor argument decimals_. Warning
There're no sanity checks for the constructor argument decimals_.
Comment on lines
+39
to
+51
Check warning Code scanning / Semgrep OSS There're no sanity checks for the constructor argument description_. Warning
There're no sanity checks for the constructor argument description_.
Comment on lines
+39
to
+51
Check warning Code scanning / Semgrep OSS There're no sanity checks for the constructor argument underlyingPriceFeed_. Warning
There're no sanity checks for the constructor argument underlyingPriceFeed_.
Comment on lines
+39
to
+51
Check warning Code scanning / Semgrep OSS Consider making costructor payable to save gas. Warning
Consider making costructor payable to save gas.
|
||
|
||
/** | ||
* @notice Price for the latest round | ||
* @return roundId Round id from the underlying price feed | ||
* @return answer Latest price for the asset in terms of ETH | ||
* @return startedAt Timestamp when the round was started; passed on from underlying price feed | ||
* @return updatedAt Timestamp when the round was last updated; passed on from underlying price feed | ||
* @return answeredInRound Round id in which the answer was computed; passed on from underlying price feed | ||
**/ | ||
function latestRoundData() override external view returns ( | ||
uint80 roundId, | ||
int256 answer, | ||
uint256 startedAt, | ||
uint256 updatedAt, | ||
uint80 answeredInRound | ||
) { | ||
(uint80 roundId_, int256 price, uint256 startedAt_, uint256 updatedAt_, uint80 answeredInRound_) = AggregatorV3Interface(underlyingPriceFeed).latestRoundData(); | ||
return (roundId_, scalePrice(price), startedAt_, updatedAt_, answeredInRound_); | ||
} | ||
|
||
function signed256(uint256 n) internal pure returns (int256) { | ||
if (n > uint256(type(int256).max)) revert InvalidInt256(); | ||
return int256(n); | ||
} | ||
|
||
function scalePrice(int256 price) internal view returns (int256) { | ||
int256 scaledPrice; | ||
if (shouldUpscale) { | ||
scaledPrice = price * rescaleFactor; | ||
} else { | ||
scaledPrice = price / rescaleFactor; | ||
} | ||
return scaledPrice; | ||
} | ||
} |
Check warning
Code scanning / Semgrep OSS
A constant name is not in UPPER_CASE like other constant variables. Warning