//address token 0xf8f0bA8CCACdD45dAD6f04cc775ac0FB069eF000
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC20.sol";
/////////////////////////////////////////////////////////////////////Safe Math Library Smart Contract////////////////////////////////////////////////////////////////////////////////////////////////////////
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @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) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @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) {
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, reverting 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) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* 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);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* 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);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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;
}
}
/////////////////////////////////////////////////////////////////////Genisis_Shards Staking Contract Start////////////////////////////////////////////////////////////////////////////////////////////////////////
contract GS_AccessPool {
using SafeMath for uint256;
address public owner ;
address public admin=0x0c3c52CeA1f315b1544d0dD72f46d8EbD2C2BAC9 ; //change the admin acc
IERC20 public GSContractAddress = IERC20(0xe0B9a2C3E9f40CF74B2C7F591B2b0CCa055c3112); //gs token contract bsc
IERC20 public GSKContractAddress = IERC20(0x2ec76424f62CEb8403fc6729D0C807Dde71E3303); //gsk token contract bsc
//original gs token address 0xe0b9a2c3e9f40cf74b2c7f591b2b0cca055c3112 on eth
uint256 public APR = 3805; // Actual value
uint256 public APR_ACCURACY_RATIO = 1000000000000 ;
bool stopContract = false ;
uint256 public deployTime = now;
struct Stake{
address user;//address of the user
uint256 amount;//total amount currently the user has staked
uint256 since; // time at which the user has
uint256 claimed; // already claimed by the user
uint256 claimable;// This claimable field is new and used to tell how big of a reward is currently available
}
mapping(address=>Stake) private stakers;
uint256 public totalGenisis_ShardsStaked ; // Total Genisis_Shards Staked
mapping(address => bool) public isStaking;
//////////////////////////////////////////////////////////////////////////////EVENT DECLERATION//////////////////////////////////////////////////////////////////////////////////////////////////////
event Staked(address indexed _from, uint256 _value);
event ClaimedReward(address indexed _from, uint256 _value);
event UnStaked(address indexed _from, uint256 _value);
event ClaimAndWithdraw(address indexed _from, uint256 _value);
event OwnershipTransferred(address _owner,address newOwner);
//////////////////////////////////////////////////////////////////////////////Constructor Function///////////////////////////////////////////////////////////////////////////////////////////////////
constructor() public {
owner = msg.sender;
}
//////////////////////////////////////////////////////////////////////////////////////Modifier Definitations////////////////////////////////////////////////////////////////////////////////////////////
modifier onlyOwner {
require (msg.sender == owner , 'Only owner has right to execute this function');
_;
}
modifier currentlyStaked {
require (isStaking [msg.sender] == true , 'Only staked user has right to execute this function');
_;
}
modifier poolStatus {
require (stopContract == false , 'Only when the pool is running user has right to execute this function');
_;
}
//////////////////////////////////////////////////////////////////////////////////////Staking Function//////////////////////////////////////////////////////////////////////////////////////////////////
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
owner = newOwner;
emit OwnershipTransferred(owner, newOwner);
}
function stakeTokens(uint256 _amount) external poolStatus {
require(IERC20(GSContractAddress).transferFrom(msg.sender, address(this), _amount));
totalGenisis_ShardsStaked=totalGenisis_ShardsStaked.add(_amount);
if (isStaking[msg.sender] == false)
{
stakers[msg.sender]=Stake(msg.sender,_amount,now,stakers[msg.sender].claimed,0);
isStaking[msg.sender] = true;
}
else
{
uint256 totalReward=_calculateReward(stakers[msg.sender]);
uint256 totalAmount=stakers[msg.sender].amount.add(_amount);
stakers[msg.sender]=Stake(msg.sender,totalAmount,now,stakers[msg.sender].claimed,totalReward);
}
emit Staked(msg.sender, _amount);
}
//////////////////////////////////////////////////////////////////////////////////////Reward Generation Function //////////////////////////////////////////////////////////////////////////////////////////////////
function _calculateReward(Stake memory _currentUser) internal view returns(uint256) {
uint256 totalTime=now.sub(_currentUser.since);
uint256 reward=_currentUser.amount.mul(totalTime).mul(APR).div(APR_ACCURACY_RATIO);
uint256 totalReward=_currentUser.claimable.add(reward);
return totalReward;
}
/////////////////////////////////////////////////////////////////Claim Rewards///////////////////////////////////////////////////////////////////////////////////////////////
function claimReward() external currentlyStaked poolStatus {
uint256 reward=_calculateReward(stakers[msg.sender]);
stakers[msg.sender].since=now;
stakers[msg.sender].claimable=0;
stakers[msg.sender].claimed=stakers[msg.sender].claimed+reward;
require(IERC20(GSKContractAddress).transferFrom(admin, msg.sender, reward));
emit ClaimedReward(msg.sender, reward);
}
//////////////////////////////////////////////////Claim and Withdraw All /////////////////////////////////////////////////////////////////////////////////////////////////////////////
function claimAndWithdrawAll() external currentlyStaked poolStatus {
// Fetch staking balance
uint256 balance = stakers[msg.sender].amount;
// Fetch Reward balance
uint256 totalReward = _calculateReward(stakers[msg.sender]);
// Require amount greater than 0
require((balance+totalReward > 0 ) , "staking balance cannot be 0 ");
totalGenisis_ShardsStaked=totalGenisis_ShardsStaked.sub(balance);
stakers[msg.sender]=Stake(msg.sender,0,0,stakers[msg.sender].claimed+totalReward,0);
// Update staking status
isStaking[msg.sender] = false;
if(totalReward==0)
{
require(IERC20(GSContractAddress).transfer(msg.sender,balance));
}
else if(balance==0)
{
require(IERC20(GSKContractAddress).transferFrom(admin, msg.sender, totalReward));
}
else
{
require(IERC20(GSContractAddress).transfer(msg.sender,balance));
require(IERC20(GSKContractAddress).transferFrom(admin, msg.sender, totalReward));
}
emit ClaimAndWithdraw(msg.sender, totalReward);
}
//////////////////////////////////////////////////////////////////////////////////////Unstaking the GS Tokens Function //////////////////////////////////////////////////////////////////////////////////////////////////
// Unstaking Tokens (Withdraw)
function unstakeTokens(uint _amount) external currentlyStaked poolStatus {
// Fetch staking balance
uint256 balance = stakers[msg.sender].amount;
require((balance>= _amount ) , "unstaking balance cannot be more");
uint256 totalReward=_calculateReward(stakers[msg.sender]);
uint256 totalAmount=balance.sub(_amount);
stakers[msg.sender]=Stake(msg.sender,totalAmount,now,stakers[msg.sender].claimed,totalReward);
totalGenisis_ShardsStaked=totalGenisis_ShardsStaked.sub(_amount);
require(IERC20(GSContractAddress).transfer(msg.sender,_amount));
emit UnStaked(msg.sender, _amount);
}
///////////////////////////////////////////////////////////////////staking Information functions/////////////////////////////////////////////////////////////////////////////////////////////////
function stakeInfo_totalAmount() external view returns(uint256){
require(msg.sender!=address(0) , "Invalid Address");
Stake memory currentUser=stakers[msg.sender];
uint256 totalAmount=stakers[msg.sender].amount.add(_calculateReward(currentUser));
return totalAmount;
}
function stakeInfo_totalBalance() external view returns(uint256){
require(msg.sender!=address(0) , "Invalid Address");
return stakers[msg.sender].amount;
}
function stakeInfo_totalClaimed() external view returns(uint256){
require(msg.sender!=address(0) , "Invalid Address");
return stakers[msg.sender].claimed;
}
function stakeInfo_totalReward() external view returns(uint256){
require(msg.sender!=address(0) , "Invalid Address");
Stake memory currentUser=stakers[msg.sender];
uint256 totalReward=_calculateReward(currentUser);
return totalReward;
}
///////////////////////////////////////////////////////////////////Implement Circuit Breaker Start/////////////////////////////////////////////////////////////////////////////////////////////////
function stopPoolContractInEmergencySituation() external onlyOwner {
require(stopContract == false , 'Contract has been already stoped in Emergency Situation') ;
stopContract = true ;
}
function startPoolContractAfterEmergencySituationEnds() external onlyOwner {
require(stopContract == true , 'Contract is already running ') ;
stopContract = false ;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
{
"compilationTarget": {
"AccessPool.sol": "GS_AccessPool"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"ClaimAndWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"ClaimedReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_owner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"UnStaked","type":"event"},{"inputs":[],"name":"APR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"APR_ACCURACY_RATIO","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GSContractAddress","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GSKContractAddress","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimAndWithdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"deployTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isStaking","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakeInfo_totalAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakeInfo_totalBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakeInfo_totalClaimed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakeInfo_totalReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"stakeTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startPoolContractAfterEmergencySituationEnds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stopPoolContractInEmergencySituation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalGenisis_ShardsStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"unstakeTokens","outputs":[],"stateMutability":"nonpayable","type":"function"}]