Skip to content

Commit 97c3f98

Browse files
authored
Merge pull request #172 from threshold-network/pre-unlock
Pre-unlock updates
2 parents e5c41a1 + 92b92b7 commit 97c3f98

File tree

2 files changed

+252
-977
lines changed

2 files changed

+252
-977
lines changed

contracts/staking/TokenStaking.sol

Lines changed: 30 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -330,53 +330,6 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
330330
cleanAuthorizedApplications(stakingProviderStruct, 1);
331331
}
332332

333-
/// @notice Forced deauthorization of stake above 15m T.
334-
/// Can be called by anyone.
335-
function forceAuthorizationCap(address[] memory _stakingProviders)
336-
external
337-
{
338-
require(_stakingProviders.length > 0, "Wrong input parameters");
339-
for (uint256 i = 0; i < _stakingProviders.length; i++) {
340-
forceAuthorizationCap(_stakingProviders[i]);
341-
}
342-
}
343-
344-
/// @notice Allows to instantly deauthorize up to 50% of max authorization.
345-
/// Can be called only by the delegation owner or the staking
346-
/// provider.
347-
function optOutDecreaseAuthorization(address stakingProvider, uint96 amount)
348-
public
349-
onlyAuthorizerOf(stakingProvider)
350-
{
351-
require(amount > 0, "Parameters must be specified");
352-
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
353-
stakingProvider
354-
];
355-
(
356-
uint96 availableToOptOut,
357-
uint96 maxAuthorization
358-
) = getAvailableOptOutAmount(stakingProvider, stakingProviderStruct);
359-
if (maxAuthorization > MAX_STAKE) {
360-
forceDecreaseAuthorization(stakingProvider, MAX_STAKE);
361-
maxAuthorization = MAX_STAKE;
362-
availableToOptOut = HALF_MAX_STAKE;
363-
}
364-
require(availableToOptOut >= amount, "Opt-out amount too high");
365-
forceDecreaseAuthorization(stakingProvider, maxAuthorization - amount);
366-
stakingProviderStruct.optOutAmount += amount;
367-
}
368-
369-
/// @notice Forced deauthorization of Beta stakers.
370-
/// Can be called only by the governance.
371-
function forceBetaStakerDecreaseAuthorization(address[] memory betaStakers)
372-
external
373-
{
374-
require(betaStakers.length > 0, "Wrong input parameters");
375-
for (uint256 i = 0; i < betaStakers.length; i++) {
376-
forceBetaStakerDecreaseAuthorization(betaStakers[i]);
377-
}
378-
}
379-
380333
/// @notice Pauses the given application’s eligibility to slash stakes.
381334
/// Besides that stakers can't change authorization to the application.
382335
/// Can be called only by the Panic Button of the particular
@@ -651,48 +604,41 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
651604
/// application. See `IApplication`.
652605
function requestAuthorizationDecrease(
653606
address stakingProvider,
654-
address,
607+
address application,
655608
uint96 amount
656609
) public override onlyAuthorizerOf(stakingProvider) {
657-
optOutDecreaseAuthorization(stakingProvider, amount);
658-
}
659-
660-
/// @notice Forced deauthorization of Beta staker.
661-
/// Can be called only by the governance.
662-
function forceBetaStakerDecreaseAuthorization(address betaStaker)
663-
public
664-
onlyGovernance
665-
{
666-
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
667-
betaStaker
610+
require(!skipApplication(application), "Application is deprecated");
611+
ApplicationInfo storage applicationStruct = applicationInfo[
612+
application
668613
];
669-
uint256 authorizedApplications = stakingProviderStruct
670-
.authorizedApplications
671-
.length;
614+
require(
615+
applicationStruct.status == ApplicationStatus.APPROVED,
616+
"Application is not approved"
617+
);
672618

673-
require(authorizedApplications > 0, "Nothing was authorized");
674-
uint256 temp = 0;
675-
for (uint256 i = 0; i < authorizedApplications; i++) {
676-
address application = stakingProviderStruct.authorizedApplications[
677-
i
678-
];
679-
if (skipApplication(application)) {
680-
continue;
681-
}
682-
forceDecreaseAuthorization(
683-
betaStaker,
684-
stakingProviderStruct,
685-
application
686-
);
687-
temp++;
688-
}
689-
cleanAuthorizedApplications(stakingProviderStruct, temp);
690-
}
619+
require(amount > 0, "Parameters must be specified");
691620

692-
/// @notice Forced deauthorization of stake above 15m T.
693-
/// Can be called by anyone.
694-
function forceAuthorizationCap(address stakingProvider) public {
695-
forceDecreaseAuthorization(stakingProvider, MAX_STAKE);
621+
AppAuthorization storage authorization = stakingProviders[
622+
stakingProvider
623+
].authorizations[application];
624+
require(
625+
authorization.authorized >= amount,
626+
"Amount exceeds authorized"
627+
);
628+
629+
authorization.deauthorizing = amount;
630+
uint96 deauthorizingTo = authorization.authorized - amount;
631+
emit AuthorizationDecreaseRequested(
632+
stakingProvider,
633+
application,
634+
authorization.authorized,
635+
deauthorizingTo
636+
);
637+
IApplication(application).authorizationDecreaseRequested(
638+
stakingProvider,
639+
authorization.authorized,
640+
deauthorizingTo
641+
);
696642
}
697643

698644
/// @notice Returns the maximum application authorization
@@ -745,21 +691,6 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
745691
}
746692
}
747693

748-
/// @notice Returns available amount to instantly deauthorize.
749-
function getAvailableOptOutAmount(address stakingProvider)
750-
public
751-
view
752-
returns (uint96 availableToOptOut)
753-
{
754-
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
755-
stakingProvider
756-
];
757-
(availableToOptOut, ) = getAvailableOptOutAmount(
758-
stakingProvider,
759-
stakingProviderStruct
760-
);
761-
}
762-
763694
/// @notice Delegate voting power from the stake associated to the
764695
/// `stakingProvider` to a `delegatee` address. Caller must be the owner
765696
/// of this stake.
@@ -938,23 +869,6 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
938869
require(deauthorized > 0, "Nothing to deauthorize");
939870
}
940871

941-
function getAvailableOptOutAmount(
942-
address stakingProvider,
943-
StakingProviderInfo storage stakingProviderStruct
944-
)
945-
internal
946-
view
947-
returns (uint96 availableToOptOut, uint96 maxAuthorization)
948-
{
949-
maxAuthorization = getMaxAuthorization(stakingProvider);
950-
uint96 optOutAmount = stakingProviderStruct.optOutAmount.toUint96();
951-
if (maxAuthorization < optOutAmount) {
952-
availableToOptOut = 0;
953-
} else {
954-
availableToOptOut = (maxAuthorization - optOutAmount) / 2;
955-
}
956-
}
957-
958872
// slither-disable-next-line dead-code
959873
function skipApplication(address application)
960874
internal

0 commit comments

Comments
 (0)