Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schemeConstraint - add enableSendEth flag #816

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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