Lumia L2 integrates with Supra's high-performance oracle system to provide fast, reliable price feeds through their Distributed Oracle Agreement (DORA) protocol. This guide explains how to integrate Supra oracles into your dApps on Lumia L2.
Overview
Supra provides two types of oracle implementations:
Pull Oracle: On-demand price data with sub-second response time
Push Oracle: Automated price updates with layer-1 security guarantees
This guide focuses on the Pull Oracle implementation, which gives you maximum control over when and how to fetch price data.
Integration Process
Full list of feeds:
1. Smart Contract Setup
First, create your smart contract that will receive and process oracle data:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "@openzeppelin/contracts/access/Ownable.sol";
interface ISupraOraclePull {
struct PriceData {
uint256[] pairs; // List of pairs
uint256[] prices; // prices[i] is the price of pairs[i]
uint256[] decimals; // decimals[i] is the decimals of pairs[i]
}
function verifyOracleProof(bytes calldata _bytesproof)
external
returns (PriceData memory);
}
contract SupraPriceConsumer is Ownable {
ISupraOraclePull internal oracle;
// Store latest prices
mapping(uint256 => uint256) public latestPrices;
constructor(address oracle_) Ownable(msg.sender) {
oracle = ISupraOraclePull(oracle_);
}
function deliverPriceData(bytes calldata _bytesProof)
external
onlyOwner
{
ISupraOraclePull.PriceData memory prices =
oracle.verifyOracleProof(_bytesProof);
// Store the latest prices
for (uint256 i = 0; i < prices.pairs.length; i++) {
latestPrices[prices.pairs[i]] = prices.prices[i];
}
}
function updateOracleAddress(address oracle_)
external
onlyOwner
{
oracle = ISupraOraclePull(oracle_);
}
}
2. Web2 Integration
You'll need a Node.js application to fetch price data from Supra's gRPC server and send it to your smart contract. Here's a basic implementation: