Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write a int token Minting contract where the transfer function is restricted to council members(Multisig aggregator contract ) and the burn function is restricted to the burning contract #17

Closed
shivasai780 opened this issue Jul 26, 2023 · 5 comments · May be fixed by #28

Comments

@shivasai780
Copy link
Collaborator

@YashPandey59 @shivasai780 @vinaykumar0103 @sscodez @123456788940

@shivasai780
Copy link
Collaborator Author

shivasai780 commented Jul 27, 2023

pragma solidity ^0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract INT is ERC20 {
    address public weuFoundation;
    address public BurningAddress;
    address public Owner;

    constructor() ERC20("INT Token", "INPUT") {
        Owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == Owner, "Only WEU Foundation can perform this action");
        _;
    }
    modifier onlyBurning(){
        require(msg.sender == BurningAddress,"Only burning address can perform this action");
        _;
    }

    function mint(address account, uint256 amount) external  {
        require(msg.sender == weuFoundation,"the caller needs to be from WeuFoundation");
        require(account != address(0),"The account address should not be equal to zero address");
        _mint(account, amount);
    }

    function ChangeWeuFoundationaddress(address _weuFoundation)external  onlyOwner{
        require(_weuFoundation != address(0),"The Weu foundation address should not be equal to zero address");
        weuFoundation = _weuFoundation;
    }

    function changeBurningAddress(address _burningAddress)external onlyOwner{
         require(_burningAddress != address(0),"The Burning address should not be equal to zero address");
        BurningAddress = _burningAddress;
    }
    function burn(uint256 amount) external onlyBurning {
        _burn(msg.sender, amount);
    }

    function transfer(address to,uint256 value)public  override virtual  returns(bool)
    {
        require(msg.sender == weuFoundation,"the caller needs to be from WeuFoundation");
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    function transferFrom(address _from,address _to,uint256 value)public  override virtual  returns(bool)
    {
        require(msg.sender == weuFoundation || msg.sender == BurningAddress,"the caller needs to be from WeuFoundation or the burning Contract");
        address spender = _msgSender();
        _spendAllowance(_from, spender, value);
        _transfer(_from, _to, value);
        return true;
    }

    function approve(address spender,uint256 value)public  override virtual  returns(bool)
    {
        require(msg.sender == weuFoundation || spender == BurningAddress,"the caller needs to be from WeuFoundation or the to address needs to be the burning address");
         address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

}

@sscodez
Copy link

sscodez commented Jul 28, 2023

pragma solidity ^0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract INT is ERC20 {
    address public weuFoundation;
    mapping(address => bool) public weuFoundationMember;
    address public BurningAddress;
    address public Owner;

    constructor() ERC20("INT Token", "INPUT") {
        Owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == Owner, "Only WEU Foundation can perform this action");
        _;
    }
    modifier onlyBurning(){
        require(msg.sender == BurningAddress,"Only burning address can perform this action");
        _;
    }

     function addCouncilMember(address councilMember) external onlyOwner {
        require(councilMember != address(0), "Council member address should not be equal to the zero address");
        weuFoundationMember[councilMember] = true;
    }

    function mint(address account, uint256 amount) external  {
        require(msg.sender == weuFoundation,"the caller needs to be from WeuFoundation");
        require(account != address(0),"The account address should not be equal to zero address");
        _mint(account, amount);
    }

    function ChangeWeuFoundationaddress(address _weuFoundation)external  onlyOwner{
        require(_weuFoundation != address(0),"The Weu foundation address should not be equal to zero address");
        weuFoundation = _weuFoundation;
    }

    function changeBurningAddress(address _burningAddress)external onlyOwner{
         require(_burningAddress != address(0),"The Burning address should not be equal to zero address");
        BurningAddress = _burningAddress;
    }
    function burn(uint256 amount) external onlyBurning {
        _burn(msg.sender, amount);
    }

    function transfer(address to,uint256 value)public  override virtual  returns(bool)
    {
        require(weuFoundationMember[to], "Transfer is restricted to council members");
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    function transferFrom(address _from,address _to,uint256 value)public  override virtual  returns(bool)
    {
        require(msg.sender == weuFoundation || msg.sender == BurningAddress,"the caller needs to be from WeuFoundation or the burning Contract");
        address spender = _msgSender();
        _spendAllowance(_from, spender, value);
        _transfer(_from, _to, value);
        return true;
    }

    function approve(address spender,uint256 value)public  override virtual  returns(bool)
    {
        require(msg.sender == weuFoundation || spender == BurningAddress,"the caller needs to be from WeuFoundation or the to address needs to be the burning address");
         address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

}


I have added two functions

Add council Member

   function addCouncilMember(address councilMember) external onlyOwner {
        require(councilMember != address(0), "Council member address should not be equal to the zero address");
        weuFoundationMember[councilMember] = true;
    }

Did some modification my adding mapping in transfer function

   function transfer(address to,uint256 value)public  override virtual  returns(bool)
    {
        require(weuFoundationMember[to], "Transfer is restricted to council members");
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }
    ```

@123456788940
Copy link
Collaborator

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

contract INT is ERC20, AccessControl {
using SafeMath for uint256;
address public weuFoundation;
address burningAddress;

bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
bytes32 public constant COUNCIL_MEMBER_ROLE = keccak256("COUNCIL_MEMBER_ROLE");

constructor() ERC20("INT Token", "INPUT") {
    _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
}

function mint(address account, uint256 amount) external onlyRole(MINTER_ROLE) {
    require(account != address(0), "Mint: Account cannot be the zero address");
    _mint(account, amount);
}

function burn(uint256 amount) external onlyRole(BURNER_ROLE) {
    _burn(msg.sender, amount);
}

function changeWeuFoundationAddress(address _weuFoundation) external onlyRole(DEFAULT_ADMIN_ROLE) {
    require(_weuFoundation != address(0), "ChangeWeuFoundationAddress: Address cannot be the zero address");
    weuFoundation = _weuFoundation;
}

function changeBurningAddress(address _burningAddress) external onlyRole(DEFAULT_ADMIN_ROLE) {
    require(_burningAddress != address(0), "ChangeBurningAddress: Address cannot be the zero address");
    burningAddress = _burningAddress;
}

function transfer(address to, uint256 value) public override returns (bool) {
    require(hasRole(COUNCIL_MEMBER_ROLE, msg.sender), "Transfer: Only council members can perform this action");
    _transfer(msg.sender, to, value);
    return true;
}

function transferFrom(address from, address to, uint256 value) public override returns (bool) {
    require(msg.sender == weuFoundation || hasRole(BURNER_ROLE, msg.sender), "TransferFrom: Only WEU Foundation or the Burning Contract can perform this action");
    _transfer(from, to, value);
    _approve(from, msg.sender, allowance(from, msg.sender).sub(value, "TransferFrom: Transfer amount exceeds allowance"));
    return true;
}

function approve(address spender, uint256 value) public override returns (bool) {
    require(msg.sender == weuFoundation || spender == burningAddress, "Approve: Only WEU Foundation or the Burning Contract can perform this action");
    _approve(msg.sender, spender, value);
    return true;
}

}

@Adityapandey59
Copy link
Collaborator

pragma solidity ^0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/Context.sol";

contract INT is ERC20 {
using EnumerableSet for EnumerableSet.AddressSet;

address public weuFoundation;
address public burningAddress;
address public owner;

uint256 public burnStartTime;
uint256 public constant BURN_DURATION = 365 days; // 1 year

struct VestingSchedule {
    uint256 releaseTime;
    uint256 amount;
}

mapping(address => VestingSchedule[]) public vestingSchedules;

constructor() ERC20("INT Token", "INPUT") {
    owner = msg.sender;
}

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

modifier onlyBurning() {
    require(
        msg.sender == burningAddress && block.timestamp >= burnStartTime,
        "Burning is locked or can only be performed by the burning address"
    );
    _;
}

modifier onlyVestingBeneficiary() {
    require(
        msg.sender == weuFoundation || isVestingBeneficiary(msg.sender),
        "Only vesting beneficiaries or the WEU Foundation can perform this action"
    );
    _;
}

function isVestingBeneficiary(address beneficiary) public view returns (bool) {
    return vestingSchedules[beneficiary].length > 0;
}

function addVestingSchedule(address beneficiary, uint256 releaseTime, uint256 amount) external onlyOwner {
    require(beneficiary != address(0), "Beneficiary address should not be equal to zero address");
    require(amount > 0, "Amount should be greater than zero");
    require(releaseTime > block.timestamp, "Release time should be in the future");

    vestingSchedules[beneficiary].push(VestingSchedule(releaseTime, amount));
    _mint(address(this), amount);
}

function releaseVestedTokens() external {
    require(isVestingBeneficiary(msg.sender), "Not a vesting beneficiary");
    VestingSchedule[] storage schedules = vestingSchedules[msg.sender];
    uint256 totalReleased;
    for (uint256 i = 0; i < schedules.length; i++) {
        if (block.timestamp >= schedules[i].releaseTime) {
            uint256 amountToRelease = schedules[i].amount;
            totalReleased += amountToRelease;
            delete schedules[i];
            _transfer(address(this), msg.sender, amountToRelease);
        }
    }
    require(totalReleased > 0, "No tokens to release yet");
}

function setBurnStartTime(uint256 startTime) external onlyOwner {
    require(burnStartTime == 0, "Burn start time is already set");
    burnStartTime = startTime;
}

function burn(uint256 amount) external onlyBurning {
    _burn(msg.sender, amount);
}

function changeWEUFoundationAddress(address newWEUFoundation) external onlyOwner {
    require(newWEUFoundation != address(0), "New WEU Foundation address should not be equal to zero address");
    weuFoundation = newWEUFoundation;
}

function changeBurningAddress(address newBurningAddress) external onlyOwner {
    require(newBurningAddress != address(0), "New burning address should not be equal to zero address");
    burningAddress = newBurningAddress;
}

function transfer(address to, uint256 value) public override virtual returns (bool) {
    require(msg.sender == weuFoundation, "The caller needs to be from WEU Foundation");
    address owner = _msgSender();
    _transfer(owner, to, value);
    return true;
}

function transferFrom(address from, address to, uint256 value) public override virtual returns (bool) {
    require(
        msg.sender == weuFoundation || msg.sender == burningAddress,
        "The caller needs to be from WEU Foundation or the burning address"
    );
    address spender = _msgSender();
    _approve(from, spender, allowance(from, spender) - value);
    _transfer(from, to, value);
    return true;
}

function approve(address spender, uint256 value) public override virtual returns (bool) {
    require(
        msg.sender == weuFoundation || spender == burningAddress,
        "The caller needs to be from WEU Foundation or the to address needs to be the burning address"
    );
    address owner = _msgSender();
    _approve(owner, spender, value);
    return true;
}

}

@123456788940
Copy link
Collaborator

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract INT is ERC20 {
address public councilContract; // Address of the Multisig aggregator contract for council members
address public burningContract; // Address of the burning contract
address public owner;

constructor() ERC20("INT Token", "INPUT") {
    owner = msg.sender;
    _mint(msg.sender, 1000000 * (10**18)); // Mint an initial supply of tokens to the contract deployer
}

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

modifier onlyBurningContract() {
    require(msg.sender == burningContract, "Only the burning contract can call this function");
    _;
}

function setCouncilContract(address _councilContract) external onlyOwner {
    require(_councilContract != address(0), "SetCouncilContract: Address cannot be the zero address");
    councilContract = _councilContract;
}

function setBurningContract(address _burningContract) external onlyOwner {
    require(_burningContract != address(0), "SetBurningContract: Address cannot be the zero address");
    burningContract = _burningContract;
}

function mint(address account, uint256 amount) external onlyBurningContract {
    require(account != address(0), "Mint: Account cannot be the zero address");
    _mint(account, amount);
}

function burn(uint256 amount) external onlyBurningContract {
    _burn(msg.sender, amount);
}

function transfer(address to, uint256 value) public override returns (bool) {
    require(councilContract != address(0), "Transfer: Council contract not set");
    require(msg.sender == councilContract, "Transfer: Only the council contract can perform this action");
    _transfer(msg.sender, to, value);
    return true;
}

// Optional function to be called by the owner to transfer tokens
function transferTokens(address to, uint256 amount) external onlyOwner {
    require(to != address(0), "TransferTokens: Address cannot be the zero address");
    _transfer(msg.sender, to, amount);
}

}

@shivasai780 shivasai780 linked a pull request Aug 3, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants