Skip to content

Commit

Permalink
added ChefIncentivesMultiRewarder
Browse files Browse the repository at this point in the history
  • Loading branch information
gas-limit committed Nov 19, 2024
1 parent 93ebd67 commit bfebad7
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 15 deletions.
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This repository offers a suite of smart contracts designed to facilitate multi-t
2. **MasterChefRewarder**: Integrates with MasterChef to provide multi-token rewards for liquidity providers.
3. **ChefIncentivesRewarder**: Extends ChefIncentivesController, rewarding users holding aTokens or LP tokens.

Each directory includes a README.md file with detailed information on the contract's purpose, implementation instructions, and usage examples.

---

## Getting Started
Expand Down Expand Up @@ -51,21 +53,6 @@ forge test

---

## Deployment

Deploy contracts as per your requirements:

- **StandaloneRewarder**: For independent staking and rewards.
- **MasterChefRewarder**: To integrate with MasterChef.
- **ChefIncentivesRewarder**: For use with ChefIncentivesController.

Modify deployment scripts in the `script/` directory accordingly and run:
```bash
forge script script/Deploy.s.sol --broadcast
```

---

## Contribution

Contributions are welcome. To contribute:
Expand Down
117 changes: 117 additions & 0 deletions src/ChefIncentivesController/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# ChefIncentivesMultiRewarder

The `ChefIncentivesMultiRewarder` contract extends the functionality of the `ChefIncentivesController` by enabling multi-token reward distribution for users holding aTokens or liquidity provider (LP) tokens. This enhancement allows for more flexible and diverse incentive mechanisms within decentralized finance (DeFi) protocols.

---

## Overview

The `ChefIncentivesMultiRewarder` contract introduces the capability to distribute multiple reward tokens to users based on their staked aTokens or LP tokens. It maintains accounting for each reward token separately, ensuring accurate distribution according to predefined rates.

---

## Key Features

- **Multi-Token Rewards**: Supports distribution of various reward tokens for staked assets.
- **Flexible Reward Rates**: Allows setting and adjusting reward rates per token.
- **Accurate Accounting**: Maintains precise tracking of user stakes and pending rewards.
- **Administrative Control**: Provides functions for administrators to manage reward tokens and rates.

---

## Integration Guide

To integrate the `ChefIncentivesMultiRewarder` into the `ChefIncentivesController`, follow these steps:

1. **Inherit the Contract**: Modify the `ChefIncentivesController` to inherit from `ChefIncentivesMultiRewarder`.

```solidity
contract ChefIncentivesController is ChefIncentivesMultiRewarder {
// Existing code...
}
```

2. **Modify `handleAction` Function**: Update the `handleAction` function to incorporate multi-incentive staking and unstaking logic.

```solidity
function handleAction(address _user, uint256 _balance, uint256 _totalSupply) external {
// Existing code...
// Multi-Incentive Module
uint256 previousAmount = user.amount;
if (_balance > previousAmount) {
uint256 amountStaked = _balance.sub(previousAmount);
_stakeIncentiveTokens(msg.sender, amountStaked, _user);
} else if (_balance < previousAmount) {
uint256 amountUnstaked = previousAmount.sub(_balance);
_unstakeIncentiveTokens(msg.sender, amountUnstaked, _user);
}
// Existing code...
}
```

3. **Modify `claim` Function**: Enhance the `claim` function to process multi-token rewards.

```solidity
function claim(address _user, address[] calldata _tokens) external {
// Existing code...
for (uint i = 0; i < _tokens.length; i++) {
// Existing code...
// Multi-Incentive Module
_claimMultiRewards(_tokens[i], _user);
}
// Existing code...
}
```

---

## Administrative Functions

The contract provides several administrative functions for managing rewards:

- **`addIncentiveReward`**: Adds a new reward token for a specific aToken with a defined reward rate.
- **`removeIncentiveReward`**: Removes an existing reward token from a specific aToken.
- **`adjustRewardRate`**: Updates the reward rate for a specific reward token and aToken pair.
- **`depositReward`**: Deposits reward tokens into the contract for distribution.
- **`withdrawReward`**: Withdraws reward tokens from the contract.

---

## User Functions

Users can interact with the contract through the following functions:

- **`_stakeIncentiveTokens`**: Internal function to record staking of aTokens.
- **`_unstakeIncentiveTokens`**: Internal function to record unstaking of aTokens.
- **`_claimMultiRewards`**: Internal function to claim pending multi-token rewards.
- **`previewEarned`**: Public function to view pending rewards for a user and aToken.

---

## Events

The contract emits several events to facilitate tracking and integration:

- **`multiStakeRecorded`**: Emitted when a user stakes aTokens.
- **`multiUnstakeRecorded`**: Emitted when a user unstakes aTokens.
- **`multiRewardHarvested`**: Emitted when a user claims rewards.
- **`multiRewardAdded`**: Emitted when a new reward token is added.
- **`multiRewardRemoved`**: Emitted when a reward token is removed.
- **`multiRewardUpdated`**: Emitted when a reward rate is updated.
- **`multiRewardDeposited`**: Emitted when reward tokens are deposited.
- **`multiRewardWithdrawn`**: Emitted when reward tokens are withdrawn.

---

## Disclaimer

**Important**: This contract has not undergone formal security audits. It is provided "as-is" without any warranties or guarantees. The author assumes no responsibility for any issues, losses, or damages arising from the use of this code. Users are advised to conduct their own thorough testing and audits before deploying this contract in a production environment.

---

By integrating the `ChefIncentivesMultiRewarder`, DeFi protocols can offer more versatile and attractive incentive structures, potentially enhancing user engagement and liquidity provision.

0 comments on commit bfebad7

Please sign in to comment.