-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |