-
Notifications
You must be signed in to change notification settings - Fork 10
/
PolicyRegistry.sol
70 lines (58 loc) · 2.66 KB
/
PolicyRegistry.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
70
/// SPDX-License-Identifier: BUSL-1.1
/// Copyright (C) 2023 Brahma.fi
pragma solidity 0.8.19;
import {AddressProviderService} from "src/core/AddressProviderService.sol";
import {WalletRegistry} from "src/core/registries/WalletRegistry.sol";
/**
* @title PolicyRegistry
* @author Brahma.fi
* @notice Registry for policy commits for wallets and sub accounts
*/
contract PolicyRegistry is AddressProviderService {
error PolicyCommitInvalid();
error UnauthorizedPolicyUpdate();
event UpdatedPolicyCommit(address indexed account, bytes32 policyCommit, bytes32 oldPolicyCommit);
/// @notice account addresses mapped to their policy commits
mapping(address account => bytes32 policyCommit) public commitments;
constructor(address _addressProvider) AddressProviderService(_addressProvider) {}
/**
* @notice Enables setting policy commits for accounts
* @param account address of account to set policy commit for
* @param policyCommit policy commit hash to set
* @dev policyCommit for an account can be set by:
* 1. by safe deployer, if the account is uninitialized
* 2. by the registered wallet, if the account is a subAccount
* 3. by the account itself, if account is a registered wallet
*/
function updatePolicy(address account, bytes32 policyCommit) external {
if (policyCommit == bytes32(0)) {
revert PolicyCommitInvalid();
}
WalletRegistry walletRegistry = WalletRegistry(AddressProviderService._getRegistry(_WALLET_REGISTRY_HASH));
bytes32 currentCommit = commitments[account];
// solhint-disable no-empty-blocks
if (
currentCommit == bytes32(0)
&& msg.sender == AddressProviderService._getAuthorizedAddress(_SAFE_DEPLOYER_HASH)
) {
// In case invoker is safe deployer
} else if (walletRegistry.isOwner(msg.sender, account)) {
//In case invoker is updating on behalf of sub account
} else if (msg.sender == account && walletRegistry.isWallet(account)) {
// In case invoker is a registered wallet
} else {
revert UnauthorizedPolicyUpdate();
}
// solhint-enable no-empty-blocks
_updatePolicy(account, policyCommit);
}
/**
* @notice Internal function to update policy commit for an account
* @param account address of account to set policy commit for
* @param policyCommit policy commit hash to set
*/
function _updatePolicy(address account, bytes32 policyCommit) internal {
emit UpdatedPolicyCommit(account, policyCommit, commitments[account]);
commitments[account] = policyCommit;
}
}