Skip to content

Commit

Permalink
schemeConstraint - add enableSendEth flag (#816)
Browse files Browse the repository at this point in the history
* schemeConstraint - add enableSendEth flag

* bump v to rc.56
  • Loading branch information
orenyodfat authored Feb 3, 2021
1 parent 24f5a6c commit 26abb69
Show file tree
Hide file tree
Showing 6 changed files with 1,213 additions and 997 deletions.
17 changes: 14 additions & 3 deletions contracts/schemes/SimpleSchemeConstraints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ contract SimpleSchemeConstraints is SchemeConstraints {

mapping(address=>bool) public contractsWhiteListMap;
bool public initialized;
bool public enableSendEth;

/* @dev initialize
* @param _contractsWhiteList the contracts the scheme is allowed to interact with
* @param _descriptionHash can be used to add detalis description of the constraints.
*/
function initialize(
address[] calldata _contractsWhiteList,
string calldata _descriptionHash
string calldata _descriptionHash,
bool _enableSendEth
)
external {
require(!initialized, "cannot initialize twice");
Expand All @@ -26,43 +28,52 @@ contract SimpleSchemeConstraints is SchemeConstraints {
}
contractsWhiteList = _contractsWhiteList;
descriptionHash = _descriptionHash;
enableSendEth = _enableSendEth;
}

/*
* @dev isAllowedToCall should be called upon a proposal execution.
* @param _contractsToCall the contracts to be called
* @param _values value(ETH) to transfer with the calls
* @return bool value true-allowed false not allowed
*/
function isAllowedToCall(
address[] calldata _contractsToCall,
bytes[] calldata,
uint256[] calldata,
uint256[] calldata _values,
Avatar
)
external
returns(bool)
{
for (uint i = 0; i < _contractsToCall.length; i++) {
require(contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted");
if (!enableSendEth) {
require(_values[i] == 0, "sending eth is not allowed");
}
}
return true;
}

/*
* @dev isAllowedToPropose should be called upon a proposal submition.
* @param _contractsToCall the contracts to be called
* @param _values value(ETH) to transfer with the calls
* @return bool value true-allowed false not allowed
*/
function isAllowedToPropose(
address[] calldata _contractsToCall,
bytes[] calldata,
uint256[] calldata,
uint256[] calldata _values,
Avatar)
external
returns(bool)
{
for (uint i = 0; i < _contractsToCall.length; i++) {
require(contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted");
if (!enableSendEth) {
require(_values[i] == 0, "sending eth is not allowed");
}
}
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion contracts/utils/GenericSchemeMultiCallFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ contract GenericSchemeMultiCallFactory {
uint256[11] memory _votingParams,
address _voteOnBehalf,
address[] memory _contractsWhiteList,
bool _enableSendEth,
string memory _descriptionHash
) public returns(address) {
require(_voteParamsType < 4, "Vote params type specified does not exist");
GenericSchemeMultiCall genericSchemeMultiCall = new GenericSchemeMultiCall();
address simpleSchemeConstraints;
if (_contractsWhiteList.length > 0) {
simpleSchemeConstraints = address(new SimpleSchemeConstraints());
SimpleSchemeConstraints(simpleSchemeConstraints).initialize(_contractsWhiteList, _descriptionHash);
SimpleSchemeConstraints(simpleSchemeConstraints)
.initialize(_contractsWhiteList, _descriptionHash, _enableSendEth);
}
uint256[11] memory voteParams;
if (_voteParamsType == CUSTOM) {
Expand Down
Loading

0 comments on commit 26abb69

Please sign in to comment.