Commit 53b1fc9
committed
feat(oracle): Introduce robust and secure IPriceFeed infrastructure
This commit finalizes the core components of the Baobab Protocol's decentralized oracle infrastructure, migrating to a unified `IPriceFeed` interface across all data sources (Chainlink, Pyth, Computed Feeds, and TWAP).
The central goal is to enhance manipulation resistance, data consistency, and security through a multi-layered validation approach enforced by the new `BaobabOracleSecurity` contract.
### Key Features and Changes:
1. **BaobabOracleSecurity Integration:**
- Implements a central security gateway (`getValidatedPrice`) enforcing sequential checks: Circuit Breakers, Global Pause, Global Staleness (`maxStalenessPeriod`), and contextual risk-based Confidence checks (`PriceUse`).
- **Refinement:** Streamlined price fetching to rely solely on the `OracleRegistry` output, eliminating redundant internal calls and improving gas efficiency.
2. **OracleRegistry Role:**
- Relies on the core `OracleRegistry` to manage asset configuration (Primary/Fallback feeds) and enforce internal heartbeat/staleness logic before data is passed to the Security layer.
- The Registry acts as the sole source of data for the `BaobabOracleSecurity` layer.
3. **ComputedOracle (Derived Prices):**
- Introduced a system for deriving secondary asset prices (e.g., ETH/BTC) via multiplication or division of two base feeds.
- **Security Fix:** Updated `latestTimestamp()` logic to return the **oldest** component timestamp, preventing the computed price from falsely appearing "fresh" when an underlying feed is stale.
- **Refinement:** Optimized fixed-point division math for gas efficiency while preserving 8-decimal output precision.
4. **Oracle Adapters (Chainlink & Pyth):**
- Created `ChainlinkAdapter` and `PythAdapter` to strictly conform to the `IPriceFeed` interface.
- **Consistency:** Standardized output to 8 decimals for Pyth by implementing a robust `_scalePrice` helper that handles variable exponents.
- **Efficiency:** Refactored all adapters to ensure only a single external call is made per price query, drastically reducing transaction gas costs.
- **Fail Safe:** Ensured adapters return the sentinel value (`type(int256).min`) on any failure (call revert, stale data, non-positive price).
5. **TWAPAdapter (Manipulation Resistance):**
- Implemented a Time-Weighted Average Price (TWAP) adapter used for sensitive actions, sourcing only validated prices from `BaobabOracleSecurity`.
- **Security Principle:** The price pushing mechanism is permissionless to decentralize maintenance cost and increase data freshness.
- **Note on Pruning:** Identified gas-inefficiency in the current `_shiftLeft` array pruning method; marked for future refactor to a Ring/Circular Buffer structure for superior scalability.1 parent b3772f1 commit 53b1fc9
1 file changed
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
159 | | - | |
| 160 | + | |
160 | 161 | | |
161 | 162 | | |
162 | | - | |
| 163 | + | |
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
| |||
0 commit comments