Increment
  • 🍀OVERVIEW
    • Background
  • 🌊Protocols
    • 💱Decentralized Exchange
      • CPAMM DEX
        • User Guidance
        • AMM 101
        • Deployment Addresses
      • Stableswap DEX
        • Introduction
        • User Guidance
        • Deployment Addresses
      • DEX Aggregator
      • Smart Contract API
      • Token Listing
      • Security
    • 🏦Decentralized Money Market
      • User Guidance
      • Deployment Addresses
      • Interest Rate Model
      • Market Parameter
      • Liquidation
      • Governance
      • Security
    • 🔮Decentralized Price Feed (Oracle)
      • Architecture
      • Deployment Addresses
      • Using Price Feeds
      • Apply as Feeder
    • 👨‍🌾Liquidity Mining (Farm)
      • Token Farm
        • Deployment Addresses
      • NFT Farm
        • Deployment Addresses
    • 💧Liquid Staking
      • User Guidance
      • Deployment Addresses
      • Use stFlow
      • Protocol Overview
        • stFlow token
        • Protocol Epoch
        • Delegation Strategy
      • FAQ
      • Node Registration
      • Security
    • ✨Points
      • 📐Rules
      • 📄Terms
  • 💦Miscs
    • 📊Metrics
    • 📚Tutorials
    • 🛡️Security Audits
    • 🐛Bug Bounty
    • 🖼️Brand Assets
    • 🕸️Decentralized Web
    • 📄Term of Service
    • 📄Privacy Policy
  • 🌐Socials
    • 🐦 Twitter
    • 🤖️ Discord
    • 📚 Medium
    • ✈️ Telegram
Powered by GitBook
On this page
  • Get all supported price feeds and their addresses
  • Get latest result and update time
  • DEX-based TWAP Price Oracle
  1. Protocols
  2. Decentralized Price Feed (Oracle)

Using Price Feeds

Get all supported price feeds and their addresses

import PublicPriceOracle from 0xAddress

// oracleAddress => oracleTag
pub fun main(): {Address: String} {
    return PublicPriceOracle.getAllSupportedOracles()
}

Sample result:

{
    0xf5d12412c09d2470	:    "USDC/USD"
    0xe385412159992e11	:    "FLOW/USD"
    0x1a9caf561de25a86	:    "FUSD/USD"
    0x031dabc5ba1d2932	:    "stFlow/USD"
    0x11b69dcfd16724af	:    "BLT/USD"
    0x07e2f8fc48632ece	:    "USDT/USD"
}

Get latest result and update time

import PublicPriceOracle from 0xAddress

pub fun main(oracle: Address): [UFix64] {
    let lastResult = PublicPriceOracle.getLatestPrice(oracleAddr: oracle)
    let lastBlockNum = PublicPriceOracle.getLatestBlockHeight(oracleAddr: oracle)
    // Get block timestamp does not always work: the # of recent blocks cached and servicable are depending on execution nodes. 
    let lastTimestamp = getBlock(at: lastBlockNum)?.timestamp
    return [
        lastResult,
        UFix64(lastBlockNum),
        lastTimestamp ?? 0.0
    ]
}

Sample result for "Flow/USD" price feed:

[0.58717715, 57835057.00000000, 1690794621.00000000]

Note that:

  • The data is updated whichever condition is met first:

    • Deviation is beyond certain threshold (by default 0.5%)

    • A fixed window of time has passed (by default 2000 blocks)

  • Users of the PublicPriceOracle need to check the latest update time and handle the extreme condition if this data is too old.

DEX-based TWAP Price Oracle

PreviousDeployment AddressesNextApply as Feeder

Last updated 1 year ago

We recommend to use , as the block timestamp is not accurate or not always retrievable: the number of recent blocks cached and servicable are depending on execution nodes.

Check examples .

🌊
🔮
blockHeight
here