-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeep3rAbstract.sol
96 lines (83 loc) · 3.06 KB
/
Keep3rAbstract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// SPDX-License-Identifier: MIT
pragma solidity 0.8.4;
import '../../interfaces/keep3r/IKeep3rV1.sol';
import '../../interfaces/keep3r/IKeep3r.sol';
abstract
contract Keep3r is IKeep3r {
IKeep3rV1 internal _Keep3r;
address public override bond;
uint256 public override minBond;
uint256 public override earned;
uint256 public override age;
bool public override onlyEOA;
constructor(address _keep3r) {
_setKeep3r(_keep3r);
}
// Setters
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);
}
// Modifiers
// Only checks if caller is a valid keeper, payment should be handled manually
modifier onlyKeeper(address _keeper) {
_isKeeper(_keeper);
_;
}
// view
function keep3r() external view override returns (address _keep3r) {
return address(_Keep3r);
}
// handles default payment after execution
modifier paysKeeper(address _keeper) {
_;
_paysKeeper(_keeper);
}
// Internal helpers
function _isKeeper(address _keeper) internal {
if (onlyEOA) require(_keeper == tx.origin, "keep3r::isKeeper:keeper-is-not-eoa");
if (minBond == 0 && earned == 0 && age == 0) {
// If no custom keeper requirements are set, just evaluate if sender is a registered keeper
require(_Keep3r.isKeeper(_keeper), "keep3r::isKeeper:keeper-is-not-registered");
} else {
if (bond == address(0)) {
// Checks for min KP3R, earned and age.
require(_Keep3r.isMinKeeper(_keeper, minBond, earned, age), "keep3r::isKeeper:keeper-not-min-requirements");
} else {
// Checks for min custom-bond, earned and age.
require(_Keep3r.isBondedKeeper(_keeper, bond, minBond, earned, age), "keep3r::isKeeper:keeper-not-custom-min-requirements");
}
}
}
function _getQuoteLimitFor(address _for, uint256 _initialGas) internal view returns (uint256 _credits) {
return _Keep3r.KPRH().getQuoteLimitFor(_for, _initialGas - gasleft());
}
// pays in bonded KP3R after execution
function _paysKeeper(address _keeper) internal {
_Keep3r.worked(_keeper);
}
// pays _amount in KP3R after execution
function _paysKeeperInTokens(address _keeper, uint256 _amount) internal {
_Keep3r.receipt(address(_Keep3r), _keeper, _amount);
}
// pays _amount in bonded KP3R after execution
function _paysKeeperAmount(address _keeper, uint256 _amount) internal {
_Keep3r.workReceipt(_keeper, _amount);
}
// pays _amount in _credit after execution
function _paysKeeperCredit(address _credit, address _keeper, uint256 _amount) internal {
_Keep3r.receipt(_credit, _keeper, _amount);
}
// pays _amount in ETH after execution
function _paysKeeperEth(address _keeper, uint256 _amount) internal {
_Keep3r.receiptETH(_keeper, _amount);
}
}