// Contract: rPepeToKEK
// Target function: function ClaimStakedTokens() public
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////################################################################/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////THIS IS THE RPEPEBLU POOL OF KEK STAKING - rPepe Token Staking//////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////################################################################/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// SPDX-License-Identifier: UNLICENSED

/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 *
*/

library SafeMath {
  function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    if (a == 0) {
      return 0;
    }
    uint256 c = a * b;
    assert(c / a == b);
    return c;
  }

  function div(uint256 a, uint256 b) internal pure returns (uint256) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return c;
  }

  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  function add(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a + b;
    assert(c >= a);
    return c;
  }

  function ceil(uint a, uint m) internal pure returns (uint r) {
    return (a + m - 1) / m * m;
  }
}

interface IKEK{
    function transferFrom(address from, address to, uint256 tokens) external returns (bool success);
    function transfer(address to, uint256 tokens) external returns (bool success);
    function claimRewards(uint256 rewards, address rewardedTo) external returns(bool);
    function stakingRewardsAvailable() external view returns(uint256 _rewardsAvailable);
}

pragma solidity ^0.6.0;
contract rPepeToKEK {
    using SafeMath for uint256;
    
    uint256 public currentStakingRate;
    address public KEK = 0x31AEe7Db3b390bAaD34213C173A9df0dd11D84bd;
    address public RPepe = 0x0e9b56D2233ea2b5883861754435f9C51Dbca141;
    
    uint256 public totalRewards;
    uint256 private basePercent = 100;
    
    struct DepositedToken{
        uint256 activeDeposit;
        uint256 totalDeposits;
        uint256 startTime;
        uint256 pendingGains;
        uint256 lastClaimedDate;
        uint256 totalGained;
        uint    rate;
    }
    
    mapping(address => DepositedToken) users;
    
    event Staked(address indexed staker, uint256 indexed tokens);
    event StakingRateChanged(uint256 indexed stakingRatePerHour);
    event TokensClaimed(address indexed claimer, uint256 indexed stakedTokens);
    event RewardClaimed(address indexed claimer, uint256 indexed reward);
    
    constructor() public{
        currentStakingRate = 1e16; // 0.01 per hour
    }
    
    // ------------------------------------------------------------------------
    // Start staking
    // @param _amount amount of tokens to deposit
    // ------------------------------------------------------------------------
    function Stake(uint256 _amount) external {
        
        // transfer tokens from user to the contract balance
        require(IKEK(RPepe).transferFrom(msg.sender, address(this), _amount));
        
        uint256 tokensBurned = findTwoPointFivePercent(_amount);
        uint256 tokensTransferred = _amount.sub(tokensBurned);
    
        // add new stake
        _addToStake(tokensTransferred);
        
        emit Staked(msg.sender, _amount);
        
    }