creationRules and triggeringRules Example

As explained earlier in this section, the creationRules and triggeringRules contracts, representing key parts of governance rule-sets, are external contracts; they can be freely coded based on the needs of your organization.

On this page are some examples of creationRulesminate and triggeringRules contracts.

Note

Keep in mind that, for them to work correctly, the creationRulesminate and triggeringRules contracts must integrate the check function of the IProposalChecker interface, which is provided by the IProposalManager interface.

If you don't need creationRules and triggeringRules you can pass them as address(0), in this way, everyone will be able to create and terminate Proposals.

creationRules

Contract n1- BySpecificAddress:

pragma solidity >=0.7.0;

import "../../base/model/IProposalsManager.sol";
import "../../core/model/IOrganization.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@ethereansos/items-v2/contracts/model/Item.sol";
import {TransferUtilities} from "@ethereansos/swissknife/contracts/lib/GeneralUtilities.sol";

contract BySpecificAddress is IProposalChecker {

    string public constant LABEL = 'host';

    string public uri;
    address public value;
    bool public discriminant;

    function lazyInit(bytes memory lazyInitData) external returns(bytes memory lazyInitResponseData) {
        require(keccak256(bytes(uri)) == keccak256(""));
        (uri, lazyInitResponseData) = abi.decode(lazyInitData, (string, bytes));
        require(keccak256(bytes(uri)) != keccak256(""));

        (value, discriminant) = abi.decode(lazyInitResponseData, (address, bool));

        lazyInitResponseData = "";
    }

    function setValue(address newValue) external {
        require(msg.sender == value, "unauthorized");
        require(discriminant, "cannot change");
        require(newValue != address(0), "void");
        value = newValue;
    }

    function makeReadOnly() external {
        require(msg.sender == value, "unauthorized");
        require(discriminant, "cannot change");
        discriminant = false;
    }

    function check(address, bytes32, bytes calldata, address from, address) external override view returns(bool) {
        return from == value;
    }
}

This creationRules contract can be used to define a specific wallet that can create Proposal through the batchCreate function of the Proposal Manager.

The lazyInit initializes:

  • string uri -> represents the uri containing metadata of the contract.

  • address value -> represents the address that can create Proposals.

  • bool discriminant -> boolean value representing if the address value can be changed later using the setValue function (true) or not (false).

The setValue function can be called by the set value address to change the value address passing its power to the new value address. This function can be called only if the discriminant parameter is set as true.

No one besides the value address can create Proposals in the Proposal Manager.

triggeringRules

Coming soon

This is, of course, only an example of how creationRules and triggeringRules contracts can be used. Every project can create its own unique rules.

Last updated