diff --git a/src/Kernel.sol b/src/Kernel.sol index a7e582a0..9a0a1259 100644 --- a/src/Kernel.sol +++ b/src/Kernel.sol @@ -75,13 +75,6 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager _; } - modifier onlyEntryPointOrSelf() { - if (msg.sender != address(entrypoint) && msg.sender != address(this)) { - revert InvalidCaller(); - } - _; - } - modifier onlyEntryPointOrSelfOrRoot() { IValidator validator = ValidatorLib.getValidator(_validationStorage().rootValidator); if ( @@ -133,6 +126,22 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager emit Received(msg.sender, msg.value); } + function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) { + return this.onERC721Received.selector; + } + + function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure returns (bytes4) { + return this.onERC1155Received.selector; + } + + function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata) + external + pure + returns (bytes4) + { + return this.onERC1155BatchReceived.selector; + } + fallback() external payable { SelectorConfig memory config = _selectorConfig(msg.sig); bool success; diff --git a/src/mock/MockERC1155.sol b/src/mock/MockERC1155.sol new file mode 100644 index 00000000..cf758e2a --- /dev/null +++ b/src/mock/MockERC1155.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "solady/tokens/ERC1155.sol"; + +contract MockERC1155 is ERC1155 { + function test_ignore() public {} + + function uri(uint256) public pure override returns (string memory) { + return "https://example.com"; + } + + function mint(address to, uint256 id, uint256 amount, bytes memory data) public { + _mint(to, id, amount, data); + } + + function batchMint(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public { + _batchMint(to, ids, amounts, data); + } +} diff --git a/src/mock/MockERC20.sol b/src/mock/MockERC20.sol new file mode 100644 index 00000000..18410054 --- /dev/null +++ b/src/mock/MockERC20.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "solady/tokens/ERC20.sol"; + +contract MockERC20 is ERC20 { + constructor() ERC20() {} + + function test_ignore() public {} + + function name() public pure override returns (string memory) { + return "MockERC20"; + } + + function symbol() public pure override returns (string memory) { + return "MOCK"; + } + + function mint(address _to, uint256 _amount) external { + _mint(_to, _amount); + } +} diff --git a/src/mock/MockERC721.sol b/src/mock/MockERC721.sol new file mode 100644 index 00000000..4cc30766 --- /dev/null +++ b/src/mock/MockERC721.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "solady/tokens/ERC721.sol"; + +contract MockERC721 is ERC721 { + constructor() ERC721() {} + + function test_ignore() public {} + + function name() public pure override returns (string memory) { + return "MockERC721"; + } + + function symbol() public pure override returns (string memory) { + return "MOCK"; + } + + function tokenURI(uint256) public pure override returns (string memory) { + return ""; + } + + function mint(address _to, uint256 _id) external { + _mint(_to, _id); + } + + function safeMint(address _to, uint256 _id) external { + _safeMint(_to, _id); + } +} diff --git a/src/sdk/KernelTestBase.sol b/src/sdk/KernelTestBase.sol index 65d0bbb9..4814d03e 100644 --- a/src/sdk/KernelTestBase.sol +++ b/src/sdk/KernelTestBase.sol @@ -12,6 +12,9 @@ import "../mock/MockAction.sol"; import "../mock/MockHook.sol"; import "../mock/MockExecutor.sol"; import "../mock/MockFallback.sol"; +import "../mock/MockERC20.sol"; +import "../mock/MockERC721.sol"; +import "../mock/MockERC1155.sol"; import "../core/ValidationManager.sol"; import "./TestBase/erc4337Util.sol"; @@ -43,6 +46,9 @@ abstract contract KernelTestBase is Test { MockHook mockHook; MockFallback mockFallback; MockExecutor mockExecutor; + MockERC20 mockERC20; + MockERC721 mockERC721; + MockERC1155 mockERC1155; IValidator enabledValidator; EnableValidatorConfig validationConfig; @@ -296,6 +302,9 @@ abstract contract KernelTestBase is Test { mockHook = new MockHook(); mockFallback = new MockFallback(); mockExecutor = new MockExecutor(); + mockERC20 = new MockERC20(); + mockERC721 = new MockERC721(); + mockERC1155 = new MockERC1155(); _setRootValidationConfig(); _setEnableValidatorConfig(); _setEnablePermissionConfig(); @@ -315,6 +324,25 @@ abstract contract KernelTestBase is Test { entrypoint.handleOps(ops, payable(address(0xdeadbeef))); } + function test_receive() external whenInitialized { + vm.expectEmit(false, false, false, true, address(kernel)); + emit Kernel.Received(address(this), 1); + (bool success,) = address(kernel).call{value: 1}(hex""); + require(success, "eth transfer failed"); + + mockERC721.mint(address(kernel), 100); + mockERC721.safeMint(address(kernel), 999); + + mockERC1155.mint(address(kernel), 100, 1, hex""); + uint256[] memory ids = new uint256[](2); + uint256[] memory amounts = new uint256[](2); + ids[0] = 200; + ids[1] = 201; + amounts[0] = 1; + amounts[1] = 1000; + mockERC1155.batchMint(address(kernel), ids, amounts, hex""); + } + function initData() internal view returns (bytes memory) { return abi.encodeWithSelector( Kernel.initialize.selector, diff --git a/src/sdk/TestBase/ActionTestBase.sol b/src/sdk/TestBase/ActionTestBase.sol deleted file mode 100644 index 15a8c0d1..00000000 --- a/src/sdk/TestBase/ActionTestBase.sol +++ /dev/null @@ -1,2 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; diff --git a/src/sdk/TestBase/ExecutorTestBase.sol b/src/sdk/TestBase/ExecutorTestBase.sol deleted file mode 100644 index 15a8c0d1..00000000 --- a/src/sdk/TestBase/ExecutorTestBase.sol +++ /dev/null @@ -1,2 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; diff --git a/src/sdk/TestBase/FallbackTestBase.sol b/src/sdk/TestBase/FallbackTestBase.sol deleted file mode 100644 index 15a8c0d1..00000000 --- a/src/sdk/TestBase/FallbackTestBase.sol +++ /dev/null @@ -1,2 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; diff --git a/src/sdk/TestBase/HookTestBase.sol b/src/sdk/TestBase/HookTestBase.sol deleted file mode 100644 index 15a8c0d1..00000000 --- a/src/sdk/TestBase/HookTestBase.sol +++ /dev/null @@ -1,2 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; diff --git a/src/sdk/TestBase/PolicyTestBase.sol b/src/sdk/TestBase/PolicyTestBase.sol deleted file mode 100644 index 15a8c0d1..00000000 --- a/src/sdk/TestBase/PolicyTestBase.sol +++ /dev/null @@ -1,2 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; diff --git a/src/sdk/TestBase/SignerTestBase.sol b/src/sdk/TestBase/SignerTestBase.sol deleted file mode 100644 index 15a8c0d1..00000000 --- a/src/sdk/TestBase/SignerTestBase.sol +++ /dev/null @@ -1,2 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; diff --git a/src/sdk/TestBase/ValidatorTestBase.sol b/src/sdk/TestBase/ValidatorTestBase.sol deleted file mode 100644 index 15a8c0d1..00000000 --- a/src/sdk/TestBase/ValidatorTestBase.sol +++ /dev/null @@ -1,2 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0;