Rewards.sol

This Solidity contract is responsible for managing rewards for GPU providers within a GAN Chain ecosystem. Let's break down its main components and functionalities:

  1. Contract Setup: The contract is initialised with references to another contract named GPU and inherits from OwnableUpgradeable, UUPSUpgradeable, and ReentrancyGuardUpgradeable. These provide ownership management, upgradability, and protection against reentrancy attacks respectively.

  2. State Variables: GPUInstance: Stores the address of the GPU contract to interact with GPU-related functions. providerRewards: Keeps track of accumulated rewards for each provider. lastWithdrawalTime: Records the timestamp of the last reward withdrawal for each provider. LOCK_PERIOD: Defines the duration for which reward withdrawals are locked for providers (set to 30 days).

  3. Initialization: The initialize function sets up the contract by assigning the GPU contract address and initialising the parent contracts.

  4. Reward Accumulation: The accumulateDailyProviderRewards function calculates and accumulates daily rewards for each GPU provider based on their compute scores. It retrieves the list of providers and their compute details from the GPU contract, calculates a compute score for each provider, and distributes rewards proportionally.

  5. Compute Multiplier Calculation: The getComputeMultiplier function determines a multiplier based on the number of compute units a provider has. This multiplier is used in the reward calculation to incentivize higher compute capacity.

  6. Reward Withdrawal: The withdrawReward function allows providers to withdraw their accumulated rewards after the lock period has elapsed. It verifies that the withdrawal is not attempted before the lock period expires, checks for available contract balance, resets the provider's reward balance, updates the withdrawal timestamp, and transfers the reward to the provider's address.

  7. Events: Two events, Deposit and RewardWithdrawn, are emitted to log deposit transactions and reward withdrawals respectively.

Overall, this contract manages the distribution of rewards to GPU providers based on their compute performance, ensuring fairness and incentivizing contribution to the ecosystem.

Last updated