// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// SPDX-License-Identifier: MIT
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
//////// THIS IS THE RPEPEBLU POOL OF rPEPE STAKING - rPepe Token Staking //////////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
pragma solidity ^0.6.0;
import "./SafeMath.sol";
import "./Context.sol";
interface IPEPE {
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function transfer(address recipient, uint256 amount) external returns (bool);
}
contract RPEPEBLU is Context {
using SafeMath for uint256;
// Contract state variables
address private _RarePepeV2;
uint256 private _totalStakedAmount;
mapping(address => uint256) private _stakedAmount;
address[] private _stakers;
// Events
event Staked(address account, uint256 amount);
event Unstaked(address account, uint256 amount);
constructor(address RarePepeV2) public {
_RarePepeV2 = RarePepeV2;
}
/**
* @dev API to stake rPEPE tokens
*
* @param amount: Amount of tokens to deposit
*/
function stake(uint256 amount) external {
require(amount > 0, "Staking amount must be more than zero");
// Transfer tokens from staker to the contract amount
require(IPEPE(_RarePepeV2).transferFrom(_msgSender(), address(this), amount), "It has failed to transfer tokens from staker to contract.");
// add staker to array
if (_stakedAmount[_msgSender()] == 0) {
_stakers.push(_msgSender());
}
// considering the burning 2.5%
uint256 burnedAmount = amount.ceil(100).mul(100).div(4000);
uint256 realStakedAmount = amount.sub(burnedAmount);
// Increase the total staked amount
_totalStakedAmount = _totalStakedAmount.add(realStakedAmount);
// Add staked amount
_stakedAmount[_msgSender()] = _stakedAmount[_msgSender()].add(realStakedAmount);
emit Staked(_msgSender(), realStakedAmount);
}
/**
* @dev API to unstake staked rPEPE tokens
*
* @param amount: Amount of tokens to unstake
*
* requirements:
*
* - Must not be consider the burning amount
*/
function unstake(uint256 amount) public {
require(_stakedAmount[_msgSender()] > 0, "No running stake.");
require(amount > 0, "Unstaking amount must be more than zero.");
require(_stakedAmount[_msgSender()] >= amount, "Staked amount must be ustaking amount or more.");
// Transfer tokens from contract amount to staker
require(IPEPE(_RarePepeV2).transfer(_msgSender(), amount), "It has failed to transfer tokens from contract to staker.");
// Decrease the total staked amount
_totalStakedAmount = _totalStakedAmount.sub(amount);
// Decrease the staker's staked amount
_stakedAmount[_msgSender()] = _stakedAmount[_msgSender()].sub(amount);
// remove staker from array
if (_stakedAmount[_msgSender()] == 0) {
for (uint256 i=0; i < _stakers.length; i++) {
if (_stakers[i] == _msgSender()) {
_stakers[i] = _stakers[_stakers.length.sub(1)];
_stakers.pop();
break;
}
}
}
emit Unstaked(_msgSender(), amount);
}
/**
* @dev API to get the total staked amount of all stakers
*/
function getTotalStakedAmount() external view returns (uint256) {
return _totalStakedAmount;
}
/**
* @dev API to get the staker's staked amount
*/
function getStakedAmount(address account) external view returns (uint256) {
return _stakedAmount[account];
}
/**
* @dev API to get the staker's array
*/
function getStakers() external view returns (address[] memory) {
return _stakers;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
function ceil(uint256 a, uint256 m) internal pure returns (uint256) {
uint256 c = add(a, m);
uint256 d = sub(c, 1);
return mul(div(d,m),m);
}
}
{
"compilationTarget": {
"RPEPEBLU.sol": "RPEPEBLU"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 0
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"RarePepeV2","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unstaked","type":"event"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getStakedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStakers","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalStakedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"}]