Closed Havoc19 closed 2 weeks ago
A bitmap can represent up to 256 tokens using a single uint256 variable, where each bit represents one token:
uint256
0
1
Each token's position is determined by the least significant byte (LSB) of its address:
uint256 bitPos = uint256(uint160(token)) & 0xFF;
This maps each token address to a position between 0-255.
To mark a token as present, set its corresponding bit to 1:
tokenBitmap |= 1 << bitPos;
To remove a token, clear its bit to 0:
tokenBitmap &= ~(1 << bitPos);
To verify if a token exists in the bitmap:
if (tokenBitmap & (1 << bitPos) != 0) { // Token is present }
This method validates new tokens being added:
newTokens
_ensoBuyTokens
This method uses the bitmap for:
Bitmap Token Tracking System
Overview
A bitmap can represent up to 256 tokens using a single
uint256
variable, where each bit represents one token:0
: Token is not present1
: Token is presentHow It Works
Bit Positioning
Each token's position is determined by the least significant byte (LSB) of its address:
This maps each token address to a position between 0-255.
Token Operations
Adding Tokens
To mark a token as present, set its corresponding bit to 1:
Removing Tokens
To remove a token, clear its bit to 0:
Checking Token Presence
To verify if a token exists in the bitmap:
Implementation Details
verifyNewTokenList
This method validates new tokens being added:
newTokens
:_ensoBuyTokens
exists in bitmapupdateTokens
This method uses the bitmap for:
Technical Notes
uint256
for storage efficiency