Skip to content

Commit 3138f31

Browse files
committed
feat: implement fee on claim
1 parent 7a3e2b5 commit 3138f31

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

contracts/Distributor.sol

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ contract Distributor is UUPSHelper {
9797
/// @dev If the mapping is empty, by default rewards will accrue on the user address
9898
mapping(address => mapping(address => address)) public claimRecipient;
9999

100-
uint256[36] private __gap;
100+
/// @notice Minimum fee amount to be paid for claiming
101+
uint256 public singleClaimFeeInWei;
102+
103+
uint256[35] private __gap;
101104

102105
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103106
EVENTS
@@ -115,6 +118,7 @@ contract Distributor is UUPSHelper {
115118
event OperatorToggled(address indexed user, address indexed operator, bool isWhitelisted);
116119
event Recovered(address indexed token, address indexed to, uint256 amount);
117120
event Revoked(); // With this event an indexer could maintain a table (timestamp, merkleRootUpdate)
121+
event SingleClaimFeeInWeiUpdated(uint256 newValue);
118122
event TreeUpdated(bytes32 merkleRoot, bytes32 ipfsHash, uint48 endOfDisputePeriod);
119123
event TrustedToggled(address indexed eoa, bool trust);
120124
event UpgradeabilityRevoked();
@@ -129,6 +133,12 @@ contract Distributor is UUPSHelper {
129133
_;
130134
}
131135

136+
/// @notice Checks whether the `msg.sender` has the governor or the guardian role
137+
modifier onlyGovernorOrGuardian() {
138+
if (!accessControlManager.isGovernorOrGuardian(msg.sender)) revert Errors.NotGovernorOrGuardian();
139+
_;
140+
}
141+
132142
/// @notice Checks whether the `msg.sender` is the `user` address or is a trusted address
133143
modifier onlyTrustedOrUser(address user) {
134144
if (
@@ -190,6 +200,7 @@ contract Distributor is UUPSHelper {
190200
uint256[] calldata amounts,
191201
bytes32[][] calldata proofs
192202
) external {
203+
if (singleClaimFeeInWei > 0) revert Errors.InvalidFee();
193204
address[] memory recipients = new address[](users.length);
194205
bytes[] memory datas = new bytes[](users.length);
195206
_claim(users, tokens, amounts, proofs, recipients, datas);
@@ -208,6 +219,34 @@ contract Distributor is UUPSHelper {
208219
address[] calldata recipients,
209220
bytes[] memory datas
210221
) external {
222+
if (singleClaimFeeInWei > 0) revert Errors.InvalidFee();
223+
_claim(users, tokens, amounts, proofs, recipients, datas);
224+
}
225+
226+
/// @notice Same as the function above but with the ability to pay a fee in ETH when claiming
227+
function claimRewards(
228+
address[] calldata users,
229+
address[] calldata tokens,
230+
uint256[] calldata amounts,
231+
bytes32[][] calldata proofs
232+
) external payable {
233+
uint256 usersLength = users.length;
234+
if (msg.value < singleClaimFeeInWei * usersLength) revert Errors.InvalidFee();
235+
address[] memory recipients = new address[](usersLength);
236+
bytes[] memory datas = new bytes[](usersLength);
237+
_claim(users, tokens, amounts, proofs, recipients, datas);
238+
}
239+
240+
/// @notice Same as the function above but with the ability to pay a fee in ETH when claiming
241+
function claimRewardsWithRecipients(
242+
address[] calldata users,
243+
address[] calldata tokens,
244+
uint256[] calldata amounts,
245+
bytes32[][] calldata proofs,
246+
address[] calldata recipients,
247+
bytes[] memory datas
248+
) external payable {
249+
if (msg.value < singleClaimFeeInWei * users.length) revert Errors.InvalidFee();
211250
_claim(users, tokens, amounts, proofs, recipients, datas);
212251
}
213252

@@ -345,6 +384,21 @@ contract Distributor is UUPSHelper {
345384
emit DisputeAmountUpdated(_disputeAmount);
346385
}
347386

387+
/// @notice Sets the minimum fee to claim a given reward token on Merkl
388+
function updateSingleClaimFeeInWei(uint256 amount) external onlyGovernor {
389+
singleClaimFeeInWei = amount;
390+
emit SingleClaimFeeInWeiUpdated(amount);
391+
}
392+
393+
/// @notice Withdraws the ETH accumulated on the contract
394+
function withdrawETH(address payable recipient) external onlyGovernorOrGuardian {
395+
uint256 balance = address(this).balance;
396+
if (balance > 0) {
397+
(bool success, ) = recipient.call{ value: balance }("");
398+
if (!success) revert Errors.InvalidParam();
399+
}
400+
}
401+
348402
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
349403
INTERNAL HELPERS
350404
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

contracts/utils/Errors.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ library Errors {
1010
error CampaignRewardTooLow();
1111
error CampaignShouldStartInFuture();
1212
error InvalidDispute();
13+
error InvalidFee();
1314
error InvalidLengths();
1415
error InvalidOverride();
1516
error InvalidParam();

0 commit comments

Comments
 (0)