编译器
0.8.16+commit.07a7930e
文件 1 的 5:BaseERC20.sol
pragma solidity 0.8.16;
contract BaseERC20 {
uint public constant MAX_INT = 2**256 - 1;
string public name;
string public symbol;
uint public decimals = 18;
uint public _totalSupply;
mapping(address => uint256) public _balanceOf;
mapping(address => mapping(address => uint256)) public _allowance;
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
constructor(string memory _name){
name = _name;
symbol = _name;
}
function _mint(address to, uint256 value) internal {
_totalSupply += value;
_balanceOf[to] += value;
emit Transfer(address(0), to, value);
}
function _burn(address from, uint256 value) internal {
_balanceOf[from] -= value;
_totalSupply -= value;
emit Transfer(from, address(0), value);
}
function _transfer(
address from,
address to,
uint256 value
) internal {
_balanceOf[from] -= value;
_balanceOf[to] += value;
emit Transfer(from, to, value);
}
function _approve(
address owner,
address spender,
uint256 value
) internal {
_allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function balanceOf(address account) public virtual view returns (uint256){
return _balanceOf[account];
}
function totalSupply() public virtual view returns (uint256){
return _totalSupply;
}
function allowance(address owner, address spender) public virtual view returns (uint256){
return _allowance[owner][spender];
}
function approve(address spender, uint256 value) public virtual returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
}
文件 2 的 5:IERC20.sol
pragma solidity 0.8.16;
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);
}
文件 3 的 5:IManagement.sol
pragma solidity 0.8.16;
interface IManagement {
function platformFeeAddress() external view returns (address);
function isContractManager(address manager) external view returns (bool);
function isWhiteInvestor(address investor) external view returns (bool);
function isRestrictInvestor(address investor) external view returns (bool);
function isWhiteContract(address contractAddress) external view returns (bool);
function isBlockInvestor(address investor) external view returns (bool);
}
文件 4 的 5:IUpgradedToken.sol
pragma solidity 0.8.16;
interface IUpgradedToken{
function transferByLegacy (address sender,address to,uint256 value) external returns (bool) ;
function transferFromByLegacy (address sender,address from,address to,uint256 value) external returns (bool);
function balanceOf(address account) external view returns (uint);
function approveByLegacy (address sender,address to,uint256 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
function totalSupply() external view returns (uint);
}
文件 5 的 5:SecurityToken.sol
pragma solidity 0.8.16;
import './interfaces/IERC20.sol';
import './interfaces/IManagement.sol';
import './BaseERC20.sol';
import './interfaces/IUpgradedToken.sol';
contract SecurityToken is BaseERC20 {
uint8 public transferFlag = 1;
bool public upgraded;
address public upgradedAddress;
address public management;
bool public paused;
address public issuer;
event SetSTManagement(address indexed from, address indexed newManagement);
event Issue(address indexed from, address indexed to, uint256 value);
event Redeem(address indexed from, address indexed to, uint256 value);
event Paused(bool paused);
event Flag(uint8 transferFlag);
event Upgrade(address newAddress);
modifier whenNotPaused() {
require(!paused,"Paused");
_;
}
modifier onlyManagement() {
require(msg.sender == management,"Caller is not management");
_;
}
modifier onlyContractManager() {
require(IManagement(management).isContractManager(msg.sender),"Caller is not contract manager");
_;
}
constructor(
string memory _name,
address _issuer,
uint _amount,
address _management
) BaseERC20(_name) {
require(_management!= address(0));
management = _management;
issuer = _issuer;
decimals = _amount;
}
function transfer(
address to,
uint value
)external whenNotPaused returns (bool) {
if(upgraded){
return IUpgradedToken(upgradedAddress).transferByLegacy(msg.sender, to, value);
}
if(transferFlag == 1){
require(IManagement(management).isWhiteContract(msg.sender)&&
(IManagement(management).isWhiteInvestor(to) || IManagement(management).isRestrictInvestor(to)),'Forbid transfer');
}else if(transferFlag == 2){
require((IManagement(management).isWhiteContract(msg.sender)||IManagement(management).isWhiteInvestor(msg.sender) || IManagement(management).isRestrictInvestor(msg.sender)) &&
(IManagement(management).isWhiteInvestor(to) || IManagement(management).isRestrictInvestor(to)),'Forbid transfer');
}else{
require(!IManagement(management).isBlockInvestor(msg.sender),'Block');
}
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(
address from,
address to,
uint value
)external whenNotPaused returns (bool) {
if(upgraded){
return IUpgradedToken(upgradedAddress).transferFromByLegacy(msg.sender, from ,to, value);
}
if(transferFlag == 1){
require(IManagement(management).isWhiteContract(msg.sender)&&
(IManagement(management).isWhiteInvestor(from) || IManagement(management).isRestrictInvestor(from))&&
(IManagement(management).isWhiteContract(to)||IManagement(management).isWhiteInvestor(to) || IManagement(management).isRestrictInvestor(to)),'Forbid transferFrom');
}else if(transferFlag == 2){
require((IManagement(management).isWhiteContract(msg.sender)||IManagement(management).isWhiteInvestor(msg.sender) || IManagement(management).isRestrictInvestor(msg.sender))&&
(IManagement(management).isWhiteInvestor(from) || IManagement(management).isRestrictInvestor(from))&&
(IManagement(management).isWhiteContract(to)||IManagement(management).isWhiteInvestor(to) || IManagement(management).isRestrictInvestor(to)),'Forbid transferFrom');
}else{
require(!IManagement(management).isBlockInvestor(from),'Block');
}
if (_allowance[from][msg.sender] != MAX_INT) {
_allowance[from][msg.sender] -= value;
}
_transfer(from, to, value);
return true;
}
function totalSupply() override public view returns (uint) {
if (upgraded) {
return IUpgradedToken(upgradedAddress).totalSupply();
} else {
return super.totalSupply();
}
}
function approve(address _spender, uint _value) public override returns(bool) {
if (upgraded) {
return IUpgradedToken(upgradedAddress).approveByLegacy(msg.sender, _spender, _value);
} else {
return super.approve(_spender, _value);
}
}
function balanceOf(address who) public view override returns (uint) {
if (upgraded) {
return IUpgradedToken(upgradedAddress).balanceOf(who);
} else {
return super.balanceOf(who);
}
}
function allowance(address _owner, address _spender) public view override returns (uint remaining) {
if (upgraded) {
return IUpgradedToken(upgradedAddress).allowance(_owner, _spender);
} else {
return super.allowance(_owner, _spender);
}
}
function setManagement(address _management) external onlyManagement {
require(_management!= address(0));
management = _management;
emit SetSTManagement(address(this),_management);
}
function setTransferFlag(uint8 _transferFlag) external onlyContractManager {
transferFlag = _transferFlag;
emit Flag(_transferFlag);
}
function setPause(bool _paused) external onlyContractManager {
paused = _paused;
emit Paused(_paused);
}
function issue(
address investor,
uint256 value
) external onlyContractManager {
if (transferFlag == 1 || transferFlag == 2){
require(IManagement(management).isWhiteInvestor(investor) || IManagement(management).isWhiteContract(investor),"Forbid issue");
}else{
require(!IManagement(management).isBlockInvestor(investor),"Block");
}
_mint(investor,value);
emit Issue(address(this),investor,value);
}
function redeem(
address investor,
uint256 value
) external onlyContractManager {
_burn(investor,value);
emit Redeem(address(this),investor,value);
}
function upgrade(address _upgradedAddress) external onlyContractManager {
require(_upgradedAddress!= address(0));
upgraded = true;
upgradedAddress = _upgradedAddress;
emit Upgrade(_upgradedAddress);
}
}
{
"compilationTarget": {
"contracts/SecurityToken.sol": "SecurityToken"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"address","name":"_issuer","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_management","type":"address"}],"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":false,"internalType":"uint8","name":"transferFlag","type":"uint8"}],"name":"Flag","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":"Issue","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"paused","type":"bool"}],"name":"Paused","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":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"newManagement","type":"address"}],"name":"SetSTManagement","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":false,"internalType":"address","name":"newAddress","type":"address"}],"name":"Upgrade","type":"event"},{"inputs":[],"name":"MAX_INT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"_allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_balanceOf","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":"_owner","type":"address"},{"internalType":"address","name":"_spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"remaining","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"investor","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"issue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"issuer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"management","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"investor","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_management","type":"address"}],"name":"setManagement","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"setPause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"_transferFlag","type":"uint8"}],"name":"setTransferFlag","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":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"transferFlag","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_upgradedAddress","type":"address"}],"name":"upgrade","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"upgraded","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"upgradedAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]