Skip to content

Commit

Permalink
bump the MNs flow
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbeny committed Sep 5, 2024
1 parent 22646b6 commit a93e1ee
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 16 deletions.
7 changes: 7 additions & 0 deletions packages/contracts/deployments-staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"apothem": {
"daoAddress": "0x4F450D39e479bB2690AC56A5c26d5a8FAc1c6703",
"factory": "0x95377B579AFC689C1244615C950d0feFc0D641d6",
"pluginAddress": "0x27d7ab4478706d4245871F638Ff76b6A421719fA"
}
}
1 change: 1 addition & 0 deletions packages/contracts/src/Base/BaseDaofinPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ abstract contract BaseDaofinPlugin is
event HouseResignRequested(address _houseMember, uint256 _amount, uint64 _cooldown);
event HouseResigned(address _houseMember, uint256 _amount);
event ProposalMetadataUpdated(uint256 _proposalId, bytes _metadata);
event MnSynced(address _mn);

function supportsInterface(
bytes4 interfaceId
Expand Down
73 changes: 58 additions & 15 deletions packages/contracts/src/DaofinPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ contract DaofinPlugin is BaseDaofinPlugin {
// Holds Election/voting Periods
ElectionPeriod[] private _electionPeriods;

// ----------------
// UPDATED - 1

// plugin delegate => Mn owner weight
mapping(address => uint256) public mnToWeights;

// initialize function executes during the plugin setup
function initialize(
IDAO _dao,
Expand Down Expand Up @@ -205,6 +211,9 @@ contract DaofinPlugin is BaseDaofinPlugin {
if (committee == PeoplesHouseCommittee) {
votingPower = _voterToLockedAmounts[voter_].amount / (10 ** 18);
}
if (committee == MasterNodeCommittee) {
votingPower = mnToWeights[voter_];
}
if (voteOption_ == VoteOption.Yes) {
td.yes += votingPower;
} else if (voteOption_ == VoteOption.No) {
Expand Down Expand Up @@ -559,29 +568,39 @@ contract DaofinPlugin is BaseDaofinPlugin {
emit MasterNodeDelegateeUpdated(masterNode, delegatee_);
}

function syncWithXdcValidator(address masterNode_) external {
function syncWithXdcValidator(address masterNode_) external returns (bool) {
// supplied addresses must not be zero
if (masterNode_ == address(0)) revert AddressIsZero();
address delegatee = _masterNodeDelegatee.masterNodeToDelegatee[masterNode_];

// if mn has already a non-zero delegatee, means mn has already registered.
// && if mn has resigned from xdcValidator
if (delegatee != address(0) && !isXDCValidatorCandidate(masterNode_)) {
if (delegatee != address(0)) {
if (isWithinProposalSession()) revert InValidTime();
delete _masterNodeDelegatee.delegateeToMasterNode[delegatee];
delete _masterNodeDelegatee.masterNodeToDelegatee[masterNode_];
_masterNodeDelegatee.numberOfJointMasterNodes--;
} else revert InValidAddress();
emit MasterNodeDelegateeUpdated(masterNode_, delegatee);
if (!isXDCValidatorCandidate(masterNode_)) {
delete _masterNodeDelegatee.delegateeToMasterNode[delegatee];
delete _masterNodeDelegatee.masterNodeToDelegatee[masterNode_];
delete mnToWeights[delegatee];
_masterNodeDelegatee.numberOfJointMasterNodes--;
}

mnToWeights[masterNode_] = getMnWeight(masterNode_);

emit MnSynced(masterNode_);
return true;
}
return false;
}

function syncXdcValidatorSnapshot() public {
function syncXdcValidatorSnapshot() public returns (bool) {
if (isWithinProposalSession()) revert InValidTime();

uint256 xdcValidatorCount = _daofinGlobalSettings.xdcValidator.candidateCount();
if (masternodeCountSnapshot != xdcValidatorCount) {
masternodeCountSnapshot = xdcValidatorCount;
return true;
}
return false;
}

function _createOrUpdateMasterNodeDelegatee(address masterNode_, address delegatee_) private {
Expand All @@ -596,7 +615,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
if (_cachedDelegatee == address(0) && _cachedMasterNode == address(0)) {
_masterNodeDelegatee.numberOfJointMasterNodes++;
}

mnToWeights[delegatee_] = getMnWeight(masterNode_);
// stores on reverse mappings for ease of accessibilities
_masterNodeDelegatee.masterNodeToDelegatee[masterNode_] = delegatee_;
_masterNodeDelegatee.delegateeToMasterNode[delegatee_] = masterNode_;
Expand Down Expand Up @@ -651,8 +670,31 @@ contract DaofinPlugin is BaseDaofinPlugin {
emit ProposalMetadataUpdated(_proposalId, _metadata);
}

function isXDCValidatorCandidate(address masterNode_) private view returns (bool isValid) {
return getGlobalSettings().xdcValidator.isCandidate(masterNode_);
// finds the number of candidates that an owner has.
// the parameter is equivalant to owner in XDOPS.
function getMnWeight(address masterNode_) public view returns (uint256) {
uint256 weight = 0;
address[] memory candidates = getGlobalSettings().xdcValidator.getCandidates();
for (uint256 i = 0; i < candidates.length; i++) {
address owner = getGlobalSettings().xdcValidator.getCandidateOwner(candidates[i]);

if (owner == masterNode_ && owner != address(0)) {
weight++;
}
}
return weight;
}

// it verifies whether the supplied arguments is owner in XDOPS or not
function isXDCValidatorCandidate(address masterNode_) public view returns (bool isValid) {
uint256 ownerCount = getGlobalSettings().xdcValidator.getOwnerCount();
for (uint256 i = 0; i < ownerCount; i++) {
address owner = getGlobalSettings().xdcValidator.owners(i);
if (owner == masterNode_) {
return true;
}
}
return false;
}

function isMasterNodeDelegatee(address delegatee_) public view returns (bool isValid) {
Expand Down Expand Up @@ -753,10 +795,11 @@ contract DaofinPlugin is BaseDaofinPlugin {
return true;
}

function getTotalNumberOfMN() public view returns (uint256, uint256) {
DaofinGlobalSettings memory _gs = getGlobalSettings();
return (_gs.xdcValidator.candidateCount(), _masterNodeDelegatee.numberOfJointMasterNodes);
}
// It's removed in V2 upgrade
// function getTotalNumberOfMN() public view returns (uint256, uint256) {
// DaofinGlobalSettings memory _gs = getGlobalSettings();
// return (_gs.xdcValidator.candidateCount(), _masterNodeDelegatee.numberOfJointMasterNodes);
// }

function getXDCTotalSupply() public pure returns (uint256) {
return 37705012699;
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/src/VotingStats.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
pragma solidity 0.8.17;

import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import {_applyRatioCeiled} from "./utils/Ratio.sol";

interface IDAOFIN {
struct TallyDatails {
Expand Down
8 changes: 8 additions & 0 deletions packages/contracts/src/interfaces/IXdcValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ interface IXDCValidator {

function getCandidates() external view returns (address[] memory);

function owners(uint256 _index) external view returns (address);

function getOwnerCount() external view returns (uint256);

function getCandidateOwner(address _candidate) external view returns (address);

function candidates() external view returns (address[] memory);

function candidateCount() external view returns (uint256);
}

0 comments on commit a93e1ee

Please sign in to comment.