Merkle Feeds

Merkle feeds provide a secure and efficient “pull oracle” model for accessing option prices and other financial data on Starknet.

The Pragma Consumer SDK is a powerful tool that allows developers to interact with Pragma’s Merkle Feed system. This SDK enables you to fetch option prices and their associated Merkle proofs, which you can then use with the Pragma Oracle contract to access on-chain data.

What is a Merkle Feed?

A Merkle Feed is an efficient way to publish and verify large amounts of data on-chain while minimizing gas costs.

In Pragma’s case, we publish a Merkle root on-chain that represents a tree of option prices for a specific blockchain height. Users can then use our SDK to retrieve prices off-chain and verify their correctness on-chain, creating a secure and efficient “pull oracle” model.

How It Works

1

Data Sourcing

The merkle trees are built with data from Deribit, the leading platform for options trading.

2

On-chain Publishing

Merkle root is published on-chain every block, ensuring data freshness.

3

Off-chain Retrieval

Merkle proofs with associated data can be retrieved through REST and WebSocket endpoints or through a Rust crate we provide.

4

On-demand Updates

Data is updated on-demand on-chain upon successful verification of the merkle proof.

Key Features

Easy Integration

Easy-to-use Rust SDK for seamless integration

Network Support

Supports both mainnet and testnet environments

Flexible Retrieval

Flexible block selection for data retrieval

Real-time Data

Access to real-time option pricing data

Usage

To start using the Pragma Consumer SDK in your Rust project:

1. Add the SDK to your Cargo.toml

[dependencies]
pragma-consumer = "0.1.0"

2. Initialize the Consumer in your code

let api_config = ApiConfig {
    base_url: PragmaBaseUrl::Prod,
    api_key: "your_api_key".into(),
};

let consumer = PragmaConsumerBuilder::new()
    .on_mainnet()
    .with_http(api_config)
    .await?;

3. Fetch Merkle Feed data

let instrument = instrument!("BTC-16AUG24-52000-P");
let merkle_feed_calldata = consumer
    .get_merkle_feed_calldata(&instrument, None)
    .await?;

4. Use the result to update the data on-chain

Next steps