-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Introduce a reward accounter to manage rewards
- Loading branch information
1 parent
661f4f9
commit 8f68817
Showing
4 changed files
with
70 additions
and
48 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
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,35 @@ | ||
// SPDX-License-Identifier: GNU GPLv3 | ||
pragma solidity 0.8.21; | ||
|
||
/// @dev Struct representing the accounter for the reward | ||
struct RewardAccounter { | ||
uint256 user; | ||
uint256 owners; | ||
uint256 content; | ||
} | ||
|
||
/// @dev Tell to use the lib below for every RewardAccounter instance | ||
using RewardAccounterLib for RewardAccounter global; | ||
|
||
/// @dev 1 ether in WAD | ||
uint256 constant WAD = 1 ether; | ||
|
||
/// @author @KONFeature | ||
/// @title RewardAccounterLib | ||
/// @notice Library to ease the usage of the RewardAccounter struct | ||
/// @custom:security-contact [email protected] | ||
library RewardAccounterLib { | ||
/// @dev Apply the user `badge` booster on the user reward | ||
function applyUserBadge(RewardAccounter memory self, uint256 badge) internal pure { | ||
unchecked { | ||
self.user = self.user * badge / WAD; | ||
} | ||
} | ||
|
||
/// @dev Get the total amount in the accounter | ||
function getTotal(RewardAccounter memory self) internal pure returns (uint256 total) { | ||
unchecked { | ||
total = self.user + self.owners + self.content; | ||
} | ||
} | ||
} |
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