@@ -6,14 +6,16 @@ contract RateLimitsUpgradeable {
6
6
*
7
7
* @param timestamp The timestamp of the last mint/burn
8
8
* @param ratePerSecond The rate per second one can mint/burn
9
- * @param maxLimit The max limit
9
+ * @param dailyLimit The max limit per day
10
10
* @param currentLimit The current limit
11
+ * @param maxLimit the maximum someone can set the currentLimit to;
11
12
*/
12
13
struct RateLimitParameters {
13
14
uint256 timestamp;
14
15
uint256 ratePerSecond;
15
- uint256 maxLimit ;
16
+ uint256 dailyLimit ;
16
17
uint256 currentLimit;
18
+ uint256 maxLimit; // Should we cap this ? it is so that an admin can set a current higher than the daily but only up to a certain amount.
17
19
}
18
20
19
21
/**
@@ -50,6 +52,32 @@ contract RateLimitsUpgradeable {
50
52
}
51
53
}
52
54
55
+ /**
56
+ * @notice set the maxlimit of a minter
57
+ * @param account The address of the minter who is being changed
58
+ * @param newMax The new maxLimit
59
+ */
60
+ function _setMinterMaxLimit (address account , uint256 newMax ) internal {
61
+ RateLimitParameters storage m = _getRateLimitsStorage ()
62
+ ._limits[account]
63
+ .mint;
64
+
65
+ m.maxLimit = newMax;
66
+ }
67
+
68
+ /**
69
+ * @notice set the maxlimit of a burner
70
+ * @param account The address of the burner who is being changed
71
+ * @param newMax The new maxLimit
72
+ */
73
+ function _setBurnerMaxLimit (address account , uint256 newMax ) internal {
74
+ RateLimitParameters storage b = _getRateLimitsStorage ()
75
+ ._limits[account]
76
+ .burn;
77
+
78
+ b.maxLimit = newMax;
79
+ }
80
+
53
81
/**
54
82
* @notice Uses the limit of a minter
55
83
* @param account The address of the minter who is being changed
@@ -80,6 +108,44 @@ contract RateLimitsUpgradeable {
80
108
b.currentLimit = currentLimit - change;
81
109
}
82
110
111
+ /**
112
+ * @notice Resets the minting limit for a given account to a specified value
113
+ * @param account The address of the minter whose limit is to be reset
114
+ * @param limit The new current limit to be set for minting
115
+ */
116
+ function _resetMinterCurrentLimit (
117
+ address account ,
118
+ uint256 limit
119
+ ) internal {
120
+ RateLimitParameters storage m = _getRateLimitsStorage ()
121
+ ._limits[account]
122
+ .mint;
123
+
124
+ require (limit <= m.maxLimit, "too high " );
125
+
126
+ m.currentLimit = limit;
127
+ m.timestamp = block .timestamp ;
128
+ }
129
+
130
+ /**
131
+ * @notice Resets the burning limit for a given account to a specified value
132
+ * @param account The address of the burner whose limit is to be reset
133
+ * @param limit The new current limit to be set for burning
134
+ */
135
+ function _resetBurnerCurrentLimit (
136
+ address account ,
137
+ uint256 limit
138
+ ) internal {
139
+ RateLimitParameters storage b = _getRateLimitsStorage ()
140
+ ._limits[account]
141
+ .burn;
142
+
143
+ require (limit <= b.maxLimit, "too high " );
144
+
145
+ b.currentLimit = limit;
146
+ b.timestamp = block .timestamp ;
147
+ }
148
+
83
149
/**
84
150
* @notice Updates the limit of a minter
85
151
* @param account The address of the minter we are setting the limit too
@@ -90,9 +156,11 @@ contract RateLimitsUpgradeable {
90
156
._limits[account]
91
157
.mint;
92
158
93
- uint256 oldLimit = m.maxLimit;
159
+ require (limit <= m.maxLimit, "too high " );
160
+
161
+ uint256 oldLimit = m.dailyLimit;
94
162
uint256 currentLimit = mintingCurrentLimitOf (account);
95
- m.maxLimit = limit;
163
+ m.dailyLimit = limit;
96
164
97
165
m.currentLimit = _calculateNewCurrentLimit (
98
166
limit,
@@ -114,9 +182,11 @@ contract RateLimitsUpgradeable {
114
182
._limits[account]
115
183
.burn;
116
184
117
- uint256 oldLimit = b.maxLimit;
185
+ require (limit <= b.maxLimit, "too high " );
186
+
187
+ uint256 oldLimit = b.dailyLimit;
118
188
uint256 currentLimit = burningCurrentLimitOf (account);
119
- b.maxLimit = limit;
189
+ b.dailyLimit = limit;
120
190
121
191
b.currentLimit = _calculateNewCurrentLimit (
122
192
limit,
@@ -140,7 +210,7 @@ contract RateLimitsUpgradeable {
140
210
RateLimitParameters storage m = _getRateLimitsStorage ()
141
211
._limits[account]
142
212
.mint;
143
- limit = m.maxLimit ;
213
+ limit = m.dailyLimit ;
144
214
}
145
215
146
216
/**
@@ -155,7 +225,7 @@ contract RateLimitsUpgradeable {
155
225
RateLimitParameters storage b = _getRateLimitsStorage ()
156
226
._limits[account]
157
227
.burn;
158
- limit = b.maxLimit ;
228
+ limit = b.dailyLimit ;
159
229
}
160
230
161
231
/**
@@ -172,7 +242,7 @@ contract RateLimitsUpgradeable {
172
242
.mint;
173
243
limit = _getCurrentLimit (
174
244
m.currentLimit,
175
- m.maxLimit ,
245
+ m.dailyLimit ,
176
246
m.timestamp,
177
247
m.ratePerSecond
178
248
);
@@ -192,7 +262,7 @@ contract RateLimitsUpgradeable {
192
262
.burn;
193
263
limit = _getCurrentLimit (
194
264
b.currentLimit,
195
- b.maxLimit ,
265
+ b.dailyLimit ,
196
266
b.timestamp,
197
267
b.ratePerSecond
198
268
);
@@ -228,27 +298,27 @@ contract RateLimitsUpgradeable {
228
298
* @notice Gets the current limit
229
299
*
230
300
* @param _currentLimit The current limit
231
- * @param _maxLimit The max limit
301
+ * @param _dailyLimit The max limit
232
302
* @param _timestamp The timestamp of the last update
233
303
* @param _ratePerSecond The rate per second
234
304
* @return _limit The current limit
235
305
*/
236
306
function _getCurrentLimit (
237
307
uint256 _currentLimit ,
238
- uint256 _maxLimit ,
308
+ uint256 _dailyLimit ,
239
309
uint256 _timestamp ,
240
310
uint256 _ratePerSecond
241
311
) internal view returns (uint256 _limit ) {
242
312
_limit = _currentLimit;
243
- if (_limit == _maxLimit ) {
313
+ if (_limit >= _dailyLimit ) {
244
314
return _limit;
245
315
} else if (_timestamp + _DURATION <= block .timestamp ) {
246
- _limit = _maxLimit ;
316
+ _limit = _dailyLimit ;
247
317
} else if (_timestamp + _DURATION > block .timestamp ) {
248
318
uint256 _timePassed = block .timestamp - _timestamp;
249
319
uint256 _calculatedLimit = _limit + (_timePassed * _ratePerSecond);
250
- _limit = _calculatedLimit > _maxLimit
251
- ? _maxLimit
320
+ _limit = _calculatedLimit > _dailyLimit
321
+ ? _dailyLimit
252
322
: _calculatedLimit;
253
323
}
254
324
}
0 commit comments