Skip to content

Commit 1bc2a56

Browse files
vzotovacygnusvlukasz-zimnoch
committed
Apply suggestions from code review
Co-authored-by: David Núñez <[email protected]> Co-authored-by: Łukasz Zimnoch <[email protected]>
1 parent 837744c commit 1bc2a56

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

contracts/staking/IStaking.sol

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,16 @@ interface IStaking {
185185
/// called only by the delegation owner or the staking provider.
186186
function unstakeKeep(address stakingProvider) external;
187187

188-
/// @notice Sets the legacy NU staking contract active stake amount cached
189-
/// in T staking contract to 0. Reverts if there is at least one
188+
/// @notice Sets to 0 the amount of T that is cached from the legacy
189+
/// NU staking contract. Reverts if there is at least one
190190
/// authorization higher than the sum of remaining legacy NU stake
191-
/// and liquid T stake for that staking provider or if the unstaked
191+
/// and native T stake for that staking provider or if the unstaked
192192
/// amount is higher than the cached legacy stake amount. If succeeded,
193193
/// the legacy NU stake can be partially or fully undelegated on
194-
/// the legacy staking contract. This function allows to unstake
194+
/// the legacy NU staking contract. This function allows to unstake
195195
/// from NU staking contract while still being able to operate in
196-
/// T network and earning rewards based on the liquid T staked.
197-
/// Can be called only by the delegation owner or the staking provider.
196+
/// T network and earning rewards based on the native T staked.
197+
/// Can be called only by the stake owner or the staking provider.
198198
function unstakeNu(address stakingProvider) external;
199199

200200
/// @notice Sets cached legacy stake amount to 0, sets the liquid T stake
@@ -303,20 +303,20 @@ interface IStaking {
303303

304304
/// @notice Returns minimum possible stake for T, KEEP or NU in T
305305
/// denomination.
306-
/// @dev For example, suppose the given staking provider has 10 T, 20 T
307-
/// worth of KEEP, and 30 T worth of NU all staked, and the maximum
306+
/// @dev For example, suppose the given staking provider has 10 T, 20 T worth
307+
/// of KEEP, and 30 T worth of NU all staked, and the maximum
308308
/// application authorization is 40 T, then `getMinStaked` for
309309
/// that staking provider returns:
310310
/// * 0 T if KEEP stake type specified i.e.
311-
/// min = 40 T max - (10 T + 30 T worth of NU) = 0 T
311+
/// min = 40 T max - (10 T) = 30 T
312312
/// * 10 T if NU stake type specified i.e.
313-
/// min = 40 T max - (10 T + 20 T worth of KEEP) = 10 T
313+
/// min = 40 T max - (10 T) = 30 T
314314
/// * 0 T if T stake type specified i.e.
315-
/// min = 40 T max - (20 T worth of KEEP + 30 T worth of NU) < 0 T
315+
/// min = 40 T max = 40 T
316316
/// In other words, the minimum stake amount for the specified
317317
/// stake type is the minimum amount of stake of the given type
318-
/// needed to satisfy the maximum application authorization given the
319-
/// staked amounts of the other stake types for that staking provider.
318+
/// needed to satisfy the maximum application authorization given
319+
/// the staked amounts of the T stake types for that staking provider.
320320
function getMinStaked(address stakingProvider, StakeType stakeTypes)
321321
external
322322
view

contracts/staking/TokenStaking.sol

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -664,16 +664,16 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
664664
decreaseStakeCheckpoint(stakingProvider, keepInTStake);
665665
}
666666

667-
/// @notice Sets the legacy NU staking contract active stake amount cached
668-
/// in T staking contract to 0. Reverts if there is at least one
667+
/// @notice Sets to 0 the amount of T that is cached from the legacy
668+
/// NU staking contract. Reverts if there is at least one
669669
/// authorization higher than the sum of remaining legacy NU stake
670-
/// and liquid T stake for that staking provider or if the unstaked
670+
/// and native T stake for that staking provider or if the unstaked
671671
/// amount is higher than the cached legacy stake amount. If succeeded,
672672
/// the legacy NU stake can be partially or fully undelegated on
673-
/// the legacy staking contract. This function allows to unstake
673+
/// the legacy NU staking contract. This function allows to unstake
674674
/// from NU staking contract while still being able to operate in
675-
/// T network and earning rewards based on the liquid T staked.
676-
/// Can be called only by the delegation owner or the staking provider.
675+
/// T network and earning rewards based on the native T staked.
676+
/// Can be called only by the stake owner or the staking provider.
677677
/// @dev This function (or `unstakeAll`) must be called before `withdraw`
678678
/// in NuCypher staking contract. Otherwise NU tokens can't be
679679
/// unlocked.
@@ -1089,7 +1089,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
10891089
/// * 10 T if NU stake type specified i.e.
10901090
/// min = 40 T max - (10 T) = 30 T
10911091
/// * 0 T if T stake type specified i.e.
1092-
/// min = 40 T max = 40 T < 0 T
1092+
/// min = 40 T max = 40 T
10931093
/// In other words, the minimum stake amount for the specified
10941094
/// stake type is the minimum amount of stake of the given type
10951095
/// needed to satisfy the maximum application authorization given
@@ -1244,11 +1244,9 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
12441244
stakingProviderStruct.keepInTStake +
12451245
stakingProviderStruct.nuInTStake;
12461246
// slash T
1247-
if (tAmountToSlash <= stakingProviderStruct.tStake) {
1248-
tAmountToBurn = tAmountToSlash;
1249-
} else {
1250-
tAmountToBurn = stakingProviderStruct.tStake;
1251-
}
1247+
tAmountToBurn = MathUpgradeable
1248+
.min(tAmountToSlash, stakingProviderStruct.tStake)
1249+
.toUint96();
12521250
stakingProviderStruct.tStake -= tAmountToBurn;
12531251
tAmountToSlash -= tAmountToBurn;
12541252

docs/rfc-1-staking-contract.adoc

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ network throughput without compromising the security of the owners’ stake.
1919

2020
This proposal aims at implementing a minimum viable staking contract version
2121
allowing to support native T delegations in all applications developed against
22-
this staking contract version. It means that stakers will be able to participate
23-
in all applications developed against this staking contract version on equal rules.
24-
The functionality of the staking contract can be further extended by the
25-
upgradeability of the contract code.
22+
this staking contract version. The functionality of the staking contract can be
23+
further extended by the upgradeability of the contract code.
2624

2725
=== Terminology
2826

@@ -131,9 +129,9 @@ increase the authorization for applications. This increases the probability of b
131129
chosen for work in the application but is only effective for future checks of the
132130
authorized amount.
133131

134-
Stakers can only top-up their stakes with a liquid T.
132+
Stakes can only be topped-up with liquid T.
135133

136-
Anyone can execute a stake top-up for a staking provider using a liquid T.
134+
Anyone can execute a stake top-up for a staking provider using liquid T.
137135
Stake top-up does not automatically increase authorization levels for applications.
138136
Stake top-up is a one-step process and does not require any delay.
139137

@@ -308,14 +306,14 @@ delegation owner or the staking provider.
308306

309307
==== `unstakeNu(address stakingProvider, uint96 amount) external onlyOwnerOrStakingProvider(stakingProvider)`
310308

311-
Reduces cached legacy NU stake amount by `amount`. Reverts if there is at least
312-
one authorization higher than the sum of remaining legacy NU stake and liquid T
313-
stake for that provider or if amount is higher than the cached legacy stake
314-
amount. If succeeded, the legacy NU stake can be partially or fully undelegated
315-
on the legacy staking contract. This function allows to unstake from NU staking
316-
contract while sill being able to operate in T network and earning rewards based
317-
on the liquid T staked. Can be called only by the delegation owner or the
318-
staking provider.
309+
Sets to 0 the amount of T that is cached from the legacy NU staking contract.
310+
Reverts if there is at least one authorization higher than the sum of remaining
311+
legacy NU stake and native T stake for that staking provider or if the unstaked
312+
amount is higher than the cached legacy stake amount. If succeeded, the legacy
313+
NU stake can be partially or fully undelegated on the legacy NU staking contract.
314+
This function allows to unstake from NU staking contract while still being able
315+
to operate in T network and earning rewards based on the native T staked.
316+
Can be called only by the stake owner or the staking provider.
319317

320318
==== `unstakeAll(address stakingProvider) external onlyOwnerOrStakingProvider(stakingProvider)`
321319

@@ -402,7 +400,7 @@ and 30 T worth of NU all staked, and the maximum application authorization is
402400

403401
* 0 T if KEEP stake type specified i.e. min = 40 T max - (10 T) = 30 T
404402
* 10 T if NU stake type specified i.e. min = 40 T max - (10 T) = 30 T
405-
* 0 T if T stake type specified i.e. min = 40 T max = 40 T < 0 T
403+
* 0 T if T stake type specified i.e. min = 40 T max = 40 T
406404

407405
In other words, the minimum stake amount for
408406
the specified stake type is the minimum amount of stake of the given type needed

0 commit comments

Comments
 (0)