forked from zerodevapp/kernel
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKernelFactory.sol
More file actions
61 lines (49 loc) · 2.22 KB
/
KernelFactory.sol
File metadata and controls
61 lines (49 loc) · 2.22 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {AdminLessERC1967Factory} from "./AdminLessERC1967Factory.sol";
import {IEntryPoint} from "I4337/interfaces/IEntryPoint.sol";
import {Ownable} from "solady/auth/Ownable.sol";
contract KernelFactory is AdminLessERC1967Factory, Ownable {
/// Error throwned when an implementation isn't allowed
error ImplementationNotAllowed();
/// @dev The entry point contract.
IEntryPoint public entryPoint;
/// @dev Check if an implementation is allowed.
mapping(address implementation => bool isAllowed) public isAllowedImplementation;
constructor(address _owner, IEntryPoint _entryPoint) {
_initializeOwner(_owner);
entryPoint = _entryPoint;
}
function setImplementation(address _implementation, bool _allow) external onlyOwner {
isAllowedImplementation[_implementation] = _allow;
}
function setEntryPoint(IEntryPoint _entryPoint) external onlyOwner {
entryPoint = _entryPoint;
}
function createAccount(address _implementation, bytes calldata _data, uint256 _index)
external
payable
returns (address proxy)
{
// Ensure that the implementation contract is allowed
if (!isAllowedImplementation[_implementation]) revert ImplementationNotAllowed();
// Create the salt for the account
bytes32 salt = bytes32(uint256(keccak256(abi.encodePacked(_data, _index))) & type(uint96).max);
// Deploy the proxy and return it's address
proxy = deployDeterministicAndCall(_implementation, salt, _data);
}
function getAccountAddress(bytes calldata _data, uint256 _index) public view returns (address) {
bytes32 salt = bytes32(uint256(keccak256(abi.encodePacked(_data, _index))) & type(uint96).max);
return predictDeterministicAddress(salt);
}
// stake functions
function addStake(uint32 unstakeDelaySec) external payable onlyOwner {
entryPoint.addStake{value: msg.value}(unstakeDelaySec);
}
function unlockStake() external onlyOwner {
entryPoint.unlockStake();
}
function withdrawStake(address payable withdrawAddress) external onlyOwner {
entryPoint.withdrawStake(withdrawAddress);
}
}