编译器
0.6.12+commit.27d51765
文件 1 的 27:Address.sol
pragma solidity >=0.6.2 <0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(account) }
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 27:CollectableDust.sol
pragma solidity 0.6.12;
import '@openzeppelin/contracts/utils/Address.sol';
import '@openzeppelin/contracts/utils/EnumerableSet.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import '../../interfaces/utils/ICollectableDust.sol';
abstract
contract CollectableDust is ICollectableDust {
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
address public constant ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
EnumerableSet.AddressSet internal protocolTokens;
constructor() public {}
function _addProtocolToken(address _token) internal {
require(!protocolTokens.contains(_token), 'collectable-dust/token-is-part-of-the-protocol');
protocolTokens.add(_token);
}
function _removeProtocolToken(address _token) internal {
require(protocolTokens.contains(_token), 'collectable-dust/token-not-part-of-the-protocol');
protocolTokens.remove(_token);
}
function _sendDust(
address _to,
address _token,
uint256 _amount
) internal {
require(_to != address(0), 'collectable-dust/cant-send-dust-to-zero-address');
require(!protocolTokens.contains(_token), 'collectable-dust/token-is-part-of-the-protocol');
if (_token == ETH_ADDRESS) {
payable(_to).transfer(_amount);
} else {
IERC20(_token).safeTransfer(_to, _amount);
}
emit DustSent(_to, _token, _amount);
}
}
文件 3 的 27:EnumerableSet.sol
pragma solidity >=0.6.0 <0.8.0;
library EnumerableSet {
struct Set {
bytes32[] _values;
mapping (bytes32 => uint256) _indexes;
}
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
function _remove(Set storage set, bytes32 value) private returns (bool) {
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
bytes32 lastvalue = set._values[lastIndex];
set._values[toDeleteIndex] = lastvalue;
set._indexes[lastvalue] = toDeleteIndex + 1;
set._values.pop();
delete set._indexes[value];
return true;
} else {
return false;
}
}
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
struct Bytes32Set {
Set _inner;
}
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
struct AddressSet {
Set _inner;
}
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(value)));
}
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(value)));
}
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(value)));
}
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint256(_at(set._inner, index)));
}
struct UintSet {
Set _inner;
}
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
文件 4 的 27:Governable.sol
pragma solidity 0.6.12;
import '../../interfaces/utils/IGovernable.sol';
abstract
contract Governable is IGovernable {
address public override governor;
address public override pendingGovernor;
constructor(address _governor) public {
require(_governor != address(0), 'governable/governor-should-not-be-zero-address');
governor = _governor;
}
function _setPendingGovernor(address _pendingGovernor) internal {
require(_pendingGovernor != address(0), 'governable/pending-governor-should-not-be-zero-addres');
pendingGovernor = _pendingGovernor;
emit PendingGovernorSet(_pendingGovernor);
}
function _acceptGovernor() internal {
governor = pendingGovernor;
pendingGovernor = address(0);
emit GovernorAccepted();
}
function isGovernor(address _account) public view override returns (bool _isGovernor) {
return _account == governor;
}
modifier onlyGovernor {
require(isGovernor(msg.sender), 'governable/only-governor');
_;
}
modifier onlyPendingGovernor {
require(msg.sender == pendingGovernor, 'governable/only-pending-governor');
_;
}
}
文件 5 的 27:HarvestV2Keep3rJob.sol
pragma solidity 0.6.12;
import "./V2Keep3rJob.sol";
contract HarvestV2Keep3rJob is V2Keep3rJob {
constructor(
address _mechanicsRegistry,
address _keep3r,
address _bond,
uint256 _minBond,
uint256 _earned,
uint256 _age,
bool _onlyEOA,
address _keep3rHelper,
address _slidingOracle,
address _v2Keeper,
uint256 _workCooldown
)
public
V2Keep3rJob(
_mechanicsRegistry,
_keep3r,
_bond,
_minBond,
_earned,
_age,
_onlyEOA,
_keep3rHelper,
_slidingOracle,
_v2Keeper,
_workCooldown
)
{}
function workable(address _strategy) external view override returns (bool) {
return _workable(_strategy);
}
function _workable(address _strategy) internal view override returns (bool) {
if (!super._workable(_strategy)) return false;
(, uint256 _ethCallCost) = _getCallCosts(_strategy);
return IBaseStrategy(_strategy).harvestTrigger(_ethCallCost);
}
function _work(address _strategy) internal override {
lastWorkAt[_strategy] = block.timestamp;
V2Keeper.harvest(_strategy);
}
function work(address _strategy) external override returns (uint256 _credits) {
return workForBond(_strategy);
}
function workForBond(address _strategy) public override notPaused onlyKeeper returns (uint256 _credits) {
_credits = _workInternal(_strategy, false);
_paysKeeperAmount(msg.sender, _credits);
}
function workForTokens(address _strategy) external override notPaused onlyKeeper returns (uint256 _credits) {
_credits = _workInternal(_strategy, true);
_paysKeeperInTokens(msg.sender, _credits);
}
}
文件 6 的 27:IBaseStrategy.sol
pragma solidity 0.6.12;
interface IBaseStrategy {
function vault() external view returns (address _vault);
function strategist() external view returns (address _strategist);
function rewards() external view returns (address _rewards);
function keeper() external view returns (address _keeper);
function want() external view returns (address _want);
function name() external view returns (string memory _name);
function setStrategist(address _strategist) external;
function setKeeper(address _keeper) external;
function setRewards(address _rewards) external;
function tendTrigger(uint256 callCost) external view returns (bool);
function tend() external;
function harvestTrigger(uint256 callCost) external view returns (bool);
function harvest() external;
}
文件 7 的 27:ICollectableDust.sol
pragma solidity 0.6.12;
interface ICollectableDust {
event DustSent(address _to, address token, uint256 amount);
function sendDust(address _to, address _token, uint256 _amount) external;
}
文件 8 的 27:IERC20.sol
pragma solidity >=0.6.0 <0.8.0;
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);
}
文件 9 的 27:IGovernable.sol
pragma solidity 0.6.12;
interface IGovernable {
event PendingGovernorSet(address pendingGovernor);
event GovernorAccepted();
function setPendingGovernor(address _pendingGovernor) external;
function acceptGovernor() external;
function governor() external view returns (address _governor);
function pendingGovernor() external view returns (address _pendingGovernor);
function isGovernor(address _account) external view returns (bool _isGovernor);
}
文件 10 的 27:IKeep3r.sol
pragma solidity 0.6.12;
interface IKeep3r {
event Keep3rSet(address _keep3r);
event Keep3rRequirementsSet(address _bond, uint256 _minBond, uint256 _earned, uint256 _age, bool _onlyEOA);
function keep3r() external view returns (address _keep3r);
function setKeep3r(address _keep3r) external;
function setKeep3rRequirements(address _bond, uint256 _minBond, uint256 _earned, uint256 _age, bool _onlyEOA) external;
}
文件 11 的 27:IKeep3rJob.sol
pragma solidity 0.6.12;
interface IKeep3rJob {
event SetRewardMultiplier(uint256 _rewardMultiplier);
function rewardMultiplier() external view returns (uint256 _rewardMultiplier);
function setRewardMultiplier(uint256 _rewardMultiplier) external;
}
文件 12 的 27:IKeep3rV1.sol
pragma solidity 0.6.12;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IKeep3rV1Helper.sol";
interface IKeep3rV1 is IERC20 {
function name() external returns (string memory);
function KPRH() external view returns (IKeep3rV1Helper);
function isKeeper(address _keeper) external returns (bool);
function isMinKeeper(address _keeper, uint256 _minBond, uint256 _earned, uint256 _age) external returns (bool);
function isBondedKeeper(address _keeper, address bond, uint256 _minBond, uint256 _earned, uint256 _age) external returns (bool);
function addKPRCredit(address _job, uint256 _amount) external;
function addJob(address _job) external;
function addVotes(address voter, uint256 amount) external;
function removeVotes(address voter, uint256 amount) external;
function worked(address _keeper) external;
function workReceipt(address _keeper, uint256 _amount) external;
function receipt(address credit, address _keeper, uint256 _amount) external;
function receiptETH(address _keeper, uint256 _amount) external;
function addLiquidityToJob(address liquidity, address job, uint amount) external;
function applyCreditToJob(address provider, address liquidity, address job) external;
function unbondLiquidityFromJob(address liquidity, address job, uint amount) external;
function removeLiquidityFromJob(address liquidity, address job) external;
function credits(address _job, address _credit) external view returns (uint256 _amount);
function liquidityAccepted(address _liquidity) external view returns (bool);
function liquidityProvided(address _provider, address _liquidity, address _job) external view returns (uint256 _amount);
function liquidityApplied(address _provider, address _liquidity, address _job) external view returns (uint256 _amount);
function liquidityAmount(address _provider, address _liquidity, address _job) external view returns (uint256 _amount);
function liquidityUnbonding(address _provider, address _liquidity, address _job) external view returns (uint256 _amount);
function liquidityAmountsUnbonding(address _provider, address _liquidity, address _job) external view returns (uint256 _amount);
function bond(address bonding, uint256 amount) external;
function activate(address bonding) external;
function unbond(address bonding, uint256 amount) external;
function withdraw(address bonding) external;
}
文件 13 的 27:IKeep3rV1Helper.sol
pragma solidity 0.6.12;
interface IKeep3rV1Helper {
function quote(uint256 eth) external view returns (uint256);
function getFastGas() external view returns (uint256);
function bonds(address keeper) external view returns (uint256);
function getQuoteLimit(uint256 gasUsed) external view returns (uint256);
function getQuoteLimitFor(address origin, uint256 gasUsed) external view returns (uint256);
}
文件 14 的 27:IMachinery.sol
pragma solidity 0.6.12;
interface IMachinery {
function mechanicsRegistry() external view returns (address _mechanicsRegistry);
function isMechanic(address mechanic) external view returns (bool _isMechanic);
function setMechanicsRegistry(address _mechanicsRegistry) external;
}
文件 15 的 27:IMechanicsRegistry.sol
pragma solidity 0.6.12;
interface IMechanicsRegistry {
event MechanicAdded(address _mechanic);
event MechanicRemoved(address _mechanic);
function addMechanic(address _mechanic) external;
function removeMechanic(address _mechanic) external;
function mechanics() external view returns (address[] memory _mechanicsList);
function isMechanic(address mechanic) external view returns (bool _isMechanic);
}
文件 16 的 27:IPausable.sol
pragma solidity 0.6.12;
interface IPausable {
event Paused(bool _paused);
function pause(bool _paused) external;
}
文件 17 的 27:IUniswapV2SlidingOracle.sol
pragma solidity 0.6.12;
interface IUniswapV2SlidingOracle {
function current(
address tokenIn,
uint256 amountIn,
address tokenOut
) external view returns (uint256);
function updatePair(address pair) external returns (bool);
function workable(address pair) external view returns (bool);
function workForFree() external;
}
文件 18 的 27:IV2Keep3rJob.sol
pragma solidity >=0.6.8;
import "../IKeep3rJob.sol";
interface IV2Keep3rJob is IKeep3rJob {
event Keep3rSet(address keep3r);
event Keep3rHelperSet(address keep3rHelper);
event SlidingOracleSet(address slidingOracle);
event StrategyAdded(address _strategy, uint256 _requiredAmount);
event StrategyModified(address _strategy, uint256 _requiredAmount);
event StrategyRemoved(address _strategy);
event Worked(address _strategy, address _keeper, uint256 _credits, bool _workForTokens);
event ForceWorked(address _strategy);
function strategies() external view returns (address[] memory);
function workable(address _strategy) external view returns (bool);
function setWorkCooldown(uint256 _workCooldown) external;
function addStrategies(address[] calldata _strategy, uint256[] calldata _requiredAmount) external;
function addStrategy(address _strategy, uint256 _requiredAmount) external;
function updateRequiredAmounts(address[] calldata _strategies, uint256[] calldata _requiredAmounts) external;
function updateRequiredAmount(address _strategy, uint256 _requiredAmount) external;
function removeStrategy(address _strategy) external;
function work(address _strategy) external returns (uint256 _credits);
function workForBond(address _strategy) external returns (uint256 _credits);
function workForTokens(address _strategy) external returns (uint256 _credits);
function forceWork(address _strategy) external;
}
文件 19 的 27:IV2Keeper.sol
pragma solidity >=0.6.8;
interface IV2Keeper {
function jobs() external view returns (address[] memory);
event JobAdded(address _job);
event JobRemoved(address _job);
function addJobs(address[] calldata _jobs) external;
function addJob(address _job) external;
function removeJob(address _job) external;
function tend(address _strategy) external;
function harvest(address _strategy) external;
}
文件 20 的 27:Keep3rAbstract.sol
pragma solidity 0.6.12;
import '@openzeppelin/contracts/math/SafeMath.sol';
import '../../interfaces/keep3r/IKeep3rV1.sol';
import '../../interfaces/keep3r/IKeep3r.sol';
abstract
contract Keep3r is IKeep3r {
using SafeMath for uint256;
IKeep3rV1 internal _Keep3r;
address public bond;
uint256 public minBond;
uint256 public earned;
uint256 public age;
bool public onlyEOA;
constructor(address _keep3r) public {
_setKeep3r(_keep3r);
}
function _setKeep3r(address _keep3r) internal {
_Keep3r = IKeep3rV1(_keep3r);
emit Keep3rSet(_keep3r);
}
function _setKeep3rRequirements(address _bond, uint256 _minBond, uint256 _earned, uint256 _age, bool _onlyEOA) internal {
bond = _bond;
minBond = _minBond;
earned = _earned;
age = _age;
onlyEOA = _onlyEOA;
emit Keep3rRequirementsSet(_bond, _minBond, _earned, _age, _onlyEOA);
}
modifier onlyKeeper() {
_isKeeper();
_;
}
function keep3r() external view override returns (address _keep3r) {
return address(_Keep3r);
}
modifier paysKeeper() {
_;
_paysKeeper(msg.sender);
}
function _isKeeper() internal {
if (onlyEOA) require(msg.sender == tx.origin, "keep3r::isKeeper:keeper-is-not-eoa");
if (minBond == 0 && earned == 0 && age == 0) {
require(_Keep3r.isKeeper(msg.sender), "keep3r::isKeeper:keeper-is-not-registered");
} else {
if (bond == address(0)) {
require(_Keep3r.isMinKeeper(msg.sender, minBond, earned, age), "keep3r::isKeeper:keeper-not-min-requirements");
} else {
require(_Keep3r.isBondedKeeper(msg.sender, bond, minBond, earned, age), "keep3r::isKeeper:keeper-not-custom-min-requirements");
}
}
}
function _getQuoteLimit(uint256 _gasUsed) internal view returns (uint256 _credits) {
return _Keep3r.KPRH().getQuoteLimit(_gasUsed.sub(gasleft()));
}
function _paysKeeper(address _keeper) internal {
_Keep3r.worked(_keeper);
}
function _paysKeeperInTokens(address _keeper, uint256 _amount) internal {
_Keep3r.receipt(address(_Keep3r), _keeper, _amount);
}
function _paysKeeperAmount(address _keeper, uint256 _amount) internal {
_Keep3r.workReceipt(_keeper, _amount);
}
function _paysKeeperCredit(address _credit, address _keeper, uint256 _amount) internal {
_Keep3r.receipt(_credit, _keeper, _amount);
}
function _paysKeeperEth(address _keeper, uint256 _amount) internal {
_Keep3r.receiptETH(_keeper, _amount);
}
}
文件 21 的 27:Machinery.sol
pragma solidity 0.6.12;
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import '../../interfaces/utils/IMachinery.sol';
import '../../interfaces/mechanics/IMechanicsRegistry.sol';
abstract
contract Machinery is IMachinery {
using EnumerableSet for EnumerableSet.AddressSet;
IMechanicsRegistry internal MechanicsRegistry;
constructor(address _mechanicsRegistry) public {
_setMechanicsRegistry(_mechanicsRegistry);
}
function _setMechanicsRegistry(address _mechanicsRegistry) internal {
MechanicsRegistry = IMechanicsRegistry(_mechanicsRegistry);
}
function mechanicsRegistry() external view override returns (address _mechanicRegistry) {
return address(MechanicsRegistry);
}
function isMechanic(address _mechanic) public view override returns (bool _isMechanic) {
return MechanicsRegistry.isMechanic(_mechanic);
}
}
文件 22 的 27:MachineryReady.sol
pragma solidity 0.6.12;
import './UtilsReady.sol';
import '../utils/Machinery.sol';
abstract
contract MachineryReady is UtilsReady, Machinery {
constructor(address _mechanicsRegistry) public Machinery(_mechanicsRegistry) UtilsReady() {
}
function setMechanicsRegistry(address _mechanicsRegistry) external override onlyGovernor {
_setMechanicsRegistry(_mechanicsRegistry);
}
modifier onlyGovernorOrMechanic() {
require(isGovernor(msg.sender) || isMechanic(msg.sender), "Machinery::onlyGovernorOrMechanic:invalid-msg-sender");
_;
}
}
文件 23 的 27:Pausable.sol
pragma solidity 0.6.12;
import '../../interfaces/utils/IPausable.sol';
abstract
contract Pausable is IPausable {
bool public paused;
constructor() public {}
modifier notPaused() {
require(!paused, 'paused');
_;
}
function _pause(bool _paused) internal {
require(paused != _paused, 'no-change');
paused = _paused;
emit Paused(_paused);
}
}
文件 24 的 27:SafeERC20.sol
pragma solidity >=0.6.0 <0.8.0;
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 25 的 27:SafeMath.sol
pragma solidity >=0.6.0 <0.8.0;
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
文件 26 的 27:UtilsReady.sol
pragma solidity 0.6.12;
import '../utils/Governable.sol';
import '../utils/CollectableDust.sol';
import '../utils/Pausable.sol';
abstract
contract UtilsReady is Governable, CollectableDust, Pausable {
constructor() public Governable(msg.sender) {
}
function setPendingGovernor(address _pendingGovernor) external override onlyGovernor {
_setPendingGovernor(_pendingGovernor);
}
function acceptGovernor() external override onlyPendingGovernor {
_acceptGovernor();
}
function sendDust(
address _to,
address _token,
uint256 _amount
) external override virtual onlyGovernor {
_sendDust(_to, _token, _amount);
}
function pause(bool _paused) external override onlyGovernor {
_pause(_paused);
}
}
文件 27 的 27:V2Keep3rJob.sol
pragma solidity 0.6.12;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "@lbertenasco/contract-utils/contracts/abstract/MachineryReady.sol";
import "@lbertenasco/contract-utils/interfaces/keep3r/IKeep3rV1Helper.sol";
import "@lbertenasco/contract-utils/contracts/keep3r/Keep3rAbstract.sol";
import "../../interfaces/jobs/v2/IV2Keeper.sol";
import "../../interfaces/jobs/v2/IV2Keep3rJob.sol";
import "../../interfaces/yearn/IBaseStrategy.sol";
import "../../interfaces/keep3r/IUniswapV2SlidingOracle.sol";
abstract contract V2Keep3rJob is MachineryReady, Keep3r, IV2Keep3rJob {
using SafeMath for uint256;
address public constant WETH = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
uint256 public constant PRECISION = 1_000;
uint256 public constant MAX_REWARD_MULTIPLIER = 1 * PRECISION;
uint256 public override rewardMultiplier = MAX_REWARD_MULTIPLIER;
IV2Keeper public V2Keeper;
address public keep3rHelper;
address public slidingOracle;
EnumerableSet.AddressSet internal _availableStrategies;
mapping(address => uint256) public requiredAmount;
mapping(address => uint256) public lastWorkAt;
uint256 public workCooldown;
constructor(
address _mechanicsRegistry,
address _keep3r,
address _bond,
uint256 _minBond,
uint256 _earned,
uint256 _age,
bool _onlyEOA,
address _keep3rHelper,
address _slidingOracle,
address _v2Keeper,
uint256 _workCooldown
) public MachineryReady(_mechanicsRegistry) Keep3r(_keep3r) {
_setKeep3rRequirements(_bond, _minBond, _earned, _age, _onlyEOA);
V2Keeper = IV2Keeper(_v2Keeper);
keep3rHelper = _keep3rHelper;
slidingOracle = _slidingOracle;
if (_workCooldown > 0) _setWorkCooldown(_workCooldown);
}
function setKeep3r(address _keep3r) external override onlyGovernor {
_setKeep3r(_keep3r);
}
function setKeep3rRequirements(
address _bond,
uint256 _minBond,
uint256 _earned,
uint256 _age,
bool _onlyEOA
) external override onlyGovernor {
_setKeep3rRequirements(_bond, _minBond, _earned, _age, _onlyEOA);
}
function setRewardMultiplier(uint256 _rewardMultiplier) external override onlyGovernorOrMechanic {
_setRewardMultiplier(_rewardMultiplier);
emit SetRewardMultiplier(_rewardMultiplier);
}
function _setRewardMultiplier(uint256 _rewardMultiplier) internal {
require(_rewardMultiplier <= MAX_REWARD_MULTIPLIER, "CrvStrategyKeep3rJob::set-reward-multiplier:multiplier-exceeds-max");
rewardMultiplier = _rewardMultiplier;
}
function setWorkCooldown(uint256 _workCooldown) external override onlyGovernorOrMechanic {
_setWorkCooldown(_workCooldown);
}
function _setWorkCooldown(uint256 _workCooldown) internal {
require(_workCooldown > 0, "V2Keep3rJob::set-work-cooldown:should-not-be-zero");
workCooldown = _workCooldown;
}
function addStrategies(address[] calldata _strategies, uint256[] calldata _requiredAmounts) external override onlyGovernorOrMechanic {
require(_strategies.length == _requiredAmounts.length, "V2Keep3rJob::add-strategies:strategies-required-amounts-different-length");
for (uint256 i; i < _strategies.length; i++) {
_addStrategy(_strategies[i], _requiredAmounts[i]);
}
}
function addStrategy(address _strategy, uint256 _requiredAmount) external override onlyGovernorOrMechanic {
_addStrategy(_strategy, _requiredAmount);
}
function _addStrategy(address _strategy, uint256 _requiredAmount) internal {
require(!_availableStrategies.contains(_strategy), "V2Keep3rJob::add-strategy:strategy-already-added");
_setRequiredAmount(_strategy, _requiredAmount);
emit StrategyAdded(_strategy, _requiredAmount);
_availableStrategies.add(_strategy);
}
function updateRequiredAmounts(address[] calldata _strategies, uint256[] calldata _requiredAmounts)
external
override
onlyGovernorOrMechanic
{
require(_strategies.length == _requiredAmounts.length, "V2Keep3rJob::update-strategies:strategies-required-amounts-different-length");
for (uint256 i; i < _strategies.length; i++) {
_updateRequiredAmount(_strategies[i], _requiredAmounts[i]);
}
}
function updateRequiredAmount(address _strategy, uint256 _requiredAmount) external override onlyGovernorOrMechanic {
_updateRequiredAmount(_strategy, _requiredAmount);
}
function _updateRequiredAmount(address _strategy, uint256 _requiredAmount) internal {
require(_availableStrategies.contains(_strategy), "V2Keep3rJob::update-required-amount:strategy-not-added");
_setRequiredAmount(_strategy, _requiredAmount);
emit StrategyModified(_strategy, _requiredAmount);
}
function removeStrategy(address _strategy) external override onlyGovernorOrMechanic {
require(_availableStrategies.contains(_strategy), "V2Keep3rJob::remove-strategy:strategy-not-added");
delete requiredAmount[_strategy];
_availableStrategies.remove(_strategy);
emit StrategyRemoved(_strategy);
}
function _setRequiredAmount(address _strategy, uint256 _requiredAmount) internal {
requiredAmount[_strategy] = _requiredAmount;
}
function strategies() public view override returns (address[] memory _strategies) {
_strategies = new address[](_availableStrategies.length());
for (uint256 i; i < _availableStrategies.length(); i++) {
_strategies[i] = _availableStrategies.at(i);
}
}
function _workable(address _strategy) internal view virtual returns (bool) {
require(_availableStrategies.contains(_strategy), "V2Keep3rJob::workable:strategy-not-added");
if (workCooldown == 0 || block.timestamp > lastWorkAt[_strategy].add(workCooldown)) return true;
return false;
}
function _getCallCosts(address _strategy) internal view returns (uint256 _kp3rCallCost, uint256 _ethCallCost) {
if (requiredAmount[_strategy] == 0) return (0, 0);
_kp3rCallCost = IKeep3rV1Helper(keep3rHelper).getQuoteLimit(requiredAmount[_strategy]);
_ethCallCost = IUniswapV2SlidingOracle(slidingOracle).current(address(_Keep3r), _kp3rCallCost, WETH);
}
function _workInternal(address _strategy, bool _workForTokens) internal returns (uint256 _credits) {
uint256 _initialGas = gasleft();
require(_workable(_strategy), "V2Keep3rJob::work:not-workable");
_work(_strategy);
_credits = _calculateCredits(_initialGas);
emit Worked(_strategy, msg.sender, _credits, _workForTokens);
}
function _calculateCredits(uint256 _initialGas) internal view returns (uint256 _credits) {
return _getQuoteLimit(_initialGas).mul(rewardMultiplier).div(PRECISION);
}
function forceWork(address _strategy) external override onlyGovernorOrMechanic {
_work(_strategy);
emit ForceWorked(_strategy);
}
function _work(address _strategy) internal virtual {}
}
{
"compilationTarget": {
"contracts/jobs/v2/HarvestV2Keep3rJob.sol": "HarvestV2Keep3rJob"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_mechanicsRegistry","type":"address"},{"internalType":"address","name":"_keep3r","type":"address"},{"internalType":"address","name":"_bond","type":"address"},{"internalType":"uint256","name":"_minBond","type":"uint256"},{"internalType":"uint256","name":"_earned","type":"uint256"},{"internalType":"uint256","name":"_age","type":"uint256"},{"internalType":"bool","name":"_onlyEOA","type":"bool"},{"internalType":"address","name":"_keep3rHelper","type":"address"},{"internalType":"address","name":"_slidingOracle","type":"address"},{"internalType":"address","name":"_v2Keeper","type":"address"},{"internalType":"uint256","name":"_workCooldown","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DustSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_strategy","type":"address"}],"name":"ForceWorked","type":"event"},{"anonymous":false,"inputs":[],"name":"GovernorAccepted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"keep3rHelper","type":"address"}],"name":"Keep3rHelperSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_bond","type":"address"},{"indexed":false,"internalType":"uint256","name":"_minBond","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_earned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_age","type":"uint256"},{"indexed":false,"internalType":"bool","name":"_onlyEOA","type":"bool"}],"name":"Keep3rRequirementsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"keep3r","type":"address"}],"name":"Keep3rSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"_paused","type":"bool"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pendingGovernor","type":"address"}],"name":"PendingGovernorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_rewardMultiplier","type":"uint256"}],"name":"SetRewardMultiplier","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"slidingOracle","type":"address"}],"name":"SlidingOracleSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_strategy","type":"address"},{"indexed":false,"internalType":"uint256","name":"_requiredAmount","type":"uint256"}],"name":"StrategyAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_strategy","type":"address"},{"indexed":false,"internalType":"uint256","name":"_requiredAmount","type":"uint256"}],"name":"StrategyModified","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_strategy","type":"address"}],"name":"StrategyRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_strategy","type":"address"},{"indexed":false,"internalType":"address","name":"_keeper","type":"address"},{"indexed":false,"internalType":"uint256","name":"_credits","type":"uint256"},{"indexed":false,"internalType":"bool","name":"_workForTokens","type":"bool"}],"name":"Worked","type":"event"},{"inputs":[],"name":"ETH_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_REWARD_MULTIPLIER","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRECISION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"V2Keeper","outputs":[{"internalType":"contract IV2Keeper","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_strategies","type":"address[]"},{"internalType":"uint256[]","name":"_requiredAmounts","type":"uint256[]"}],"name":"addStrategies","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"},{"internalType":"uint256","name":"_requiredAmount","type":"uint256"}],"name":"addStrategy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"age","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bond","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"}],"name":"forceWork","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"governor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"isGovernor","outputs":[{"internalType":"bool","name":"_isGovernor","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_mechanic","type":"address"}],"name":"isMechanic","outputs":[{"internalType":"bool","name":"_isMechanic","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"keep3r","outputs":[{"internalType":"address","name":"_keep3r","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"keep3rHelper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastWorkAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mechanicsRegistry","outputs":[{"internalType":"address","name":"_mechanicRegistry","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minBond","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"onlyEOA","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingGovernor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"}],"name":"removeStrategy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"requiredAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"sendDust","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_keep3r","type":"address"}],"name":"setKeep3r","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_bond","type":"address"},{"internalType":"uint256","name":"_minBond","type":"uint256"},{"internalType":"uint256","name":"_earned","type":"uint256"},{"internalType":"uint256","name":"_age","type":"uint256"},{"internalType":"bool","name":"_onlyEOA","type":"bool"}],"name":"setKeep3rRequirements","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_mechanicsRegistry","type":"address"}],"name":"setMechanicsRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_pendingGovernor","type":"address"}],"name":"setPendingGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rewardMultiplier","type":"uint256"}],"name":"setRewardMultiplier","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_workCooldown","type":"uint256"}],"name":"setWorkCooldown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"slidingOracle","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"strategies","outputs":[{"internalType":"address[]","name":"_strategies","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"},{"internalType":"uint256","name":"_requiredAmount","type":"uint256"}],"name":"updateRequiredAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_strategies","type":"address[]"},{"internalType":"uint256[]","name":"_requiredAmounts","type":"uint256[]"}],"name":"updateRequiredAmounts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"}],"name":"work","outputs":[{"internalType":"uint256","name":"_credits","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"workCooldown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"}],"name":"workForBond","outputs":[{"internalType":"uint256","name":"_credits","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"}],"name":"workForTokens","outputs":[{"internalType":"uint256","name":"_credits","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"}],"name":"workable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]