Read on-chain Indices
Last updated
Last updated
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.
Important: Please make sure you read and understand before start using Supra products and services.
Import interface from git repository and add subdirectory mainnet or testnet whatever you would like to use for integration.
Create your project and add the below dependencies in your Move.toml
Testnet
Now you can simply access the Index-Value of our supported indices.
Import 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.
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.
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
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.