Skip to content

Commit 417942f

Browse files
committed
Removes ability to create new requests for decrease authorization
1 parent d78cbda commit 417942f

File tree

4 files changed

+122
-541
lines changed

4 files changed

+122
-541
lines changed

contracts/staking/IStaking.sol

-15
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ interface IStaking {
4545
//
4646
//
4747

48-
/// @notice Allows the Governance to approve the particular application
49-
/// before individual stake authorizers are able to authorize it.
50-
function approveApplication(address application) external;
51-
5248
/// @notice Requests decrease of the authorization for the given staking
5349
/// provider on the given application by the provided amount.
5450
/// It may not change the authorized amount immediatelly. When
@@ -66,17 +62,6 @@ interface IStaking {
6662
uint96 amount
6763
) external;
6864

69-
/// @notice Requests decrease of all authorizations for the given staking
70-
/// provider on all applications by all authorized amount.
71-
/// It may not change the authorized amount immediatelly. When
72-
/// it happens depends on the application. Can only be called by the
73-
/// given staking provider’s authorizer. Overwrites pending
74-
/// authorization decrease for the given staking provider and
75-
/// application.
76-
/// @dev Calls `authorizationDecreaseRequested(address stakingProvider, uint256 amount)`
77-
/// for each authorized application. See `IApplication`.
78-
function requestAuthorizationDecrease(address stakingProvider) external;
79-
8065
/// @notice Called by the application at its discretion to approve the
8166
/// previously requested authorization decrease request. Can only be
8267
/// called by the application that was previously requested to

contracts/staking/TokenStaking.sol

+5-94
Original file line numberDiff line numberDiff line change
@@ -260,66 +260,6 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
260260
//
261261
//
262262

263-
/// @notice Allows the Governance to approve the particular application
264-
/// before individual stake authorizers are able to authorize it.
265-
function approveApplication(address application)
266-
external
267-
override
268-
onlyGovernance
269-
{
270-
require(application != address(0), "Parameters must be specified");
271-
ApplicationInfo storage info = applicationInfo[application];
272-
require(
273-
info.status == ApplicationStatus.NOT_APPROVED ||
274-
info.status == ApplicationStatus.PAUSED,
275-
"Can't approve application"
276-
);
277-
278-
if (info.status == ApplicationStatus.NOT_APPROVED) {
279-
applications.push(application);
280-
}
281-
info.status = ApplicationStatus.APPROVED;
282-
emit ApplicationStatusChanged(application, ApplicationStatus.APPROVED);
283-
}
284-
285-
/// @notice Requests decrease of all authorizations for the given staking
286-
/// provider on all applications by all authorized amount.
287-
/// It may not change the authorized amount immediatelly. When
288-
/// it happens depends on the application. Can only be called by the
289-
/// given staking provider’s authorizer. Overwrites pending
290-
/// authorization decrease for the given staking provider and
291-
/// application.
292-
/// @dev Calls `authorizationDecreaseRequested` callback
293-
/// for each authorized application. See `IApplication`.
294-
function requestAuthorizationDecrease(address stakingProvider) external {
295-
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
296-
stakingProvider
297-
];
298-
uint96 deauthorizing = 0;
299-
for (
300-
uint256 i = 0;
301-
i < stakingProviderStruct.authorizedApplications.length;
302-
i++
303-
) {
304-
address application = stakingProviderStruct.authorizedApplications[
305-
i
306-
];
307-
uint96 authorized = stakingProviderStruct
308-
.authorizations[application]
309-
.authorized;
310-
if (authorized > 0) {
311-
requestAuthorizationDecrease(
312-
stakingProvider,
313-
application,
314-
authorized
315-
);
316-
deauthorizing += authorized;
317-
}
318-
}
319-
320-
require(deauthorizing > 0, "Nothing was authorized");
321-
}
322-
323263
/// @notice Called by the application at its discretion to approve the
324264
/// previously requested authorization decrease request. Can only be
325265
/// called by the application that was previously requested to
@@ -399,8 +339,8 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
399339
/// Can be called only by the delegation owner or the staking
400340
/// provider.
401341
function optOutDecreaseAuthorization(address stakingProvider, uint96 amount)
402-
external
403-
onlyOwnerOrStakingProvider(stakingProvider)
342+
public
343+
onlyAuthorizerOf(stakingProvider)
404344
{
405345
require(amount > 0, "Parameters must be specified");
406346
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
@@ -682,40 +622,10 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
682622
/// application. See `IApplication`.
683623
function requestAuthorizationDecrease(
684624
address stakingProvider,
685-
address application,
625+
address,
686626
uint96 amount
687627
) public override onlyAuthorizerOf(stakingProvider) {
688-
ApplicationInfo storage applicationStruct = applicationInfo[
689-
application
690-
];
691-
require(
692-
applicationStruct.status == ApplicationStatus.APPROVED,
693-
"Application is not approved"
694-
);
695-
696-
require(amount > 0, "Parameters must be specified");
697-
698-
AppAuthorization storage authorization = stakingProviders[
699-
stakingProvider
700-
].authorizations[application];
701-
require(
702-
authorization.authorized >= amount,
703-
"Amount exceeds authorized"
704-
);
705-
706-
authorization.deauthorizing = amount;
707-
uint96 deauthorizingTo = authorization.authorized - amount;
708-
emit AuthorizationDecreaseRequested(
709-
stakingProvider,
710-
application,
711-
authorization.authorized,
712-
deauthorizingTo
713-
);
714-
IApplication(application).authorizationDecreaseRequested(
715-
stakingProvider,
716-
authorization.authorized,
717-
deauthorizingTo
718-
);
628+
optOutDecreaseAuthorization(stakingProvider, amount);
719629
}
720630

721631
/// @notice Forced deauthorization of Beta staker.
@@ -1016,6 +926,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
1016926
}
1017927
}
1018928

929+
// slither-disable-next-line dead-code
1019930
function skipApplication(address application)
1020931
internal
1021932
pure

contracts/test/TokenStakingTestSet.sol

+87
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,55 @@ contract ExtendedTokenStaking is TokenStaking {
259259
token.safeTransferFrom(msg.sender, address(this), reward);
260260
}
261261

262+
/// @notice Allows the Governance to approve the particular application
263+
/// before individual stake authorizers are able to authorize it.
264+
function approveApplication(address application) external {
265+
require(application != address(0), "Parameters must be specified");
266+
ApplicationInfo storage info = applicationInfo[application];
267+
require(
268+
info.status == ApplicationStatus.NOT_APPROVED ||
269+
info.status == ApplicationStatus.PAUSED,
270+
"Can't approve application"
271+
);
272+
273+
if (info.status == ApplicationStatus.NOT_APPROVED) {
274+
applications.push(application);
275+
}
276+
info.status = ApplicationStatus.APPROVED;
277+
emit ApplicationStatusChanged(application, ApplicationStatus.APPROVED);
278+
}
279+
280+
function legacyRequestAuthorizationDecrease(address stakingProvider)
281+
external
282+
{
283+
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
284+
stakingProvider
285+
];
286+
uint96 deauthorizing = 0;
287+
for (
288+
uint256 i = 0;
289+
i < stakingProviderStruct.authorizedApplications.length;
290+
i++
291+
) {
292+
address application = stakingProviderStruct.authorizedApplications[
293+
i
294+
];
295+
uint96 authorized = stakingProviderStruct
296+
.authorizations[application]
297+
.authorized;
298+
if (authorized > 0) {
299+
legacyRequestAuthorizationDecrease(
300+
stakingProvider,
301+
application,
302+
authorized
303+
);
304+
deauthorizing += authorized;
305+
}
306+
}
307+
308+
require(deauthorizing > 0, "Nothing was authorized");
309+
}
310+
262311
function getAuthorizedApplications(address stakingProvider)
263312
external
264313
view
@@ -277,6 +326,44 @@ contract ExtendedTokenStaking is TokenStaking {
277326
.deauthorizing;
278327
}
279328

329+
function legacyRequestAuthorizationDecrease(
330+
address stakingProvider,
331+
address application,
332+
uint96 amount
333+
) public {
334+
ApplicationInfo storage applicationStruct = applicationInfo[
335+
application
336+
];
337+
require(
338+
applicationStruct.status == ApplicationStatus.APPROVED,
339+
"Application is not approved"
340+
);
341+
342+
require(amount > 0, "Parameters must be specified");
343+
344+
AppAuthorization storage authorization = stakingProviders[
345+
stakingProvider
346+
].authorizations[application];
347+
require(
348+
authorization.authorized >= amount,
349+
"Amount exceeds authorized"
350+
);
351+
352+
authorization.deauthorizing = amount;
353+
uint96 deauthorizingTo = authorization.authorized - amount;
354+
emit AuthorizationDecreaseRequested(
355+
stakingProvider,
356+
application,
357+
authorization.authorized,
358+
deauthorizingTo
359+
);
360+
IApplication(application).authorizationDecreaseRequested(
361+
stakingProvider,
362+
authorization.authorized,
363+
deauthorizingTo
364+
);
365+
}
366+
280367
/// @notice Creates new checkpoints due to an increment of a stakers' stake
281368
/// @param _delegator Address of the staking provider acting as delegator
282369
/// @param _amount Amount of T to increment

0 commit comments

Comments
 (0)