Index Contract

Index Contract

interface

pragma solidity ^0.6.7;
interface Index {
  event AddIndex(uint256 _indexNo, bool _isOpen, uint256 _initIndexPrice);
  event UpdateIndex(uint256 _indexNo, bool _isOpen);
  event ExecuteOracleTimeClock(address new_oracle);
  event SetOracleTimeClock(address _newOracleAddr, uint256 oracleUpdateAt);
  function batchIndexPrice(uint256[] calldata _indexNoArr) external view returns (uint256[] memory _prices);
  function getIndexPrice(uint256 _indexNo) public view returns (uint256 _indexPrice);
  function indexLength() external view returns (uint256);
  function getIndex(uint256 _indexNo) external view
    returns (address[] memory tokens,uint8[] memory weights,uint256[] memory circleSupply,uint256 k,bool isOpen);
  function isIndexOpen(uint256 _indexNo) external view returns (bool);
}

Index price is calculated by the price and liquidity of multiple coins, and the price formula is =(Token0 price* Token0 circle supply + Token1 price* Token 1 circle supply)/K The value of K is determined when the index is generated and remains unchanged after it is generated. After the index is generated, the liquidity of each token remains unchanged, except that the token price fluctuates. The price of a single token is get from the oracle, and different oracle are connected to ensure the accuracy of the price.

events

  • UpdateIndex(uint256 _indexNo, bool _isOpen) The index status is on or off.

  • AddIndex(uint256 _indexNo, bool _isOpen,uint256 _initIndexPrice) add new index.

  • SetOracleTimeClock(address _newOracleAddr, uint256 oracleUpdateAt) Execute the new oracle,and it can be enabled after 7 days.

  • ExecuteOracleTimeClock(address new_oracle) Switch to the new oracle.

Methods(Read Contract)

1. batchIndexPrice

function batchIndexPrice(uint256[] calldata _indexNoArr) external view returns (uint256[] memory _prices)

batch get index price

param
type
description

_indexNoArr

uint256[]

indexNo array

return
type
description

_prices

uint256[]

price array

2. getIndexPrice

function getIndexPrice(uint256 _indexNo) public view returns (uint256 _indexPrice)

get index price

param
type
description

_indexNo

uint256

indexNo

return
type
description

_price

uint256

price

3. indexLength

function indexLength() external view returns (uint256)

get index array length

param
type
description

length

uint256

index length

4. isIndexOpen

function isIndexOpen(uint256 _indexNo) external view returns (bool)

isset index is open

param
type
description

indexNo

uint256

indexNo

return
type
description

isOpen

bool

index is open

5. getIndex

function getIndex(uint256 _indexNo) external view returns ( address[] memory tokens, uint8[] memory weights, uint256[] memory circleSupply, uint256 k, bool isOpen )

** get Index tokens and weight,circleSupply **

param
type
description

indexNo

uint256

indexNo

return
type
description

tokens

address[]

index tokens

weights

uint256[]

weight of tokens

circleSupply

uint256[]

circly supply of tokens

isOpen

bool

index open status

Last updated