-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeeperProxy.sol
More file actions
118 lines (93 loc) · 2.94 KB
/
KeeperProxy.sol
File metadata and controls
118 lines (93 loc) · 2.94 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
import {
SafeMath,
Address
} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import {VaultAPI} from "@yearnvaults/contracts/BaseStrategy.sol";
/**
* This interface is here for the keeper proxy to interact
* with the strategy
*/
interface CoreStrategyAPI {
function harvestTrigger(uint256 callCost) external view returns (bool);
function harvest() external;
function calcDebtRatio() external view returns (uint256);
function calcCollateral() external view returns (uint256);
function rebalanceDebt() external;
function rebalanceCollateral() external;
function strategist() external view returns (address);
}
/**
* @title Robovault Keeper Proxy
* @author robovault
* @notice
* KeeperProxy implements a proxy for Robovaults CoreStrategy. The proxy provide
* More flexibility will roles, allowing for multiple addresses to be granted
* keeper permissions.
*
*/
contract KeeperProxy {
using Address for address;
using SafeMath for uint256;
CoreStrategyAPI public strategy;
address public strategist;
mapping(address => bool) public keepers;
address[] public keepersList;
constructor(address _strategy) public {
setStrategyInternal(_strategy);
}
function _onlyStrategist() internal {
require(msg.sender == address(strategist));
}
/**
* @notice
* Only the strategist and approved keepers can call authorized
* functions
*/
function _onlyKeepers() internal {
require(
keepers[msg.sender] == true || msg.sender == address(strategist),
"!authorized"
);
}
function setStrategy(address _strategy) external {
_onlyStrategist();
setStrategyInternal(_strategy);
}
function addKeeper(address _newKeeper) external {
_onlyStrategist();
keepers[_newKeeper] = true;
keepersList.push(_newKeeper);
}
function removeKeeper(address _removeKeeper) external {
_onlyStrategist();
keepers[_removeKeeper] = false;
}
function harvestTrigger(uint256 _callCost) external view returns (bool) {
return strategy.harvestTrigger(_callCost);
}
function harvest() external {
_onlyKeepers();
strategy.harvest();
}
function calcDebtRatio() external view returns (uint256) {
return strategy.calcDebtRatio();
}
function rebalanceDebt() external {
_onlyKeepers();
strategy.rebalanceDebt();
}
function calcCollateral() external view returns (uint256) {
return strategy.calcCollateral();
}
function rebalanceCollateral() external {
_onlyKeepers();
strategy.rebalanceCollateral();
}
function setStrategyInternal(address _strategy) internal {
strategy = CoreStrategyAPI(_strategy);
strategist = strategy.strategist();
}
}