BounceBit Documentation
HomepagePortalBounceClub
  • 🔳Welcome to BounceBit
    • BounceBit's Philosophy
    • Challenges Addressed By BounceBit
    • BounceClub: Build on BounceBit
  • CeDeFi
    • 🏦BounceBit CeFi + DeFi
      • Infrastructure
      • Yield Structure
    • 📊CeDeFi Yield
      • Funding Rate Arbitrage
      • Fixed
      • Auto
      • Manual
      • Integration of Node Staking Rewards
      • Rebasing Mechanism
      • Asset Manager Directory
    • 🌎RWA (Real World Assets)
      • RWA in Yield Generation
      • RWA on BounceBit Chain
    • Subscription & Redemption Rules
      • Auto & Manual
      • Fixed
    • Security Risk Management
    • dApp
      • ⚡Superfast
      • Ethena <> BounceBit
      • Convert
  • Infrastructure
    • ⛓️BounceBit PoS Chain
      • Dual-Token Staking Consensus
      • EVM Compatibility and Developer Support
    • 🔐Shared Security Clients
    • 🌉BTC Bridge
    • 🔮Oracle
      • Price Feed On-chain
      • Price Feed Off-chain
      • Data Feed Addresses
    • 💽Ecosystem Integrations
  • ♣️BounceClub
    • Intro
    • 🫂BounceClub Membership
    • MEME
    • Quanto
    • AI Agents
  • Token
    • 🏦BounceBit Tokenomics
      • Key Terms
      • 🪙BB Coin
      • Liquid Staking Token (stBBTC & stBB)
      • Bitcoin on BounceBit (BBTC)
      • Stablecoins on BounceBit (BBUSD)
    • 🧱Staking Delegation
    • 💧Liquid Staking
    • 📤Liquid Custody
    • 🍞Bread and Butter (BB Cross-chain Liquidity)
  • User Guides
    • General
      • How to Get BTCB from Binance
        • How to Transfer BTCB to your Binance Web3 Wallet
      • How to Use the Testnet Faucet
      • How to Add BounceBit Network to Your Wallet
    • 🌉Bridging
      • Portal Bridge
      • MultiBit Bridge
    • BounceClub V2
      • How to Launch a Memecoin
      • Arcade
      • DeFi
        • Quanto
        • Stablecoin
      • AI Agents
    • 📊CeDeFi
      • How to Withdraw/Redeem Your LCT
      • How to Subscribe to CeDeFi (V2)
      • How to Unsubscribe from CeDeFi (V2)
      • How to Wrap / How to get BBTC, BBUSD
      • Ethena <> BounceBit
      • Superfast Trading Guide
    • 💠Node Staking and Delegation
      • How to Stake/Unstake on Portal
      • How to Stake/Unstake BB and BBTC (Delegation)
  • Assets
    • 🪪Brand Guidelines
      • 🎨Logo Kit
    • ✅BounceBit's TVL
    • ✅Smart Contract Audit Report
    • First BounceBit's BTC TVL Audit Report
  • Developer Resources
    • BounceBit Mainnet Node Setup
      • Cosmovisor
    • Chain Info
    • RPC Support
    • How to Verify Smart Contracts
    • How to Withdraw Validator Commission
  • OTHER
    • 🌐BounceBit Official Social Media Channels
    • Terms of Use
    • Privacy Policy
Powered by GitBook
On this page
  1. Infrastructure
  2. Oracle

Price Feed On-chain

PreviousOracleNextPrice Feed Off-chain

Last updated 11 months ago

Bracle Price feeds continuously stream price updates to blockchains, with each feed stored within a smart contract. Application developers can easily pass these contracts on their own, then deserialize the data to read the current feed value. Bracle Price Feeds also offer a "pull" model for price updates, where users are responsible for posting updates to the chain as needed. For more information on this model and its implications for integrators, refer to . In the pull model, developers should integrate Bracle into both their on-chain and off-chain code:

  • On-chain programs should read prices from the Bracle program deployed on the same chain.

Bracle provides BounceBit-specific SDK to assist with the integration process, both on-chain and off-chain. The simplest way to utilize Bracle price feeds is to integrate the relevant SDKs into your application."

Reading data feeds on-chain

To consume price data, your smart contract should reference IAggregator.sol, which defines the external functions implemented by Data Feeds.

IAggregator.sol

// SPDX-License-Identifier: LGPL-3.0
pragma solidity 0.8.20;

interface IAggregator {
  /**
   * @notice median from the most recent report
   */
  function latestAnswer() external view returns (int256);

  /**
   * @notice timestamp of block in which last report was transmitted
   */
  function latestTimestamp() external view returns (uint256);

  /**
   * @notice Aggregator round (NOT OCR round) in which last report was transmitted
   */
  function latestRound() external view returns (uint256);

  /**
   * @notice median of report from given aggregator round (NOT OCR round)
   * @param _roundId the aggregator round of the target report
   */
  function getAnswer(uint256 _roundId) external view returns (int256);

  /**
   * @notice timestamp of block in which report from given aggregator round was transmitted
   * @param _roundId aggregator round (NOT OCR round) of target report
   */
  function getTimestamp(uint256 _roundId) external view returns (uint256);

  /**
   * @return answers are stored in fixed-point format, with this many digits of precision
   */
  function decimals() external view returns (uint8);

  /**
   * @notice human-readable description of observable this contract is reporting on
   */
  function description() external view returns (string memory);

  /**
   * @notice aggregator contract version
   */
  function version() external view returns (uint256);

  /**
   * @notice details for the given aggregator round
   * @param _roundId target aggregator round (NOT OCR round). Must fit in uint32
   * @return roundId _roundId
   * @return answer median of report from given _roundId
   * @return startedAt timestamp of block in which report from given _roundId was transmitted
   * @return updatedAt timestamp of block in which report from given _roundId was transmitted
   * @return answeredInRound _roundId
   */
  function getRoundData(
    uint80 _roundId
  ) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

  /**
   * @notice aggregator details for the most recently transmitted report
   * @return roundId aggregator round of latest report (NOT OCR round)
   * @return answer median of latest report
   * @return startedAt timestamp of block containing latest report
   * @return updatedAt timestamp of block containing latest report
   * @return answeredInRound aggregator round of latest report
   */
  function latestRoundData()
    external
    view
    returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}

Example

// SPDX-License-Identifier: LGPL-3.0
pragma solidity 0.8.20;

import {IAggregator} from "../interfaces/IAggregator.sol";

/**
 * THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED
 * VALUES FOR CLARITY.
 * THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
 * DO NOT USE THIS CODE IN PRODUCTION.
 */
contract DataConsumer {
    IAggregator internal dataFeed;

    /**
     * Network: BounceBit
     * Aggregator: BBTC/USD
     * Address: 0xf136f4Af2F431034C8803C4c892609292D915A46
     */
    constructor() {
        dataFeed = IAggregator(
            0xf136f4Af2F431034C8803C4c892609292D915A46
        );
    }

    /**
     * Returns the latest answer.
     */
    function getBracleDataFeedLatestAnswer() public view returns (int) {
        // prettier-ignore
        (
            /* uint80 roundID */,
            int answer,
            /*uint startedAt*/,
            /*uint timeStamp*/,
            /*uint80 answeredInRound*/
        ) = dataFeed.latestRoundData();
        return answer;
    }
}

🔮
Bracles documentation