WeuFoundDev / Governance-token-contracts

Governance contract of INPUT (INT) | A development based minting tokens for developers and researchers ecosystem.
GNU General Public License v3.0
2 stars 0 forks source link

Create the Foundation Members Contract #32

Open shivasai780 opened 1 year ago

shivasai780 commented 1 year ago

This Contracts will be responsible for storing the Different category members in our Foundation

123456788940 commented 1 year ago

// SPDX-License-Identifier: MIT pragma solidity ^0.8.0;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";

contract Foundation {

enum Role { Research, Technical, FoundationMember }

using ECDSA for bytes32;

struct CommitteeMember {
    address addr;
    Role role;
    bytes32 sessionKeyShare; // Session key share for role rotation
    bool hasSessionKey; // To track if the committee member has a session key
}

struct Proposal {
    address addr; // Address of the council member
    uint proposalIndex; // Index of the proposal
}

mapping(address => CommitteeMember) public committeeMembers;
Proposal[] public proposals;
address public owner; // Contract owner

uint public lastRotationBlock; // Block number when the last rotation occurred
uint public rotationThreshold = 5; // Number of blocks before a rotation is initiated

modifier onlyOwner() {
    require(msg.sender == owner, "Only the owner can call this function.");
    _;
}

event NewChainInitiated(address[] newCouncilMembers);

constructor(address[] memory researchMembers, address[] memory technicalMembers, address[] memory foundationMembers) {
    owner = msg.sender; // Set the contract owner

    // Initialize committee members and their roles
    for (uint i = 0; i < researchMembers.length; i++) {
        committeeMembers[researchMembers[i]] = CommitteeMember(researchMembers[i], Role.Research, bytes32(0), false);
    }
    for (uint i = 0; i < technicalMembers.length; i++) {
        committeeMembers[technicalMembers[i]] = CommitteeMember(technicalMembers[i], Role.Technical, bytes32(0), false);
    }
    for (uint i = 0; i < foundationMembers.length; i++) {
        committeeMembers[foundationMembers[i]] = CommitteeMember(foundationMembers[i], Role.FoundationMember, bytes32(0), false);
    }
}

// Function to initiate a new chain and rotate council members
function initiateNewChain(address[] memory newCouncilMembers) public onlyOwner {
    // Destroy existing session keys
    for (uint i = 0; i < newCouncilMembers.length; i++) {
        committeeMembers[newCouncilMembers[i]].hasSessionKey = false;
        committeeMembers[newCouncilMembers[i]].sessionKeyShare = bytes32(0);
    }
    // Generate and set new session key shares for new council members
    for (uint i = 0; i < newCouncilMembers.length; i++) {
        committeeMembers[newCouncilMembers[i]].sessionKeyShare = generateSessionKeyShare();
        committeeMembers[newCouncilMembers[i]].hasSessionKey = true;
    }
    // Update the last rotation block
    lastRotationBlock = block.number;
    // Emit an event indicating a new chain initiation
    emit NewChainInitiated(newCouncilMembers);
}

// Function to generate session key share using ECDSA
function generateSessionKeyShare() private view returns (bytes32) {
    bytes32 msgHash = keccak256(abi.encodePacked(msg.sender));
    return msgHash.toEthSignedMessageHash().recover(msgHash);
}

// Function to change committee members' roles using session keys
function changeMembersUsingSessionKeys() public {
    require(committeeMembers[msg.sender].addr != address(0), "You are not a committee member.");

    // Check if it's time to initiate a rotation
    if (block.number - lastRotationBlock >= rotationThreshold) {
        // Rotate committee members' roles using session keys
        rotateRolesUsingSessionKeys();

        // Update the last rotation block
        lastRotationBlock = block.number;
    } else {
        revert("Rotation not yet due.");
    }
}

// Function to rotate committee members' roles using session keys
function rotateRolesUsingSessionKeys() private {
    address[] memory councilMembers = getCouncilMembers();

    for (uint i = 0; i < councilMembers.length; i++) {
        CommitteeMember storage member = committeeMembers[councilMembers[i]];

        if (member.hasSessionKey) {
            Role newRole = computeNewRole(member);
            member.role = newRole;
        }
    }
}

// Function to get the list of council members
function getCouncilMembers() private view returns (address[] memory) {
    uint n = 0;
    for (uint i = 0; i < proposals.length; i++) {
        if (committeeMembers[proposals[i].addr].hasSessionKey) {
            n++;
        }
    }
    address[] memory councilMembers = new address[](n);
    uint index = 0;
    for (uint i = 0; i < proposals.length; i++) {
        if (committeeMembers[proposals[i].addr].hasSessionKey) {
            councilMembers[index] = proposals[i].addr;
            index++;
        }
    }
    return councilMembers;
}

// Function to compute the new role based on session key
function computeNewRole(CommitteeMember memory member) private view returns (Role) {
    // Simulate a more sophisticated role computation using session key
    bytes32 keyHash = keccak256(abi.encodePacked(member.sessionKeyShare));
    uint randValue = uint(keyHash) % 100; // Assuming 100 roles (Research, Technical, FoundationMember)
    if (randValue < 33) {
        return Role.Research;
    } else if (randValue < 66) {
        return Role.Technical;
    } else {
        return Role.FoundationMember;
    }
}

}

WeuFoundDev commented 1 year ago

there are other functions missing like post council , cancellation to stand in queue and lot of other functions n constructs not present . Review the doc and update it @123456788940

123456788940 commented 1 year ago

Foundation Smart Contract

Overview:

The Foundation Smart Contract is a Solidity-based contract that facilitates the management of a committee with various roles (Research, Technical, FoundationMember) and the rotation of those roles using session keys. It provides a structured way to handle changes in committee member roles and enables role rotation based on specific criteria.

Features:

Getting Started:

Prerequisites:

To interact with the Foundation Smart Contract, you'll need:

Usage:

Contract Initialization:

The contract should be deployed with the following parameters:

Transferring Roles:

Advanced Features:

Contributing:

Contributions to this project are welcome. Follow these guidelines:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and test thoroughly.
  4. Commit your changes with clear and concise messages.
  5. Push your changes to your fork.
  6. Create a pull request to the main repository.

License:

This project is licensed under the MIT License (see the LICENSE file).

Customize this README to include any specific information or instructions relevant to your contract.