文件 2 的 5:AddressPools.sol
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/SafeERC20.sol";
contract AddressPools {
using SafeERC20 for IERC20;
IERC20 private usdt;
address public admin;
mapping (address => bool) public operatorExists;
modifier onlyOperator {
require(operatorExists[msg.sender], "O_01");
_;
}
modifier onlyAdmin {
require(msg.sender == admin, "O_02");
_;
}
constructor(address _admin, address[] memory _opeators, address _usdt_Address) public {
require(_admin != address(0));
for (uint32 idx = 0; idx < _opeators.length; idx++) {
require(_opeators[idx] != address(0));
operatorExists[_opeators[idx]] = true;
}
usdt = IERC20(_usdt_Address);
admin = _admin;
}
function modifyOperators(address[] memory _addresses, bool[] memory valid) external onlyAdmin {
for (uint32 idx = 0; idx < _addresses.length; idx++) {
operatorExists[_addresses[idx]] = valid[idx];
}
}
function changeAdmin(address _address) external onlyAdmin {
require(_address != address(0));
admin = _address;
}
function depositEthPools(address payable[] memory _addresses, uint256[] memory _values) payable external onlyOperator {
require(_addresses.length > 0 && _addresses.length <= 300, "DE_01");
require(_addresses.length == _values.length, "DE_02");
for (uint idx = 0; idx < _addresses.length; idx++) {
require(_addresses[idx] != address(0), "DE_03");
_addresses[idx].transfer(_values[idx]);
}
}
function depositUsdtPools(address payable[] memory _recipients, uint256[] memory _usdtFunds, uint256[] memory _ethFunds) payable external onlyOperator {
require(_recipients.length > 0 && _recipients.length <= 40, "DU_01");
require(_recipients.length == _usdtFunds.length && _recipients.length == _ethFunds.length, "DU_02");
for (uint idx = 0; idx < _recipients.length; idx++) {
require(_recipients[idx] != address(0), "DU_05");
if (_usdtFunds[idx] > 0) {
usdt.safeTransferFrom(msg.sender, _recipients[idx], _usdtFunds[idx]);
}
if (_ethFunds[idx] > 0) {
_recipients[idx].transfer(_ethFunds[idx]);
}
}
}
function skim(address payable _to, address _tokenAddress) payable external onlyAdmin {
require(_to != address(0), "S_01");
uint256 amount;
if (_tokenAddress == address(0)) {
amount = address(this).balance;
require(amount > 0, "S_02");
_to.transfer(amount);
} else {
IERC20 token = IERC20(_tokenAddress);
amount = token.balanceOf(address(this));
require(amount > 0, "S_03");
token.safeTransfer(_to, amount);
}
}
}
{
"compilationTarget": {
"browser/tests/AddressPools.sol": "AddressPools"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}