Spectra Developer Docs
  • Developers Documentation
  • Getting Started
  • Guides
    • Tokenizing Yield
    • Providing Liquidity
    • Deploy PT and Curve Pool
    • Routing
    • IBT Additional Rewards
    • Locking APW for veAPW
    • Voting and Earning Rewards
  • Technical Reference
    • Deployed Contracts
    • Contract Functions
      • Principal Token
      • Yield Token
      • Registry
      • RateOracle
      • Factory
      • Access Manager
      • RouterUtil
      • Router
      • GovernanceRegistry
      • Voter
      • VotingReward
        • BribeVotingReward
        • FeesVotingReward
      • FeeDistributor
      • Spectra4626Wrapper
    • Yield Calculations
    • Spectra's Automated Market Makers
      • Rate Adjusted StableSwap pools
  • Glossary
  • INTEGRATION REFERENCE
    • Spectra Oracles
      • TWAP Oracles
      • Deterministic Oracles
        • Linear APR model
        • Linear Discount Model
        • Zero Coupon Bond Model
        • Comparison
      • Oracle Deployment
        • Deterministic Oracles Deployment
        • TWAP Oracles Deployment
Powered by GitBook
On this page
  • Base Oracle Templates
  • Chainlink Feeds
  • Creating a Spectra Oracle instance
  1. INTEGRATION REFERENCE
  2. Spectra Oracles

TWAP Oracles

PreviousSpectra OraclesNextDeterministic Oracles

Last updated 5 days ago

The TWAP oracles report an of the prices of Principal Tokens, Yield Tokens and LP tokens, quoted in either interest bearing token or underlying asset. They primarily serve as one of the pricing references for lending market integrations.

Base Oracle Templates

The BaseOracle provides the base template of Spectra TWAP oracles. It follows Chainlink's . This template takes the address of the Principal Token and the address of the underlying pool at construction. Currently, we integrate the and the AMMs from Curve.

The prices are fetched through the getRoundData() and latestRoundData() functions, both returning the latest version of the price data. The decimals() method is overriden and specifies the decimals in which the prices are quoted. The _getQuoteAmount() function is internally overriden and fetches the price data.

This template is used to create the BaseOracleCurveYT, BaseOracleCurvePT and BaseOracleCurveLP contracts, which provide templates for reporting prices of the Yield Token, the Principal Token and the LP token respectively in a quote asset. In our case, the quote asset will either be the corresponding interest bearing token or the underlying asset.

The aforementioned contracts define the virtual methods _YTPrice() , _PTPrice() and _LPTPrice() , whose role is to report the oracle price of the corresponding asset in a given quote asset. These have to be defined in the corresponding Chainlink Feed.

Chainlink Feeds

The Chainlink feeds acts as an isolated price data provider for a given base asset and a quote asset. Since we have 3 base assets to report the price of (PT, YT, LP), 2 quote assets (IBT, Underlying) and we support 2 AMMs (twocrypto-ng, stableswap-ng), we need 12 feeds.

The feeds define _YTPrice() , _PTPrice() and _LPTPrice() by making calls to the library CurveOracleLib . It also specifies the decimals of the data feed, which are the decimals of the quote asset.

This library takes care of fetching the prices from the underlying Curve pool by calling the price_oracle() method. This method implements an exponential moving average of the spot prices as given by the AMM, along with native oracle manipulation protection. For further information, we refer the reader to the

Creating a Spectra Oracle instance

To deploy a TWAP oracle instance, you must create and deploy a contract inheriting from the appropriate Chainlink feed class. For instance, to deploy a price oracle for a PrincipalToken quoted in the underlying asset within a StableSwap pool, your contract should inherit from BaseFeedCurvePTAssetSNG.

Below is an example of a mock TWAP oracle implementation designed for obtaining PrincipalToken prices quoted in the underlying asset from a StableSwap AMM.

// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.20;

import {AggregatorV3Interface} from "src/interfaces/AggregatorV3Interface.sol";
import {BaseFeedCurvePTAssetSNG} from "src/spectra-oracles/chainlinkFeeds/stableswap-ng/BaseFeedCurvePTAsset.sol";

/// @dev Mock Curve PT price feed that gives the PT price in a provided IBT/PT Curve Pool in asset
contract MockPriceFeedCurvePTAssetSNG is BaseFeedCurvePTAssetSNG {
    string public constant description = "IBT/PT Curve Pool Oracle: PT price in asset";

    /* CONSTRUCTOR
     *****************************************************************************************************************/
    /**
     * @notice Constructor for a Mock Price Feed of a Curve Pool (in asset)
     */
    constructor(address _pt, address _pool) BaseFeedCurvePTAssetSNG(_pt, _pool) {}
}

If you do not plan on defining additional logic, you can deploy Spectra's oracles through the .

exponential moving average
AggregatorV3Interface
twocrypto-ng
stableswap-ng
Curve Documentation.
Spectra Oracle Factory