Cluster Marketplace

Introduction

This document represents the specification for the cluster registry various clusters for the network are registered.

Data Structures

Type aliases

Name Type Description Example
MIN_CLUSTER_STAKE uint256 Minimum amount of stake for a cluster to register TBD
CLUSTER_EXIT_WAIT_EPOCHS uint256 Wait time to withdraw a cluster
clusterId uit256 Unique id for the cluster

ClusterData

This data structure provides the details regarding the cluster.

struct ClusterData {
    uint256 status;
    uint256 stake;
    uint256 startEpoch;
    uint256 exitEpoch;
}

Storage

ClusterMap

ClusterData for various clusters is stored as part of the clusterMap.

mapping(clusterId => ClusterData) clusterMap

Events

ClusterCreated

event ClusterCreated(address creator, address admin, address staker, address withdrawer, uint256 clusterId)

Note: Capabilities and members are not part of event as they can be retrieved from calldata given the transaction can be identified from the event.

ClusterClosureRequested

event ClusterClosureRequested(address requestor, uint256 clusterId)

ClusterWithdrawn

event ClusterWithdrawn(address withdrawer, uint256 clusterId)

Functions

Create Cluster

function createCluster(Capability[] capabilities, address admin, address staker, address[] members, address withdrawer) {
    ClusterData clusterData = ClusterData(capabilities, admin, members, withdrawer, address(0), 0)
    Cluster cluster = new Cluster(admin, members, withdrawer)
    // Check if prescribed stake is allocated to the cluster
    require(LINToken.transferFrom(staker, address(cluster), CLUSTER_STAKE))
    clusterData.cluster = address(cluster)
    // get clusterId from the generated cluster
    uint256 clusterId = cluster.id()
    // Save the cluster details
    clusterMap[clusterId] = clusterData
    // emit event to announce cluster creation
    emit ClusterCreated(msg.sender, admin, staker, withdrawer)
}

Request Cluster Closure

function initiateClusterWithdrawal(uint256 clusterId) {
    ClusterData clusterData = clusterMap[clusterId]
    require(msg.sender == clusterData.admin)
    clusterData.closureRequestTime = now
    Cluster cluster = Cluster(clusterData.cluster)
    clusterMap[clusterId] = clusterData
    require(cluster.initiateWithdrawal())
    emit ClusterClosureRequested(msg.sender, clusterId)
}

Remove Cluster

function withdrawCluster(clusterId) {
    ClusterData clusterData = clusterMap[clusterId]
    require( clusterData.closureRequestTime != 0 && (now - clusterData.closureRequestTime >= CLUSTER_CLOSE_WAIT_TIME) )
    Cluster cluster = Cluster(clusterData.cluster)
    require(cluster.withdrawCluster())
    emit ClusterWithdrawn(msg.sender, clusterId)
}

isCluster

function getClusterAddress(clusterId) {
    return clusterMap[clusterId].admin
}

Imports

  • LINToken
  • Pot