Contract Source Code:
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;
/**
* @title ERC1132 interface
* @dev see https://github.com/ethereum/EIPs/issues/1132
*/
abstract contract ERC1132 {
/**
* @dev Reasons why a user's tokens have been locked
*/
mapping(address => bytes32[]) public lockReason;
/**
* @dev locked token structure
*/
struct lockToken {
uint256 amount;
uint256 validity;
bool claimed;
}
/**
* @dev Holds number & validity of tokens locked for a given reason for
* a specified address
*/
mapping(address => mapping(bytes32 => lockToken)) public locked;
/**
* @dev Records data of all the tokens Locked
*/
event Locked(
address indexed _of,
bytes32 indexed _reason,
uint256 _amount,
uint256 _validity
);
/**
* @dev Records data of all the tokens unlocked
*/
event Unlocked(
address indexed _of,
bytes32 indexed _reason,
uint256 _amount
);
/**
* @dev Locks a specified amount of tokens against an address,
* for a specified reason and time
* @param _reason The reason to lock tokens
* @param _amount Number of tokens to be locked
* @param _time Lock time in seconds
*/
function lock(bytes32 _reason, uint256 _amount, uint256 _time) virtual
public returns (bool);
/**
* @dev Returns tokens locked for a specified address for a
* specified reason
*
* @param _of The address whose tokens are locked
* @param _reason The reason to query the lock tokens for
*/
function tokensLocked(address _of, bytes32 _reason) virtual
public view returns (uint256 amount);
/**
* @dev Returns tokens locked for a specified address for a
* specified reason at a specific time
*
* @param _of The address whose tokens are locked
* @param _reason The reason to query the lock tokens for
* @param _time The timestamp to query the lock tokens for
*/
function tokensLockedAtTime(address _of, bytes32 _reason, uint256 _time) virtual
public view returns (uint256 amount);
/**
* @dev Returns total tokens held by an address (locked + transferable)
* @param _of The address to query the total balance of
*/
function totalBalanceOf(address _of) virtual
public view returns (uint256 amount);
/**
* @dev Extends lock for a specified reason and time
* @param _reason The reason to lock tokens
* @param _time Lock extension time in seconds
*/
function extendLock(bytes32 _reason, uint256 _time) virtual
public returns (bool);
/**
* @dev Increase number of tokens locked for a specified reason
* @param _reason The reason to lock tokens
* @param _amount Number of tokens to be increased
*/
function increaseLockAmount(bytes32 _reason, uint256 _amount) virtual
public returns (bool);
/**
* @dev Returns unlockable tokens for a specified address for a specified reason
* @param _of The address to query the the unlockable token count of
* @param _reason The reason to query the unlockable tokens for
*/
function tokensUnlockable(address _of, bytes32 _reason) virtual
public view returns (uint256 amount);
/**
* @dev Unlocks the unlockable tokens of a specified address
* @param _of Address of user, claiming back unlockable tokens
*/
function unlock(address _of) virtual
public returns (uint256 unlockableTokens);
/**
* @dev Gets the unlockable tokens of a specified address
* @param _of The address to query the the unlockable token count of
*/
function getUnlockableTokens(address _of) virtual
public view returns (uint256 unlockableTokens);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;
import "../contracts/LockableToken.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract FLyToken is LockableToken, Ownable {
/**
* @dev Indicates that the contract has been initialized with locked tokens for round 1.
*/
bool private _initializedRound1;
/**
* @dev Indicates that the contract is in the process of being initialized for round 1.
*/
bool private _initializingRound1;
/**
* @dev Indicates that the contract has been initialized with locked tokens for round 2.
*/
bool private _initializedRound2;
/**
* @dev Indicates that the contract is in the process of being initialized for round 2.
*/
bool private _initializingRound2;
constructor() public LockableToken(17011706000000, "Franklin", "FLy", 4) {
}
function initializeRound1() public initializerR1 onlyOwner {
_initRound1();
}
function initializeRound2() public initializerR2 onlyOwner {
_initRound2();
}
function _initRound1() internal {
uint256 vestingRound1Seconds = 1617235200 - now;
uint256 vrAmount = 63964014560;
uint256 days30 = 2592000;
//round 1
_lock('v1_1', vrAmount, vestingRound1Seconds);
_lock('v1_2', vrAmount, vestingRound1Seconds.add(days30));
_lock('v1_3', vrAmount, vestingRound1Seconds.add(days30.mul(2)));
_lock('v1_4', vrAmount, vestingRound1Seconds.add(days30.mul(3)));
_lock('v1_5', vrAmount, vestingRound1Seconds.add(days30.mul(4)));
_lock('v1_6', vrAmount, vestingRound1Seconds.add(days30.mul(5)));
_lock('v1_7', vrAmount, vestingRound1Seconds.add(days30.mul(6)));
_lock('v1_8', vrAmount, vestingRound1Seconds.add(days30.mul(7)));
_lock('v1_9', vrAmount, vestingRound1Seconds.add(days30.mul(8)));
_lock('v1_10', vrAmount, vestingRound1Seconds.add(days30.mul(9)));
_lock('v1_11', vrAmount, vestingRound1Seconds.add(days30.mul(10)));
_lock('v1_12', vrAmount, vestingRound1Seconds.add(days30.mul(11)));
_lock('v1_13', vrAmount, vestingRound1Seconds.add(days30.mul(12)));
_lock('v1_14', vrAmount, vestingRound1Seconds.add(days30.mul(13)));
_lock('v1_15', vrAmount, vestingRound1Seconds.add(days30.mul(14)));
_lock('v1_16', vrAmount, vestingRound1Seconds.add(days30.mul(15)));
_lock('v1_17', vrAmount, vestingRound1Seconds.add(days30.mul(16)));
_lock('v1_18', vrAmount, vestingRound1Seconds.add(days30.mul(17)));
_lock('v1_19', vrAmount, vestingRound1Seconds.add(days30.mul(18)));
_lock('v1_20', vrAmount, vestingRound1Seconds.add(days30.mul(19)));
_lock('v1_21', vrAmount, vestingRound1Seconds.add(days30.mul(20)));
_lock('v1_22', vrAmount, vestingRound1Seconds.add(days30.mul(21)));
_lock('v1_23', vrAmount, vestingRound1Seconds.add(days30.mul(22)));
_lock('v1_24', vrAmount, vestingRound1Seconds.add(days30.mul(23)));
_lock('v1_25', vrAmount, vestingRound1Seconds.add(days30.mul(24)));
_lock('v1_26', vrAmount, vestingRound1Seconds.add(days30.mul(25)));
_lock('v1_27', vrAmount, vestingRound1Seconds.add(days30.mul(26)));
_lock('v1_28', vrAmount, vestingRound1Seconds.add(days30.mul(27)));
_lock('v1_29', vrAmount, vestingRound1Seconds.add(days30.mul(28)));
_lock('v1_30', vrAmount, vestingRound1Seconds.add(days30.mul(29)));
_lock('v1_31', vrAmount, vestingRound1Seconds.add(days30.mul(30)));
_lock('v1_32', vrAmount, vestingRound1Seconds.add(days30.mul(31)));
_lock('v1_33', vrAmount, vestingRound1Seconds.add(days30.mul(32)));
_lock('v1_34', vrAmount, vestingRound1Seconds.add(days30.mul(33)));
_lock('v1_35', vrAmount, vestingRound1Seconds.add(days30.mul(34)));
_lock('v1_36', vrAmount, vestingRound1Seconds.add(days30.mul(35)));
_lock('v1_37', vrAmount, vestingRound1Seconds.add(days30.mul(36)));
_lock('v1_38', vrAmount, vestingRound1Seconds.add(days30.mul(37)));
_lock('v1_39', vrAmount, vestingRound1Seconds.add(days30.mul(38)));
_lock('v1_40', vrAmount, vestingRound1Seconds.add(days30.mul(39)));
_lock('v1_41', vrAmount, vestingRound1Seconds.add(days30.mul(40)));
_lock('v1_42', vrAmount, vestingRound1Seconds.add(days30.mul(41)));
_lock('v1_43', vrAmount, vestingRound1Seconds.add(days30.mul(42)));
_lock('v1_44', vrAmount, vestingRound1Seconds.add(days30.mul(43)));
_lock('v1_45', vrAmount, vestingRound1Seconds.add(days30.mul(44)));
_lock('v1_46', vrAmount, vestingRound1Seconds.add(days30.mul(45)));
_lock('v1_47', vrAmount, vestingRound1Seconds.add(days30.mul(46)));
_lock('v1_48', vrAmount, vestingRound1Seconds.add(days30.mul(47)));
_lock('v1_49', vrAmount, vestingRound1Seconds.add(days30.mul(48)));
_lock('v1_50', vrAmount, vestingRound1Seconds.add(days30.mul(49)));
//round 1: transfer locked total
transfer(address(this), 3198200728000);
}
function _initRound2() internal {
uint256 vestingRound2Seconds = 1625097600 - now;
uint256 days30 = 2592000;
// round 2 - starting from 01.07.2021 - autogenerated from excel output
_lock('v2_1', 29770485500, vestingRound2Seconds);
_lock('v2_2', 30365895210, vestingRound2Seconds.add(days30));
_lock('v2_3', 30978316626, vestingRound2Seconds.add(days30.mul(2)));
_lock('v2_4', 31590738042, vestingRound2Seconds.add(days30.mul(3)));
_lock('v2_5', 32220171164, vestingRound2Seconds.add(days30.mul(4)));
_lock('v2_6', 32866615992, vestingRound2Seconds.add(days30.mul(5)));
_lock('v2_7', 33530072526, vestingRound2Seconds.add(days30.mul(6)));
_lock('v2_8', 34193529060, vestingRound2Seconds.add(days30.mul(7)));
_lock('v2_9', 34873997300, vestingRound2Seconds.add(days30.mul(8)));
_lock('v2_10', 35571477246, vestingRound2Seconds.add(days30.mul(9)));
_lock('v2_11', 36285968898, vestingRound2Seconds.add(days30.mul(10)));
_lock('v2_12', 37017472256, vestingRound2Seconds.add(days30.mul(11)));
_lock('v2_13', 37748975614, vestingRound2Seconds.add(days30.mul(12)));
_lock('v2_14', 38514502384, vestingRound2Seconds.add(days30.mul(13)));
_lock('v2_15', 39280029154, vestingRound2Seconds.add(days30.mul(14)));
_lock('v2_16', 40062567630, vestingRound2Seconds.add(days30.mul(15)));
_lock('v2_17', 40862117812, vestingRound2Seconds.add(days30.mul(16)));
_lock('v2_18', 41678679700, vestingRound2Seconds.add(days30.mul(17)));
_lock('v2_19', 42512253294, vestingRound2Seconds.add(days30.mul(18)));
_lock('v2_20', 43362838594, vestingRound2Seconds.add(days30.mul(19)));
_lock('v2_21', 44230435600, vestingRound2Seconds.add(days30.mul(20)));
_lock('v2_22', 45115044312, vestingRound2Seconds.add(days30.mul(21)));
_lock('v2_23', 46016664730, vestingRound2Seconds.add(days30.mul(22)));
_lock('v2_24', 46952308560, vestingRound2Seconds.add(days30.mul(23)));
_lock('v2_25', 47887952390, vestingRound2Seconds.add(days30.mul(24)));
_lock('v2_26', 48840607926, vestingRound2Seconds.add(days30.mul(25)));
_lock('v2_27', 49810275168, vestingRound2Seconds.add(days30.mul(26)));
_lock('v2_28', 50813965822, vestingRound2Seconds.add(days30.mul(27)));
_lock('v2_29', 51834668182, vestingRound2Seconds.add(days30.mul(28)));
_lock('v2_30', 52872382248, vestingRound2Seconds.add(days30.mul(29)));
_lock('v2_31', 53927108020, vestingRound2Seconds.add(days30.mul(30)));
_lock('v2_32', 54998845498, vestingRound2Seconds.add(days30.mul(31)));
_lock('v2_33', 56104606388, vestingRound2Seconds.add(days30.mul(32)));
_lock('v2_34', 57227378984, vestingRound2Seconds.add(days30.mul(33)));
_lock('v2_35', 58367163286, vestingRound2Seconds.add(days30.mul(34)));
_lock('v2_36', 59540971000, vestingRound2Seconds.add(days30.mul(35)));
_lock('v2_37', 60731790420, vestingRound2Seconds.add(days30.mul(36)));
_lock('v2_38', 61939621546, vestingRound2Seconds.add(days30.mul(37)));
_lock('v2_39', 63181476084, vestingRound2Seconds.add(days30.mul(38)));
_lock('v2_40', 64440342328, vestingRound2Seconds.add(days30.mul(39)));
_lock('v2_41', 65733231984, vestingRound2Seconds.add(days30.mul(40)));
_lock('v2_42', 67043133346, vestingRound2Seconds.add(days30.mul(41)));
_lock('v2_43', 68387058120, vestingRound2Seconds.add(days30.mul(42)));
_lock('v2_44', 69765006306, vestingRound2Seconds.add(days30.mul(43)));
_lock('v2_45', 71159966198, vestingRound2Seconds.add(days30.mul(44)));
_lock('v2_46', 72571937796, vestingRound2Seconds.add(days30.mul(45)));
_lock('v2_47', 74034944512, vestingRound2Seconds.add(days30.mul(46)));
_lock('v2_48', 94823249244, vestingRound2Seconds.add(days30.mul(47)));
//round 2: transfer locked total
transfer(address(this), 2381638840000);
}
function _lock(
bytes32 _reason,
uint256 _amount,
uint256 _time
) internal returns (bool) {
uint256 validUntil = now.add(_time); //solhint-disable-line
if (locked[_msgSender()][_reason].amount == 0)
lockReason[_msgSender()].push(_reason);
locked[_msgSender()][_reason] = lockToken(_amount, validUntil, false);
return true;
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
unlock(from);
}
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializerR1() {
require(_initializingRound1 || !_initializedRound1, "InitializerR1: contract is already initialized");
bool isTopLevelCall = !_initializingRound1;
if (isTopLevelCall) {
_initializingRound1 = true;
_initializedRound1 = true;
}
_;
if (isTopLevelCall) {
_initializingRound1 = false;
}
}
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializerR2() {
require(_initializingRound2 || !_initializedRound2, "InitializerR2: contract is already initialized");
bool isTopLevelCall = !_initializingRound2;
if (isTopLevelCall) {
_initializingRound2 = true;
_initializedRound2 = true;
}
_;
if (isTopLevelCall) {
_initializingRound2 = false;
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;
import "../contracts/ERC1132.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
contract LockableToken is ERC1132, ERC20Burnable {
/**
* @dev Error messages for require statements
*/
string internal constant ALREADY_LOCKED = "Tokens already locked";
string internal constant NOT_LOCKED = "No tokens locked";
string internal constant AMOUNT_ZERO = "Amount can not be 0";
/**
* @dev constructor to mint initial tokens
* Shall update to _mint once openzepplin updates their npm package.
*/
constructor(
uint256 _supply,
string memory _name,
string memory _symbol,
uint8 _decimals
) public ERC20(_name, _symbol) {
_setupDecimals(_decimals);
_mint(_msgSender(), _supply);
}
/**
* @dev Locks a specified amount of tokens against an address,
* for a specified reason and time
* @param _reason The reason to lock tokens
* @param _amount Number of tokens to be locked
* @param _time Lock time in seconds
*/
function lock(
bytes32 _reason,
uint256 _amount,
uint256 _time
) public override returns (bool) {
uint256 validUntil = now.add(_time); //solhint-disable-line
// If tokens are already locked, then functions extendLock or
// increaseLockAmount should be used to make any changes
require(tokensLocked(_msgSender(), _reason) == 0, ALREADY_LOCKED);
require(_amount != 0, AMOUNT_ZERO);
if (locked[_msgSender()][_reason].amount == 0)
lockReason[_msgSender()].push(_reason);
transfer(address(this), _amount);
locked[_msgSender()][_reason] = lockToken(_amount, validUntil, false);
emit Locked(_msgSender(), _reason, _amount, validUntil);
return true;
}
/**
* @dev Transfers and Locks a specified amount of tokens,
* for a specified reason and time
* @param _to adress to which tokens are to be transfered
* @param _reason The reason to lock tokens
* @param _amount Number of tokens to be transfered and locked
* @param _time Lock time in seconds
*/
function transferWithLock(
address _to,
bytes32 _reason,
uint256 _amount,
uint256 _time
) public returns (bool) {
uint256 validUntil = now.add(_time); //solhint-disable-line
require(tokensLocked(_to, _reason) == 0, ALREADY_LOCKED);
require(_amount != 0, AMOUNT_ZERO);
if (locked[_to][_reason].amount == 0) lockReason[_to].push(_reason);
transfer(address(this), _amount);
locked[_to][_reason] = lockToken(_amount, validUntil, false);
emit Locked(_to, _reason, _amount, validUntil);
return true;
}
/**
* @dev Returns tokens locked for a specified address for a
* specified reason
*
* @param _of The address whose tokens are locked
* @param _reason The reason to query the lock tokens for
*/
function tokensLocked(address _of, bytes32 _reason)
public
view
override
returns (uint256 amount)
{
if (!locked[_of][_reason].claimed) amount = locked[_of][_reason].amount;
}
/**
* @dev Returns tokens locked for a specified address for a
* specified reason at a specific time
*
* @param _of The address whose tokens are locked
* @param _reason The reason to query the lock tokens for
* @param _time The timestamp to query the lock tokens for
*/
function tokensLockedAtTime(
address _of,
bytes32 _reason,
uint256 _time
) public view override returns (uint256 amount) {
if (locked[_of][_reason].validity > _time)
amount = locked[_of][_reason].amount;
}
/**
* @dev Returns total tokens held by an address (locked + transferable)
* @param _of The address to query the total balance of
*/
function totalBalanceOf(address _of)
public
view
override
returns (uint256 amount)
{
amount = balanceOf(_of);
for (uint256 i = 0; i < lockReason[_of].length; i++) {
amount = amount.add(tokensLocked(_of, lockReason[_of][i]));
}
}
/**
* @dev Extends lock for a specified reason and time
* @param _reason The reason to lock tokens
* @param _time Lock extension time in seconds
*/
function extendLock(bytes32 _reason, uint256 _time)
public
override
returns (bool)
{
require(tokensLocked(_msgSender(), _reason) > 0, NOT_LOCKED);
locked[_msgSender()][_reason].validity = locked[_msgSender()][_reason]
.validity
.add(_time);
emit Locked(
_msgSender(),
_reason,
locked[_msgSender()][_reason].amount,
locked[_msgSender()][_reason].validity
);
return true;
}
/**
* @dev Increase number of tokens locked for a specified reason
* @param _reason The reason to lock tokens
* @param _amount Number of tokens to be increased
*/
function increaseLockAmount(bytes32 _reason, uint256 _amount)
public
override
returns (bool)
{
require(tokensLocked(_msgSender(), _reason) > 0, NOT_LOCKED);
transfer(address(this), _amount);
locked[_msgSender()][_reason].amount = locked[_msgSender()][_reason]
.amount
.add(_amount);
emit Locked(
_msgSender(),
_reason,
locked[_msgSender()][_reason].amount,
locked[_msgSender()][_reason].validity
);
return true;
}
/**
* @dev Returns unlockable tokens for a specified address for a specified reason
* @param _of The address to query the the unlockable token count of
* @param _reason The reason to query the unlockable tokens for
*/
function tokensUnlockable(address _of, bytes32 _reason)
public
view
override
returns (uint256 amount)
{
if (
locked[_of][_reason].validity <= now &&
!locked[_of][_reason].claimed
)
//solhint-disable-line
amount = locked[_of][_reason].amount;
}
/**
* @dev Unlocks the unlockable tokens of a specified address
* @param _of Address of user, claiming back unlockable tokens
*/
function unlock(address _of)
public
override
returns (uint256 unlockableTokens)
{
uint256 lockedTokens;
for (uint256 i = 0; i < lockReason[_of].length; i++) {
lockedTokens = tokensUnlockable(_of, lockReason[_of][i]);
if (lockedTokens > 0) {
unlockableTokens = unlockableTokens.add(lockedTokens);
locked[_of][lockReason[_of][i]].claimed = true;
emit Unlocked(_of, lockReason[_of][i], lockedTokens);
}
}
if (unlockableTokens > 0) this.transfer(_of, unlockableTokens);
}
/**
* @dev Gets the unlockable tokens of a specified address
* @param _of The address to query the the unlockable token count of
*/
function getUnlockableTokens(address _of)
public
view
override
returns (uint256 unlockableTokens)
{
for (uint256 i = 0; i < lockReason[_of].length; i++) {
unlockableTokens = unlockableTokens.add(
tokensUnlockable(_of, lockReason[_of][i])
);
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "../GSN/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.
*/
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 () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view 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 {
emit OwnershipTransferred(_owner, address(0));
_owner = 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");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "../../GSN/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "../../GSN/Context.sol";
import "./ERC20.sol";
/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for, in a way that can be
* recognized off-chain (via event analysis).
*/
abstract contract ERC20Burnable is Context, ERC20 {
/**
* @dev Destroys `amount` tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 amount) public virtual {
_burn(_msgSender(), amount);
}
/**
* @dev Destroys `amount` tokens from `account`, deducting from the caller's
* allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `amount`.
*/
function burnFrom(address account, uint256 amount) public virtual {
uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance");
_approve(account, _msgSender(), decreasedAllowance);
_burn(account, amount);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;
/**
* @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
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies in extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 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");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(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");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
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
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}