mirror of
https://github.com/status-im/visual-identity.git
synced 2025-02-12 20:46:35 +00:00
democracy , constitution and factory refactor
This commit is contained in:
parent
1544368968
commit
ed798f4a91
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.17;
|
||||
pragma solidity ^0.4.21;
|
||||
|
||||
import "../common/Controlled.sol";
|
||||
import "../token/ERC20Token.sol";
|
||||
|
@ -1,5 +0,0 @@
|
||||
pragma solidity ^0.4.17;
|
||||
|
||||
contract ProposalExecutor {
|
||||
function executeProposal(address topic, uint value, bytes data) external returns (bool success);
|
||||
}
|
@ -1,58 +1,18 @@
|
||||
pragma solidity ^0.4.17;
|
||||
pragma solidity ^0.4.21;
|
||||
|
||||
import "./ProposalManagerInterface.sol";
|
||||
import "./TrustNetworkInterface.sol";
|
||||
import "./DelegationProxyInterface.sol";
|
||||
import "../token/MiniMeTokenInterface.sol";
|
||||
import "../common/Controlled.sol";
|
||||
import "./ProposalExecutor.sol";
|
||||
|
||||
/**
|
||||
* @title ProposalManager
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* Store the proposals, votes and results for other smartcontracts
|
||||
*/
|
||||
contract ProposalManager is Controlled {
|
||||
|
||||
TrustNetworkInterface public trustNet;
|
||||
MiniMeTokenInterface public token;
|
||||
uint256 public tabulationBlockDelay = 10000;
|
||||
|
||||
Proposal[] proposals;
|
||||
|
||||
struct Proposal {
|
||||
bytes32 topic;
|
||||
|
||||
bytes32 txHash;
|
||||
|
||||
uint stake;
|
||||
address staker;
|
||||
|
||||
uint blockStart;
|
||||
uint voteBlockEnd;
|
||||
uint vetoBlockEnd;
|
||||
|
||||
mapping(address => Vote) voteMap;
|
||||
|
||||
mapping(address => Tabulations) tabulated;
|
||||
|
||||
mapping(uint8 => uint256) results;
|
||||
|
||||
bool approved;
|
||||
bool executed;
|
||||
}
|
||||
|
||||
struct Tabulations {
|
||||
bool vote;
|
||||
bool veto;
|
||||
}
|
||||
|
||||
enum Vote {
|
||||
Null,
|
||||
Reject,
|
||||
Approve,
|
||||
Veto
|
||||
}
|
||||
|
||||
contract ProposalManager is ProposalManagerInterface, Controlled {
|
||||
|
||||
function ProposalManager(MiniMeTokenInterface _SNT, TrustNetworkInterface _trustNet) public {
|
||||
trustNet = _trustNet;
|
||||
token = _SNT;
|
||||
@ -85,14 +45,6 @@ contract ProposalManager is Controlled {
|
||||
return proposals[id].txHash;
|
||||
}
|
||||
|
||||
function execute(uint id, address dest, uint value, bytes data) public {
|
||||
Proposal memory p = proposals[id];
|
||||
require(p.approved == true);
|
||||
require(keccak256(dest, value, data) == p.txHash);
|
||||
proposals[id].executed = true;
|
||||
ProposalExecutor(controller).executeProposal(dest, value, data);
|
||||
}
|
||||
|
||||
function vote(uint _proposal, Vote _vote) public {
|
||||
Proposal storage proposal = proposals[_proposal];
|
||||
require(block.number >= proposal.blockStart);
|
||||
@ -106,17 +58,14 @@ contract ProposalManager is Controlled {
|
||||
|
||||
}
|
||||
|
||||
function tabulateVote(uint _proposal, address _delegator) public {
|
||||
function tabulateVote(uint _proposal, address _delegator) public {
|
||||
Proposal storage proposal = proposals[_proposal];
|
||||
require(block.number > proposal.voteBlockEnd);
|
||||
require(!proposal.tabulated[_delegator].vote);
|
||||
proposal.tabulated[_delegator].vote = true;
|
||||
Vote _vote = proposal.voteMap[_delegator];
|
||||
if(_vote == Vote.Null) {
|
||||
DelegationProxyInterface voteDelegation;
|
||||
DelegationProxyInterface vetoDelegation;
|
||||
(voteDelegation, vetoDelegation) = trustNet.getTopic(proposal.topic);
|
||||
address delegate = voteDelegation.delegationOfAt(_delegator, proposal.vetoBlockEnd);
|
||||
address delegate = trustNet.getVoteDelegation(proposal.topic).delegationOfAt(_delegator, proposal.vetoBlockEnd);
|
||||
_vote = proposal.voteMap[delegate];
|
||||
}
|
||||
|
||||
@ -132,10 +81,7 @@ contract ProposalManager is Controlled {
|
||||
proposal.tabulated[_delegator].veto = true;
|
||||
Vote _vote = proposal.voteMap[_delegator];
|
||||
if (_vote == Vote.Null) {
|
||||
DelegationProxyInterface voteDelegation;
|
||||
DelegationProxyInterface vetoDelegation;
|
||||
(voteDelegation, vetoDelegation) = trustNet.getTopic(proposal.topic);
|
||||
address delegate = vetoDelegation.delegationOfAt(_delegator, proposal.vetoBlockEnd);
|
||||
address delegate = trustNet.getVetoDelegation(proposal.topic).delegationOfAt(_delegator, proposal.vetoBlockEnd);
|
||||
_vote = proposal.voteMap[delegate];
|
||||
}
|
||||
|
||||
@ -159,4 +105,11 @@ contract ProposalManager is Controlled {
|
||||
proposal.approved = true;
|
||||
require(token.transferFrom(address(this), proposal.staker, proposal.stake));
|
||||
}
|
||||
|
||||
function setExecuted(uint id) public onlyController {
|
||||
Proposal memory p = proposals[id];
|
||||
require(p.approved);
|
||||
require(!p.executed);
|
||||
proposals[id].executed = true;
|
||||
}
|
||||
}
|
59
contracts/democracy/ProposalManagerInterface.sol
Normal file
59
contracts/democracy/ProposalManagerInterface.sol
Normal file
@ -0,0 +1,59 @@
|
||||
pragma solidity ^0.4.21;
|
||||
|
||||
import "./TrustNetworkInterface.sol";
|
||||
import "./DelegationProxyInterface.sol";
|
||||
import "../token/MiniMeTokenInterface.sol";
|
||||
|
||||
/**
|
||||
* @title ProposalManager
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* Store the proposals, votes and results for other smartcontracts
|
||||
*/
|
||||
contract ProposalManagerInterface {
|
||||
|
||||
TrustNetworkInterface public trustNet;
|
||||
MiniMeTokenInterface public token;
|
||||
uint256 public tabulationBlockDelay;
|
||||
|
||||
Proposal[] public proposals;
|
||||
|
||||
struct Proposal {
|
||||
bytes32 topic;
|
||||
bytes32 txHash;
|
||||
|
||||
uint stake;
|
||||
address staker;
|
||||
|
||||
uint blockStart;
|
||||
uint voteBlockEnd;
|
||||
uint vetoBlockEnd;
|
||||
|
||||
mapping(address => Vote) voteMap;
|
||||
mapping(address => Tabulations) tabulated;
|
||||
mapping(uint8 => uint256) results;
|
||||
|
||||
bool approved;
|
||||
bool executed;
|
||||
}
|
||||
|
||||
struct Tabulations {
|
||||
bool vote;
|
||||
bool veto;
|
||||
}
|
||||
|
||||
enum Vote {
|
||||
Null,
|
||||
Reject,
|
||||
Approve,
|
||||
Veto
|
||||
}
|
||||
|
||||
function addProposal(bytes32 _topic, bytes32 _txHash, uint _stake) public returns (uint);
|
||||
function getProposal(uint id) public constant returns (bytes32 topic, bytes32 txHash, uint stake, address staker, bool approved, bool executed);
|
||||
function getProposalTxHash(uint id) public constant returns(bytes32);
|
||||
function vote(uint _proposal, Vote _vote) public;
|
||||
function tabulateVote(uint _proposal, address _delegator) public;
|
||||
function tabulateVeto(uint _proposal, address _delegator) public;
|
||||
function approve(uint _proposal) public;
|
||||
function setExecuted(uint id) public;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.10;
|
||||
pragma solidity ^0.4.21;
|
||||
|
||||
import "../common/Controlled.sol";
|
||||
import "./TrustNetworkInterface.sol";
|
||||
@ -16,8 +16,8 @@ contract TrustNetwork is TrustNetworkInterface, Controlled {
|
||||
DelegationProxyFactory delegationFactory;
|
||||
|
||||
struct Topic {
|
||||
DelegationProxy voteProxy;
|
||||
DelegationProxy vetoProxy;
|
||||
DelegationProxy voteDelegation;
|
||||
DelegationProxy vetoDelegation;
|
||||
}
|
||||
|
||||
function TrustNetwork(address _delegationFactory) public {
|
||||
@ -27,29 +27,49 @@ contract TrustNetwork is TrustNetworkInterface, Controlled {
|
||||
|
||||
function addTopic(bytes32 topicId, bytes32 parentTopic) public onlyController {
|
||||
Topic memory parent = topics[parentTopic];
|
||||
address vote = address(parent.voteProxy);
|
||||
address veto = address(parent.vetoProxy);
|
||||
address vote = address(parent.voteDelegation);
|
||||
address veto = address(parent.vetoDelegation);
|
||||
require(vote != 0x0);
|
||||
require(veto != 0x0);
|
||||
|
||||
Topic storage topic = topics[topicId];
|
||||
require(address(topic.voteProxy) == 0x0);
|
||||
require(address(topic.vetoProxy) == 0x0);
|
||||
|
||||
require(address(topic.voteDelegation) == 0x0);
|
||||
require(address(topic.vetoDelegation) == 0x0);
|
||||
|
||||
topics[topicId] = newTopic(vote, veto);
|
||||
}
|
||||
|
||||
function getTopic(bytes32 _topicId) public constant returns (DelegationProxyInterface vote, DelegationProxyInterface veto) {
|
||||
Topic memory topic = topics[_topicId];
|
||||
vote = topic.voteProxy;
|
||||
veto = topic.vetoProxy;
|
||||
vote = topic.voteDelegation;
|
||||
veto = topic.vetoDelegation;
|
||||
}
|
||||
|
||||
function getVoteDelegation(
|
||||
bytes32 _topicId
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (DelegationProxyInterface voteDelegation)
|
||||
{
|
||||
return topics[_topicId].voteDelegation;
|
||||
}
|
||||
|
||||
function getVetoDelegation(
|
||||
bytes32 _topicId
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (DelegationProxyInterface vetoDelegation)
|
||||
{
|
||||
return topics[_topicId].vetoDelegation;
|
||||
}
|
||||
|
||||
|
||||
function newTopic(address _vote, address _veto) internal returns (Topic topic) {
|
||||
topic = Topic ({
|
||||
voteProxy: delegationFactory.create(_vote),
|
||||
vetoProxy: delegationFactory.create(_veto)
|
||||
voteDelegation: delegationFactory.createDelegationProxy(_vote),
|
||||
vetoDelegation: delegationFactory.createDelegationProxy(_veto)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.17;
|
||||
pragma solidity ^0.4.21;
|
||||
|
||||
import "./DelegationProxyInterface.sol";
|
||||
|
||||
@ -6,5 +6,6 @@ contract TrustNetworkInterface {
|
||||
|
||||
function addTopic(bytes32 topicId, bytes32 parentTopic) public;
|
||||
function getTopic(bytes32 _topicId) public constant returns (DelegationProxyInterface vote, DelegationProxyInterface veto);
|
||||
|
||||
function getVoteDelegation(bytes32 _topicId) public view returns (DelegationProxyInterface voteDelegation);
|
||||
function getVetoDelegation(bytes32 _topicId) public view returns (DelegationProxyInterface vetoDelegation);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
pragma solidity ^0.4.10;
|
||||
|
||||
import "./TrustNetwork.sol";
|
||||
import "../deploy/KillableModel.sol";
|
||||
|
||||
/**
|
||||
* @title TrustNetworkModel
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* Model for TrustNetwork
|
||||
*/
|
||||
contract TrustNetworkModel is KillableModel, TrustNetwork {
|
||||
|
||||
|
||||
function TrustNetworkModel(address _watchdog) KillableModel(_watchdog) TrustNetwork(0x0) public {
|
||||
|
||||
}
|
||||
|
||||
function create(address _delegationFactory) public {
|
||||
require(topics[0x0].voteProxy == address(0x0));
|
||||
delegationFactory = DelegationProxyFactory(_delegationFactory);
|
||||
topics[0x0] = newTopic(0x0, 0x0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user