编译器
0.8.13+commit.abaa5c0e
文件 1 的 3:ClaimComptrollers.sol
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/access/Ownable.sol";
interface IComptroller {
function compAccrued(address account) external view returns (uint256);
function claimComp(address holder) external;
function claimComp(address[] memory holder, address[] memory cTokens, bool borrowers, bool suppliers) external;
}
contract ClaimComptrollers is Ownable {
struct CTokenList {
address comptroller;
address[] cTokenList;
}
address public admin;
address[] private comptrollers;
modifier onlyOwnerOrAdmin() {
require(msg.sender == owner() || msg.sender == admin, "caller is not owner or admin");
_;
}
constructor(address[] memory _comptrollers, address _admin) {
comptrollers = _comptrollers;
admin = _admin;
}
function claimAll(address holder) external {
address[] memory comptrollers_ = comptrollers;
for (uint256 i = 0; i < comptrollers_.length; i++) {
uint256 claimAmount_ = IComptroller(comptrollers_[i]).compAccrued(holder);
if (claimAmount_ > 0) {
IComptroller(comptrollers_[i]).claimComp(holder);
}
}
}
function claimAllWithAddress(address holder, address[] memory _comptrollers) external {
for (uint256 i = 0; i < _comptrollers.length; i++) {
IComptroller(_comptrollers[i]).claimComp(holder);
}
}
function claimAllWithCTokens(address[] memory holder, CTokenList[] memory cTokenInfo) external {
for (uint256 i = 0; i < cTokenInfo.length; i++) {
IComptroller(cTokenInfo[i].comptroller).claimComp(holder, cTokenInfo[i].cTokenList, true, true);
}
}
function getAllComAccrued(address holder) external view returns (uint256 totalAmount) {
address[] memory comptrollers_ = comptrollers;
for (uint256 i = 0; i < comptrollers_.length; i++) {
uint256 claimAmount_ = IComptroller(comptrollers_[i]).compAccrued(holder);
totalAmount += claimAmount_;
}
}
function getAllComptrollers() external view returns (address[] memory) {
return comptrollers;
}
function getCompAddressOf(address holder) external view returns (address[] memory) {
address[] memory comptrollers_ = comptrollers;
address[] memory addresses = new address[](comptrollers_.length);
for (uint256 i = 0; i < comptrollers_.length; i++) {
uint256 claimAmount_ = IComptroller(comptrollers_[i]).compAccrued(holder);
if (claimAmount_ > 0) {
addresses[i] = comptrollers_[i];
}
}
return addresses;
}
function removeComptroller(uint index) external onlyOwnerOrAdmin {
require(index <= comptrollers.length, "index should be less than length of comptrollers");
comptrollers[index] = comptrollers[comptrollers.length - 1];
comptrollers.pop();
}
function addComptroller(address comptroller) external onlyOwnerOrAdmin {
require(comptroller != address(0), "invalid address");
comptrollers[comptrollers.length] = comptroller;
}
function changeAdmin(address newAdmin) external onlyOwner {
require(newAdmin != address(0), "invalid address");
admin = newAdmin;
}
}
文件 2 的 3:Context.sol
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) {
return msg.data;
}
}
文件 3 的 3:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
{
"compilationTarget": {
"contracts/ClaimComptrollers.sol": "ClaimComptrollers"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address[]","name":"_comptrollers","type":"address[]"},{"internalType":"address","name":"_admin","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"address","name":"comptroller","type":"address"}],"name":"addComptroller","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"changeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"}],"name":"claimAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"},{"internalType":"address[]","name":"_comptrollers","type":"address[]"}],"name":"claimAllWithAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"holder","type":"address[]"},{"components":[{"internalType":"address","name":"comptroller","type":"address"},{"internalType":"address[]","name":"cTokenList","type":"address[]"}],"internalType":"struct ClaimComptrollers.CTokenList[]","name":"cTokenInfo","type":"tuple[]"}],"name":"claimAllWithCTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"}],"name":"getAllComAccrued","outputs":[{"internalType":"uint256","name":"totalAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllComptrollers","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"}],"name":"getCompAddressOf","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"removeComptroller","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]