-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLRTConfig.sol
180 lines (157 loc) · 6.01 KB
/
LRTConfig.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.21;
import { UtilLib } from "./utils/UtilLib.sol";
import { LRTConstants } from "./utils/LRTConstants.sol";
import { ILRTConfig } from "./interfaces/ILRTConfig.sol";
import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
/// @title LRTConfig - LRT Config Contract
/// @notice Handles LRT configuration
contract LRTConfig is ILRTConfig, AccessControlUpgradeable {
mapping(bytes32 tokenKey => address tokenAddress) public tokenMap;
mapping(bytes32 contractKey => address contractAddress) public contractMap;
mapping(address token => bool isSupported) public isSupportedAsset;
mapping(address token => uint256 amount) public depositLimitByAsset;
mapping(address token => address strategy) public override assetStrategy;
address[] public supportedAssetList;
address public rsETH;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
modifier onlySupportedAsset(address asset) {
if (!isSupportedAsset[asset]) {
revert AssetNotSupported();
}
_;
}
/// @dev Initializes the contract
/// @param admin Admin address
/// @param stETH stETH address
/// @param rETH rETH address
/// @param cbETH cbETH address
/// @param rsETH_ cbETH address
function initialize(
address admin,
address stETH,
address rETH,
address cbETH,
address rsETH_
)
external
initializer
{
UtilLib.checkNonZeroAddress(admin);
UtilLib.checkNonZeroAddress(stETH);
UtilLib.checkNonZeroAddress(rETH);
UtilLib.checkNonZeroAddress(cbETH);
UtilLib.checkNonZeroAddress(rsETH_);
__AccessControl_init();
_setToken(LRTConstants.ST_ETH_TOKEN, stETH);
_setToken(LRTConstants.R_ETH_TOKEN, rETH);
_setToken(LRTConstants.CB_ETH_TOKEN, cbETH);
_addNewSupportedAsset(stETH, 100_000 ether);
_addNewSupportedAsset(rETH, 100_000 ether);
_addNewSupportedAsset(cbETH, 100_000 ether);
_grantRole(DEFAULT_ADMIN_ROLE, admin);
rsETH = rsETH_;
}
/// @dev Adds a new supported asset
/// @param asset Asset address
/// @param depositLimit Deposit limit for the asset
function addNewSupportedAsset(address asset, uint256 depositLimit) external onlyRole(LRTConstants.MANAGER) {
_addNewSupportedAsset(asset, depositLimit);
}
/// @dev private function to add a new supported asset
/// @param asset Asset address
/// @param depositLimit Deposit limit for the asset
function _addNewSupportedAsset(address asset, uint256 depositLimit) private {
UtilLib.checkNonZeroAddress(asset);
if (isSupportedAsset[asset]) {
revert AssetAlreadySupported();
}
isSupportedAsset[asset] = true;
supportedAssetList.push(asset);
depositLimitByAsset[asset] = depositLimit;
emit AddedNewSupportedAsset(asset, depositLimit);
}
/// @dev Updates the deposit limit for an asset
/// @param asset Asset address
/// @param depositLimit New deposit limit
function updateAssetDepositLimit(
address asset,
uint256 depositLimit
)
external
onlyRole(LRTConstants.MANAGER)
onlySupportedAsset(asset)
{
depositLimitByAsset[asset] = depositLimit;
emit AssetDepositLimitUpdate(asset, depositLimit);
}
/// @dev Updates the strategy for an asset
/// @param asset Asset address
/// @param strategy New strategy address
function updateAssetStrategy(
address asset,
address strategy
)
external
onlyRole(DEFAULT_ADMIN_ROLE)
onlySupportedAsset(asset)
{
UtilLib.checkNonZeroAddress(strategy);
if (assetStrategy[asset] == strategy) {
revert ValueAlreadyInUse();
}
assetStrategy[asset] = strategy;
}
/*//////////////////////////////////////////////////////////////
GETTERS
//////////////////////////////////////////////////////////////*/
function getLSTToken(bytes32 tokenKey) external view override returns (address) {
return tokenMap[tokenKey];
}
function getContract(bytes32 contractKey) external view override returns (address) {
return contractMap[contractKey];
}
function getSupportedAssetList() external view override returns (address[] memory) {
return supportedAssetList;
}
/*//////////////////////////////////////////////////////////////
SETTERS
//////////////////////////////////////////////////////////////*/
/// @dev Sets the rsETH contract address. Only callable by the admin
/// @param rsETH_ rsETH contract address
function setRSETH(address rsETH_) external onlyRole(DEFAULT_ADMIN_ROLE) {
UtilLib.checkNonZeroAddress(rsETH_);
rsETH = rsETH_;
}
function setToken(bytes32 tokenKey, address assetAddress) external onlyRole(DEFAULT_ADMIN_ROLE) {
_setToken(tokenKey, assetAddress);
}
/// @dev private function to set a token
/// @param key Token key
/// @param val Token address
function _setToken(bytes32 key, address val) private {
UtilLib.checkNonZeroAddress(val);
if (tokenMap[key] == val) {
revert ValueAlreadyInUse();
}
tokenMap[key] = val;
emit SetToken(key, val);
}
function setContract(bytes32 contractKey, address contractAddress) external onlyRole(DEFAULT_ADMIN_ROLE) {
_setContract(contractKey, contractAddress);
}
/// @dev private function to set a contract
/// @param key Contract key
/// @param val Contract address
function _setContract(bytes32 key, address val) private {
UtilLib.checkNonZeroAddress(val);
if (contractMap[key] == val) {
revert ValueAlreadyInUse();
}
contractMap[key] = val;
emit SetContract(key, val);
}
}