Skip to content

Commit badb64f

Browse files
authored
add SimpleSchemeConstraint.sol (#803)
* add SimpleSchemeConstraint.sol * test coverage * bump v to rc.48
1 parent b2e988e commit badb64f

File tree

5 files changed

+408
-150
lines changed

5 files changed

+408
-150
lines changed

contracts/schemes/SchemeConstraints.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import "../controller/Avatar.sol";
66
contract SchemeConstraints {
77

88
address[] public contractsWhiteList;
9+
//descriptionHash can be used to add detalis description of the constraints.
10+
//e.g it can be ipfs hash of the contractsWhiteList abis +names.
11+
string public descriptionHash;
912

1013
/*
1114
* @dev isAllowedToCall should be called upon a proposal execution.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
pragma solidity 0.5.17;
2+
pragma experimental ABIEncoderV2;
3+
4+
import "./SchemeConstraints.sol";
5+
6+
//a simple genericSchemeMultiCall constraint which put constraints only on white listed contracts to call.
7+
8+
contract SimpleSchemeConstraints is SchemeConstraints {
9+
10+
mapping(address=>bool) public contractsWhiteListMap;
11+
bool public initialized;
12+
13+
/* @dev initialize
14+
* @param _contractsWhiteList the contracts the scheme is allowed to interact with
15+
* @param _descriptionHash can be used to add detalis description of the constraints.
16+
*/
17+
function initialize(
18+
address[] calldata _contractsWhiteList,
19+
string calldata _descriptionHash
20+
)
21+
external {
22+
require(!initialized, "cannot initialize twice");
23+
initialized = true;
24+
for (uint i = 0; i < _contractsWhiteList.length; i++) {
25+
contractsWhiteListMap[_contractsWhiteList[i]] = true;
26+
}
27+
contractsWhiteList = _contractsWhiteList;
28+
descriptionHash = _descriptionHash;
29+
}
30+
31+
/*
32+
* @dev isAllowedToCall should be called upon a proposal execution.
33+
* @param _contractsToCall the contracts to be called
34+
* @return bool value true-allowed false not allowed
35+
*/
36+
function isAllowedToCall(
37+
address[] calldata _contractsToCall,
38+
bytes[] calldata,
39+
uint256[] calldata,
40+
Avatar
41+
)
42+
external
43+
returns(bool)
44+
{
45+
for (uint i = 0; i < _contractsToCall.length; i++) {
46+
require(contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted");
47+
}
48+
return true;
49+
}
50+
51+
/*
52+
* @dev isAllowedToPropose should be called upon a proposal submition.
53+
* @param _contractsToCall the contracts to be called
54+
* @return bool value true-allowed false not allowed
55+
*/
56+
function isAllowedToPropose(
57+
address[] calldata _contractsToCall,
58+
bytes[] calldata,
59+
uint256[] calldata,
60+
Avatar)
61+
external
62+
returns(bool)
63+
{
64+
for (uint i = 0; i < _contractsToCall.length; i++) {
65+
require(contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted");
66+
}
67+
return true;
68+
}
69+
}

0 commit comments

Comments
 (0)