// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "./IERC20.sol";
import "./Ownable.sol";
import "./Whitelist.sol";
/**
* @title ERC20 Basic.
*
* @dev ERC20 SOUL token.
*/
contract ERC20Basic is IERC20, Ownable, Whitelist {
string public name = "SOUL TOKEN";
string public symbol = "SOUL";
uint8 public constant decimals = 18;
uint256 private _totalSupply = 10000000000000000000000000000 wei;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => uint256) private _lockedAmount;
event Lock(address indexed owner, address account, uint256 amount);
event Unlock(address indexed owner, address account, uint256 amount);
constructor() {
_balances[msg.sender] = _totalSupply;
}
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @return The amount of tokens locked to `account`.
*/
function lockedAmountOf(address account) public view returns (uint256) {
return _lockedAmount[account];
}
function transfer(address to, uint256 amount) public override returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
/**
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*/
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
// OPTIONAL
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
_spendAllowance(from, msg.sender, amount);
_transfer(from, to, amount);
return true;
}
function _transfer(address from, address to, uint256 amount) internal {
require(from != address(0), "ERC20Basic: transfer from the zero address");
require(to != address(0), "ERC20Basic: transfer to the zero address");
uint256 currentBalance = balanceOf(from);
uint256 lockedAmount = lockedAmountOf(from);
uint256 availableAmount;
require(currentBalance >= lockedAmount);
unchecked { availableAmount = currentBalance - lockedAmount; }
require(availableAmount >= amount, "ERC20Basic: transfer amount exceeds balance");
unchecked {
_balances[from] -= amount;
_balances[to] += amount;
require(_balances[to] >= amount, "ERC20Basic: overflow of the to's balance");
}
emit Transfer(from, to, amount);
}
function _approve(address owner, address spender, uint256 amount) internal {
require(owner != address(0), "ERC20Basic: approve owner the zero address");
require(spender != address(0), "ERC20Basic: approve spender the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal {
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= amount, "ERC20Basic: insufficient allowance");
if (currentAllowance != type(uint256).max) {
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
uint256 currentAllowance = allowance(msg.sender, spender);
unchecked {
uint256 newAllowance = currentAllowance + addedValue;
require(newAllowance >= currentAllowance, "ERC20Basic: overflow of the allowance");
_approve(msg.sender, spender, newAllowance);
}
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
uint256 currentAllowance = allowance(msg.sender, spender);
require(currentAllowance >= subtractedValue, "ERC20Basic: decreased allowance below zero");
unchecked {
_approve(msg.sender, spender, currentAllowance - subtractedValue);
}
return true;
}
function lock(address account, uint256 amount) public onlyWhitelisted returns (bool) {
require(balanceOf(account) >= amount, "ERC20Basic: Insufficient balance to lock");
unchecked {
_lockedAmount[account] += amount;
require(_lockedAmount[account] >= amount, "ERC20Basic: overflow of locked amount");
emit Lock(msg.sender, account, amount);
}
return true;
}
function unlock(address account, uint256 amount) public onlyWhitelisted returns (bool) {
require(_lockedAmount[account] >= amount, "ERC20Basic: underflow of locked amount");
unchecked {
_lockedAmount[account] -= amount;
emit Unlock(msg.sender, account, amount);
}
return true;
}
function transferWithLock(address to, uint256 amount) public onlyWhitelisted returns (bool) {
_transfer(msg.sender, to, amount);
lock(to, amount);
return true;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.9;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
// OPTIONAL public state variable getter is automatically generated.
// function name() public view returns (string);
// function symbol() public view returns (uint8);
// function decimals() public view returns (uint256);
/**
* @return The amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @param account ? caller msg.sender ?
* @return The amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev This is zero by default.
* This value changes when {approve} or {transferFrom} are called.
*
* @return The remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Emits a {Transfer} event.
*
* @return A boolean value indicating whether the operation succeeded.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Emits an {Approval} event.
*
* 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
*
* @return A boolean value indicating whether the operation succeeded.
*/
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.
*
* Emits a {Transfer} event.
*
* @return A boolean value indicating whether the operation succeeded.
*/
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 (access/Ownable.sol)
pragma solidity ^0.8.9;
/**
* @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 {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(msg.sender);
}
/**
* @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() == msg.sender, "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
pragma solidity ^0.8.9;
import "./Ownable.sol";
contract Whitelist is Ownable {
mapping(address => bool) private whitelist;
mapping(address => uint) private addressIdx;
address[] private whiteArr;
event WhitelistedAddressAdded(address addr);
event WhitelistedAddressRemoved(address addr);
constructor() {
addAddressToWhitelist(msg.sender);
}
modifier onlyWhitelisted() {
require(whitelist[msg.sender]);
_;
}
function isWhitelist(address addr) public view returns (bool success) {
return whitelist[addr];
}
function addAddressToWhitelist(address addr) onlyOwner public returns (bool success) {
if (!whitelist[addr]) {
whitelist[addr] = true;
addressIdx[addr] = whiteArr.length;
whiteArr.push(addr);
emit WhitelistedAddressAdded(addr);
success = true;
}
}
function removeAddressFromWhitelist(address addr) onlyOwner public returns (bool success) {
if (whitelist[addr]) {
whitelist[addr] = false;
uint deleteIdx = addressIdx[addr];
address lastAddr = whiteArr[whiteArr.length - 1];
addressIdx[lastAddr] = deleteIdx;
delete addressIdx[addr];
whiteArr[deleteIdx] = lastAddr;
whiteArr.pop();
emit WhitelistedAddressRemoved(addr);
success = true;
}
}
function getCountWhiteArr() public onlyOwner view returns (uint count) {
count = whiteArr.length;
}
function getWhiteArrByIdx(uint idx) public onlyOwner view returns (address whiteAddress) {
whiteAddress = whiteArr[idx];
}
function getWhiteArr() public onlyOwner view returns (address[] memory whiteArray) {
whiteArray = whiteArr;
}
}
{
"compilationTarget": {
"ERC20Basic.sol": "ERC20Basic"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Lock","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unlock","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"}],"name":"WhitelistedAddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"}],"name":"WhitelistedAddressRemoved","type":"event"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"addAddressToWhitelist","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getCountWhiteArr","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getWhiteArr","outputs":[{"internalType":"address[]","name":"whiteArray","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"idx","type":"uint256"}],"name":"getWhiteArrByIdx","outputs":[{"internalType":"address","name":"whiteAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"isWhitelist","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"lock","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"lockedAmountOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"removeAddressFromWhitelist","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferWithLock","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"unlock","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]