Creating a new on-chain index
Important: Please make sure you read and understand Terms of Use before start using Supra products and services.
Supra Index Contracts
Below contracts facilitate index creation and modification on Supra L1.
Testnet
0x5615001f63d3223f194498787647bb6f8d37b8d1e6773c00dcdd894079e56190
Mainnet
0xe3948c9e3a24c51c4006ef2acc44606055117d021158f320062df099c4a94150
Creating an Index on Supra L1
The first step of the process is to decide the assets you want to be included in the index, these can be selected from Supra Data feeds catalog.
Next, you can decide on the index related variables given below:
Asset Weight : This defines how each asset contributes to the calculation of index value. Currently Supra facilitates static weights only.
Initial Value:= This is optional. This is the value your index would start on at the time of creation.
Now, let's move to create your first on-chain index.
Indices with no initial Value
The simplest form of creating an index would be without an initial value. In this case you need to call the following function,
pair_ids is the list of pair indexes from the data sheet provided above.
weights is the list of integers that denotes the corresponding weights of the pair from the list provided in the params pair_ids.
If we are creating an index with an equally weighted set of 10 data feeds from Supra (denoted by Supra Data feed index number), it would be as follows.
Indices with initial value
In this case you need to call the following function
pair_ids is the list of pair indexes from the data sheet provided above.
weights is the list of integers that denotes the corresponding weights of the pair from the list provided in the params pair_ids.
init_value is the initial value of the index thats the creator wants to start with.
If we are to try the same example above with an initial value of 100, it would be as follows:.
In this case the actual weights are converted to scaled weight according to a scaling factor mentioned below.
Scaling Factor = init_value / dot_product(init_weights,price_pair_values);
This conversion is done so that the index_value can be adjusted with the init_value.
Upon successful execution of creating an index function you will get this kind of receipt and in the data section you can find the fields like:
NOTE :
All the weights and intermediary values are converted to MAX_INDEX_DECIMAL decimals before doing any operations on them. This is done to make sure there are very low precision errors.
Index values have MAX_INDEX_DECIMAL decimal places, so make sure to convert to desired decimals before doing any operations on them.
Modifying an Index
To update the constituents pairs or or its weight or to modify the the pair list the index creator need to call this function:
index_object is the address of the object in which the index details is stored.
pair_ids is the list of pair indexes from the data sheet provided above.
weights is the list of integers that denotes the corresponding weights of the pair from the list provided in the params pair_ids.
Example;
Note: The Scaling Factor will remain the same and the new weights will be adjusted to the scaled weights according to the scaling factor calculated at the time of creation
Deleting an Index
To delete an index, the index creator needs to call this function. Once deleted, the index cannot be restored back.
Note: index_object is the address of the object in which the index details is stored. Example;
Last updated