POL Price: $0.717337 (-2.50%)

Contract Diff Checker

Contract Name:
TRDODAO

Contract Source Code:

File 1 of 1 : TRDODAO

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

interface ITRDOToken {
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

contract TRDODAO {
    ITRDOToken public trdoToken;
    ITRDOToken public wtrdoToken;

    struct Proposal {
        string title;
        string description;
        address creator;
        uint256 startDate;
        uint256 expireDate;
        uint256 maxVotes; // Maximum votes allowed for this proposal
        uint256 votesInFavor; // Current number of votes in favor
        uint256 minPercentage; // Minimum percentage of maxVotes needed for success
        bool executed; // Whether the proposal has been executed (considered successful or failed)
        string remark;
    }

    mapping(address => uint256) public wtrdoBalances;
    mapping(uint256 => Proposal) public proposals;
    mapping(uint256 => address[]) public proposalVoters;
    mapping(uint256 => mapping(address => bool)) public hasVoted;
    uint256 public nextProposalId;
    address public owner;
    constructor(address _trdoTokenAddress,address _wtrdoTokenAddress) {
        trdoToken = ITRDOToken(_trdoTokenAddress);
        wtrdoToken = ITRDOToken(_wtrdoTokenAddress);
        owner = msg.sender;
    }

    function wrapTRDO(uint256 amount) public {
        require(trdoToken.transferFrom(msg.sender, address(this), amount), "TRDO transfer failed");
        require(wtrdoToken.transfer(msg.sender, amount), "WTRDO transfer failed");
        wtrdoBalances[msg.sender] += amount;
    }
    function getTrdoTokenBalance() public view returns (uint256) {
        return trdoToken.balanceOf(address(this));
    }
    function getWtrdoTokenBalance() public view returns (uint256) {
        return wtrdoToken.balanceOf(address(this));
    }

    function unwrapTRDO(uint256 amount) public {
        require(wtrdoBalances[msg.sender] >= amount, "Insufficient WTRDO balance");
         require(wtrdoToken.transferFrom(msg.sender,address(this), amount), "WTRDO transfer to contract failed");
        wtrdoBalances[msg.sender] -= amount;
        require(trdoToken.transfer(msg.sender, amount), "TRDO transfer failed");
    }
    

    function createProposal(string memory title, string memory description, uint256 expireDate, uint256 maxVotes, uint256 minPercentage) public {
        require(wtrdoBalances[msg.sender] >= 500000e18, "Insufficient WTRDO to create proposal");
        proposals[nextProposalId] = Proposal({
            title: title,
            description: description,
            creator: msg.sender,
            startDate: block.timestamp,
            expireDate: expireDate,
            maxVotes: maxVotes,
            votesInFavor: 0,
            minPercentage: minPercentage,
            executed: false,
            remark: ""
        });
        nextProposalId++;
    }

    function vote(uint256 proposalId) public {
        require(wtrdoBalances[msg.sender] >= 100000e18, "Insufficient WTRDO to vote");
        Proposal storage proposal = proposals[proposalId];
        require(block.timestamp < proposal.expireDate, "Proposal expired");
        require(!proposal.executed, "Proposal already executed");
        require(!hasVoted[proposalId][msg.sender], "Already voted");

            uint8 votes = 0;
           if(wtrdoBalances[msg.sender] >= 500000e18)
           {
            votes = 5;
           }else if(wtrdoBalances[msg.sender] >= 300000e18) {
                votes = 3;
           }
           else{
                votes = 1;
           }
         proposal.votesInFavor += votes;
        proposalVoters[proposalId].push(msg.sender);
        hasVoted[proposalId][msg.sender] = true;

        // Check if the votes in favor have reached the required minimum percentage of the maximum votes
        if (proposal.votesInFavor * 100 >= proposal.maxVotes * proposal.minPercentage) {
            proposal.executed = true;
        }
    }

    function getVoters(uint256 proposalId) public view returns (address[] memory) {
        return proposalVoters[proposalId];
    }
    

     function addRemark(uint256 proposalId, string memory remark) public onlyOwner {
        require(proposals[proposalId].executed, "Proposal must be executed before adding a remark.");
        proposals[proposalId].remark = remark;
    }

    function WtrdoTreasury(uint256 amount) public onlyOwner {
        require(wtrdoToken.transfer(msg.sender, amount), "WTRDO treasurt transfer failed");
           
    }
     function trdoTreasury(uint256 amount) public onlyOwner {
        require(trdoToken.transfer(msg.sender, amount), "TRDO Treasury transfer failed");
           
    }


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

}

Please enter a contract address above to load the contract details and source code.

Context size (optional):