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
EpochManagerto get current and previous epochs. - Interacts with
NodeRegistryto obtain active nodes. - Uses
Stakingcontract 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
Stakingcontract for staking and withdrawing tokens. - Interacts with the
Rewardercontract 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
Stakingcontract for staking and withdrawing tokens. - Interacts with the
Rewardercontract to manage rewards. - Interacts with the
Disputecontract 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
ProjectionRegistryto manage projection stakes. - Interfaces with
NodeRegistryfor node-related staking operations. - Works with the
Disputecontract 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
ProjectionRegistryto modify projection statuses during disputes. - Works with the
Stakingcontract 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
NodeRegistryto verify gateway statuses and obtain gateway addresses. - Transfers tokens to the
Treasuryupon 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
RewarderandStakingfor 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
EpochManagerto obtain epoch data. - Retrieves active nodes from
NodeRegistry. - Distributes rewards, involving
Stakingfor staking logic.
- Uses
- NodeRegistry:
- Calls
Stakingfor staking and withdrawing tokens during node operations. - Communicates with
Rewarderduring node withdrawal for reward claiming.
- Calls
- Staking:
- Interacts with
ProjectionRegistryfor projection stakes. - Works with
NodeRegistryfor node staking. - Collaborates with
Disputefor dispute-related staking adjustments.
- Interacts with
- Dispute:
- Modifies projection statuses via
ProjectionRegistry. - Adjusts stakes using the
Stakingcontract.
- 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.