From 941ea8f049374817fd816a37ea3e184c707ca833 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Wed, 20 Feb 2019 04:54:14 -0300 Subject: [PATCH] add default delegation --- contracts/democracy/DefaultDelegation.sol | 59 +++++++++++++++++++++++ contracts/democracy/Democracy.sol | 3 +- contracts/democracy/TrustNetwork.sol | 10 ++-- 3 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 contracts/democracy/DefaultDelegation.sol diff --git a/contracts/democracy/DefaultDelegation.sol b/contracts/democracy/DefaultDelegation.sol new file mode 100644 index 0000000..52f1eb3 --- /dev/null +++ b/contracts/democracy/DefaultDelegation.sol @@ -0,0 +1,59 @@ +pragma solidity >=0.5.0 <0.6.0; + +import "./Delegation.sol"; +import "../common/Controlled.sol"; + +contract DefaultDelegation is Delegation, Controlled { + address public defaultDelegate; + + constructor(address _defaultDelegate) public { + defaultDelegate = _defaultDelegate; + } + + /** + * @notice Changes default delegation + * @param _to What is the default delegate. + */ + function delegate(address _to) external onlyController { + defaultDelegate = _to; + } + + function delegatedTo(address) + external + view + returns (address directDelegate) + { + return defaultDelegate; + } + + function delegationOf(address) + external + view + returns(address finalDelegate) + { + return defaultDelegate; + } + + function delegatedToAt( + address, + uint + ) + external + view + returns (address directDelegate) + { + return defaultDelegate; + } + + function delegationOfAt( + address, + uint + ) + external + view + returns(address finalDelegate) + { + return defaultDelegate; + } + +} \ No newline at end of file diff --git a/contracts/democracy/Democracy.sol b/contracts/democracy/Democracy.sol index dbe2b23..f10f45f 100644 --- a/contracts/democracy/Democracy.sol +++ b/contracts/democracy/Democracy.sol @@ -2,6 +2,7 @@ pragma solidity >=0.5.0 <0.6.0; import "../token/MiniMeToken.sol"; import "./DelegationFactory.sol"; +import "./DefaultDelegation.sol"; import "./TrustNetwork.sol"; import "./ProposalCuration.sol"; import "./ProposalManager.sol"; @@ -23,7 +24,7 @@ contract Democracy { constructor(MiniMeToken _token, DelegationFactory _DelegationFactory) public { token = _token; - trustNet = new TrustNetwork(_DelegationFactory); + trustNet = new TrustNetwork(_DelegationFactory, new DefaultDelegation()); proposalManager = new ProposalCuration(_token, trustNet).proposalManager(); } diff --git a/contracts/democracy/TrustNetwork.sol b/contracts/democracy/TrustNetwork.sol index d801968..9488443 100644 --- a/contracts/democracy/TrustNetwork.sol +++ b/contracts/democracy/TrustNetwork.sol @@ -21,9 +21,9 @@ contract TrustNetwork is TrustNetworkInterface, Controlled { Delegation vetoDelegation; } - constructor(DelegationFactory _delegationFactory) public { + constructor(DelegationFactory _delegationFactory, Delegation defaultDelegation) public { delegationFactory = _delegationFactory; - topics[bytes32(0)] = newTopic(address(0), address(0)); + topics[bytes32(0)] = newTopic(defaultDelegation, defaultDelegation); } function addTopic(bytes32 topicId, bytes32 parentTopic) public onlyController { @@ -67,10 +67,10 @@ contract TrustNetwork is TrustNetworkInterface, Controlled { } - function newTopic(address _vote, address _veto) internal returns (Topic memory topic) { + function newTopic(Delegation _vote, Delegation _veto) internal returns (Topic memory topic) { topic = Topic ({ - voteDelegation: Delegation(address(delegationFactory.createDelegation(_vote))), - vetoDelegation: Delegation(address(delegationFactory.createDelegation(_veto))) + voteDelegation: Delegation(address(delegationFactory.createDelegation(address(_vote)))), + vetoDelegation: Delegation(address(delegationFactory.createDelegation(address(_vote)))) }); }