Skip to content
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

New Price Feeds #29

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions contracts/IRateProvider.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

interface IRateProvider {
function getRate() external view returns (uint256);
}
5 changes: 1 addition & 4 deletions contracts/pricefeeds/RateBasedScalingPriceFeed.sol
Original file line number Diff line number Diff line change
@@ -3,10 +3,7 @@

import "../vendor/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "../IPriceFeed.sol";

interface IRateProvider {
function getRate() external view returns (uint256);
}
import "../IRateProvider.sol";

/**
* @title Scaling price feed for rate based oracles
@@ -18,7 +15,7 @@
error InvalidInt256();

/// @notice Version of the price feed
uint public constant override version = 1;

Check notice

Code scanning / Semgrep OSS

Semgrep Finding: compound.solidity.constant-not-in-uppercase Note

A constant name is not in UPPER_CASE like other constant variables.

/// @notice Description of the price feed
string public description;
@@ -40,19 +37,19 @@
* @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_, uint8 underlyingDecimals_, string memory description_) {
underlyingPriceFeed = underlyingPriceFeed_;
decimals = decimals_;
description = description_;

uint8 priceFeedDecimals = underlyingDecimals_;
// Note: Solidity does not allow setting immutables in if/else statements
shouldUpscale = priceFeedDecimals < decimals_ ? true : false;
rescaleFactor = (shouldUpscale
? signed256(10 ** (decimals_ - priceFeedDecimals))
: signed256(10 ** (priceFeedDecimals - decimals_))
);
}

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_.

Check warning

Code scanning / Semgrep OSS

There're no sanity checks for the constructor argument underlyingDecimals_. Warning

There're no sanity checks for the constructor argument underlyingDecimals_.

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_.

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: compound.solidity.missing-constructor-sanity-checks Warning

There're no sanity checks for the constructor argument underlyingPriceFeed_.

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
@@ -69,7 +66,7 @@
uint256 updatedAt,
uint80 answeredInRound
) {
uint256 rate = IRateProvider(underlyingPriceFeed).getRate();

Check failure

Code scanning / Semgrep OSS

Semgrep Finding: rules.solidity.security.balancer-readonly-reentrancy-getrate Error

IRateProvider(underlyingPriceFeed).getRate() call on a Balancer pool is not protected from the read-only reentrancy.
return (roundId, scalePrice(int256(rate)), startedAt, updatedAt, answeredInRound);
}

Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
pragma solidity 0.8.15;

import "../vendor/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "../vendor/kelp/IrsETHOracle.sol";
import "../vendor/kelp/ILRTOracle.sol";
import "../IPriceFeed.sol";

/**
@@ -10,12 +10,12 @@
* @notice A custom price feed that scales up or down the price received from an underlying Kelp price feed and returns the result
* @author Compound
*/
contract rsETHScalingPriceFeed is IPriceFeed {

Check warning on line 13 in contracts/pricefeeds/RsETHScalingPriceFeed.sol

GitHub Actions / Contract linter

Contract name must be in CamelCase
/** Custom errors **/
error InvalidInt256();

/// @notice Version of the price feed
uint public constant override version = 1;

Check notice

Code scanning / Semgrep OSS

Semgrep Finding: compound.solidity.constant-not-in-uppercase Note

A constant name is not in UPPER_CASE like other constant variables.

/// @notice Description of the price feed
string public description;
@@ -37,19 +37,19 @@
* @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 kelpPriceFeedDecimals = 18;
uint8 underlyingPriceFeedDecimals = 18;
// Note: Solidity does not allow setting immutables in if/else statements
shouldUpscale = kelpPriceFeedDecimals < decimals_ ? true : false;
shouldUpscale = underlyingPriceFeedDecimals < decimals_ ? true : false;
rescaleFactor = (shouldUpscale
? signed256(10 ** (decimals_ - kelpPriceFeedDecimals))
: signed256(10 ** (kelpPriceFeedDecimals - decimals_))
? signed256(10 ** (decimals_ - underlyingPriceFeedDecimals))
: signed256(10 ** (underlyingPriceFeedDecimals - decimals_))
);
}

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_.

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_.

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: compound.solidity.missing-constructor-sanity-checks Warning

There're no sanity checks for the constructor argument underlyingPriceFeed_.

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
@@ -66,7 +66,7 @@
uint256 updatedAt,
uint80 answeredInRound
) {
int256 price = int256(IrsETHOracle(underlyingPriceFeed).rsETHPrice());
int256 price = int256(ILRTOracle(underlyingPriceFeed).rsETHPrice());
return (roundId, scalePrice(price), startedAt, updatedAt, answeredInRound);
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

interface IrsETHOracle {
interface ILRTOracle {
function rsETHPrice() external view returns (uint256);
}