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()
} {
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
]
}DEX-based TWAP Price Oracle
Last updated