generated from z0r0z/zenplate
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Account.sol
69 lines (64 loc) · 1.97 KB
/
Account.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
67
68
69
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import {ERC4337} from "@solady/src/accounts/ERC4337.sol";
/// @notice Simple extendable smart account implementation.
/// @author nani.eth (https://github.com/NaniDAO/accounts/blob/main/src/Account.sol)
contract Account is ERC4337 {
/// @dev Constructs
/// this implementation.
constructor() payable {}
/// @dev Returns domain name
/// & version of implementation.
function _domainNameAndVersion()
internal
pure
virtual
override
returns (string memory, string memory)
{
return ("NANI", "0.0.0");
}
/// @dev Validates userOp
/// with nonce handling.
function validateUserOp(
UserOperation calldata userOp,
bytes32 userOpHash,
uint256 missingAccountFunds
)
external
payable
virtual
override
onlyEntryPoint
payPrefund(missingAccountFunds)
returns (uint256)
{
return userOp.nonce < type(uint64).max
? _validateSignature(userOp, userOpHash)
: _validateUserOp();
}
/// @dev Extends validation by forwarding calldata to validator.
function _validateUserOp() internal virtual returns (uint256) {
/// @solidity memory-safe-assembly
assembly {
calldatacopy(0x00, 0x00, calldatasize())
if iszero(
call(
gas(),
/*validator*/
shr(96, sload(shl(64, /*key*/ shr(64, /*nonce*/ calldataload(0x84))))),
0,
0x00,
calldatasize(),
0x00,
0x20
)
) {
// Bubble up the revert if the call reverts.
returndatacopy(0x00, 0x00, returndatasize())
revert(0x00, returndatasize())
}
return(0x00, 0x20) // `validationData`.
}
}
}