@@ -60,6 +60,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
6060 mapping (address => AppAuthorization) authorizations;
6161 address [] authorizedApplications;
6262 uint256 startStakingTimestamp;
63+ bool autoIncrease;
6364 }
6465
6566 struct AppAuthorization {
@@ -150,6 +151,10 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
150151 );
151152 event AuthorizationCeilingSet (uint256 ceiling );
152153 event ToppedUp (address indexed stakingProvider , uint96 amount );
154+ event AutoIncreaseToggled (
155+ address indexed stakingProvider ,
156+ bool autoIncrease
157+ );
153158 event Unstaked (address indexed stakingProvider , uint96 amount );
154159 event TokensSeized (
155160 address indexed stakingProvider ,
@@ -575,6 +580,8 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
575580 //
576581
577582 /// @notice Increases the amount of the stake for the given staking provider.
583+ /// If `autoIncrease` flag is true then the amount will be added for
584+ /// all authorized applications.
578585 /// @dev The sender of this transaction needs to have the amount approved to
579586 /// transfer to the staking contract.
580587 function topUp (address stakingProvider , uint96 amount ) external override {
@@ -590,6 +597,54 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
590597 emit ToppedUp (stakingProvider, amount);
591598 increaseStakeCheckpoint (stakingProvider, amount);
592599 token.safeTransferFrom (msg .sender , address (this ), amount);
600+
601+ if (! stakingProviderStruct.autoIncrease) {
602+ return ;
603+ }
604+
605+ // increase authorization for all authorized app
606+ for (
607+ uint256 i = 0 ;
608+ i < stakingProviderStruct.authorizedApplications.length ;
609+ i++
610+ ) {
611+ address application = stakingProviderStruct.authorizedApplications[
612+ i
613+ ];
614+ AppAuthorization storage authorization = stakingProviderStruct
615+ .authorizations[application];
616+ uint96 fromAmount = authorization.authorized;
617+ authorization.authorized += amount;
618+ emit AuthorizationIncreased (
619+ stakingProvider,
620+ application,
621+ fromAmount,
622+ authorization.authorized
623+ );
624+ IApplication (application).authorizationIncreased (
625+ stakingProvider,
626+ fromAmount,
627+ authorization.authorized
628+ );
629+ }
630+ }
631+
632+ /// @notice Toggle `autoIncrease` flag. If true then the complete amount
633+ /// in top-up will be added to already authorized applications.
634+ function toggleAutoAuthorizationIncrease (address stakingProvider )
635+ external
636+ override
637+ onlyAuthorizerOf (stakingProvider)
638+ {
639+ StakingProviderInfo storage stakingProviderStruct = stakingProviders[
640+ stakingProvider
641+ ];
642+ stakingProviderStruct.autoIncrease = ! stakingProviderStruct
643+ .autoIncrease;
644+ emit AutoIncreaseToggled (
645+ stakingProvider,
646+ stakingProviderStruct.autoIncrease
647+ );
593648 }
594649
595650 //
@@ -918,6 +973,16 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
918973 return stakingProviders[stakingProvider].startStakingTimestamp;
919974 }
920975
976+ /// @notice Returns auto-increase flag.
977+ function getAutoIncreaseFlag (address stakingProvider )
978+ external
979+ view
980+ override
981+ returns (bool )
982+ {
983+ return stakingProviders[stakingProvider].autoIncrease;
984+ }
985+
921986 /// @notice Returns staked amount of NU for the specified staking provider.
922987 function stakedNu (address stakingProvider )
923988 external
0 commit comments