-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup claim condition extension classes (#171)
* cleanup claim condition extension classes * fix import casing * more cleanup, fix foundry config * rename Bitmaps to TWBitMaps * fix imports
- Loading branch information
1 parent
ad487f2
commit d331efc
Showing
9 changed files
with
136 additions
and
63 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
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,55 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts v4.4.1 (utils/structs/BitMaps.sol) | ||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential. | ||
* Largelly inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor]. | ||
*/ | ||
library TWBitMaps { | ||
struct BitMap { | ||
mapping(uint256 => uint256) _data; | ||
} | ||
|
||
/** | ||
* @dev Returns whether the bit at `index` is set. | ||
*/ | ||
function get(BitMap storage bitmap, uint256 index) internal view returns (bool) { | ||
uint256 bucket = index >> 8; | ||
uint256 mask = 1 << (index & 0xff); | ||
return bitmap._data[bucket] & mask != 0; | ||
} | ||
|
||
/** | ||
* @dev Sets the bit at `index` to the boolean `value`. | ||
*/ | ||
function setTo( | ||
BitMap storage bitmap, | ||
uint256 index, | ||
bool value | ||
) internal { | ||
if (value) { | ||
set(bitmap, index); | ||
} else { | ||
unset(bitmap, index); | ||
} | ||
} | ||
|
||
/** | ||
* @dev Sets the bit at `index`. | ||
*/ | ||
function set(BitMap storage bitmap, uint256 index) internal { | ||
uint256 bucket = index >> 8; | ||
uint256 mask = 1 << (index & 0xff); | ||
bitmap._data[bucket] |= mask; | ||
} | ||
|
||
/** | ||
* @dev Unsets the bit at `index`. | ||
*/ | ||
function unset(BitMap storage bitmap, uint256 index) internal { | ||
uint256 bucket = index >> 8; | ||
uint256 mask = 1 << (index & 0xff); | ||
bitmap._data[bucket] &= ~mask; | ||
} | ||
} |
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
Oops, something went wrong.