-
Notifications
You must be signed in to change notification settings - Fork 3
/
Safe4337SessionKeyModule.sol
66 lines (56 loc) · 2.33 KB
/
Safe4337SessionKeyModule.sol
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
62
63
64
65
66
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "./UserOperation.sol";
import "./SessionKeyManager.sol";
import {BasePluginWithEventMetadata, PluginMetadata} from "./Base.sol";
interface ISafe {
/// @dev Allows a Module to execute a Safe transaction without any further confirmations.
/// @param to Destination address of module transaction.
/// @param value Ether value of module transaction.
/// @param data Data payload of module transaction.
/// @param operation Operation type of module transaction.
function execTransactionFromModule(address to, uint256 value, bytes calldata data, uint8 operation)
external
returns (bool success);
}
contract Safe4337SessionKeyPlugin is BasePluginWithEventMetadata {
address public immutable entryPoint;
SessionKeyManager public immutable sessionKeyManager;
constructor(address _entryPoint)
BasePluginWithEventMetadata(
PluginMetadata({
name: "Safe4337SessionKeyPlugin",
version: "0.0.1",
requiresRootAccess: false,
iconUrl: "",
appUrl: ""
})
)
{
entryPoint = _entryPoint;
sessionKeyManager = new SessionKeyManager(address(this));
}
function validateUserOp(UserOperation calldata userOp, bytes32 userOpHash, uint256 missingAccountFunds)
external
returns (uint256 validationData)
{
require(msg.sender == entryPoint, "only entry point");
validationData = sessionKeyManager.validateUserOp(userOp, userOpHash);
if (validationData != 0) {
return validationData;
}
address payable safeAddress = payable(userOp.sender);
ISafe senderSafe = ISafe(safeAddress);
if (missingAccountFunds != 0) {
senderSafe.execTransactionFromModule(entryPoint, missingAccountFunds, "", 0);
}
}
function execTransaction(address safeAddress, address to, uint256 value, bytes calldata data) external payable {
require(msg.sender == entryPoint, "only entry point");
ISafe safe = ISafe(safeAddress);
require(safe.execTransactionFromModule(to, value, data, 0), "tx failed");
}
function setMerkleRoot(bytes32 merkleRoot) external {
sessionKeyManager.setMerkleRootSafe(msg.sender, merkleRoot);
}
}