// SPDX-License-Identifier: MITpragmasolidity >=0.6.0 <0.8.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (addresspayable) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
Contract Source Code
File 2 of 5: FluxAggregatorSweeper.sol
// SPDX-License-Identifier: UNLICENSEDpragmasolidity 0.7.4;import"./IFluxAggregator.sol";
import"./Sweeper.sol";
/**
* @title FluxAggregatorSweeper
* @dev Handles withdrawing of rewards from flux aggregator Chainlink contracts.
*/contractFluxAggregatorSweeperisSweeper{
addresspublic oracle;
constructor(address _nodeRewards,
uint256 _minTowithdraw,
address _oracle
) Sweeper(_nodeRewards, _minTowithdraw) {
oracle = _oracle;
}
/**
* @dev returns withdrawable amount for each flux aggregator
* @return withdrawable balance of each flux aggregator
**/functionwithdrawable() externalviewoverridereturns (uint256[] memory) {
uint256[] memory _withdrawable =newuint256[](contracts.length);
for (uint i =0; i < contracts.length; i++) {
_withdrawable[i] = IFluxAggregator(contracts[i]).withdrawablePayment(oracle);
}
return _withdrawable;
}
/**
* @dev withdraw rewards from flux aggregators
* @param _contractIdxs indexes corresponding to the flux aggregators
**/function_withdraw(uint256[] calldata _contractIdxs) internaloverride{
for (uint i =0; i < _contractIdxs.length; i++) {
require(_contractIdxs[i] < contracts.length, "contractIdx must be < contracts length");
IFluxAggregator aggregator = IFluxAggregator(contracts[_contractIdxs[i]]);
uint256 amount = aggregator.withdrawablePayment(oracle);
if (amount >= minToWithdraw) {
aggregator.withdrawPayment(oracle, msg.sender, amount);
}
}
}
/**
* @dev transfers admin to new address for selected flux aggregators
* @param _contractIdxs indexes corresponsing to flux aggregators
* @param _newAdmin address to transfer admin to
**/function_transferAdmin(uint256[] calldata _contractIdxs, address _newAdmin) internaloverride{
for (uint i =0; i < _contractIdxs.length; i++) {
require(_contractIdxs[i] < contracts.length, "contractIdx must be < contracts length");
IFluxAggregator(contracts[_contractIdxs[i]]).transferAdmin(oracle, _newAdmin);
}
}
/**
* @dev accepts admin for flux aggregators
* @param _contractIdxs corresponding to the flux aggregators
**/function_acceptAdmin(uint256[] calldata _contractIdxs) internaloverride{
for (uint i =0; i < _contractIdxs.length; i++) {
require(_contractIdxs[i] < contracts.length, "contractIdx must be < contracts length");
IFluxAggregator(contracts[_contractIdxs[i]]).acceptAdmin(oracle);
}
}
}
// SPDX-License-Identifier: MITpragmasolidity >=0.6.0 <0.8.0;import"./Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor () internal{
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
emit OwnershipTransferred(_owner, address(0));
_owner =address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
Contract Source Code
File 5 of 5: Sweeper.sol
// SPDX-License-Identifier: UNLICENSEDpragmasolidity 0.7.4;import"./Ownable.sol";
/**
* @title Sweeper
* @dev Base sweeper contract that other sweeper contracts should inherit from
*/abstractcontractSweeperisOwnable{
uint256public minToWithdraw;
address[] public contracts;
address nodeRewards;
modifieronlyNodeRewards() {
require(nodeRewards ==msg.sender, "NodeRewards only");
_;
}
constructor(address _nodeRewards, uint256 _minToWithdraw) {
nodeRewards = _nodeRewards;
minToWithdraw = _minToWithdraw;
}
/**
* @dev returns current list of contracts
* @return list of contracts
**/functiongetContracts() externalviewreturns (address[] memory) {
return contracts;
}
/**
* @dev withdraws rewards from contracts
* @param _contractIdxs indexes corresponding to the contracts
**/functionwithdraw(uint256[] calldata _contractIdxs) externalvirtualonlyNodeRewards() {
require(_contractIdxs.length<= contracts.length, "contractIdxs length must be <= contracts length");
_withdraw(_contractIdxs);
}
/**
* @dev returns the withdrawable amount for each contract
* @return withdrawable balance of each contract
**/functionwithdrawable() externalviewvirtualreturns (uint256[] memory);
/**
* @dev transfers admin to new address for selected contracts
* @param _contractIdxs indexes corresponsing to contracts
* @param _newAdmin address to transfer admin to
**/functiontransferAdmin(uint256[] calldata _contractIdxs, address _newAdmin) externalonlyOwner() {
require(_contractIdxs.length<= contracts.length, "contractIdxs length must be <= contracts length");
_transferAdmin(_contractIdxs, _newAdmin);
}
/**
* @dev accepts admin transfer for selected contracts
* @param _contractIdxs indexes corresponsing to contracts
**/functionacceptAdmin(uint256[] calldata _contractIdxs) externalonlyOwner() {
require(_contractIdxs.length<= contracts.length, "contractIdxs length must be <= contracts length");
_acceptAdmin(_contractIdxs);
}
/**
* @dev sets the minimum amount needed to withdraw for each contract
* @param _minToWithdraw amount to set
**/functionsetMinToWithdraw(uint256 _minToWithdraw) externalonlyOwner() {
minToWithdraw = _minToWithdraw;
}
/**
* @dev adds contract addresses
* @param _contracts contracts to add
**/functionaddContracts(address[] calldata _contracts) externalonlyOwner() {
for (uint i =0; i < _contracts.length; i++) {
contracts.push(_contracts[i]);
}
}
/**
* @dev removes contract address
* @param _index index of contract to remove
**/functionremoveContract(uint256 _index) externalonlyOwner() {
require(_index < contracts.length, "Contract does not exist");
contracts[_index] = contracts[contracts.length-1];
delete contracts[contracts.length-1];
}
/**
* @dev withdraws rewards from contracts
* @param _contractIdxs indexes corresponding to the contracts
**/function_withdraw(uint256[] calldata _contractIdxs) internalvirtual;
/**
* @dev transfers admin to new address for selected contracts
* @param _contractIdxs indexes corresponsing to contracts
* @param _newAdmin address to transfer admin to
**/function_transferAdmin(uint256[] calldata _contractIdxs, address _newAdmin) internalvirtual;
/**
* @dev accepts admin transfer for selected contracts
* @param _contractIdxs indexes corresponsing to contracts
**/function_acceptAdmin(uint256[] calldata _contractIdxs) internalvirtual{}
}