Push Oracle
Quick Start: Supra Price Feeds
Supra's Push oracle publishes price pairs on-chain regularly and at high frequencies, enabling consumers to get near real-time prices for their smart contracts. The Push oracle functions via partnerships Supra has with respective chains to share, ensuring that frequent feed updates are available for these destination chains without interruption. Both the Push model and Pull model (on demand) have the same number of data pairs offered by Supra.
Integrating with Supra price feeds is quick and easy. The price feed value published by Supra is known as an S-Value (aka Supra Value). In the following sections, we will demonstrate how to retrieve an S-Value using Supra's Push model.
Please refer to the below resources for a better understanding of our price feeds.
Data Feeds - This explains how Supra calculates the S-value for an asset.
Data Feeds Index - This provides a list of data pairs currently offered by Supra.
Available Networks - This is a list of available networks and Supra contract addresses.
Important: Please make sure you read and understand Terms of Use before start using Supra products and services.
Let's begin!
Step 1: Create the S-value interface
Import the interface from the DORA Interface (https://github.com/Entropy-Foundation/dora-interface) Git repository, and add the subdirectory Testnet you to use for integration.
Step 2: Configure the S-value feed dependency
Create your project and add the below dependencies in your Move.toml
Testnet
Mainnet
Step 3: Request S-values for data feeds
Now you can easily request S-values of any supported data pairs.
Import :
supra_oracle::supra_oracle_storage
Add the following structs
PriceConfiguration is the main resource structure for this module. It has a `feeds` map that stores the price strategy feeds. PriceStrategy represents a strategy feed entry with high, low, start time, and end time.
Next, add the `init_module function below:
This initializes the PriceConfiguration with an empty feeds vector map. Then, it shares this resource.
Add the
set_high_low
function. This function sets the high and low price of a specific pair in the PriceConfiguration. If the pair already exists, it updates the existing PriceStrategy; if not, it inserts a new PriceStrategy.
Add the following
check_price_strategy
function to retrieve Strategic Price of one pair between an interval. This public view function fetches the strategic price for a single pair thats been updated by the above functionset_high_low
.
To retrieve a S-value for multiple pairs you can design a public view function
get_pair_price_sum
that fetches prices for multiple pairs from the oracle, adds them and returns the sum.
Derived Pairs - Convert a data pair to any currency with ease
There have been many requests to provide functionality convert the prices to USD. While we take data directly from exchange quoted pairs mostly in stable coins (USDT/USDC), conversion at our end adds more latency and extra layer of margin for error. (*The oracle services who provide USD prices are already converting the USDT prices at their backend with previously mentioned disadvantages of that method). Still, for those who are in need we provide that as a custom function to convert and derive any pair using operators of Multiplication(parameter=0) or Division(Parameter=1).
Import supra_oracle::supra_oracle_storage dependency:
Next, add the `init_module function below:
Add the following get_update_derived_price
function to retrieve S-value for the derived pair. This public entry function fetches the price for a derived pair from the supra_oracle_storage module and emits an event for the Derived Pair Feed.
From the above code:
pair: a pair index number from which you want to retrieve the price value
pairs: Index numbers of multiple pairs from which you want to retrieve the price value
Tada! You now have a method in your Smart Contract that you can call at any time to retrieve the price of the selected pair.
Last updated