Transaction Hash:
Block:
16725572 at Feb-28-2023 08:48:59 AM +UTC
Transaction Fee:
0.0012231701052634 ETH
$2.95
Gas Used:
73,400 Gas / 16.664442851 Gwei
Emitted Events:
203 |
StakingManager.UserBalanceChanged( account=[Sender] 0xe8d2c3eeb434d152163ad5d0eeecc2a2e43de139, poolId=3, totalUserDeposits=51428000000000000000000 )
|
Account State Difference:
Address | Before | After | State Difference | ||
---|---|---|---|---|---|
0x690B9A9E...Db4FaC990
Miner
| (builder0x69) | 2.032464811861724268 Eth | 2.032501511861724268 Eth | 0.0000367 | |
0xe8d2C3ee...2e43dE139 |
0.012071044893368365 Eth
Nonce: 283
|
0.010847874788104965 Eth
Nonce: 284
| 0.0012231701052634 |
Execution Trace
StakingManager.claimReward( poolId=3 )
-
0x675620ad09088389417419be14d4215e3c1ae887.94f649dd( )
-
0x675620ad09088389417419be14d4215e3c1ae887.94f649dd( )
-
0x675620ad09088389417419be14d4215e3c1ae887.1c260b5f( )
-
MainToken.balanceOf( _owner=0x675620AD09088389417419BE14D4215e3c1AE887 ) => ( balance=3088179000000000000000000 )
-
0x675620ad09088389417419be14d4215e3c1ae887.STATICCALL( )
-
0x675620ad09088389417419be14d4215e3c1ae887.STATICCALL( )
-
0x675620ad09088389417419be14d4215e3c1ae887.1c260b5f( )
-
0x675620ad09088389417419be14d4215e3c1ae887.70a08231( )
claimReward[StakingManager (ln:747)]
getDeposits[StakingManager (ln:749)]
getReward[StakingManager (ln:752)]
getDeposits[StakingManager (ln:792)]
min[StakingManager (ln:796)]
getEndTime[StakingManager (ln:797)]
balanceOf[StakingManager (ln:800)]
getAvailableRewards[StakingManager (ln:801)]
getCampaignElapsedMinutes[StakingManager (ln:784)]
id[StakingManager (ln:802)]
getTimePeriod[StakingManager (ln:802)]
max[StakingManager (ln:806)]
min[StakingManager (ln:753)]
getEndTime[StakingManager (ln:755)]
safeTransfer[StakingManager (ln:759)]
UserBalanceChanged[StakingManager (ln:761)]
balanceOf[StakingManager (ln:761)]
File 1 of 2: StakingManager
File 2 of 2: MainToken
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) pragma solidity ^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 `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, 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 `from` to `to` 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 from, address to, 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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.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 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) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a / b + (a % b == 0 ? 0 : 1); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.11; import "./StakingManager.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; /// @title Efforce farming pool for WOZX token /// @author Ackee Blockchain /// @notice Contract holds information about users deposit amounts and deposit times contract Pool { using SafeERC20 for IERC20; struct Deposit { uint256 amount; uint256 depositTime; } StakingManager public manager; uint8 public immutable id; mapping(address => Deposit[]) public deposits; modifier onlyManager() { require(msg.sender == address(manager), "Unauthorized"); _; } /// @param _id ID of the pool (0 = whole campaign, 1 = 1 month, 2 = 3 months, 3 = 6 months) /// @param _manager Staking manager contract address constructor(uint8 _id, address _manager) { require(_id < 4, "Invalid pool ID"); require( StakingManager(_manager).CONTRACT_TYPE() == keccak256("Efforce Staking Manager"), "Not a Efforce Staking Manager" ); id = _id; manager = StakingManager(_manager); } function getTimePeriod() public view returns (uint256) { if (id == 1) { return 2_592_000; } else if (id == 2) { return 7_776_000; } else if (id == 3) { return 15_552_000; } else { return 0; } } /// @notice Deposits WOZX tokens and save deposit amount and deposit time /// @param account Users's address /// @param amount Amount to deposit function deposit(address account, uint256 amount) external onlyManager { require( block.timestamp < manager.getCampaignEnd(), "Campaign ended, can't deposit" ); uint256 timePeriod = getTimePeriod(); if (deposits[account].length == 0) { // User joining the pool require( block.timestamp + manager.BUFFER_PERIOD() + timePeriod < manager.getCampaignEnd(), "Too late to join this pool" ); deposits[account].push( Deposit(amount, block.timestamp + manager.BUFFER_PERIOD()) ); } else if (block.timestamp < deposits[account][0].depositTime) { // User is in buffering period deposits[account].push( Deposit(amount, deposits[account][0].depositTime) ); } else { // User is staking if (timePeriod != 0) { require( block.timestamp < getStartTime(account) + timePeriod, "Can't deposit after the pool period" ); } deposits[account].push(Deposit(amount, block.timestamp)); } } /// @notice Withdraws deposited tokens from this pool and delete deposit records /// @param account User's address /// @return totalWithdraw sum of the user's all deposit amounts function withdraw(address account) external onlyManager returns (uint256 totalWithdraw) { totalWithdraw = balanceOf(account); delete deposits[account]; manager.wozxToken().safeTransfer(account, totalWithdraw); return totalWithdraw; } /// @notice Returns array of the deposits containing deposit amount and deposit time /// @param account User's address /// @return Array [] of Deposit structures function getDeposits(address account) external view returns (Deposit[] memory) { return deposits[account]; } /// @notice Returns sum of the user's all deposit amounts /// @param account User's address /// @return sum of the user's deposits function balanceOf(address account) public view returns (uint256 sum) { for (uint256 i = 0; i < deposits[account].length; i++) { sum += deposits[account][i].amount; } return sum; } /// @notice Returns time of user's first deposit /// @param account User's address /// @return Timestamp (uint256) function getStartTime(address account) public view returns (uint256) { require(deposits[account].length > 0, "Unknown address"); return deposits[account][0].depositTime; } /// @notice Returns end time of user's staking period /// @param account User's address /// @return Timestamp (uint256) function getEndTime(address account) public view returns (uint256) { require(deposits[account].length > 0, "Unknown address"); return id == 0 ? manager.getCampaignEnd() : (getStartTime(account) + getTimePeriod()); } /// @notice Returns elapsed time of the staking period. If still in buffering period, returns negative number (remaining buffering time) /// @param account User's address /// @return elapsed time of the staking period or negative number if is in buffering period function getElapsedTime(address account) public view returns (int256) { require(deposits[account].length > 0, "Unknown address"); return int256(block.timestamp) - int256(getStartTime(account)); } /// @notice Returns true when user is in buffering period /// @param account User's address /// @return Buffering period bool function isInBufferingPeriod(address account) external view returns (bool) { return getElapsedTime(account) < 0; } /// @notice Returns true when user's staking period is over /// @param account User's address /// @return Staking finished bool function isStakingFinished(address account) external view returns (bool) { return block.timestamp > getEndTime(account); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.11; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "./Pool.sol"; /// @title Efforce staking manager is the contract for managing the farming pools /// @author Ackee Blockchain /// @notice Staking manager contracts handles 4 staking pools with different staking periods contract StakingManager is Ownable { using SafeERC20 for IERC20; struct PoolInfo { address payable addr; uint256 totalRewards; uint256 rewardPerMinute; uint256 claimedRewards; mapping(address => uint256) lastRewardsClaim; } bytes32 public constant CONTRACT_TYPE = keccak256("Efforce Staking Manager"); uint256 public constant CAMPAIGN_PERIOD = 365 days; uint256 public constant BUFFER_PERIOD = 3 days; IERC20 public immutable wozxToken; // 0x34950ff2b487d9e5282c5ab342d08a2f712eb79f; PoolInfo[4] public pools; uint256 public campaignStart; event PoolBalanceChanged(uint8 indexed poolId, uint256 totalPoolAmount); event UserBalanceChanged(address indexed account, uint8 indexed poolId, uint256 totalUserDeposits); modifier isInitialized() { require(campaignStart != 0, "Not initialized"); _; } constructor(IERC20 _wozxToken) { require(address(_wozxToken) != address(0), "Unexpected zero address"); wozxToken = _wozxToken; } /// @dev Set pools addresses and start the whole campaign /// @param poolGlobal address of whole campaign pool /// @param pool1Month address of 1 month pool /// @param pool3Months address of 3 months pool /// @param pool6Months address of 6 months pool function init( address payable poolGlobal, address payable pool1Month, address payable pool3Months, address payable pool6Months ) external onlyOwner { require(campaignStart == 0, "Pools are already initialized"); require(Pool(poolGlobal).id() == 0, "Pool 0 id mismatch"); require(Pool(pool1Month).id() == 1, "Pool 1 id mismatch"); require(Pool(pool3Months).id() == 2, "Pool 2 id mismatch"); require(Pool(pool6Months).id() == 3, "Pool 3 id mismatch"); require( address(Pool(poolGlobal).manager()) == address(this), "Pool 0 manager mismatch" ); require( address(Pool(pool1Month).manager()) == address(this), "Pool 1 manager mismatch" ); require( address(Pool(pool3Months).manager()) == address(this), "Pool 2 manager mismatch" ); require( address(Pool(pool6Months).manager()) == address(this), "Pool 3 manager mismatch" ); require( wozxToken.balanceOf(address(this)) >= 13_140_000e18, "Rewards not ready" ); pools[0].addr = poolGlobal; pools[0].totalRewards = 5_256_000; pools[0].rewardPerMinute = 10e18; pools[1].addr = pool1Month; pools[1].totalRewards = 108_000; pools[1].rewardPerMinute = 25e17; pools[2].addr = pool3Months; pools[2].totalRewards = 648_000; pools[2].rewardPerMinute = 5e18; pools[3].addr = pool6Months; pools[3].totalRewards = 1_944_000; pools[3].rewardPerMinute = 75e17; campaignStart = block.timestamp; } /// @notice Deposits WOZX tokens to the given pool. Min deposit is 100 WOZX, max deposit is 200 000 WOZX /// @param poolId Id of the pool /// @param amount Amount to deposit function deposit(uint8 poolId, uint256 amount) external isInitialized { Pool p = Pool(pools[poolId].addr); require(amount >= 100e18, "Minimum deposit = 100 WOZX"); require( p.balanceOf(msg.sender) + amount <= 200_000e18, "Maximum deposit = 200 000 WOZX" ); p.deposit(msg.sender, amount); wozxToken.safeTransferFrom(msg.sender, pools[poolId].addr, amount); emit PoolBalanceChanged(poolId, wozxToken.balanceOf(pools[poolId].addr)); emit UserBalanceChanged(msg.sender, poolId, p.balanceOf(msg.sender)); } /// @notice Withdraws deposited tokens from the given pool + rewards /// @param poolId Id of the pool function withdraw(uint8 poolId) external isInitialized { Pool p = Pool(pools[poolId].addr); require( block.timestamp < p.getStartTime(msg.sender) || block.timestamp > p.getEndTime(msg.sender), "Can't withdraw during the staking" ); claimReward(poolId); p.withdraw(msg.sender); emit PoolBalanceChanged(poolId, wozxToken.balanceOf(pools[poolId].addr)); emit UserBalanceChanged(msg.sender, poolId, p.balanceOf(msg.sender)); } /// @notice Withdraws earned rewards from the pool /// @param poolId Id of the pool function claimReward(uint8 poolId) public isInitialized { Pool p = Pool(pools[poolId].addr); Pool.Deposit[] memory deposits = p.getDeposits(msg.sender); require(deposits.length > 0, "You have no deposits"); uint256 reward = getReward(poolId); pools[poolId].lastRewardsClaim[msg.sender] = Math.min( block.timestamp, p.getEndTime(msg.sender) ); if (reward > 0) { pools[poolId].claimedRewards += reward; wozxToken.safeTransfer(msg.sender, reward); } emit UserBalanceChanged(msg.sender, poolId, p.balanceOf(msg.sender)); } /// @notice Returns how much rewards have been already claimed from the pool /// @param poolId Id of the pool /// @return uint256 function getClaimedRewards(uint8 poolId) external view returns (uint256) { return pools[poolId].claimedRewards; } /// @notice Returns how much time has passed from campaign start (in minutes) /// @return uint256 function getCampaignElapsedMinutes() public view returns (uint256) { return Math.min((block.timestamp - campaignStart), CAMPAIGN_PERIOD) / 60; } /// @notice Returns campaign end /// @return Timestamp (uint256) function getCampaignEnd() public view returns (uint256) { return campaignStart + CAMPAIGN_PERIOD; } /// @notice Returns available rewards in the pool /// @param poolId Id of the pool /// @return uint256 function getAvailableRewards(uint8 poolId) public view returns (uint256) { return (getCampaignElapsedMinutes() * pools[poolId].rewardPerMinute) - pools[poolId].claimedRewards; } /// @notice Returns reward calculated by formula for the given pool and the message sender based on the deposits time /// @param poolId Id of the pool /// @return uint256 function getReward(uint8 poolId) public view returns (uint256) { Pool p = Pool(pools[poolId].addr); Pool.Deposit[] memory deposits = p.getDeposits(msg.sender); if (deposits.length == 0 || block.timestamp <= deposits[0].depositTime) { return 0; } uint256 stakingEnd = Math.min( p.getEndTime(msg.sender), block.timestamp ); uint256 totalDeposits = wozxToken.balanceOf(pools[poolId].addr); uint256 availableRewardPerMinute = getAvailableRewards(poolId) / ((p.id() == 0 ? CAMPAIGN_PERIOD : p.getTimePeriod()) / 60); uint256 reward; for (uint256 i = 0; i < deposits.length; i++) { uint256 depositElapsedMinutes = (stakingEnd - Math.max( deposits[i].depositTime, pools[poolId].lastRewardsClaim[msg.sender] )) / 60; reward += (availableRewardPerMinute * depositElapsedMinutes * deposits[i].amount) / totalDeposits; } return reward; } /// @notice Witdraws remaining rewards, afer 1 year reward claiming period after the campaign end /// @param account Address of recipient function withdrawRemainingRewards(address account) external isInitialized onlyOwner { require( getCampaignEnd() + 365 days < block.timestamp, "Remaining rewards can be withdrawn a year after the campaign end" ); wozxToken.safeTransfer(account, wozxToken.balanceOf(address(this))); } }
File 2 of 2: MainToken
/* * EFFORCE IEO CONTRACT * Submitted for verification at Etherscan.io on 13 december 2019 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ pragma solidity ^0.4.23; /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/179 */ contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { // Gas optimization: this is cheaper than asserting 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ 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 a / b; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; uint256 totalSupply_; /** * @dev total number of tokens in existence */ function totalSupply() public view returns (uint256) { return totalSupply_; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } } /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval( address indexed owner, address indexed spender, uint256 value ); } /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * 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 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance( address _owner, address _spender ) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval( address _spender, uint _addedValue ) public returns (bool) { allowed[msg.sender][_spender] = ( allowed[msg.sender][_spender].add(_addedValue)); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval( address _spender, uint _subtractedValue ) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipRenounced(address indexed previousOwner); event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to relinquish control of the contract. */ function renounceOwnership() public onlyOwner { emit OwnershipRenounced(owner); owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param _newOwner The address to transfer ownership to. */ function transferOwnership(address _newOwner) public onlyOwner { _transferOwnership(_newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param _newOwner The address to transfer ownership to. */ function _transferOwnership(address _newOwner) internal { require(_newOwner != address(0)); emit OwnershipTransferred(owner, _newOwner); owner = _newOwner; } } /** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation * @dev Issue: * https://github.com/OpenZeppelin/openzeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */ contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } modifier hasMintPermission() { require(msg.sender == owner); _; } /** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint( address _to, uint256 _amount ) hasMintPermission canMint public returns (bool) { totalSupply_ = totalSupply_.add(_amount); balances[_to] = balances[_to].add(_amount); emit Mint(_to, _amount); emit Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; emit MintFinished(); return true; } } contract FreezableToken is StandardToken { // freezing chains mapping (bytes32 => uint64) internal chains; // freezing amounts for each chain mapping (bytes32 => uint) internal freezings; // total freezing balance per address mapping (address => uint) internal freezingBalance; event Freezed(address indexed to, uint64 release, uint amount); event Released(address indexed owner, uint amount); /** * @dev Gets the balance of the specified address include freezing tokens. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return super.balanceOf(_owner) + freezingBalance[_owner]; } /** * @dev Gets the balance of the specified address without freezing tokens. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function actualBalanceOf(address _owner) public view returns (uint256 balance) { return super.balanceOf(_owner); } function freezingBalanceOf(address _owner) public view returns (uint256 balance) { return freezingBalance[_owner]; } /** * @dev gets freezing count * @param _addr Address of freeze tokens owner. */ function freezingCount(address _addr) public view returns (uint count) { uint64 release = chains[toKey(_addr, 0)]; while (release != 0) { count++; release = chains[toKey(_addr, release)]; } } /** * @dev gets freezing end date and freezing balance for the freezing portion specified by index. * @param _addr Address of freeze tokens owner. * @param _index Freezing portion index. It ordered by release date descending. */ function getFreezing(address _addr, uint _index) public view returns (uint64 _release, uint _balance) { for (uint i = 0; i < _index + 1; i++) { _release = chains[toKey(_addr, _release)]; if (_release == 0) { return; } } _balance = freezings[toKey(_addr, _release)]; } /** * @dev freeze your tokens to the specified address. * Be careful, gas usage is not deterministic, * and depends on how many freezes _to address already has. * @param _to Address to which token will be freeze. * @param _amount Amount of token to freeze. * @param _until Release date, must be in future. */ function freezeTo(address _to, uint _amount, uint64 _until) public { require(_to != address(0)); require(_amount <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_amount); bytes32 currentKey = toKey(_to, _until); freezings[currentKey] = freezings[currentKey].add(_amount); freezingBalance[_to] = freezingBalance[_to].add(_amount); freeze(_to, _until); emit Transfer(msg.sender, _to, _amount); emit Freezed(_to, _until, _amount); } /** * @dev release first available freezing tokens. */ function releaseOnce() public { bytes32 headKey = toKey(msg.sender, 0); uint64 head = chains[headKey]; require(head != 0); require(uint64(block.timestamp) > head); bytes32 currentKey = toKey(msg.sender, head); uint64 next = chains[currentKey]; uint amount = freezings[currentKey]; delete freezings[currentKey]; balances[msg.sender] = balances[msg.sender].add(amount); freezingBalance[msg.sender] = freezingBalance[msg.sender].sub(amount); if (next == 0) { delete chains[headKey]; } else { chains[headKey] = next; delete chains[currentKey]; } emit Released(msg.sender, amount); } /** * @dev release all available for release freezing tokens. Gas usage is not deterministic! * @return how many tokens was released */ function releaseAll() public returns (uint tokens) { uint release; uint balance; (release, balance) = getFreezing(msg.sender, 0); while (release != 0 && block.timestamp > release) { releaseOnce(); tokens += balance; (release, balance) = getFreezing(msg.sender, 0); } } function toKey(address _addr, uint _release) internal pure returns (bytes32 result) { // WISH masc to increase entropy result = 0x5749534800000000000000000000000000000000000000000000000000000000; assembly { result := or(result, mul(_addr, 0x10000000000000000)) result := or(result, _release) } } function freeze(address _to, uint64 _until) internal { require(_until > block.timestamp); bytes32 key = toKey(_to, _until); bytes32 parentKey = toKey(_to, uint64(0)); uint64 next = chains[parentKey]; if (next == 0) { chains[parentKey] = _until; return; } bytes32 nextKey = toKey(_to, next); uint parent; while (next != 0 && _until > next) { parent = next; parentKey = nextKey; next = chains[nextKey]; nextKey = toKey(_to, next); } if (_until == next) { return; } if (next != 0) { chains[key] = next; } chains[parentKey] = _until; } } /** * @title Burnable Token * @dev Token that can be irreversibly burned (destroyed). */ contract BurnableToken is BasicToken { event Burn(address indexed burner, uint256 value); /** * @dev Burns a specific amount of tokens. * @param _value The amount of token to be burned. */ function burn(uint256 _value) public { _burn(msg.sender, _value); } function _burn(address _who, uint256 _value) internal { require(_value <= balances[_who]); // no need to require value <= totalSupply, since that would imply the // sender's balance is greater than the totalSupply, which *should* be an assertion failure balances[_who] = balances[_who].sub(_value); totalSupply_ = totalSupply_.sub(_value); emit Burn(_who, _value); emit Transfer(_who, address(0), _value); } } /** * @title Pausable * @dev Base contract which allows children to implement an emergency stop mechanism. */ contract Pausable is Ownable { event Pause(); event Unpause(); bool public paused = false; /** * @dev Modifier to make a function callable only when the contract is not paused. */ modifier whenNotPaused() { require(!paused); _; } /** * @dev Modifier to make a function callable only when the contract is paused. */ modifier whenPaused() { require(paused); _; } /** * @dev called by the owner to pause, triggers stopped state */ function pause() onlyOwner whenNotPaused public { paused = true; emit Pause(); } /** * @dev called by the owner to unpause, returns to normal state */ function unpause() onlyOwner whenPaused public { paused = false; emit Unpause(); } } contract FreezableMintableToken is FreezableToken, MintableToken { /** * @dev Mint the specified amount of token to the specified address and freeze it until the specified date. * Be careful, gas usage is not deterministic, * and depends on how many freezes _to address already has. * @param _to Address to which token will be freeze. * @param _amount Amount of token to mint and freeze. * @param _until Release date, must be in future. * @return A boolean that indicates if the operation was successful. */ function mintAndFreeze(address _to, uint _amount, uint64 _until) public onlyOwner canMint returns (bool) { totalSupply_ = totalSupply_.add(_amount); bytes32 currentKey = toKey(_to, _until); freezings[currentKey] = freezings[currentKey].add(_amount); freezingBalance[_to] = freezingBalance[_to].add(_amount); freeze(_to, _until); emit Mint(_to, _amount); emit Freezed(_to, _until, _amount); emit Transfer(msg.sender, _to, _amount); return true; } } contract Consts { uint public constant TOKEN_DECIMALS = 18; uint8 public constant TOKEN_DECIMALS_UINT8 = 18; uint public constant TOKEN_DECIMAL_MULTIPLIER = 10 ** TOKEN_DECIMALS; string public constant TOKEN_NAME = "EFFORCE IEO"; string public constant TOKEN_SYMBOL = "WOZX"; bool public constant PAUSED = false; address public constant TARGET_USER = 0x9d9e8607f0EB69C37Cb14B7110cd458bfB14d0eE; bool public constant CONTINUE_MINTING = true; } contract MainToken is Consts, FreezableMintableToken, BurnableToken, Pausable { event Initialized(); bool public initialized = false; constructor() public { init(); transferOwnership(TARGET_USER); } function name() public pure returns (string _name) { return TOKEN_NAME; } function symbol() public pure returns (string _symbol) { return TOKEN_SYMBOL; } function decimals() public pure returns (uint8 _decimals) { return TOKEN_DECIMALS_UINT8; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool _success) { require(!paused); return super.transferFrom(_from, _to, _value); } function transfer(address _to, uint256 _value) public returns (bool _success) { require(!paused); return super.transfer(_to, _value); } function init() private { require(!initialized); initialized = true; if (PAUSED) { pause(); } address[1] memory addresses = [address(0x9d9e8607f0EB69C37Cb14B7110cd458bfB14d0eE)]; uint[1] memory amounts = [uint(350000000000000000000000000)]; uint64[1] memory freezes = [uint64(0)]; for (uint i = 0; i < addresses.length; i++) { if (freezes[i] == 0) { mint(addresses[i], amounts[i]); } else { mintAndFreeze(addresses[i], amounts[i], freezes[i]); } } if (!CONTINUE_MINTING) { finishMinting(); } emit Initialized(); } }