Skip to content

Commit

Permalink
Allow encodeMode to be inlinable
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Dec 18, 2024
1 parent 7307154 commit c563087
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/accounts/LibERC7579.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ library LibERC7579 {
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, callType)
mstore(0x01, execType)
mstore(0x02, shr(32, selector)) // Clean the lower bytes of `execType`.
mstore(0x0a, payload)
result := mload(0x00)
}
return bytes32(
uint256(bytes32(callType)) | (uint256(bytes32(execType)) >> 8)
| (uint256(bytes32(selector)) >> 48) | (uint256(uint176(payload)))
);
}

/// @dev Returns the call type of the mode.
Expand Down
7 changes: 7 additions & 0 deletions test/LibERC7579.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ contract LibERC7579Test is SoladyTest {
}
}

function testEncodeAndDecodeMode() public {
bytes32 mode = LibERC7579.encodeMode(
0x01, 0x00, 0x11223344, 0xffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb
);
assertEq(mode, 0x01000000000011223344ffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb);
}

struct Call {
address target;
uint256 value;
Expand Down

0 comments on commit c563087

Please sign in to comment.