Skip to main content

currentPrice

Contract: JBChainlinkV3PriceFeed​‌

Interface: IJBPriceFeed

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

  1. 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:

  2. 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:

  3. 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: