Skip to content

Commit

Permalink
Adds tracking of overall authorized amount for each application
Browse files Browse the repository at this point in the history
  • Loading branch information
vzotova committed Mar 23, 2024
1 parent fe1353a commit ede54f4
Show file tree
Hide file tree
Showing 2 changed files with 251 additions and 18 deletions.
44 changes: 43 additions & 1 deletion contracts/staking/TokenStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
struct ApplicationInfo {
ApplicationStatus status;
address panicButton;
uint96 authorizedOverall;
}

struct SlashingEvent {
Expand Down Expand Up @@ -328,6 +329,36 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
emit ApplicationStatusChanged(application, ApplicationStatus.APPROVED);
}

/// @notice Update `authorizedOverall` field for each application.
/// Can only be called by Governance. `authorizedOVerall` should be
/// equal to the sum of all authorization for particular application.
// TODO remove after use
function updateAuthorizedOverall(int96[] memory authorizedOverallValues)
external
onlyGovernance
{
require(
authorizedOverallValues.length == applications.length,
"Wrong input parameters"
);
for (uint256 i = 0; i < applications.length; i++) {
address application = applications[i];
ApplicationInfo storage applicationStruct = applicationInfo[
application
];
int96 authorizedOverall = authorizedOverallValues[i];
if (authorizedOverall >= 0) {
applicationStruct.authorizedOverall += uint96(
authorizedOverall
);
} else {
applicationStruct.authorizedOverall -= uint96(
-authorizedOverall
);
}
}
}

/// @notice Increases the authorization of the given staking provider for
/// the given application by the given amount. Can only be called by
/// the given staking provider’s authorizer.
Expand Down Expand Up @@ -370,6 +401,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
);
require(availableTValue >= amount, "Not enough stake to authorize");
authorization.authorized += amount;
applicationStruct.authorizedOverall += amount;
emit AuthorizationIncreased(
stakingProvider,
application,
Expand Down Expand Up @@ -446,6 +478,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {

uint96 fromAmount = authorization.authorized;
authorization.authorized -= authorization.deauthorizing;
applicationStruct.authorizedOverall -= authorization.deauthorizing;
authorization.deauthorizing = 0;
emit AuthorizationDecreaseApproved(
stakingProvider,
Expand All @@ -469,8 +502,11 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
address stakingProvider,
address application
) external override {
ApplicationInfo storage applicationStruct = applicationInfo[
application
];
require(
applicationInfo[application].status == ApplicationStatus.DISABLED,
applicationStruct.status == ApplicationStatus.DISABLED,
"Application is not disabled"
);

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

emit AuthorizationDecreaseApproved(
stakingProvider,
Expand Down Expand Up @@ -612,6 +649,8 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
.authorizations[application];
uint96 fromAmount = authorization.authorized;
authorization.authorized += amount;
//slither-disable-next-line reentrancy-benign
applicationInfo[application].authorizedOverall += amount;
emit AuthorizationIncreased(
stakingProvider,
application,
Expand Down Expand Up @@ -1116,6 +1155,9 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
if (authorization.authorized > totalStake) {
authorization.authorized = totalStake;
}
applicationInfo[authorizedApplication].authorizedOverall -=
fromAmount -
authorization.authorized;

bool successful = true;
//slither-disable-next-line calls-loop
Expand Down
Loading

0 comments on commit ede54f4

Please sign in to comment.