Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/helpers/ModuleEntityLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
pragma solidity ^0.8.20;

import {ModuleEntity} from "../interfaces/IModularAccount.sol";
// ModuleEntity is a packed representation of a module function
// Layout:
// 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA________________________ // Address
// 0x________________________________________BBBBBBBB________________ // Entity ID
// 0x________________________________________________0000000000000000 // unused
Comment on lines +5 to +9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also maybe newline before this, and consider making this a NatSpec @dev comment?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see that this is for ModuleEntity imported above. Is this necessary? IModularAccount already describes it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's repeated in both IModularAccount and each of the type encoding / decoding libraries (ValidationConfigLib, HookConfigLib) so I added it here too.


library ModuleEntityLib {
// Magic value for hooks that should always revert.
ModuleEntity internal constant _PRE_HOOK_ALWAYS_DENY = ModuleEntity.wrap(bytes24(uint192(2)));

function pack(address addr, uint32 entityId) internal pure returns (ModuleEntity) {
return ModuleEntity.wrap(bytes24(bytes20(addr)) | bytes24(uint192(entityId)));
}

function unpack(ModuleEntity fr) internal pure returns (address addr, uint32 entityId) {
bytes24 underlying = ModuleEntity.unwrap(fr);
function unpack(ModuleEntity moduleEntity) internal pure returns (address addr, uint32 entityId) {
bytes24 underlying = ModuleEntity.unwrap(moduleEntity);
addr = address(bytes20(underlying));
entityId = uint32(bytes4(underlying << 160));
}

function isEmpty(ModuleEntity fr) internal pure returns (bool) {
return ModuleEntity.unwrap(fr) == bytes24(0);
function isEmpty(ModuleEntity moduleEntity) internal pure returns (bool) {
return ModuleEntity.unwrap(moduleEntity) == bytes24(0);
}

function notEmpty(ModuleEntity fr) internal pure returns (bool) {
return ModuleEntity.unwrap(fr) != bytes24(0);
function notEmpty(ModuleEntity moduleEntity) internal pure returns (bool) {
return ModuleEntity.unwrap(moduleEntity) != bytes24(0);
}

function eq(ModuleEntity a, ModuleEntity b) internal pure returns (bool) {
Expand Down