Skip to content

Commit

Permalink
add SimpleSchemeConstraint.sol (#803)
Browse files Browse the repository at this point in the history
* add SimpleSchemeConstraint.sol

* test coverage

* bump v to rc.48
  • Loading branch information
orenyodfat authored Nov 9, 2020
1 parent b2e988e commit badb64f
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 150 deletions.
3 changes: 3 additions & 0 deletions contracts/schemes/SchemeConstraints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import "../controller/Avatar.sol";
contract SchemeConstraints {

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

/*
* @dev isAllowedToCall should be called upon a proposal execution.
Expand Down
69 changes: 69 additions & 0 deletions contracts/schemes/SimpleSchemeConstraints.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
pragma solidity 0.5.17;
pragma experimental ABIEncoderV2;

import "./SchemeConstraints.sol";

//a simple genericSchemeMultiCall constraint which put constraints only on white listed contracts to call.

contract SimpleSchemeConstraints is SchemeConstraints {

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

/* @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
)
external {
require(!initialized, "cannot initialize twice");
initialized = true;
for (uint i = 0; i < _contractsWhiteList.length; i++) {
contractsWhiteListMap[_contractsWhiteList[i]] = true;
}
contractsWhiteList = _contractsWhiteList;
descriptionHash = _descriptionHash;
}

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

/*
* @dev isAllowedToPropose should be called upon a proposal submition.
* @param _contractsToCall the contracts to be called
* @return bool value true-allowed false not allowed
*/
function isAllowedToPropose(
address[] calldata _contractsToCall,
bytes[] calldata,
uint256[] calldata,
Avatar)
external
returns(bool)
{
for (uint i = 0; i < _contractsToCall.length; i++) {
require(contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted");
}
return true;
}
}
Loading

0 comments on commit badb64f

Please sign in to comment.