-
Notifications
You must be signed in to change notification settings - Fork 0
/
PermissionCallableCounterAllowance.sol
66 lines (56 loc) · 2.68 KB
/
PermissionCallableCounterAllowance.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: UNLICENSED
pragma solidity ^0.8.13;
import {IPermissionContract} from "../../../lib/smart-wallet-permissions/src/interfaces/IPermissionContract.sol";
import {UserOperation} from "../../../lib/smart-wallet-permissions/src/utils/UserOperationLib.sol";
import {CounterAllowance} from "../logic/CounterAllowance.sol";
contract PermissionCallableCounterAllowance is CounterAllowance, IPermissionContract {
/// @notice Permission-specific values for this permission contract.
struct PermissionValues {
/// @dev Recurring native token allowance value (struct).
CounterAllowanceDetails counterAllowance;
/// @dev Single contract allowed to make custom external calls to.
address allowedContract;
}
/// @notice Address of the permission manager.
address permissionManager;
/// @notice Constructor.
///
/// @param permissionManager_ Address of the permission manager.
constructor(address permissionManager_) {
permissionManager = permissionManager_;
}
/// @notice Initialize the permission values.
///
/// @dev Called by permission manager on approval transaction.
///
/// @param account Account of the permission.
/// @param permissionHash Hash of the permission.
/// @param permissionValues Permission-specific values for this permission contract.
function initializePermission(address account, bytes32 permissionHash, bytes calldata permissionValues) external {
(PermissionValues memory values) = abi.decode(permissionValues, (PermissionValues));
// check sender is permission manager
if (msg.sender != permissionManager) revert InvalidInitializePermissionSender(msg.sender);
_initializeCounterAllowance(account, permissionHash, values.counterAllowance);
}
/// @notice Use the counter allowance.
///
/// @dev Called by permission manager on transaction.
///
/// @param permissionHash Hash of the permission.
function useCounterAllowance(bytes32 permissionHash) external {
_useCounterAllowance({account: msg.sender, permissionHash: permissionHash});
}
/// @notice Validate the permission to execute a userOp.
///
/// @dev Does not have access to certain storage values. Just checks selectors and addresses called are allowed
///
/// @param permissionHash Hash of the permission.
/// @param permissionValues Permission-specific values for this permission contract.
/// @param userOp User operation to validate permission for.
function validatePermission(bytes32 permissionHash, bytes calldata permissionValues, UserOperation calldata userOp)
external
view
{
// todo
}
}