Skip to content

Commit

Permalink
feat guardian governor
Browse files Browse the repository at this point in the history
  • Loading branch information
sogipec committed Dec 5, 2023
1 parent a816e65 commit 27a5119
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
42 changes: 24 additions & 18 deletions contracts/DistributionCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ import { RewardTokenAmounts } from "./struct/RewardTokenAmounts.sol";

struct CampaignParameters {
// Populated once created
bytes32 rewardId;
bytes32 campaignId;
address creator;
//
uint256 amount;
// Chosen by campaign creator
address rewardToken;
uint256 amount;
uint32 campaignType;
uint32 epochStart;
uint32 numEpoch;
Expand Down Expand Up @@ -160,6 +160,12 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
_;
}

/// @notice Checks whether the `msg.sender` has the governor role or the guardian role
modifier onlyGovernor() {
if (!core.isGovernor(msg.sender)) revert NotGovernor();
_;
}

/// @notice Checks whether an address has signed the message or not
modifier hasSigned() {
if (
Expand All @@ -184,7 +190,7 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
constructor() initializer {}

/// @inheritdoc UUPSUpgradeable
function _authorizeUpgrade(address) internal view override onlyGuardianUpgrader(core) {}
function _authorizeUpgrade(address) internal view override onlyGovernorUpgrader(core) {}

// ============================== DEPOSIT FUNCTION =============================

Expand Down Expand Up @@ -294,7 +300,7 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
bytes32 campaignId;
(campaignAmountMinusFees, campaignId) = _computeFees(_fees, campaign.amount, campaign.rewardToken);
campaign.amount = campaignAmountMinusFees;
campaign.rewardId = campaignId;
campaign.campaignId = campaignId;
campaign.creator = msg.sender;
uint256 lookupIndex = campaignList.length;
campaignLookup[campaignId] = lookupIndex;
Expand Down Expand Up @@ -453,38 +459,32 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
// ============================ GOVERNANCE FUNCTIONS ===========================

/// @notice Sets a new `distributor` to which rewards should be distributed
function setNewDistributor(address _distributor) external onlyGovernorOrGuardian {
function setNewDistributor(address _distributor) external onlyGovernor {
if (_distributor == address(0)) revert InvalidParam();
distributor = _distributor;
emit DistributorUpdated(_distributor);
}

/// @notice Sets the fees on deposit
function setFees(uint256 _fees) external onlyGovernorOrGuardian {
function setFees(uint256 _fees) external onlyGovernor {
if (_fees >= BASE_9) revert InvalidParam();
fees = _fees;
emit FeesSet(_fees);
}

function setCampaignFees(uint32 campaignType, uint256 _fees) external onlyGovernorOrGuardian {
function setCampaignFees(uint32 campaignType, uint256 _fees) external onlyGovernor {
campaignSpecificFees[campaignType] = _fees;
}

/// @notice Sets fee rebates for a given user
function setUserFeeRebate(address user, uint256 userFeeRebate) external onlyGovernorOrGuardian {
feeRebate[user] = userFeeRebate;
emit FeeRebateUpdated(user, userFeeRebate);
}

/// @notice Toggles the fee whitelist for `token`
function toggleTokenWhitelist(address token) external onlyGovernorOrGuardian {
function toggleTokenWhitelist(address token) external onlyGovernor {
uint256 toggleStatus = 1 - isWhitelistedToken[token];
isWhitelistedToken[token] = toggleStatus;
emit TokenWhitelistToggled(token, toggleStatus);
}

/// @notice Recovers fees accrued on the contract for a list of `tokens`
function recoverFees(IERC20[] calldata tokens, address to) external onlyGovernorOrGuardian {
function recoverFees(IERC20[] calldata tokens, address to) external onlyGovernor {
uint256 tokensLength = tokens.length;
for (uint256 i; i < tokensLength; ) {
tokens[i].safeTransfer(to, tokens[i].balanceOf(address(this)));
Expand All @@ -494,6 +494,12 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
}
}

/// @notice Sets fee rebates for a given user
function setUserFeeRebate(address user, uint256 userFeeRebate) external onlyGovernorOrGuardian {
feeRebate[user] = userFeeRebate;
emit FeeRebateUpdated(user, userFeeRebate);
}

/// @notice Sets the minimum amounts per distribution epoch for different reward tokens
function setRewardTokenMinAmounts(
address[] calldata tokens,
Expand All @@ -512,13 +518,13 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
}

/// @notice Sets a new address to receive fees
function setFeeRecipient(address _feeRecipient) external onlyGovernorOrGuardian {
function setFeeRecipient(address _feeRecipient) external onlyGovernor {
feeRecipient = _feeRecipient;
emit FeeRecipientUpdated(_feeRecipient);
}

/// @notice Sets the message that needs to be signed by users before posting rewards
function setMessage(string memory _message) external onlyGovernorOrGuardian {
function setMessage(string memory _message) external onlyGovernor {
message = _message;
bytes32 _messageHash = ECDSA.toEthSignedMessageHash(bytes(_message));
messageHash = _messageHash;
Expand Down
14 changes: 10 additions & 4 deletions contracts/Distributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ contract Distributor is UUPSHelper {
_;
}

/// @notice Checks whether the `msg.sender` has the governor role or the guardian role
modifier onlyGovernor() {
if (!core.isGovernor(msg.sender)) revert NotGovernor();
_;
}

/// @notice Checks whether the `msg.sender` is the `user` address or is a trusted address
modifier onlyTrustedOrUser(address user) {
if (user != msg.sender && canUpdateMerkleRoot[msg.sender] != 1 && !core.isGovernorOrGuardian(msg.sender))
Expand All @@ -147,7 +153,7 @@ contract Distributor is UUPSHelper {
}

/// @inheritdoc UUPSUpgradeable
function _authorizeUpgrade(address) internal view override onlyGuardianUpgrader(core) {}
function _authorizeUpgrade(address) internal view override onlyGovernorUpgrader(core) {}

// =============================== MAIN FUNCTION ===============================

Expand Down Expand Up @@ -205,7 +211,7 @@ contract Distributor is UUPSHelper {
// ============================ GOVERNANCE FUNCTIONS ===========================

/// @notice Adds or removes EOAs which are trusted to update the Merkle root
function toggleTrusted(address eoa) external onlyGovernorOrGuardian {
function toggleTrusted(address eoa) external onlyGovernor {
uint256 trustedStatus = 1 - canUpdateMerkleRoot[eoa];
canUpdateMerkleRoot[eoa] = trustedStatus;
emit TrustedToggled(eoa, trustedStatus == 1);
Expand All @@ -218,7 +224,7 @@ contract Distributor is UUPSHelper {
// A trusted address cannot update a tree right after a precedent tree update otherwise it can de facto
// validate a tree which has not passed the dispute period
((canUpdateMerkleRoot[msg.sender] != 1 || block.timestamp < endOfDisputePeriod) &&
!core.isGovernorOrGuardian(msg.sender))
!core.isGovernor(msg.sender))
) revert NotTrusted();
MerkleTree memory _lastTree = tree;
tree = _tree;
Expand Down Expand Up @@ -278,7 +284,7 @@ contract Distributor is UUPSHelper {
}

/// @notice Recovers any ERC20 token
function recoverERC20(address tokenAddress, address to, uint256 amountToRecover) external onlyGovernorOrGuardian {
function recoverERC20(address tokenAddress, address to, uint256 amountToRecover) external onlyGovernor {
IERC20(tokenAddress).safeTransfer(to, amountToRecover);
emit Recovered(tokenAddress, to, amountToRecover);
}
Expand Down

0 comments on commit 27a5119

Please sign in to comment.