reorg folder + proposal factory
This commit is contained in:
parent
7b24a56cfd
commit
1f972e201d
|
@ -1,7 +1,7 @@
|
|||
pragma solidity >=0.5.0 <0.6.0;
|
||||
|
||||
import "./Delegation.sol";
|
||||
import "../common/Controlled.sol";
|
||||
import "../../common/Controlled.sol";
|
||||
|
||||
contract DefaultDelegation is Delegation, Controlled {
|
||||
address public defaultDelegate;
|
|
@ -1,6 +1,6 @@
|
|||
pragma solidity >=0.5.0 <0.6.0;
|
||||
|
||||
import "../deploy/InstanceAbstract.sol";
|
||||
import "../../deploy/InstanceAbstract.sol";
|
||||
import "./Delegation.sol";
|
||||
|
||||
/**
|
|
@ -1,7 +1,7 @@
|
|||
pragma solidity >=0.5.0 <0.6.0;
|
||||
|
||||
import "../deploy/InstanceFactory.sol";
|
||||
import "../deploy/Instance.sol";
|
||||
import "../../deploy/InstanceFactory.sol";
|
||||
import "../../deploy/Instance.sol";
|
||||
import "./DelegationAbstract.sol";
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,7 @@ contract DelegationFactory is InstanceFactory {
|
|||
external
|
||||
returns (DelegationAbstract instance)
|
||||
{
|
||||
instance = new Instance(base, prototypes[address(base)].init, msg.data);
|
||||
instance = DelegationAbstract(new Instance(base, prototypes[address(base)].init, msg.data));
|
||||
emit InstanceCreated(instance);
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
pragma solidity >=0.5.0 <0.6.0;
|
||||
|
||||
/**
|
||||
* @title Proposal
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* Store votes and tabulate results for Democracy
|
||||
*/
|
||||
interface Proposal {
|
||||
|
||||
enum Vote {
|
||||
Null,
|
||||
Reject,
|
||||
Approve
|
||||
}
|
||||
|
||||
|
||||
function voteSigned(bytes32 _signatures) external;
|
||||
|
||||
function voteDirect(Vote _vote) external;
|
||||
|
||||
function tabulateDirect(address _voter) external;
|
||||
|
||||
function tabulateSigned(Vote _vote, uint256 _position, bytes32[] calldata _proof, bytes calldata _signature) external;
|
||||
|
||||
function tabulateDelegated(address _voter) external;
|
||||
|
||||
function precomputeDelegation(address _start, bool _clean) external;
|
||||
|
||||
function finalize() external;
|
||||
|
||||
function clear() external;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
pragma solidity >=0.5.0 <0.6.0;
|
||||
|
||||
import "../../common/Controlled.sol";
|
||||
import "../../deploy/InstanceAbstract.sol";
|
||||
import "../../token/MiniMeToken.sol";
|
||||
import "../delegation/Delegation.sol";
|
||||
import "./Proposal.sol";
|
||||
|
||||
/**
|
||||
* @title Proposal
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* Store votes and tabulate results for Democracy
|
||||
*/
|
||||
contract ProposalAbstract is InstanceAbstract, Proposal, Controlled {
|
||||
|
||||
MiniMeToken public token;
|
||||
Delegation public delegation;
|
||||
uint256 public tabulationBlockDelay;
|
||||
|
||||
bytes32 topic;
|
||||
bytes32 txHash;
|
||||
uint blockStart;
|
||||
uint voteBlockEnd;
|
||||
|
||||
//votes storage
|
||||
bytes32[] signatures;
|
||||
mapping(address => Vote) voteMap;
|
||||
|
||||
//tabulation process
|
||||
uint256 lastTabulationBlock;
|
||||
mapping(address => address) delegationOf;
|
||||
mapping(address => address) tabulated;
|
||||
mapping(uint8 => uint256) results;
|
||||
|
||||
Vote result;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,65 +1,22 @@
|
|||
pragma solidity >=0.5.0 <0.6.0;
|
||||
|
||||
import "../common/Controlled.sol";
|
||||
import "../common/MessageSigned.sol";
|
||||
import "../common/MerkleProof.sol";
|
||||
import "../token/MiniMeToken.sol";
|
||||
import "./Delegation.sol";
|
||||
import "./TrustNetworkInterface.sol";
|
||||
import "../../common/MessageSigned.sol";
|
||||
import "../../common/MerkleProof.sol";
|
||||
import "./ProposalAbstract.sol";
|
||||
|
||||
/**
|
||||
* @title Proposal
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* Store votes and tabulate results for Democracy
|
||||
*/
|
||||
contract Proposal is Controlled, MessageSigned {
|
||||
MiniMeToken public token;
|
||||
Delegation public delegation;
|
||||
uint256 public tabulationBlockDelay;
|
||||
|
||||
bytes32 topic;
|
||||
bytes32 txHash;
|
||||
uint blockStart;
|
||||
uint voteBlockEnd;
|
||||
contract ProposalBase is ProposalAbstract, MessageSigned {
|
||||
|
||||
//votes storage
|
||||
bytes32[] signatures;
|
||||
mapping(address => Vote) voteMap;
|
||||
|
||||
//tabulation process
|
||||
uint256 lastTabulationBlock;
|
||||
mapping(address => address) delegationOf;
|
||||
mapping(address => address) tabulated;
|
||||
mapping(uint8 => uint256) results;
|
||||
|
||||
Vote result;
|
||||
|
||||
|
||||
enum Vote {
|
||||
Null,
|
||||
Reject,
|
||||
Approve
|
||||
}
|
||||
|
||||
constructor(
|
||||
MiniMeToken _token,
|
||||
Delegation _delegation,
|
||||
bytes32 _topic,
|
||||
bytes32 _txHash,
|
||||
uint256 _tabulationBlockDelay,
|
||||
uint256 _blockStart,
|
||||
uint256 _blockEndDelay
|
||||
)
|
||||
constructor()
|
||||
public
|
||||
|
||||
{
|
||||
delegation = _delegation;
|
||||
token = _token;
|
||||
tabulationBlockDelay = _tabulationBlockDelay;
|
||||
topic = _topic;
|
||||
txHash = _txHash;
|
||||
blockStart = _blockStart;
|
||||
voteBlockEnd = blockStart + _blockEndDelay;
|
||||
blockStart = uint256(-1);
|
||||
voteBlockEnd = uint256(-1);
|
||||
}
|
||||
|
||||
function voteSigned(bytes32 _signatures)
|
||||
|
@ -169,20 +126,22 @@ contract Proposal is Controlled, MessageSigned {
|
|||
}
|
||||
}
|
||||
|
||||
function cacheDelegation(address _delegator, bool _clean) private returns (address) {
|
||||
address delegate;
|
||||
if(!_clean) {
|
||||
delegate = delegationOf[_delegator];
|
||||
}
|
||||
if(delegate == address(0)){
|
||||
delegate = delegation.delegatedToAt(_delegator, voteBlockEnd); //get delegate chain tail
|
||||
function cacheDelegation(address _delegator, bool _clean) private returns (address delegate) {
|
||||
delegate = _delegator;
|
||||
if(voteMap[_delegator] == Vote.Null) {
|
||||
if(!_clean) {
|
||||
delegate = delegationOf[delegate];
|
||||
}
|
||||
if(delegate == address(0)){
|
||||
delegate = delegation.delegatedToAt(_delegator, voteBlockEnd); //get delegate chain tail
|
||||
}
|
||||
}
|
||||
|
||||
require(delegate != address(0), "No delegate vote found");
|
||||
if(voteMap[delegate] == Vote.Null) {
|
||||
delegate = cacheDelegation(delegate, _clean);
|
||||
}
|
||||
delegationOf[_delegator] = delegate;
|
||||
|
||||
return delegate;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
pragma solidity >=0.5.0 <0.6.0;
|
||||
|
||||
import "../../deploy/InstanceFactory.sol";
|
||||
import "../../deploy/Instance.sol";
|
||||
import "./ProposalAbstract.sol";
|
||||
|
||||
/**
|
||||
* @title DelegationFactory
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* @dev Upgradable delegation proxy factory
|
||||
*/
|
||||
contract ProposalFactory is InstanceFactory {
|
||||
|
||||
constructor(InstanceAbstract _base, InstanceAbstract _init, InstanceAbstract _emergency)
|
||||
InstanceFactory(_base, _init, _emergency)
|
||||
public
|
||||
{ }
|
||||
|
||||
function createProposal(
|
||||
MiniMeToken _token,
|
||||
Delegation _delegation,
|
||||
bytes32 _topic,
|
||||
bytes32 _txHash,
|
||||
uint256 _tabulationBlockDelay,
|
||||
uint256 _blockStart,
|
||||
uint256 _blockEndDelay
|
||||
)
|
||||
external
|
||||
returns (ProposalAbstract instance)
|
||||
{
|
||||
instance = ProposalAbstract(new Instance(base, prototypes[address(base)].init, msg.data));
|
||||
emit InstanceCreated(instance);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
pragma solidity >=0.5.0 <0.6.0;
|
||||
|
||||
import "./ProposalAbstract.sol";
|
||||
|
||||
/**
|
||||
* @title Proposal
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* Store votes and tabulate results for Democracy
|
||||
*/
|
||||
contract ProposalInit is ProposalAbstract {
|
||||
|
||||
constructor() public {
|
||||
token = MiniMeToken(address(-1));
|
||||
}
|
||||
|
||||
function createProposal(
|
||||
MiniMeToken _token,
|
||||
Delegation _delegation,
|
||||
bytes32 _topic,
|
||||
bytes32 _txHash,
|
||||
uint256 _tabulationBlockDelay,
|
||||
uint256 _blockStart,
|
||||
uint256 _blockEndDelay
|
||||
)
|
||||
external
|
||||
{
|
||||
require(address(token) == address(0), "Already initialized");
|
||||
delegation = _delegation;
|
||||
token = _token;
|
||||
tabulationBlockDelay = _tabulationBlockDelay;
|
||||
topic = _topic;
|
||||
txHash = _txHash;
|
||||
blockStart = _blockStart;
|
||||
voteBlockEnd = blockStart + _blockEndDelay;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue