currentPrice
Contract: JBChainlinkV3PriceFeed
Interface: IJBPriceFeed
- Step by step
- Code
- Bug bounty
Gets the current price from the feed, normalized to the specified number of decimals.
Definition
function currentPrice(uint256 _decimals) external view override returns (uint256) { ... }
- Arguments:
_decimals
is the number of decimals the returned fixed point price should include.
- The view function can be accessed externally by anyone.
- The view function does not alter state on the blockchain.
- The function overrides a function definition from the
IJBPriceFeed
interface. - The function returns the current price of the feed, as a fixed point number with the specified number of decimals.
Body
-
Get the latest price being reported by the price feed. The
latestRoundData
function returns several feed parameters, but only the_price
is needed.// Get the latest round information. Only need the price is needed.
(, int256 _price, , , ) = feed.latestRoundData();Internal references:
External references:
-
Get the number of decimals being reported by the price feed that the provided price is expected to have.
// Get a reference to the number of decimals the feed uses.
uint256 _feedDecimals = feed.decimals();Internal references:
External references:
-
Return the fixed point price after normalizing the value to the desired number of decimals.
// Return the price, adjusted to the target decimals.
return uint256(_price).adjustDecimals(_feedDecimals, _decimals);Library references:
JBFixedPointNumber
.adjustDecimals(...)
/**
@notice
Gets the current price from the feed, normalized to the specified number of decimals.
@param _decimals The number of decimals the returned fixed point price should include.
@return The current price of the feed, as a fixed point number with the specified number of decimals.
*/
function currentPrice(uint256 _decimals) external view override returns (uint256) {
// Get the latest round information. Only need the price is needed.
(, int256 _price, , , ) = feed.latestRoundData();
// Get a reference to the number of decimals the feed uses.
uint256 _feedDecimals = feed.decimals();
// Return the price, adjusted to the target decimals.
return uint256(_price).adjustDecimals(_feedDecimals, _decimals);
}
Category | Description | Reward |
---|---|---|
Optimization | Help make this operation more efficient. | 0.5ETH |
Low severity | Identify a vulnerability in this operation that could lead to an inconvenience for a user of the protocol or for a protocol developer. | 1ETH |
High severity | Identify a vulnerability in this operation that could lead to data corruption or loss of funds. | 5+ETH |