Read on-chain Indices

Reading index values is permissionless in Supra L1. Any user or dApp can calculate and read the latest values of any index available in Supra. While calculations would require gas, reading is free.

Step 1: Create The Supra Indices Framework.

Import interface from https://github.com/Entropy-Foundation/dora-interface git repository and add subdirectory mainnet or testnet whatever you would like 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

[dependencies]
core = { git = "https://github.com/Entropy-Foundation/dora-interface", subdir = "supra/testnet/core", rev = "master" }

Step 3: Example to access and use the S-Value Crypto Price

3.1 Supported Indices

Now you can simply access the Index-Value of our supported indices.

  • Import supra_oracle::supra_oracle_indices

use aptos_std::table::{Self, Table};
use supra_oracle::supra_oracle_indices;
  • Add the following structs &#xNAN;IndicesList is the main resource structure for this module. It has a `list` map that lists object addresses of all indices.

  • Next, add the `init_module function below: This initializes the IndicesList with an empty list map.

  • Add the store_index_object_address function. This function stores the index object address that corresponds to the index id.

Calculating the latest value of the index

To calculate and retrieve the value of multiple indices on Supra L1 , the client smart contract module can trigger following function:

  • index_objects : List of index object addresses for which you need to calculate the index values.

  • Return: Vector of Index Values corresponding to the index_objects

NOTE: When this function is triggered the storage is going to get updated* with the latest calculated index values.

*if the most recent timestamp from the constituent pair timestamps is greater than the current index timestamp.

Reading the index value

Method 1 : Without considering the timestamp of the last index update

Returns the Index details with the value that's present in the storage:

  • index_object : Index object address for which you need to fetch the index details

  • Return: Vector of Index details for corresponding to the index_object

Method 2 : Fetch the index value that can only sustain/tolerate a specific stateless period

Check if the index last calculated time falls into the staleness duration then it will simply return the value from the storage else It recalculates the index value, and if the index still falls into the staleness duration it returns either true or false:

Example:

  • Return: Vector of Index Values corresponding to the index_objects, Vector of bool that tells whether the index calculated time falls under the statelessness tolerance or not corresponding to the index_objects

NOTE: When this function is triggered the storage is going to get updated* with the latest calculated index values. &#xNAN;*if the most recent timestamp from the constituent pair timestamps is greater than the current index timestamp.

Last updated