//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface ILosslessController {
function beforeTransfer(address sender, address recipient, uint256 amount) external;
function beforeTransferFrom(address msgSender, address sender, address recipient, uint256 amount) external;
function beforeApprove(address sender, address spender, uint256 amount) external;
function beforeIncreaseAllowance(address msgSender, address spender, uint256 addedValue) external;
function beforeDecreaseAllowance(address msgSender, address spender, uint256 subtractedValue) external;
}
contract LERC20 is Context, IERC20 {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
address public recoveryAdmin;
address private recoveryAdminCanditate;
bytes32 private recoveryAdminKeyHash;
address public admin;
uint256 public timelockPeriod;
uint256 public losslessTurnOffTimestamp;
bool public isLosslessTurnOffProposed;
bool public isLosslessOn = true;
ILosslessController public lossless;
event AdminChanged(address indexed previousAdmin, address indexed newAdmin);
event RecoveryAdminChangeProposed(address indexed candidate);
event RecoveryAdminChanged(address indexed previousAdmin, address indexed newAdmin);
event LosslessTurnOffProposed(uint256 turnOffDate);
event LosslessTurnedOff();
event LosslessTurnedOn();
constructor(uint256 totalSupply_, string memory name_, string memory symbol_, address admin_, address recoveryAdmin_, uint256 timelockPeriod_, address lossless_) {
_mint(_msgSender(), totalSupply_);
_name = name_;
_symbol = symbol_;
admin = admin_;
recoveryAdmin = recoveryAdmin_;
timelockPeriod = timelockPeriod_;
lossless = ILosslessController(lossless_);
}
// --- LOSSLESS modifiers ---
modifier lssAprove(address spender, uint256 amount) {
if (isLosslessOn) {
lossless.beforeApprove(_msgSender(), spender, amount);
}
_;
}
modifier lssTransfer(address recipient, uint256 amount) {
if (isLosslessOn) {
lossless.beforeTransfer(_msgSender(), recipient, amount);
}
_;
}
modifier lssTransferFrom(address sender, address recipient, uint256 amount) {
if (isLosslessOn) {
lossless.beforeTransferFrom(_msgSender(), sender, recipient, amount);
}
_;
}
modifier lssIncreaseAllowance(address spender, uint256 addedValue) {
if (isLosslessOn) {
lossless.beforeIncreaseAllowance(_msgSender(), spender, addedValue);
}
_;
}
modifier lssDecreaseAllowance(address spender, uint256 subtractedValue) {
if (isLosslessOn) {
lossless.beforeDecreaseAllowance(_msgSender(), spender, subtractedValue);
}
_;
}
modifier onlyRecoveryAdmin() {
require(_msgSender() == recoveryAdmin, "LERC20: Must be recovery admin");
_;
}
// --- LOSSLESS management ---
function getAdmin() external view returns (address) {
return admin;
}
function transferOutBlacklistedFunds(address[] calldata from) external {
require(_msgSender() == address(lossless), "LERC20: Only lossless contract");
for (uint i = 0; i < from.length; i++) {
_transfer(from[i], address(lossless), balanceOf(from[i]));
}
}
function setLosslessAdmin(address newAdmin) external onlyRecoveryAdmin {
require(newAdmin != address(0), "LERC20: Cannot be zero address");
emit AdminChanged(admin, newAdmin);
admin = newAdmin;
}
function transferRecoveryAdminOwnership(address candidate, bytes32 keyHash) external onlyRecoveryAdmin {
require(candidate != address(0), "LERC20: Cannot be zero address");
recoveryAdminCanditate = candidate;
recoveryAdminKeyHash = keyHash;
emit RecoveryAdminChangeProposed(candidate);
}
function acceptRecoveryAdminOwnership(bytes memory key) external {
require(_msgSender() == recoveryAdminCanditate, "LERC20: Must be canditate");
require(keccak256(key) == recoveryAdminKeyHash, "LERC20: Invalid key");
emit RecoveryAdminChanged(recoveryAdmin, recoveryAdminCanditate);
recoveryAdmin = recoveryAdminCanditate;
}
function proposeLosslessTurnOff() external onlyRecoveryAdmin {
losslessTurnOffTimestamp = block.timestamp + timelockPeriod;
isLosslessTurnOffProposed = true;
emit LosslessTurnOffProposed(losslessTurnOffTimestamp);
}
function executeLosslessTurnOff() external onlyRecoveryAdmin {
require(isLosslessTurnOffProposed, "LERC20: TurnOff not proposed");
require(losslessTurnOffTimestamp <= block.timestamp, "LERC20: Time lock in progress");
isLosslessOn = false;
isLosslessTurnOffProposed = false;
emit LosslessTurnedOff();
}
function executeLosslessTurnOn() external onlyRecoveryAdmin {
isLosslessTurnOffProposed = false;
isLosslessOn = true;
emit LosslessTurnedOn();
}
// --- ERC20 methods ---
function name() external view virtual returns (string memory) {
return _name;
}
function symbol() external view virtual returns (string memory) {
return _symbol;
}
function decimals() external view virtual returns (uint8) {
return 18;
}
function totalSupply() external view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) external virtual override lssTransfer(recipient, amount) returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) external view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) external virtual override lssAprove(spender, amount) returns (bool) {
require((amount == 0) || (_allowances[_msgSender()][spender] == 0), "LERC20: Cannot change non zero allowance");
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) external virtual override lssTransferFrom(sender, recipient, amount) returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "LERC20: transfer amount exceeds allowance");
_approve(sender, _msgSender(), currentAllowance - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) external virtual lssIncreaseAllowance(spender, addedValue) returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) external virtual lssDecreaseAllowance(spender, subtractedValue) returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "LERC20: decreased allowance below zero");
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "LERC20: transfer from the zero address");
require(recipient != address(0), "LERC20: transfer to the zero address");
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "LERC20: transfer amount exceeds balance");
_balances[sender] = senderBalance - amount;
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "LERC20: mint to the zero address");
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "LERC20: approve from the zero address");
require(spender != address(0), "LERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
}
{
"compilationTarget": {
"LERC20.sol": "LERC20"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"uint256","name":"totalSupply_","type":"uint256"},{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"address","name":"admin_","type":"address"},{"internalType":"address","name":"recoveryAdmin_","type":"address"},{"internalType":"uint256","name":"timelockPeriod_","type":"uint256"},{"internalType":"address","name":"lossless_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":true,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"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":false,"internalType":"uint256","name":"turnOffDate","type":"uint256"}],"name":"LosslessTurnOffProposed","type":"event"},{"anonymous":false,"inputs":[],"name":"LosslessTurnedOff","type":"event"},{"anonymous":false,"inputs":[],"name":"LosslessTurnedOn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"candidate","type":"address"}],"name":"RecoveryAdminChangeProposed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":true,"internalType":"address","name":"newAdmin","type":"address"}],"name":"RecoveryAdminChanged","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"},{"inputs":[{"internalType":"bytes","name":"key","type":"bytes"}],"name":"acceptRecoveryAdminOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","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":"executeLosslessTurnOff","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"executeLosslessTurnOn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getAdmin","outputs":[{"internalType":"address","name":"","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":[],"name":"isLosslessOn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isLosslessTurnOffProposed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lossless","outputs":[{"internalType":"contract ILosslessController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"losslessTurnOffTimestamp","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":"proposeLosslessTurnOff","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"recoveryAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"setLosslessAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"timelockPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"from","type":"address[]"}],"name":"transferOutBlacklistedFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"candidate","type":"address"},{"internalType":"bytes32","name":"keyHash","type":"bytes32"}],"name":"transferRecoveryAdminOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]