Verified contractExactGPL-3.0
TokenLockerV3
Address0x6264624a4e8bc097c36747a246ee3e57a9514c23
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.17
- Same code
Only this contract
Details
- Compiler
- solc 0.8.17+commit.8df45f5f
- Language
- solidity
- Optimization
- No
- License
- GPL-3.0
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,378,298
- Creation transaction
- 0x939a085928…fc8cbc5998
contracts/TokenLockerV3.sol
// SPDX-License-Identifier: GPL-3.0
/**
####################################
This token or smart contract has been created using Bitbond Token Tool: https://tokentool.bitbond.com/
Token Tool enables users to easily configure and deploy smart contracts without coding such as fungible / non-fungible tokens, crowdsale contracts, token lockers, and multisenders.
Bitbond is not associated with the token creator or the respective company / project.
Join the Bitbond Token Tool Crypto Affiliate Program to get discounts and earn rewards: https://tokentool.bitbond.com/crypto-affiliate-program
####################################
*/
pragma solidity 0.8.17;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { LibCommon } from "./lib/LibCommon.sol";
contract TokenLockerV3 is Ownable {
/// @notice token on which the contract will perform locking
address public immutable token;
/// @notice time after which tokens are locked
uint40 public lockTime;
/// @notice time after which tokens are unlocked
uint40 public unlockTime;
/// @notice amount of locked tokens
uint256 public lockedTokenAmount;
address private constant FEE_RECEIVER =
0x9254C0fcB2FaA4550B9ba582558cE1D03Ba3d05d;
string public constant VERSION = "token_locker_v3";
string public constant CONTRACT_NAME = "TokenLockerV3";
bytes32 public constant CONTRACT_HASH = 0x3a5f4810fc49863de3442c664206ac954d871aa59682c0529164aa6813458155;
/// @notice emitted when contract is created
event TokenLockerCreated(address indexed owner, address indexed token);
/// @notice emitted when tokens are locked
event TokensLocked(
uint256 tokenAmount,
address indexed token,
uint40 unlockTimeToSet
);
/// @notice emitted when tokens are relocked
event TokensReLocked(address indexed token, uint40 newUnlockTimeToSet);
/// @notice emitted when excess tokens are withdrawn
event TokensWithdrawn(address indexed to);
/// @notice emitted when unsupported tokens are recovered
event TokensRecovered(address indexed token);
/// @notice raised attempting to lock already locked tokens
error TokensAlreadyLocked();
/// @notice raised when attempting to set an unlock time in the past
error UnlockTimeMustBeInFuture(uint40 unlockTime);
/// @notice raised when no tokens are sent for locking
error NoTokensToLock(uint256 amount);
/// @notice raised when attempting to relock tokens when there are no locked tokens
error NoTokensToRelock(uint256 amount);
/// @notice raised when attempting to set an unlock time earlier than current
error UnlockTimeLtPrevious();
/// @notice raised when attempting to withdraw tokens before unlock time
error CannotUnlockBeforeUnlockTime();
/// @notice raised when there are no excess tokens to be withdrawn
error NoExcessTokens(address token);
/// @notice raised when we try to recover supported token instead of unsupported one
error RecoverSupportedToken();
constructor(address tokenAddress, address owner_) {
LibCommon.validateAddress(tokenAddress);
token = tokenAddress;
// owner zero-validation is done inside this method
transferOwnership(owner_);
emit TokenLockerCreated(owner_, tokenAddress);
}
/**
* @notice method for retrieving the token address
* @return address of the token
*/
function getTokenAddress() external view returns (address) {
return address(token);
}
/**
* @notice method for locking tokens
* @param tokenAmount - amount of tokens to lock
* @param unlockTimeToSet - time after which tokens will be unlocked
* @dev only callable by owner
*/
function lock(
uint256 tokenAmount,
uint40 unlockTimeToSet
) external payable onlyOwner {
if (getLockedTokensAmount() != 0) {
revert TokensAlreadyLocked();
}
if (unlockTimeToSet <= block.timestamp) {
revert UnlockTimeMustBeInFuture(unlockTimeToSet);
}
if (tokenAmount == 0) {
revert NoTokensToLock(tokenAmount);
}
LibCommon.safeTransferETH(FEE_RECEIVER, msg.value);
lockTime = uint40(block.timestamp);
unlockTime = unlockTimeToSet;
LibCommon.safeTransferFrom(token, msg.sender, address(this), tokenAmount);
// We need to get the actual amount received on the contract in case fees or taxes are applied
lockedTokenAmount = getLockedTokensAmount();
emit TokensLocked(tokenAmount, address(token), unlockTimeToSet);
}
/**
* @notice Method allowing to relock currently locked tokens.
* Possible to relock only when tokens were deposited and new unlock
* timestamp is after current one.
* @param newUnlockTime new unlock time to be set
* @dev only callable by owner
*/
function relock(uint40 newUnlockTime) external onlyOwner {
uint256 balance = getLockedTokensAmount();
if (balance == 0) {
revert NoTokensToRelock(balance);
}
if (newUnlockTime <= unlockTime) {
revert UnlockTimeLtPrevious();
}
unlockTime = newUnlockTime;
emit TokensReLocked(address(token), newUnlockTime);
}
/**
* @notice Method allowing to withdraw locked tokens.
* Possible to unlock only after unlock time.
* @param to receiver of tokens
* @param amount amount of tokens
* @dev only callable by owner
*/
function withdraw(address to, uint256 amount) external onlyOwner {
if (block.timestamp < unlockTime) {
revert CannotUnlockBeforeUnlockTime();
}
LibCommon.safeTransfer(token, to, amount);
emit TokensWithdrawn(to);
}
/**
* @notice Method allowing to withdraw tokens exceeding the original locked tokens amount.
* @param to receiver of tokens
* @dev only callable by owner
*/
function withdrawExcessTokens(address to) external onlyOwner {
uint256 currentLockedTokens = getLockedTokensAmount();
if (currentLockedTokens <= lockedTokenAmount) {
revert NoExcessTokens(token);
}
uint256 excessTokens = currentLockedTokens - lockedTokenAmount;
LibCommon.safeTransfer(token, to, excessTokens);
emit TokensWithdrawn(to);
}
/**
* @notice Function for the owner to recover unsupported tokens
* @param tokenAddress Address of the unsupported token
*/
function recoverUnsupportedTokens(address tokenAddress) external onlyOwner {
if (tokenAddress == token) {
revert RecoverSupportedToken();
}
IERC20 unsupportedToken = IERC20(tokenAddress);
uint256 amount = unsupportedToken.balanceOf(address(this));
if (amount == 0) {
revert NoExcessTokens(tokenAddress);
}
LibCommon.safeTransfer(address(unsupportedToken), owner(), amount);
emit TokensRecovered(tokenAddress);
}
/**
* @notice Locked tokens amount
* @return amount of locked tokens
*/
function getLockedTokensAmount() public view returns (uint256) {
return IERC20(token).balanceOf(address(this));
}
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (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 Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling 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);
}
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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);
/**
* @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);
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
contracts/lib/LibCommon.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
library LibCommon {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ETH transfer has failed.
error ETHTransferFailed();
/// @dev The address is the zero address.
error ZeroAddress();
/// @notice raised when an ERC20 transfer fails
error TransferFailed();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ETH OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @notice Taken from Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Sends `amount` (in wei) ETH to `to`.
/// Reverts upon failure.
function safeTransferETH(address to, uint256 amount) internal {
// solhint-disable-next-line no-inline-assembly
assembly {
// Transfer the ETH and check if it succeeded or not.
if iszero(call(gas(), to, amount, 0, 0, 0, 0)) {
// Store the function selector of `ETHTransferFailed()`.
// bytes4(keccak256(bytes("ETHTransferFailed()"))) = 0xb12d13eb
mstore(0x00, 0xb12d13eb)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
}
}
/// @notice Validates that the address is not the zero address using assembly.
/// @dev Reverts if the address is the zero address.
function validateAddress(address addr) internal pure {
// solhint-disable-next-line no-inline-assembly
assembly {
if iszero(shl(96, addr)) {
// Store the function selector of `ZeroAddress()`.
// bytes4(keccak256(bytes("ZeroAddress()"))) = 0xd92e233d
mstore(0x00, 0xd92e233d)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
}
}
/// @notice Helper function to transfer ERC20 tokens without the need for SafeERC20.
/// @dev Reverts if the ERC20 transfer fails.
/// @param tokenAddress The address of the ERC20 token.
/// @param from The address to transfer the tokens from.
/// @param to The address to transfer the tokens to.
/// @param amount The amount of tokens to transfer.
function safeTransferFrom(
address tokenAddress,
address from,
address to,
uint256 amount
) internal returns (bool) {
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory data) = tokenAddress.call(
abi.encodeWithSignature(
"transferFrom(address,address,uint256)",
from,
to,
amount
)
);
if (!success) {
if (data.length != 0) {
// bubble up error
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(data)
revert(add(32, data), returndata_size)
}
} else {
revert TransferFailed();
}
}
return true;
}
/// @notice Helper function to transfer ERC20 tokens without the need for SafeERC20.
/// @dev Reverts if the ERC20 transfer fails.
/// @param tokenAddress The address of the ERC20 token.
/// @param to The address to transfer the tokens to.
/// @param amount The amount of tokens to transfer.
function safeTransfer(
address tokenAddress,
address to,
uint256 amount
) internal returns (bool) {
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory data) = tokenAddress.call(
abi.encodeWithSignature("transfer(address,uint256)", to, amount)
);
if (!success) {
if (data.length != 0) {
// bubble up error
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(data)
revert(add(32, data), returndata_size)
}
} else {
revert TransferFailed();
}
}
return true;
}
}
Compiler settingsShow
{
"viaIR": false,
"optimizer": {
"runs": 200,
"enabled": false
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.