-
Notifications
You must be signed in to change notification settings - Fork 49
/
ERC3000Data.sol
78 lines (66 loc) · 2.17 KB
/
ERC3000Data.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
71
72
73
74
75
76
77
78
/*
* SPDX-License-Identifier: MIT
*/
pragma solidity ^0.6.8;
pragma experimental ABIEncoderV2;
import "./IERC3000Executor.sol";
library ERC3000Data {
// TODO: come up with a non-shitty name
struct Container {
Payload payload;
Config config;
}
// WARN: Always remember to change the 'hash' function if modifying the struct
struct Payload {
uint256 nonce;
uint256 executionTime;
address submitter;
IERC3000Executor executor;
Action[] actions;
bytes32 allowFailuresMap;
bytes proof;
}
struct Action {
address to;
uint256 value;
bytes data;
}
struct Config {
uint256 executionDelay; // how many seconds to wait before being able to call `execute`.
Collateral scheduleDeposit; // fees for scheduling
Collateral challengeDeposit; // fees for challenging
address resolver; // resolver that will rule the disputes
bytes rules; // rules of how DAO should be managed
uint256 maxCalldataSize; // max calldatasize for the schedule
}
struct Collateral {
address token;
uint256 amount;
}
function containerHash(bytes32 payloadHash, bytes32 configHash) internal view returns (bytes32) {
uint chainId;
assembly {
chainId := chainid()
}
return keccak256(abi.encodePacked("erc3k-v1", address(this), chainId, payloadHash, configHash));
}
function hash(Container memory container) internal view returns (bytes32) {
return containerHash(hash(container.payload), hash(container.config));
}
function hash(Payload memory payload) internal pure returns (bytes32) {
return keccak256(
abi.encode(
payload.nonce,
payload.executionTime,
payload.submitter,
payload.executor,
keccak256(abi.encode(payload.actions)),
payload.allowFailuresMap,
keccak256(payload.proof)
)
);
}
function hash(Config memory config) internal pure returns (bytes32) {
return keccak256(abi.encode(config));
}
}