{ "language": "Solidity", "sources": { "slvmGenesis.sol": { "content": "/**\r\n *Submitted for verification at Etherscan.io on 2022-04-15\r\n*/\r\n\r\n// SPDX-License-Identifier: MIT\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Interface of the ERC20 standard as defined in the EIP.\r\n */\r\ninterface IERC20 {\r\n /**\r\n * @dev Returns the amount of tokens in existence.\r\n */\r\n function totalSupply() external view returns (uint256);\r\n\r\n /**\r\n * @dev Returns the amount of tokens owned by `account`.\r\n */\r\n function balanceOf(address account) external view returns (uint256);\r\n\r\n /**\r\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\r\n *\r\n * Returns a boolean value indicating whether the operation succeeded.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transfer(address recipient, uint256 amount) external returns (bool);\r\n\r\n /**\r\n * @dev Returns the remaining number of tokens that `spender` will be\r\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\r\n * zero by default.\r\n *\r\n * This value changes when {approve} or {transferFrom} are called.\r\n */\r\n function allowance(address owner, address spender) external view returns (uint256);\r\n\r\n /**\r\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\r\n *\r\n * Returns a boolean value indicating whether the operation succeeded.\r\n *\r\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\r\n * that someone may use both the old and the new allowance by unfortunate\r\n * transaction ordering. One possible solution to mitigate this race\r\n * condition is to first reduce the spender's allowance to 0 and set the\r\n * desired value afterwards:\r\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function approve(address spender, uint256 amount) external returns (bool);\r\n\r\n /**\r\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\r\n * allowance mechanism. `amount` is then deducted from the caller's\r\n * allowance.\r\n *\r\n * Returns a boolean value indicating whether the operation succeeded.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\r\n\r\n /**\r\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\r\n * another (`to`).\r\n *\r\n * Note that `value` may be zero.\r\n */\r\n event Transfer(address indexed from, address indexed to, uint256 value);\r\n\r\n /**\r\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\r\n * a call to {approve}. `value` is the new allowance.\r\n */\r\n event Approval(address indexed owner, address indexed spender, uint256 value);\r\n}\r\n\r\n\r\n// File @openzeppelin/contracts/math/SafeMath.sol@v3.4.2\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\r\n * checks.\r\n *\r\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\r\n * in bugs, because programmers usually assume that an overflow raises an\r\n * error, which is the standard behavior in high level programming languages.\r\n * `SafeMath` restores this intuition by reverting the transaction when an\r\n * operation overflows.\r\n *\r\n * Using this library instead of the unchecked operations eliminates an entire\r\n * class of bugs, so it's recommended to use it always.\r\n */\r\nlibrary SafeMath {\r\n /**\r\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n uint256 c = a + b;\r\n if (c < a) return (false, 0);\r\n return (true, c);\r\n }\r\n\r\n /**\r\n * @dev Returns the substraction of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n if (b > a) return (false, 0);\r\n return (true, a - b);\r\n }\r\n\r\n /**\r\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\r\n // benefit is lost if 'b' is also tested.\r\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\r\n if (a == 0) return (true, 0);\r\n uint256 c = a * b;\r\n if (c / a != b) return (false, 0);\r\n return (true, c);\r\n }\r\n\r\n /**\r\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n if (b == 0) return (false, 0);\r\n return (true, a / b);\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n if (b == 0) return (false, 0);\r\n return (true, a % b);\r\n }\r\n\r\n /**\r\n * @dev Returns the addition of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity's `+` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Addition cannot overflow.\r\n */\r\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\r\n uint256 c = a + b;\r\n require(c >= a, \"SafeMath: addition overflow\");\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting on\r\n * overflow (when the result is negative).\r\n *\r\n * Counterpart to Solidity's `-` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Subtraction cannot overflow.\r\n */\r\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\r\n require(b <= a, \"SafeMath: subtraction overflow\");\r\n return a - b;\r\n }\r\n\r\n /**\r\n * @dev Returns the multiplication of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity's `*` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Multiplication cannot overflow.\r\n */\r\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\r\n if (a == 0) return 0;\r\n uint256 c = a * b;\r\n require(c / a == b, \"SafeMath: multiplication overflow\");\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers, reverting on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * Counterpart to Solidity's `/` operator. Note: this function uses a\r\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n * uses an invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\r\n require(b > 0, \"SafeMath: division by zero\");\r\n return a / b;\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * reverting when dividing by zero.\r\n *\r\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\r\n require(b > 0, \"SafeMath: modulo by zero\");\r\n return a % b;\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\r\n * overflow (when the result is negative).\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {trySub}.\r\n *\r\n * Counterpart to Solidity's `-` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Subtraction cannot overflow.\r\n */\r\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b <= a, errorMessage);\r\n return a - b;\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers, reverting with custom message on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {tryDiv}.\r\n *\r\n * Counterpart to Solidity's `/` operator. Note: this function uses a\r\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n * uses an invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b > 0, errorMessage);\r\n return a / b;\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * reverting with custom message when dividing by zero.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {tryMod}.\r\n *\r\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b > 0, errorMessage);\r\n return a % b;\r\n }\r\n}\r\n\r\n\r\n// File @openzeppelin/contracts/utils/Address.sol@v3.4.2\r\n\r\n\r\n\r\npragma solidity >=0.6.2 <0.8.0;\r\n\r\n/**\r\n * @dev Collection of functions related to the address type\r\n */\r\nlibrary Address {\r\n /**\r\n * @dev Returns true if `account` is a contract.\r\n *\r\n * [IMPORTANT]\r\n * ====\r\n * It is unsafe to assume that an address for which this function returns\r\n * false is an externally-owned account (EOA) and not a contract.\r\n *\r\n * Among others, `isContract` will return false for the following\r\n * types of addresses:\r\n *\r\n * - an externally-owned account\r\n * - a contract in construction\r\n * - an address where a contract will be created\r\n * - an address where a contract lived, but was destroyed\r\n * ====\r\n */\r\n function isContract(address account) internal view returns (bool) {\r\n // This method relies on extcodesize, which returns 0 for contracts in\r\n // construction, since the code is only stored at the end of the\r\n // constructor execution.\r\n\r\n uint256 size;\r\n // solhint-disable-next-line no-inline-assembly\r\n assembly { size := extcodesize(account) }\r\n return size > 0;\r\n }\r\n\r\n /**\r\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\r\n * `recipient`, forwarding all available gas and reverting on errors.\r\n *\r\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\r\n * imposed by `transfer`, making them unable to receive funds via\r\n * `transfer`. {sendValue} removes this limitation.\r\n *\r\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r\n *\r\n * IMPORTANT: because control is transferred to `recipient`, care must be\r\n * taken to not create reentrancy vulnerabilities. Consider using\r\n * {ReentrancyGuard} or the\r\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r\n */\r\n function sendValue(address payable recipient, uint256 amount) internal {\r\n require(address(this).balance >= amount, \"Address: insufficient balance\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\r\n (bool success, ) = recipient.call{ value: amount }(\"\");\r\n require(success, \"Address: unable to send value, recipient may have reverted\");\r\n }\r\n\r\n /**\r\n * @dev Performs a Solidity function call using a low level `call`. A\r\n * plain`call` is an unsafe replacement for a function call: use this\r\n * function instead.\r\n *\r\n * If `target` reverts with a revert reason, it is bubbled up by this\r\n * function (like regular Solidity function calls).\r\n *\r\n * Returns the raw returned data. To convert to the expected return value,\r\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r\n *\r\n * Requirements:\r\n *\r\n * - `target` must be a contract.\r\n * - calling `target` with `data` must not revert.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\r\n return functionCall(target, data, \"Address: low-level call failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r\n * `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\r\n return functionCallWithValue(target, data, 0, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but also transferring `value` wei to `target`.\r\n *\r\n * Requirements:\r\n *\r\n * - the calling contract must have an ETH balance of at least `value`.\r\n * - the called Solidity function must be `payable`.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\r\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r\n * with `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\r\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\r\n require(isContract(target), \"Address: call to non-contract\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls\r\n (bool success, bytes memory returndata) = target.call{ value: value }(data);\r\n return _verifyCallResult(success, returndata, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\r\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\r\n require(isContract(target), \"Address: static call to non-contract\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls\r\n (bool success, bytes memory returndata) = target.staticcall(data);\r\n return _verifyCallResult(success, returndata, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\r\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\r\n require(isContract(target), \"Address: delegate call to non-contract\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls\r\n (bool success, bytes memory returndata) = target.delegatecall(data);\r\n return _verifyCallResult(success, returndata, errorMessage);\r\n }\r\n\r\n function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {\r\n if (success) {\r\n return returndata;\r\n } else {\r\n // Look for revert reason and bubble it up if present\r\n if (returndata.length > 0) {\r\n // The easiest way to bubble the revert reason is using memory via assembly\r\n\r\n // solhint-disable-next-line no-inline-assembly\r\n assembly {\r\n let returndata_size := mload(returndata)\r\n revert(add(32, returndata), returndata_size)\r\n }\r\n } else {\r\n revert(errorMessage);\r\n }\r\n }\r\n }\r\n}\r\n\r\n\r\n// File @openzeppelin/contracts/token/ERC20/SafeERC20.sol@v3.4.2\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n\r\n\r\n/**\r\n * @title SafeERC20\r\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\r\n * contract returns false). Tokens that return no value (and instead revert or\r\n * throw on failure) are also supported, non-reverting calls are assumed to be\r\n * successful.\r\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\r\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\r\n */\r\nlibrary SafeERC20 {\r\n using SafeMath for uint256;\r\n using Address for address;\r\n\r\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\r\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\r\n }\r\n\r\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\r\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\r\n }\r\n\r\n /**\r\n * @dev Deprecated. This function has issues similar to the ones found in\r\n * {IERC20-approve}, and its usage is discouraged.\r\n *\r\n * Whenever possible, use {safeIncreaseAllowance} and\r\n * {safeDecreaseAllowance} instead.\r\n */\r\n function safeApprove(IERC20 token, address spender, uint256 value) internal {\r\n // safeApprove should only be called when setting an initial allowance,\r\n // or when resetting it to zero. To increase and decrease it, use\r\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\r\n // solhint-disable-next-line max-line-length\r\n require((value == 0) || (token.allowance(address(this), spender) == 0),\r\n \"SafeERC20: approve from non-zero to non-zero allowance\"\r\n );\r\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\r\n }\r\n\r\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\r\n uint256 newAllowance = token.allowance(address(this), spender).add(value);\r\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\r\n }\r\n\r\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\r\n uint256 newAllowance = token.allowance(address(this), spender).sub(value, \"SafeERC20: decreased allowance below zero\");\r\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\r\n }\r\n\r\n /**\r\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\r\n * on the return value: the return value is optional (but if data is returned, it must not be false).\r\n * @param token The token targeted by the call.\r\n * @param data The call data (encoded using abi.encode or one of its variants).\r\n */\r\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\r\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\r\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\r\n // the target address contains contract code and also asserts for success in the low-level call.\r\n\r\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\r\n if (returndata.length > 0) { // Return data is optional\r\n // solhint-disable-next-line max-line-length\r\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\r\n }\r\n }\r\n}\r\n\r\n\r\n// File contracts/distribution/SlvmGenesisRewardPool.sol\r\n\r\n\r\ninterface INode {\r\n function whitelist(address _addr) external view returns(bool);\r\n}\r\npragma solidity 0.6.12;\r\n\r\n// Note that this pool has no minter key of SLVM (rewards).\r\n// Instead, the governance will call SLVM distributeReward method and send reward to this pool at the beginning.\r\ncontract SlvmGenesisRewardPool {\r\n using SafeMath for uint256;\r\n using SafeERC20 for IERC20;\r\n\r\n // governance\r\n address public operator;\r\n address public node;\r\n address public feeAddress;\r\n address public paxg = 0x45804880De22913dAFE09f4980848ECE6EcbAf78;\r\n\r\n uint256 public whitelistPrice = 125000000000000000;\r\n // Info of each user.\r\n struct UserInfo {\r\n uint256 amount; // How many tokens the user has provided.\r\n uint256 rewardDebt; // Reward debt. See explanation below.\r\n }\r\n\r\n // Info of each pool.\r\n struct PoolInfo {\r\n IERC20 token; // Address of LP token contract.\r\n uint256 allocPoint; // How many allocation points assigned to this pool. SLVM to distribute.\r\n uint256 lastRewardTime; // Last time that SLVM distribution occurs.\r\n uint256 accSlvmPerShare; // Accumulated SLVM per share, times 1e18. See below.\r\n bool isStarted; // if lastRewardBlock has passed\r\n uint256 fee;\r\n }\r\n\r\n IERC20 public slvm;\r\n\r\n // Info of each pool.\r\n PoolInfo[] public poolInfo;\r\n\r\n // Info of each user that stakes LP tokens.\r\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\r\n\r\n // Total allocation points. Must be the sum of all allocation points in all pools.\r\n uint256 public totalAllocPoint = 0;\r\n\r\n // The time when SLVM mining starts.\r\n uint256 public poolStartTime;\r\n\r\n // The time when SLVM mining ends.\r\n uint256 public poolEndTime;\r\n mapping (address => bool) public whitelist;\r\n bool whitelistEnabled = true;\r\n\r\n // MAINNET\r\n uint256 public slvmPerSecond = 0.0192901234567 ether; // 5000 SLVM / (24h * 60min * 60s)\r\n uint256 public runningTime = 3 days; // 3 days\r\n uint256 public constant TOTAL_REWARDS = 5000 ether;\r\n // END MAINNET\r\n\r\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\r\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\r\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\r\n event RewardPaid(address indexed user, uint256 amount);\r\n\r\n constructor(\r\n address _slvm,\r\n uint256 _poolStartTime,\r\n address _node,\r\n address _feeAddress\r\n ) public {\r\n require(block.timestamp < _poolStartTime, \"late\");\r\n\r\n if (_slvm != address(0)) slvm = IERC20(_slvm);\r\n poolStartTime = _poolStartTime;\r\n poolEndTime = poolStartTime + runningTime;\r\n operator = msg.sender;\r\n node = _node;\r\n feeAddress = _feeAddress;\r\n }\r\n \r\n\r\n modifier onlyOperator() {\r\n require(operator == msg.sender, \"SlvmGenesisPool: caller is not the operator\");\r\n _;\r\n }\r\n\r\n // set fee address\r\n function setFeeAddress(address _feeAddress) public onlyOperator{\r\n feeAddress = _feeAddress;\r\n }\r\n\r\n // set an address's whitelist state\r\n function setWhitelist(address _addr, bool _f) public onlyOperator{\r\n whitelist[_addr] = _f;\r\n }\r\n\r\n // set whitelist on or off\r\n function setWhitelistEnabled(bool _f) public onlyOperator{\r\n whitelistEnabled = _f;\r\n }\r\n\r\n // buy whitelist\r\n function buyWhitelist() public {\r\n require(isWhitelist(msg.sender) == false, \"Already in whitelist\");\r\n IERC20(paxg).transferFrom(msg.sender, feeAddress, whitelistPrice);\r\n whitelist[msg.sender] = true;\r\n }\r\n\r\n // check address is whitelisted\r\n function isWhitelist(address _addr) public view returns(bool){\r\n if ( whitelistEnabled ){\r\n bool f1 = whitelist[_addr];\r\n bool f2 = INode(node).whitelist(_addr);\r\n return f1 || f2;\r\n }\r\n return true;\r\n }\r\n\r\n // check pool duplicate\r\n function checkPoolDuplicate(IERC20 _token) internal view {\r\n uint256 length = poolInfo.length;\r\n for (uint256 pid = 0; pid < length; ++pid) {\r\n require(poolInfo[pid].token != _token, \"SlvmGenesisPool: existing pool?\");\r\n }\r\n }\r\n\r\n // Add a new token to the pool. Can only be called by the owner.\r\n function add(\r\n uint256 _allocPoint,\r\n IERC20 _token,\r\n bool _withUpdate,\r\n uint256 _lastRewardTime,\r\n uint256 _fee\r\n ) public onlyOperator {\r\n checkPoolDuplicate(_token);\r\n if (_withUpdate) {\r\n massUpdatePools();\r\n }\r\n if (block.timestamp < poolStartTime) {\r\n // chef is sleeping\r\n if (_lastRewardTime == 0) {\r\n _lastRewardTime = poolStartTime;\r\n } else {\r\n if (_lastRewardTime < poolStartTime) {\r\n _lastRewardTime = poolStartTime;\r\n }\r\n }\r\n } else {\r\n // chef is cooking\r\n if (_lastRewardTime == 0 || _lastRewardTime < block.timestamp) {\r\n _lastRewardTime = block.timestamp;\r\n }\r\n }\r\n bool _isStarted = (_lastRewardTime <= poolStartTime) || (_lastRewardTime <= block.timestamp);\r\n poolInfo.push(PoolInfo({token: _token, allocPoint: _allocPoint, lastRewardTime: _lastRewardTime, accSlvmPerShare: 0, isStarted: _isStarted, fee: _fee}));\r\n if (_isStarted) {\r\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\r\n }\r\n }\r\n\r\n // Update the given pool's SLVM allocation point. Can only be called by the owner.\r\n function set(uint256 _pid, uint256 _allocPoint, uint256 _fee) public onlyOperator {\r\n massUpdatePools();\r\n PoolInfo storage pool = poolInfo[_pid];\r\n if (pool.isStarted) {\r\n totalAllocPoint = totalAllocPoint.sub(pool.allocPoint).add(_allocPoint);\r\n }\r\n pool.allocPoint = _allocPoint;\r\n pool.fee = _fee;\r\n }\r\n\r\n // Return accumulate rewards over the given _from to _to block.\r\n function getGeneratedReward(uint256 _fromTime, uint256 _toTime) public view returns (uint256) {\r\n if (_fromTime >= _toTime) return 0;\r\n if (_toTime >= poolEndTime) {\r\n if (_fromTime >= poolEndTime) return 0;\r\n if (_fromTime <= poolStartTime) return poolEndTime.sub(poolStartTime).mul(slvmPerSecond);\r\n return poolEndTime.sub(_fromTime).mul(slvmPerSecond);\r\n } else {\r\n if (_toTime <= poolStartTime) return 0;\r\n if (_fromTime <= poolStartTime) return _toTime.sub(poolStartTime).mul(slvmPerSecond);\r\n return _toTime.sub(_fromTime).mul(slvmPerSecond);\r\n }\r\n }\r\n\r\n // View function to see pending SLVM on frontend.\r\n function pendingSLVM(uint256 _pid, address _user) external view returns (uint256) {\r\n PoolInfo storage pool = poolInfo[_pid];\r\n UserInfo storage user = userInfo[_pid][_user];\r\n uint256 accSlvmPerShare = pool.accSlvmPerShare;\r\n uint256 tokenSupply = pool.token.balanceOf(address(this));\r\n if (block.timestamp > pool.lastRewardTime && tokenSupply != 0) {\r\n uint256 _generatedReward = getGeneratedReward(pool.lastRewardTime, block.timestamp);\r\n uint256 _slvmReward = _generatedReward.mul(pool.allocPoint).div(totalAllocPoint);\r\n accSlvmPerShare = accSlvmPerShare.add(_slvmReward.mul(1e18).div(tokenSupply));\r\n }\r\n return user.amount.mul(accSlvmPerShare).div(1e18).sub(user.rewardDebt);\r\n }\r\n\r\n // Update reward variables for all pools. Be careful of gas spending!\r\n function massUpdatePools() public {\r\n uint256 length = poolInfo.length;\r\n for (uint256 pid = 0; pid < length; ++pid) {\r\n updatePool(pid);\r\n }\r\n }\r\n\r\n // Update reward variables of the given pool to be up-to-date.\r\n function updatePool(uint256 _pid) public {\r\n PoolInfo storage pool = poolInfo[_pid];\r\n if (block.timestamp <= pool.lastRewardTime) {\r\n return;\r\n }\r\n uint256 tokenSupply = pool.token.balanceOf(address(this));\r\n if (tokenSupply == 0) {\r\n pool.lastRewardTime = block.timestamp;\r\n return;\r\n }\r\n if (!pool.isStarted) {\r\n pool.isStarted = true;\r\n totalAllocPoint = totalAllocPoint.add(pool.allocPoint);\r\n }\r\n if (totalAllocPoint > 0) {\r\n uint256 _generatedReward = getGeneratedReward(pool.lastRewardTime, block.timestamp);\r\n uint256 _slvmReward = _generatedReward.mul(pool.allocPoint).div(totalAllocPoint);\r\n pool.accSlvmPerShare = pool.accSlvmPerShare.add(_slvmReward.mul(1e18).div(tokenSupply));\r\n }\r\n pool.lastRewardTime = block.timestamp;\r\n }\r\n\r\n // Deposit LP tokens.\r\n function deposit(uint256 _pid, uint256 _amount) public {\r\n address _sender = msg.sender;\r\n bool _f = isWhitelist(_sender);\r\n require(_f, \"Not in whitelist\");\r\n \r\n PoolInfo storage pool = poolInfo[_pid];\r\n UserInfo storage user = userInfo[_pid][_sender];\r\n updatePool(_pid);\r\n if (user.amount > 0) {\r\n uint256 _pending = user.amount.mul(pool.accSlvmPerShare).div(1e18).sub(user.rewardDebt);\r\n if (_pending > 0) {\r\n safeSlvmTransfer(_sender, _pending);\r\n emit RewardPaid(_sender, _pending);\r\n }\r\n }\r\n if (_amount > 0) {\r\n pool.token.safeTransferFrom(_sender, address(this), _amount);\r\n uint256 fee = _amount.mul(pool.fee).div(1000);\r\n pool.token.transfer(feeAddress, fee);\r\n user.amount = user.amount.add(_amount).sub(fee);\r\n }\r\n user.rewardDebt = user.amount.mul(pool.accSlvmPerShare).div(1e18);\r\n emit Deposit(_sender, _pid, _amount);\r\n }\r\n\r\n // Withdraw LP tokens.\r\n function withdraw(uint256 _pid, uint256 _amount) public {\r\n address _sender = msg.sender;\r\n PoolInfo storage pool = poolInfo[_pid];\r\n UserInfo storage user = userInfo[_pid][_sender];\r\n require(user.amount >= _amount, \"withdraw: not good\");\r\n updatePool(_pid);\r\n uint256 _pending = user.amount.mul(pool.accSlvmPerShare).div(1e18).sub(user.rewardDebt);\r\n if (_pending > 0) {\r\n safeSlvmTransfer(_sender, _pending);\r\n emit RewardPaid(_sender, _pending);\r\n }\r\n if (_amount > 0) {\r\n user.amount = user.amount.sub(_amount);\r\n pool.token.safeTransfer(_sender, _amount);\r\n }\r\n user.rewardDebt = user.amount.mul(pool.accSlvmPerShare).div(1e18);\r\n emit Withdraw(_sender, _pid, _amount);\r\n }\r\n\r\n // Withdraw without caring about rewards. EMERGENCY ONLY.\r\n function emergencyWithdraw(uint256 _pid) public {\r\n PoolInfo storage pool = poolInfo[_pid];\r\n UserInfo storage user = userInfo[_pid][msg.sender];\r\n uint256 _amount = user.amount;\r\n user.amount = 0;\r\n user.rewardDebt = 0;\r\n pool.token.safeTransfer(msg.sender, _amount);\r\n emit EmergencyWithdraw(msg.sender, _pid, _amount);\r\n }\r\n\r\n // Safe SLVM transfer function, just in case if rounding error causes pool to not have enough SLVMs.\r\n function safeSlvmTransfer(address _to, uint256 _amount) internal {\r\n uint256 _slvmBalance = slvm.balanceOf(address(this));\r\n if (_slvmBalance > 0) {\r\n if (_amount > _slvmBalance) {\r\n slvm.safeTransfer(_to, _slvmBalance);\r\n } else {\r\n slvm.safeTransfer(_to, _amount);\r\n }\r\n }\r\n }\r\n\r\n function setOperator(address _operator) external onlyOperator {\r\n operator = _operator;\r\n }\r\n\r\n function governanceRecoverUnsupported(\r\n IERC20 _token,\r\n uint256 amount,\r\n address to\r\n ) external onlyOperator {\r\n if (block.timestamp < poolEndTime + 90 days) {\r\n // do not allow to drain core token (SLVM or lps) if less than 90 days after pool ends\r\n require(_token != slvm, \"slvm\");\r\n uint256 length = poolInfo.length;\r\n for (uint256 pid = 0; pid < length; ++pid) {\r\n PoolInfo storage pool = poolInfo[pid];\r\n require(_token != pool.token, \"pool.token\");\r\n }\r\n }\r\n _token.safeTransfer(to, amount);\r\n }\r\n}" } }, "settings": { "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } } }