-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathController.sol
131 lines (112 loc) · 4.55 KB
/
Controller.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.10;
import "../interfaces/actions/IAction.sol";
import "../interfaces/IAddressProvider.sol";
import "../interfaces/IController.sol";
import "../interfaces/IStakerVault.sol";
import "../interfaces/pool/ILiquidityPool.sol";
import "../interfaces/tokenomics/IInflationManager.sol";
import "../libraries/AddressProviderHelpers.sol";
import "../libraries/UncheckedMath.sol";
import "./utils/Preparable.sol";
import "./access/Authorization.sol";
contract Controller is IController, Authorization, Preparable {
using UncheckedMath for uint256;
using AddressProviderHelpers for IAddressProvider;
IAddressProvider public immutable override addressProvider;
IInflationManager public inflationManager;
bytes32 internal constant _KEEPER_REQUIRED_STAKED_BKD = "KEEPER_REQUIRED_STAKED_BKD";
constructor(IAddressProvider _addressProvider)
Authorization(_addressProvider.getRoleManager())
{
addressProvider = _addressProvider;
}
function setInflationManager(address _inflationManager) external onlyGovernance {
require(address(inflationManager) == address(0), Error.ADDRESS_ALREADY_SET);
require(_inflationManager != address(0), Error.INVALID_ARGUMENT);
inflationManager = IInflationManager(_inflationManager);
}
function addStakerVault(address stakerVault)
external
override
onlyRoles2(Roles.GOVERNANCE, Roles.POOL_FACTORY)
returns (bool)
{
if (!addressProvider.addStakerVault(stakerVault)) {
return false;
}
if (address(inflationManager) != address(0)) {
address lpGauge = IStakerVault(stakerVault).getLpGauge();
if (lpGauge != address(0)) {
inflationManager.whitelistGauge(lpGauge);
}
}
return true;
}
/**
* @notice Delists pool.
* @param pool Address of pool to delist.
* @return `true` if successful.
*/
function removePool(address pool) external override onlyGovernance returns (bool) {
if (!addressProvider.removePool(pool)) {
return false;
}
address lpToken = ILiquidityPool(pool).getLpToken();
if (address(inflationManager) != address(0)) {
(bool exists, address stakerVault) = addressProvider.tryGetStakerVault(lpToken);
if (exists) {
inflationManager.removeStakerVaultFromInflation(stakerVault, lpToken);
}
}
return true;
}
/**
* @notice Prepares the minimum amount of staked BKD required by a keeper
*/
function prepareKeeperRequiredStakedBKD(uint256 amount) external override onlyGovernance {
require(addressProvider.getBKDLocker() != address(0), Error.ZERO_ADDRESS_NOT_ALLOWED);
_prepare(_KEEPER_REQUIRED_STAKED_BKD, amount);
}
/**
* @notice Resets the minimum amount of staked BKD required by a keeper
*/
function resetKeeperRequiredStakedBKD() external override onlyGovernance {
_resetUInt256Config(_KEEPER_REQUIRED_STAKED_BKD);
}
/**
* @notice Sets the minimum amount of staked BKD required by a keeper to the prepared value
*/
function executeKeeperRequiredStakedBKD() external override {
_executeUInt256(_KEEPER_REQUIRED_STAKED_BKD);
}
/**
* @notice Returns true if the given keeper has enough staked BKD to execute actions
*/
function canKeeperExecuteAction(address keeper) external view override returns (bool) {
uint256 requiredBKD = getKeeperRequiredStakedBKD();
return
requiredBKD == 0 ||
IERC20(addressProvider.getBKDLocker()).balanceOf(keeper) >= requiredBKD;
}
/**
* @return Returns the minimum amount of staked BKD required by a keeper
*/
function getKeeperRequiredStakedBKD() public view override returns (uint256) {
return currentUInts256[_KEEPER_REQUIRED_STAKED_BKD];
}
/**
* @return the total amount of ETH require by `payer` to cover the fees for
* positions registered in all actions
*/
function getTotalEthRequiredForGas(address payer) external view override returns (uint256) {
// solhint-disable-previous-line ordering
uint256 totalEthRequired;
address[] memory actions = addressProvider.allActions();
uint256 numActions = actions.length;
for (uint256 i; i < numActions; i = i.uncheckedInc()) {
totalEthRequired += IAction(actions[i]).getEthRequiredForGas(payer);
}
return totalEthRequired;
}
}