@@ -60,6 +60,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
60
60
mapping (address => AppAuthorization) authorizations;
61
61
address [] authorizedApplications;
62
62
uint256 startStakingTimestamp;
63
+ bool autoIncrease;
63
64
}
64
65
65
66
struct AppAuthorization {
@@ -150,6 +151,10 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
150
151
);
151
152
event AuthorizationCeilingSet (uint256 ceiling );
152
153
event ToppedUp (address indexed stakingProvider , uint96 amount );
154
+ event AutoIncreaseToggled (
155
+ address indexed stakingProvider ,
156
+ bool autoIncrease
157
+ );
153
158
event Unstaked (address indexed stakingProvider , uint96 amount );
154
159
event TokensSeized (
155
160
address indexed stakingProvider ,
@@ -575,6 +580,8 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
575
580
//
576
581
577
582
/// @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.
578
585
/// @dev The sender of this transaction needs to have the amount approved to
579
586
/// transfer to the staking contract.
580
587
function topUp (address stakingProvider , uint96 amount ) external override {
@@ -590,6 +597,54 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
590
597
emit ToppedUp (stakingProvider, amount);
591
598
increaseStakeCheckpoint (stakingProvider, amount);
592
599
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
+ );
593
648
}
594
649
595
650
//
@@ -918,6 +973,16 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
918
973
return stakingProviders[stakingProvider].startStakingTimestamp;
919
974
}
920
975
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
+
921
986
/// @notice Returns staked amount of NU for the specified staking provider.
922
987
function stakedNu (address stakingProvider )
923
988
external
0 commit comments