Supra

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

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:

3. Contract Deployment

Deploy your contract using your preferred method (Hardhat, Truffle, etc.) with the appropriate Supra Oracle address:

Lumia Mainnet

Best Practices

  1. Error Handling

  1. Price Validation

  1. Update Frequency

  • Consider implementing a minimum time between updates

  • Use price deviation thresholds to optimize gas costs

  • implement redundancy in your web2 infrastructure

Technical Specifications

  • Response Time: Sub-second for pull oracle

  • Data Sources: 40+ sources aggregated

  • Security: Byzantine Fault Tolerant consensus with DORA

  • Price Calculation: Median-of-medians with coherent cluster validation

  • Update Frequency: Customizable (recommended: 1-5 minutes)

  • Gas Optimization: Batch price updates supported

Support & Resources

Last updated

Was this helpful?