Contract Architecture
Rewards

Rewards Contract

Overview

The Rewards contract is designed for managing and distributing rewards in a decentralized finance platform. It interfaces with the pool, treasury, and trading contracts to track and disburse rewards to participants. These rewards could be in the collateral as part of the retail losses, or WMX tokens which will be launched later.

Contract Dependencies

  • Owner: The owner of the contract.
  • Router: The router contract's address.
  • Trading: The trading contract's address.
  • Treasury: The treasury contract's address.
  • Pool: The associated pool contract.
  • Currency: The currency in which rewards are paid.

Variables

  • Cumulative Reward Per Token Stored: Cumulative rewards calculated per token.
  • Pending Reward: Rewards that are yet to be distributed.
  • Claimable Reward: Mapping of claimable rewards for each account.
  • Previous Reward Per Token: Mapping of the previous reward per token for each account.
  • UNIT: Standard unit set to (10^{18}).

Events

  • Collected Reward: Emitted when a user collects their reward.

Constructor

  • Initializes the contract with the pool and currency.

Governance Methods

  • setOwner: Assigns a new contract owner.
  • setRouter: Sets the router and updates related contract addresses.

Core Methods

  • notifyRewardReceived: Tracks the receipt of new rewards.
  • updateRewards: Updates the reward state for a given account.
  • collectReward: Allows users to collect their available rewards.
  • getClaimableReward: Returns the amount of reward that a user can claim.

Utility Methods

  • _transferOut: Handles the transfer of rewards to a user.
  • transferTokensOut: Transfers tokens out of the contract.

Modifiers

  • onlyOwner: Ensures that only the contract owner can execute certain functions.
  • onlyTreasuryOrPool: Restricts access to the treasury and the pool contract.