-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathProposalStorage.sol
59 lines (50 loc) · 1.81 KB
/
ProposalStorage.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
// SPDX-License-Identifier: Beta Software
pragma solidity ^0.8;
import "./IProposalExecutionEngine.sol";
import "../utils/LibRawResult.sol";
import "../tokens/IERC721.sol";
// The storage bucket shared by `PartyGovernance` and the `ProposalExecutionEngine`.
// Read this for more context on the pattern motivating this:
// https://github.com/dragonfly-xyz/useful-solidity-patterns/tree/main/patterns/explicit-storage-buckets
contract ProposalStorage {
using LibRawResult for bytes;
struct SharedProposalStorage {
IProposalExecutionEngine engineImpl;
}
uint256 internal constant PROPOSAL_FLAG_UNANIMOUS = 0x1;
uint256 private constant SHARED_STORAGE_SLOT = uint256(keccak256("ProposalStorage.SharedProposalStorage"));
function _getProposalExecutionEngine()
internal
view
returns (IProposalExecutionEngine impl)
{
return _getSharedProposalStorage().engineImpl;
}
function _setProposalExecutionEngine(IProposalExecutionEngine impl) internal {
_getSharedProposalStorage().engineImpl = impl;
}
function _initProposalImpl(IProposalExecutionEngine impl, bytes memory initData)
internal
{
SharedProposalStorage storage stor = _getSharedProposalStorage();
IProposalExecutionEngine oldImpl = stor.engineImpl;
stor.engineImpl = impl;
(bool s, bytes memory r) = address(impl).delegatecall(
abi.encodeCall(
IProposalExecutionEngine.initialize,
(address(oldImpl), initData)
)
);
if (!s) {
r.rawRevert();
}
}
function _getSharedProposalStorage()
private
pure
returns (SharedProposalStorage storage stor)
{
uint256 s = SHARED_STORAGE_SLOT;
assembly { stor.slot := s }
}
}