Skip to content

Commit ede54f4

Browse files
committed
Adds tracking of overall authorized amount for each application
1 parent fe1353a commit ede54f4

File tree

2 files changed

+251
-18
lines changed

2 files changed

+251
-18
lines changed

contracts/staking/TokenStaking.sol

+43-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
7474
struct ApplicationInfo {
7575
ApplicationStatus status;
7676
address panicButton;
77+
uint96 authorizedOverall;
7778
}
7879

7980
struct SlashingEvent {
@@ -328,6 +329,36 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
328329
emit ApplicationStatusChanged(application, ApplicationStatus.APPROVED);
329330
}
330331

332+
/// @notice Update `authorizedOverall` field for each application.
333+
/// Can only be called by Governance. `authorizedOVerall` should be
334+
/// equal to the sum of all authorization for particular application.
335+
// TODO remove after use
336+
function updateAuthorizedOverall(int96[] memory authorizedOverallValues)
337+
external
338+
onlyGovernance
339+
{
340+
require(
341+
authorizedOverallValues.length == applications.length,
342+
"Wrong input parameters"
343+
);
344+
for (uint256 i = 0; i < applications.length; i++) {
345+
address application = applications[i];
346+
ApplicationInfo storage applicationStruct = applicationInfo[
347+
application
348+
];
349+
int96 authorizedOverall = authorizedOverallValues[i];
350+
if (authorizedOverall >= 0) {
351+
applicationStruct.authorizedOverall += uint96(
352+
authorizedOverall
353+
);
354+
} else {
355+
applicationStruct.authorizedOverall -= uint96(
356+
-authorizedOverall
357+
);
358+
}
359+
}
360+
}
361+
331362
/// @notice Increases the authorization of the given staking provider for
332363
/// the given application by the given amount. Can only be called by
333364
/// the given staking provider’s authorizer.
@@ -370,6 +401,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
370401
);
371402
require(availableTValue >= amount, "Not enough stake to authorize");
372403
authorization.authorized += amount;
404+
applicationStruct.authorizedOverall += amount;
373405
emit AuthorizationIncreased(
374406
stakingProvider,
375407
application,
@@ -446,6 +478,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
446478

447479
uint96 fromAmount = authorization.authorized;
448480
authorization.authorized -= authorization.deauthorizing;
481+
applicationStruct.authorizedOverall -= authorization.deauthorizing;
449482
authorization.deauthorizing = 0;
450483
emit AuthorizationDecreaseApproved(
451484
stakingProvider,
@@ -469,8 +502,11 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
469502
address stakingProvider,
470503
address application
471504
) external override {
505+
ApplicationInfo storage applicationStruct = applicationInfo[
506+
application
507+
];
472508
require(
473-
applicationInfo[application].status == ApplicationStatus.DISABLED,
509+
applicationStruct.status == ApplicationStatus.DISABLED,
474510
"Application is not disabled"
475511
);
476512

@@ -483,6 +519,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
483519
require(fromAmount > 0, "Application is not authorized");
484520
authorization.authorized = 0;
485521
authorization.deauthorizing = 0;
522+
applicationStruct.authorizedOverall -= fromAmount;
486523

487524
emit AuthorizationDecreaseApproved(
488525
stakingProvider,
@@ -612,6 +649,8 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
612649
.authorizations[application];
613650
uint96 fromAmount = authorization.authorized;
614651
authorization.authorized += amount;
652+
//slither-disable-next-line reentrancy-benign
653+
applicationInfo[application].authorizedOverall += amount;
615654
emit AuthorizationIncreased(
616655
stakingProvider,
617656
application,
@@ -1116,6 +1155,9 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
11161155
if (authorization.authorized > totalStake) {
11171156
authorization.authorized = totalStake;
11181157
}
1158+
applicationInfo[authorizedApplication].authorizedOverall -=
1159+
fromAmount -
1160+
authorization.authorized;
11191161

11201162
bool successful = true;
11211163
//slither-disable-next-line calls-loop

0 commit comments

Comments
 (0)