contract EQUUSMiningToken is IERC20, Staking {
    
    /* Constant variables created for the ERC20 requirements*/
    
    string public constant name = "EQUUSMiningToken";
    string public constant symbol = "EQMT";
    uint8 public constant decimals = 18;
    
    //Burn address saved as constant for future burning processes
    address public constant burnaddress = 0x0000000000000000000000000000000000000000;

    mapping(address => uint256) balances; //EQUUS balance for all network participants
    
    mapping(address => uint256) stakedbalances; //EQUUS stake balance to lock stakes
    
    mapping(address => uint) staketimestamps; //EQUUS stake timestamp to record updates on staking for multipliers, this involves the idea that multipliers will reset upon staking

    mapping(address => mapping (address => uint256)) allowed; //Approval array to record delegation of thrid-party accounts to handle transaction per allowance
    
    /* Total variables created to record information */
    uint256 totalSupply_;
    uint256 totalstaked = 0;
    address theowner; //Owner address saved to recognise on future processes
    
    using SafeMath for uint256; //Important*** as this library provides security to handle maths without overflow attacks
    
    constructor() public {
        totalSupply_ = 100000000000000000000000000;
        balances[msg.sender] = totalSupply_;
        theowner = msg.sender;
        emit Transfer(msg.sender, msg.sender, totalSupply_);
   } //Constructor stating the total supply as well as saving owner address and sending supply to owner address
   
   //Function to report on totalsupply following ERC20 Standard
   function totalSupply() public override view returns (uint256) {
       return totalSupply_;
   }
   
   //Function to report on account balance following ERC20 Standard
   function balanceOf(address tokenOwner) public override view returns (uint) {
       return balances[tokenOwner];
   }
   
   //Burn process is just a funtion to calculate burn amount depending on an amount of Tokens
   function cutForBurn(uint256 a) public pure returns (uint256) {
       uint256 c = a.div(20);
       return c;
   }
   
   //Straight forward transfer following ERC20 Standard
   function transfer(address receiver, uint256 numTokens) public override returns (bool) {
       require(numTokens <= balances[msg.sender], 'Amount exceeds balance.');
       balances[msg.sender] = balances[msg.sender].sub(numTokens);
       
       balances[receiver] = balances[receiver].add(numTokens);
       emit Transfer(msg.sender, receiver, numTokens);
       return true;
   }
   
   //Approve function following ERC20 Standard
   function approve(address delegate, uint256 numTokens) public override returns (bool) {
       require(numTokens <= balances[msg.sender], 'Amount exceeds balance.');
       allowed[msg.sender][delegate] = numTokens;
       emit Approval(msg.sender, delegate, numTokens);
       return true;
   }
   
   //Allowance function to verify allowance allowed on delegate address following ERC20 Standard
   function allowance(address owner, address delegate) public override view returns (uint) {
       return allowed[owner][delegate];
   }
   
   //The following function is added to mitigate ERC20 API: An Attack Vector on Approve/TransferFrom Methods
   function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
       require(addedValue <= balances[msg.sender].sub(allowed[msg.sender][spender]), 'Amount exceeds balance.');
       
       allowed[msg.sender][spender] = allowed[msg.sender][spender].add(addedValue);
       
       emit Approval(msg.sender, spender, allowed[msg.sender][spender].add(addedValue));
       return true;
   }
   
   //The following function is added to mitigate ERC20 API: An Attack Vector on Approve/TransferFrom Methods
   function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
       require(subtractedValue <= allowed[msg.sender][spender], 'Amount exceeds balance.');
       
       allowed[msg.sender][spender] = allowed[msg.sender][spender].sub(subtractedValue);
       
       emit Approval(msg.sender, spender, allowed[msg.sender][spender].sub(subtractedValue));
   }
   
   //Transfer For function for allowed accounts to allow tranfers
   function transferFrom(address owner, address buyer, uint numTokens) public override returns (bool) {
       require(numTokens <= balances[owner], 'Amount exceeds balance.');
       require(numTokens <= allowed[owner][msg.sender], 'Amount exceeds allowance.');
       
       balances[owner] = balances[owner].sub(numTokens);
       allowed[owner][msg.sender] = allowed[owner][msg.sender].sub(numTokens);
       balances[buyer] = balances[buyer].add(numTokens);
       emit Transfer(msg.sender, buyer, numTokens);
       return true;
   }
   
   //Staking processes
   
   //Stake process created updating balances, stakebalances and also recording time on process run, the process will burn 5% of the amount
   function stake(uint256 amount, bytes memory data) public override returns (bool) {
       require(amount <= balances[msg.sender]);
       require(amount < 20, "Amount to low to process");
       balances[msg.sender] = balances[msg.sender].sub(amount);
       
       uint256 burned = cutForBurn(amount);
       
       totalSupply_ = totalSupply_.sub(burned);
       
       balances[burnaddress] = balances[burnaddress].add(burned);
       
       stakedbalances[msg.sender] = stakedbalances[msg.sender].add(amount.sub(burned));
       totalstaked = totalstaked.add(amount.sub(burned));
       
       staketimestamps[msg.sender] = block.timestamp;
       
       emit Staked(msg.sender, amount.sub(burned), stakedbalances[msg.sender], data);
       emit Transfer(msg.sender, msg.sender, amount.sub(burned));
       emit Transfer(msg.sender, burnaddress, burned);
       return true;
   }
   
   //This function unstakes locked in amount and burns 5%, this also updates amounts on total supply
   function unstake(uint256 amount, bytes memory data) public override returns (bool) {
       require(amount <= stakedbalances[msg.sender]);
       require(amount <= totalstaked);
       require(amount < 20, "Amount to low to process");
       stakedbalances[msg.sender] = stakedbalances[msg.sender].sub(amount);
       totalstaked = totalstaked.sub(amount);
       
       uint256 burned = cutForBurn(amount);
       
       totalSupply_ = totalSupply_.sub(burned);
       
       balances[burnaddress] = balances[burnaddress].add(burned);
       
       balances[msg.sender] = balances[msg.sender].add(amount.sub(burned));
       
       emit Unstaked(msg.sender, amount.sub(burned), stakedbalances[msg.sender], data);
       emit Transfer(msg.sender, msg.sender, amount.sub(burned));
       emit Transfer(msg.sender, burnaddress, burned);
       return true;
   }
   
   //Function to return total staked on a single address
   function totalStakedFor(address addr) public override view returns (uint256) {
       return stakedbalances[addr];
   }
   
   //Function to shows timestamp on stake processes
   function stakeTimestampFor(address addr) public view returns (uint256) {
       return staketimestamps[addr];
   }
   
   //Function to find out time passed since last timestamp on address
   function stakeTimeFor(address addr) public view returns (uint256) {
       return block.timestamp.sub(staketimestamps[addr]);
   }
   
   //Total staked on all addresses
   function totalStaked() public override view returns (uint256) {
       return totalstaked;
   }
   
   //Support History variable to show support on optional stake details
   function supportsHistory() public override pure returns (bool) {
       return false;
   }
   
}
/*EQUUS Protocol being created with the help of the above interfaces for compatibility*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
    require(subtractedValue <= allowed[msg.sender][spender], 'Amount exceeds balance.');
       
    allowed[msg.sender][spender] = allowed[msg.sender][spender].sub(subtractedValue);
       
    emit Approval(msg.sender, spender, allowed[msg.sender][spender].sub(subtractedValue));
}

//The following function is added to mitigate ERC20 API: An Attack Vector on Approve/TransferFrom Methods