@@ -11,22 +11,26 @@ import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol
1111/// @custom:security-contact security@nillion.com
1212contract NILFaucet is Ownable , Pausable , ReentrancyGuard {
1313 using SafeERC20 for IERC20 ;
14- IERC20 public immutable token;
14+
15+ error InvalidAddress ();
16+ error ClaimNotAllowed (string reason );
17+
18+ IERC20 public immutable TOKEN;
1519 uint256 public dripAmount; // token smallest units
1620 uint256 public cooldownSeconds; // seconds between claims per address
1721 mapping (address => uint256 ) public lastClaimAt;
1822 mapping (address => uint256 ) public claimCount;
1923
20- event Claimed (address indexed claimer , uint256 amount );
21- event DripAmountUpdated (uint256 newAmount );
22- event CooldownUpdated (uint256 newCooldownSeconds );
23- event Withdrawn (address indexed to , uint256 amount );
24+ event Claimed (address indexed claimer , uint256 indexed amount );
25+ event DripAmountUpdated (uint256 indexed newAmount );
26+ event CooldownUpdated (uint256 indexed newCooldownSeconds );
27+ event Withdrawn (address indexed to , uint256 indexed amount );
2428
2529 constructor (address tokenAddress , uint256 _dripAmount , uint256 _cooldownSeconds , address initialOwner )
2630 Ownable (initialOwner)
2731 {
28- require (tokenAddress != address (0 ), " BAD_TOKEN " );
29- token = IERC20 (tokenAddress);
32+ if (tokenAddress == address (0 )) revert InvalidAddress ( );
33+ TOKEN = IERC20 (tokenAddress);
3034 dripAmount = _dripAmount;
3135 cooldownSeconds = _cooldownSeconds;
3236 }
@@ -50,7 +54,7 @@ contract NILFaucet is Ownable, Pausable, ReentrancyGuard {
5054 }
5155
5256 function faucetBalance () public view returns (uint256 ) {
53- return token .balanceOf (address (this ));
57+ return TOKEN .balanceOf (address (this ));
5458 }
5559
5660 function canClaim (address user ) public view returns (bool ok , string memory reason ) {
@@ -69,16 +73,16 @@ contract NILFaucet is Ownable, Pausable, ReentrancyGuard {
6973
7074 function claim () external whenNotPaused nonReentrant {
7175 (bool ok , string memory reason ) = canClaim (msg .sender );
72- require (ok, reason);
76+ if ( ! ok) revert ClaimNotAllowed ( reason);
7377 lastClaimAt[msg .sender ] = block .timestamp ;
74- claimCount[msg .sender ] += 1 ;
75- token .safeTransfer (msg .sender , dripAmount);
78+ ++ claimCount[msg .sender ];
79+ TOKEN .safeTransfer (msg .sender , dripAmount);
7680 emit Claimed (msg .sender , dripAmount);
7781 }
7882
7983 function withdraw (address to , uint256 amount ) external onlyOwner nonReentrant {
80- require (to != address (0 ), " BAD_TO " );
81- token .safeTransfer (to, amount);
84+ if (to == address (0 )) revert InvalidAddress ( );
85+ TOKEN .safeTransfer (to, amount);
8286 emit Withdrawn (to, amount);
8387 }
8488}
0 commit comments