# IndexerRegistry

# Overview

The IndexerRegistry contract store and track all registered Indexers and related status for these Indexers. It also provide the entry for Indexers to register, unregister, and config their metedata.

# Terminology

Indexer metadata -- The metadata of Indexer stored on IPFS include Indexer nickname, service endpoint...

# Detail

Each Indexer has two accounts: Main Account: The main account is stored in the indexer’s own wallet. The indexer can use the main account to make the following actions: - staking/unstaking - register/unregisterIndexer - set/remove a controller account - start an indexing for a query project with specific controller account

Controller Account: The controller account is set by the main account which can execute some actions on the behalf of the main account. These actions include: - reporting / updating the status of the indexing service on chain

Indexer must set a appropriate commission rate and stake enough SQT Token when registering. Indexer need to make sure all the query projects with NOT INDEXING status before unregister.

# CommissionRate

struct CommissionRate {
  uint256 era;
  uint256 valueAt;
  uint256 valueAfter;
}

# STATES

# settings

ISettings contract which stores SubQuery network contracts address

contract ISettings settings

# minimumStakingAmount

The minimum stake amount for Indexer, set by owner

uint256 minimumStakingAmount

# metadata

Indexer's metadata: indexer => metadata, if metadata = 0, no indexer

mapping(address => bytes32) metadata

# commissionRates

Delegation tax rate per indexer: indexer => commissionRate

mapping(address => struct IndexerRegistry.CommissionRate) commissionRates

# controllers

indexer's controller: indexer => controller

mapping(address => address) controllers

# EVENTS

# RegisterIndexer

Emitted when user register to an Indexer.

event RegisterIndexer(address indexer, uint256 amount, bytes32 metadata)

# UnregisterIndexer

Emitted when user unregister to an Indexer.

event UnregisterIndexer(address indexer)

# UpdateMetadata

Emitted when Indexers update their Metadata.

event UpdateMetadata(address indexer, bytes32 metadata)

# SetControllerAccount

Emitted when Indexer set the controller account.

event SetControllerAccount(address indexer, address controller)

# RemoveControllerAccount

Emitted when Indexer remove the controller account.

event RemoveControllerAccount(address indexer, address controller)

# SetCommissionRate

Emitted when Indexer set their commissionRate.

event SetCommissionRate(address indexer, uint256 amount)

MODIFIER

# onlyIndexer

only indexer can call

modifier onlyIndexer()

# FUNCTIONS

# initialize

Initialize the contract, setup the minimumStakingAmount.

function initialize(contract ISettings _settings, uint256 _minimumStakingAmount) external
Name Type Description
_settings contract ISettings ISettings contract
_minimumStakingAmount uint256

# setSettings

Update setting state.

function setSettings(contract ISettings _settings) external
Name Type Description
_settings contract ISettings ISettings contract

# setminimumStakingAmount

set the Indexer minimum staking amount only by owner.

function setminimumStakingAmount(uint256 amount) external
Name Type Description
amount uint256 new minimumStakingAmount

# registerIndexer

call to register to an Indexer, this function will interacte with staking contract to handle the Indexer first stake and commission rate setup.

function registerIndexer(uint256 amount, bytes32 _metadata, uint256 rate) external
Name Type Description
amount uint256 Indexer init staked amount(must over minimumStakingAmount)
_metadata bytes32 Indexer metadata
rate uint256 Indexer init commission rate

# unregisterIndexer

Indexer call to unregister, need to check no running indexing projects on this Indexer from ProjectRegistry contract. This function will call unstake for Indexer to make sure indexer unstaking all staked SQT Token after unregister.

function unregisterIndexer() external

# updateMetadata

Indexer call to update their Metadata.

function updateMetadata(bytes32 _metadata) external
Name Type Description
_metadata bytes32 Indexer metadata to update

# setControllerAccount

Indexers call to set the controller account, since indexer only allowed to set one controller account, we need to remove the previous controller account.

function setControllerAccount(address controller) external
Name Type Description
controller address The address of controller account, indexer to set

# removeControllerAccount

Indexers call to remove the controller account. need to remove both controllers and controllerToIndexer.

function removeControllerAccount() public

# isIndexer

Determine the address is a indexer account

function isIndexer(address _address) external view returns (bool)
Name Type Description
_address address The addree to determine is a indexer account

Return: bool -> Result of is the address is a indexer account

# getController

Get indexer's controller account

function getController(address indexer) external view returns (address)
Name Type Description
indexer address The indexer addree

Return: address -> Result of its controller

Set initial commissionRate only called by indexerRegistry contract, when indexer do registration. The commissionRate need to apply at once.

# setInitialCommissionRate

function setInitialCommissionRate(address indexer, uint256 rate) private

Set commissionRate only called by Indexer. The commissionRate need to apply at two Eras after.

# setCommissionRate

function setCommissionRate(uint256 rate) external

# getCommissionRate

function getCommissionRate(address indexer) external view returns (uint256)