Smart Contracts
List of Smart Contracts
Rewarder
Purpose: The Rewarder
contract manages the distribution of rewards within the Datai Network. It calculates and distributes rewards to indexers, gateways, and developers based on their participation and contributions.
Key Functionalities:
- Reward Calculation: Computes rewards for participants in each epoch based on predefined percentages.
- Reward Distribution: Distributes tokens to eligible participants after each epoch.
- Projection Grants: Manages grants for projections, allowing developers to claim rewards upon completion.
- Tax Mechanism: Applies a tax on rewards, directing funds to the treasury.
Interactions:
- Interfaces with
EpochManager
to get current and previous epochs. - Interacts with
NodeRegistry
to obtain active nodes. - Uses
Staking
contract to handle staking-related logic.
NodeRegistry
Purpose: The NodeRegistry
contract manages the registration and status of nodes (indexers and gateways) in the network. It ensures that only authorized and properly staked nodes participate in the network.
Key Functionalities:
- Node Registration: Allows indexers and gateways to commit their nodes by staking the required amount.
- Node Activation and Withdrawal: Handles the activation, withdrawal submission, and final withdrawal of nodes.
- Node Information Management: Stores and provides access to node statuses and related information.
- Gateway Management: Administers the registration and URL updates of gateways.
Interactions:
- Works with the
Staking
contract for staking and withdrawing tokens. - Interacts with the
Rewarder
contract to manage rewards upon node withdrawal.
ProjectionRegistry
Purpose: The ProjectionRegistry
contract manages the registration and status of projections in the network.
Key Functionalities:
- Projection commitment: Allows developers to commit to implement a projection.
- Projection registration: Developers register their projection once the implementation is deployed on IPFS.
Interactions:
- Works with the
Staking
contract for staking and withdrawing tokens. - Interacts with the
Rewarder
contract to manage rewards. - Interacts with the
Dispute
contract to handle the projection status during a dispute.
Staking
Purpose: The Staking
contract implements the staking mechanisms for projections, nodes, and disputes. It ensures that participants have economic incentives aligned with the network’s integrity.
Key Functionalities:
- Projection Staking: Manages staking for projections submitted by developers.
- Node Staking: Handles staking and withdrawal of tokens for indexers and gateways.
- Dispute Staking: Manages stakes related to disputes raised by users.
- Penalty and Reward Distribution: Processes slashing and rewards based on dispute outcomes.
Interactions:
- Interacts with
ProjectionRegistry
to manage projection stakes. - Interfaces with
NodeRegistry
for node-related staking operations. - Works with the
Dispute
contract to handle staking adjustments upon dispute resolution.
Dispute
Purpose: The Dispute
contract provides a mechanism for users to raise disputes regarding projections. It ensures fair resolution by involving developers and the admin, with staking penalties and rewards to enforce honesty.
Key Functionalities:
- Dispute Filing: Allows users to open disputes against projections by staking a specified amount.
- Dispute Resolution: Enables developers or the admin to accept or reject disputes.
- Staking Adjustments: Adjusts stakes based on the outcome of disputes, rewarding or penalizing parties accordingly.
- Dispute Tracking: Maintains records of disputes for transparency and auditing.
Interactions:
- Interacts with
ProjectionRegistry
to modify projection statuses during disputes. - Works with the
Staking
contract to manage dispute-related stakes.
Consumer
Purpose: The Consumer
contract facilitates the interaction between data consumers and gateways. It manages consumer deposits and allows gateways to deduct fees for services rendered.
Key Functionalities:
- Deposits Management: Allows consumers to deposit stable tokens for use with specific gateways.
- Balance Tracking: Maintains balances for consumers associated with gateways.
- Fee Deduction: Enables gateways to deduct fees from consumer deposits based on service usage.
- Withdrawal Mechanism: (Recommended Enhancement) Should allow consumers to withdraw unused deposits.
Interactions:
- Interfaces with
NodeRegistry
to verify gateway statuses and obtain gateway addresses. - Transfers tokens to the
Treasury
upon deposits.
EpochManager
Purpose: The EpochManager
contract handles epoch calculations and timing for the network. Epochs are essential for synchronizing reward distributions and other time-dependent processes.
Key Functionalities:
- Epoch Calculation: Determines the current and previous epochs based on the start time and epoch duration.
- Time Management: Calculates the remaining time in the current epoch.
- Administrative Controls: Allows the owner to set the start time and adjust the epoch duration.
Interactions:
- Provides epoch information to other contracts like
Rewarder
andStaking
for time-based operations.
Contract Interactions
The smart contracts are designed to interact seamlessly to support the Datai Network’s operations. Below is a simplified overview of how the contracts interact:
- Rewarder:
- Uses
EpochManager
to obtain epoch data. - Retrieves active nodes from
NodeRegistry
. - Distributes rewards, involving
Staking
for staking logic.
- Uses
- NodeRegistry:
- Calls
Staking
for staking and withdrawing tokens during node operations. - Communicates with
Rewarder
during node withdrawal for reward claiming.
- Calls
- Staking:
- Interacts with
ProjectionRegistry
for projection stakes. - Works with
NodeRegistry
for node staking. - Collaborates with
Dispute
for dispute-related staking adjustments.
- Interacts with
- Dispute:
- Modifies projection statuses via
ProjectionRegistry
. - Adjusts stakes using the
Staking
contract.
- Modifies projection statuses via
- Consumer:
- Verifies gateway information through
NodeRegistry
. - Transfers deposits to the
Treasury
.
- Verifies gateway information through
Roles and Permissions
The Datai Network smart contracts involve various roles with specific permissions:
- Owner/Admin:
- Can set critical parameters like start times, epoch durations, and contract addresses.
- Has the authority to resolve disputes at the admin level.
- Developers:
- Submit projections and can accept or reject disputes related to their projections.
- Stake tokens when submitting projections.
- Indexers and Gateways:
- Register nodes and stake required amounts.
- Receive rewards based on their contributions.
- Consumers:
- Deposit funds to use services provided by gateways.
- Can raise disputes regarding projections.
Access control is enforced using OpenZeppelin’s OwnableUpgradeable
and should be enhanced with role-based access control where necessary.