Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathModuleEntityLib.sol
More file actions
Latest commit
37 lines (30 loc) · 1.49 KB
/
Copy pathModuleEntityLib.sol
File metadata and controls
37 lines (30 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: MIT
pragma solidity^0.8.20;
import {ModuleEntity} from"../interfaces/IERC6900Account.sol";
// ModuleEntity is a packed representation of a module function
// Layout:
// 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA________________________ // Address
// 0x________________________________________BBBBBBBB________________ // Entity ID
// 0x________________________________________________0000000000000000 // unused
libraryModuleEntityLib {
function pack(addressaddr, uint32entityId) internalpurereturns (ModuleEntity) {
return ModuleEntity.wrap(bytes24(bytes20(addr)) |bytes24(uint192(entityId)));
}
function unpack(ModuleEntity moduleEntity) internalpurereturns (addressaddr, uint32entityId) {
bytes24 underlying = ModuleEntity.unwrap(moduleEntity);
addr =address(bytes20(underlying));
entityId =uint32(bytes4(underlying <<160));
}
function isEmpty(ModuleEntity moduleEntity) internalpurereturns (bool) {
return ModuleEntity.unwrap(moduleEntity) ==bytes24(0);
}
function notEmpty(ModuleEntity moduleEntity) internalpurereturns (bool) {
return ModuleEntity.unwrap(moduleEntity) !=bytes24(0);
}
function eq(ModuleEntity a, ModuleEntity b) internalpurereturns (bool) {
return ModuleEntity.unwrap(a) == ModuleEntity.unwrap(b);
}
function notEq(ModuleEntity a, ModuleEntity b) internalpurereturns (bool) {
return ModuleEntity.unwrap(a) != ModuleEntity.unwrap(b);
}
}