Price Oracle Middleware

How the price oracle middleware resolves asset prices and how to add or override a feed.

Purpose and scope

The Price Oracle Middleware system provides standardized asset valuation and conversion for the PlasmaVault ecosystem. It is centered around the PriceOracleMiddlewareWithRoles contract, which acts as a centralized price hub, and the PriceOracleMiddlewareManager, which provides a vault-specific interface for price queries and validation.

The system is responsible for:

System architecture

The architecture separates global price discovery from vault-specific price management and validation.

Logic flow and code entities

Architecture description:

  1. PlasmaVault and its Balance Fuses interact with the PriceOracleMiddlewareManager assigned to the vault contracts/vaults/PlasmaVault.sol75 (opens in new tab)
  2. The PriceOracleMiddlewareManager handles vault-specific configuration, such as custom asset sources and price validation logic stored via PriceOracleMiddlewareManagerLib contracts/managers/price/PriceOracleMiddlewareManagerLib.sol64-75 (opens in new tab)
  3. PriceOracleMiddlewareWithRoles serves as the protocol-wide price aggregator, managing specialized feeds like PtPriceFeed for Pendle tokens contracts/price_oracle/PriceOracleMiddlewareWithRoles.sol140-150 (opens in new tab)

Core components

1. PriceOracleMiddlewareWithRoles

This contract provides the "Source of Truth" for asset prices. It normalizes all outputs to 18 decimals (WAD) contracts/price_oracle/PriceOracleMiddlewareWithRoles.sol76-77 (opens in new tab)

2. PriceOracleMiddlewareManager

A per-vault manager that wraps the global middleware with validation and vault-specific overrides.

Specialized price feeds

The system supports various specialized feeds to handle complex DeFi assets.

Pendle PT Price Feed (PtPriceFeed)

Calculates the price of Pendle Principal Tokens using Pendle's TWAP oracle and the price of the underlying asset from the middleware contracts/price_oracle/price_feed/PtPriceFeed.sol12-18 (opens in new tab)

FeatureImplementation Detail
TWAP WindowMinimum 5 minutes, recommended 15 minutes contracts/price_oracle/price_feed/PtPriceFeed.sol23 (opens in new tab)
Calculation(PtToAssetRate * UnderlyingAssetPrice) / scalingFactor contracts/price_oracle/price_feed/PtPriceFeed.sol128 (opens in new tab)
MetadataReturns Chainlink-compatible latestRoundData contracts/price_oracle/price_feed/PtPriceFeed.sol109-113 (opens in new tab)

Feed factory pattern

Factories like PtPriceFeedFactory and CurveStableSwapNGPriceFeedFactory are used to deploy standardized feed instances that the middleware can then consume contracts/factory/price_feed/PtPriceFeedFactory.sol6-10 (opens in new tab)

Price validation mechanism

The validation system prevents the vault from transacting at "stale" or manipulated prices by enforcing a maximum allowed deviation.

Access control and roles

The system utilizes a hierarchy of roles defined in Roles.sol to secure configuration.

RoleEntityPermission
ADMIN_ROLEAccessManagerHighest level; manages all roles contracts/libraries/Roles.sol11-13 (opens in new tab)
ATOMIST_ROLEPlasmaVaultCan update the priceOracleMiddleware address contracts/libraries/Roles.sol44-45 (opens in new tab)
PRICE_ORACLE_MIDDLEWARE_MANAGER_ROLEPriceOracleMiddlewareManagerManages asset price sources and validation deltas contracts/libraries/Roles.sol102-105 (opens in new tab)
SET_ASSETS_PRICES_SOURCESPriceOracleMiddlewareWithRolesGlobal permission to set price sources contracts/price_oracle/PriceOracleMiddlewareWithRoles.sol27 (opens in new tab)
ADD_PT_TOKEN_PRICEPriceOracleMiddlewareWithRolesPermission to deploy Pendle PT feeds contracts/price_oracle/PriceOracleMiddlewareWithRoles.sol28 (opens in new tab)

Data normalization

All prices returned by the middleware system are normalized to 18 decimals (WAD) to ensure consistency across the IPOR Fusion protocol.

Last updated