Sweeper that reads its destination and its kill switch from a shared controller, then empties either ether or a token balance to that destination.
Historical Significance
Everything configurable lives on the controller and nothing lives here, so a deployed sweeper needs no storage writes over its whole life. That matters when the same contract is deployed many times: each deployment costs only its code, and the operator retains the ability to redirect or freeze all of them from one place.
Key Facts
Description
Two modifiers guard both entry points. The first requires the caller to be whatever address the controller returns from _mainAddress. The second reads _disabled from the same controller and reverts when it is set, which gives an operator one flag that stops every deployed sweeper at once.
sweepEth asks the controller for the destination again, sends the contract's whole ether balance with send, and logs the destination and amount. sweepTokens does the same for an ERC20, reading the contract's token balance and transferring all of it. Both return the success flag rather than reverting on a failed transfer, so a sweep that cannot complete reports back instead of throwing.
Source Verified
Bytecode Overview
Verified Source Available
This contract has verified source code.
View Verification ProofShow source code (Solidity)
// Submitted by EthereumHistory (ethereumhistory.com)
pragma solidity ^0.4.13;
contract Controller {
function _mainAddress() public returns (address);
function _disabled() public returns (bool);
}
contract ERC20 {
function balanceOf(address _owner) public returns (uint256);
function transfer(address _to, uint256 _value) public returns (bool);
}
contract Sweeper {
Controller controller;
event LogSweep(address to, uint256 amount);
modifier onlyMain() {
require(msg.sender == controller._mainAddress());
_;
}
modifier notDisabled() {
if (controller._disabled()) {
revert();
}
_;
}
function () public payable {
}
function sweepEth() public onlyMain notDisabled returns (bool success) {
address dest = controller._mainAddress();
uint256 bal = this.balance;
success = dest.send(bal);
LogSweep(dest, bal);
}
function sweepTokens(address _token) public onlyMain notDisabled returns (bool success) {
address dest = controller._mainAddress();
ERC20 token = ERC20(_token);
uint256 bal = token.balanceOf(this);
success = token.transfer(dest, bal);
LogSweep(dest, bal);
}
}