@@ -33,39 +33,41 @@ contract KarmaAirdrop is Ownable2Step, Pausable {
3333 event MerkleRootSet (bytes32 merkleRoot );
3434
3535 /// @notice The address of the Karma token contract
36- address public immutable token ;
36+ address public immutable TOKEN ;
3737 /// @notice Whether the merkle root can be updated more than once
38- bool public immutable allowMerkleRootUpdate ;
38+ bool public immutable ALLOW_MERKLE_ROOT_UPDATE ;
3939 /// @notice The default delegatee address for new claimers
40- address public immutable defaultDelegatee ;
40+ address public immutable DEFAULT_DELEGATEE ;
4141 /// @notice The Merkle root of the airdrop
4242 bytes32 public merkleRoot;
4343 /// @notice Current epoch - incremented with each merkle root update
4444 uint256 public epoch;
4545 /// @notice A bitmap to track claimed indices per epoch
4646 mapping (uint256 => mapping (uint256 => uint256 )) private claimedBitMap;
47+ /// @notice Base value for creating bitmap masks
48+ uint256 private constant BITMAP_MASK_BASE = 1 ;
4749
4850 constructor (address _token , address _owner , bool _allowMerkleRootUpdate , address _defaultDelegatee ) {
49- token = _token;
50- allowMerkleRootUpdate = _allowMerkleRootUpdate;
51- defaultDelegatee = _defaultDelegatee;
51+ TOKEN = _token;
52+ ALLOW_MERKLE_ROOT_UPDATE = _allowMerkleRootUpdate;
53+ DEFAULT_DELEGATEE = _defaultDelegatee;
5254 _transferOwnership (_owner);
5355 }
5456
5557 /**
5658 * @notice Sets the Merkle root for the airdrop. Can only be called by the owner.
57- * If allowMerkleRootUpdate is false, can only be called once.
59+ * If ALLOW_MERKLE_ROOT_UPDATE; is false, can only be called once.
5860 * When updating an existing merkle root, the contract must be paused to prevent front-running.
5961 * When the merkle root is updated, the epoch is incremented, creating a new bitmap.
6062 * @param _merkleRoot The Merkle root to set
6163 */
6264 function setMerkleRoot (bytes32 _merkleRoot ) external onlyOwner {
63- if (! allowMerkleRootUpdate && merkleRoot != bytes32 (0 )) {
65+ if (! ALLOW_MERKLE_ROOT_UPDATE && merkleRoot != bytes32 (0 )) {
6466 revert KarmaAirdrop__MerkleRootAlreadySet ();
6567 }
6668
6769 // When updating an existing merkle root (not the first time), contract must be paused
68- if (allowMerkleRootUpdate && merkleRoot != bytes32 (0 ) && ! paused ()) {
70+ if (ALLOW_MERKLE_ROOT_UPDATE && merkleRoot != bytes32 (0 ) && ! paused ()) {
6971 revert KarmaAirdrop__MustBePausedToUpdate ();
7072 }
7173
@@ -87,14 +89,15 @@ contract KarmaAirdrop is Ownable2Step, Pausable {
8789 uint256 claimedWordIndex = index / 256 ;
8890 uint256 claimedBitIndex = index % 256 ;
8991 uint256 claimedWord = claimedBitMap[epoch][claimedWordIndex];
90- uint256 mask = (1 << claimedBitIndex);
92+ uint256 mask = (BITMAP_MASK_BASE << claimedBitIndex);
9193 return claimedWord & mask == mask;
9294 }
9395
9496 function _setClaimed (uint256 index ) private {
9597 uint256 claimedWordIndex = index / 256 ;
9698 uint256 claimedBitIndex = index % 256 ;
97- claimedBitMap[epoch][claimedWordIndex] = claimedBitMap[epoch][claimedWordIndex] | (1 << claimedBitIndex);
99+ claimedBitMap[epoch][claimedWordIndex] =
100+ claimedBitMap[epoch][claimedWordIndex] | (BITMAP_MASK_BASE << claimedBitIndex);
98101 }
99102
100103 /**
@@ -130,20 +133,21 @@ contract KarmaAirdrop is Ownable2Step, Pausable {
130133 }
131134
132135 // Verify the merkle proof.
136+ /// forge-lint: disable-next-line(asm-keccak256)
133137 bytes32 node = keccak256 (abi.encodePacked (index, account, amount));
134138 if (! MerkleProof.verify (merkleProof, merkleRoot, node)) {
135139 revert KarmaAirdrop__InvalidProof ();
136140 }
137141
138142 // Mark it claimed and send the token.
139143 _setClaimed (index);
140- if (! IERC20 (token ).transfer (account, amount)) {
144+ if (! IERC20 (TOKEN ).transfer (account, amount)) {
141145 revert KarmaAirdrop__TransferFailed ();
142146 }
143147
144148 // If the account has no karma balance before this claim, delegate to the default delegatee
145- if (IERC20 (token ).balanceOf (account) == amount) {
146- IVotes (token ).delegateBySig (defaultDelegatee , nonce, expiry, v, r, s);
149+ if (IERC20 (TOKEN ).balanceOf (account) == amount) {
150+ IVotes (TOKEN ).delegateBySig (DEFAULT_DELEGATEE , nonce, expiry, v, r, s);
147151 }
148152
149153 emit Claimed (index, account, amount);
0 commit comments