diff --git a/contracts/staking/IStaking.sol b/contracts/staking/IStaking.sol index b6282958..1d7019b8 100644 --- a/contracts/staking/IStaking.sol +++ b/contracts/staking/IStaking.sol @@ -185,16 +185,16 @@ interface IStaking { /// called only by the delegation owner or the staking provider. function unstakeKeep(address stakingProvider) external; - /// @notice Sets the legacy NU staking contract active stake amount cached - /// in T staking contract to 0. Reverts if there is at least one + /// @notice Sets to 0 the amount of T that is cached from the legacy + /// NU staking contract. Reverts if there is at least one /// authorization higher than the sum of remaining legacy NU stake - /// and liquid T stake for that staking provider or if the unstaked + /// and native T stake for that staking provider or if the unstaked /// amount is higher than the cached legacy stake amount. If succeeded, /// the legacy NU stake can be partially or fully undelegated on - /// the legacy staking contract. This function allows to unstake + /// the legacy NU staking contract. This function allows to unstake /// from NU staking contract while still being able to operate in - /// T network and earning rewards based on the liquid T staked. - /// Can be called only by the delegation owner or the staking provider. + /// T network and earning rewards based on the native T staked. + /// Can be called only by the stake owner or the staking provider. function unstakeNu(address stakingProvider) external; /// @notice Sets cached legacy stake amount to 0, sets the liquid T stake @@ -303,20 +303,20 @@ interface IStaking { /// @notice Returns minimum possible stake for T, KEEP or NU in T /// denomination. - /// @dev For example, suppose the given staking provider has 10 T, 20 T - /// worth of KEEP, and 30 T worth of NU all staked, and the maximum + /// @dev For example, suppose the given staking provider has 10 T, 20 T worth + /// of KEEP, and 30 T worth of NU all staked, and the maximum /// application authorization is 40 T, then `getMinStaked` for /// that staking provider returns: /// * 0 T if KEEP stake type specified i.e. - /// min = 40 T max - (10 T + 30 T worth of NU) = 0 T + /// min = 40 T max - (10 T) = 30 T /// * 10 T if NU stake type specified i.e. - /// min = 40 T max - (10 T + 20 T worth of KEEP) = 10 T + /// min = 40 T max - (10 T) = 30 T /// * 0 T if T stake type specified i.e. - /// min = 40 T max - (20 T worth of KEEP + 30 T worth of NU) < 0 T + /// min = 40 T max = 40 T /// In other words, the minimum stake amount for the specified /// stake type is the minimum amount of stake of the given type - /// needed to satisfy the maximum application authorization given the - /// staked amounts of the other stake types for that staking provider. + /// needed to satisfy the maximum application authorization given + /// the staked amounts of the T stake types for that staking provider. function getMinStaked(address stakingProvider, StakeType stakeTypes) external view diff --git a/contracts/staking/TokenStaking.sol b/contracts/staking/TokenStaking.sol index 1aea088e..f8f17110 100644 --- a/contracts/staking/TokenStaking.sol +++ b/contracts/staking/TokenStaking.sol @@ -664,16 +664,16 @@ contract TokenStaking is Initializable, IStaking, Checkpoints { decreaseStakeCheckpoint(stakingProvider, keepInTStake); } - /// @notice Sets the legacy NU staking contract active stake amount cached - /// in T staking contract to 0. Reverts if there is at least one + /// @notice Sets to 0 the amount of T that is cached from the legacy + /// NU staking contract. Reverts if there is at least one /// authorization higher than the sum of remaining legacy NU stake - /// and liquid T stake for that staking provider or if the unstaked + /// and native T stake for that staking provider or if the unstaked /// amount is higher than the cached legacy stake amount. If succeeded, /// the legacy NU stake can be partially or fully undelegated on - /// the legacy staking contract. This function allows to unstake + /// the legacy NU staking contract. This function allows to unstake /// from NU staking contract while still being able to operate in - /// T network and earning rewards based on the liquid T staked. - /// Can be called only by the delegation owner or the staking provider. + /// T network and earning rewards based on the native T staked. + /// Can be called only by the stake owner or the staking provider. /// @dev This function (or `unstakeAll`) must be called before `withdraw` /// in NuCypher staking contract. Otherwise NU tokens can't be /// unlocked. @@ -1089,7 +1089,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints { /// * 10 T if NU stake type specified i.e. /// min = 40 T max - (10 T) = 30 T /// * 0 T if T stake type specified i.e. - /// min = 40 T max = 40 T < 0 T + /// min = 40 T max = 40 T /// In other words, the minimum stake amount for the specified /// stake type is the minimum amount of stake of the given type /// needed to satisfy the maximum application authorization given @@ -1244,11 +1244,9 @@ contract TokenStaking is Initializable, IStaking, Checkpoints { stakingProviderStruct.keepInTStake + stakingProviderStruct.nuInTStake; // slash T - if (tAmountToSlash <= stakingProviderStruct.tStake) { - tAmountToBurn = tAmountToSlash; - } else { - tAmountToBurn = stakingProviderStruct.tStake; - } + tAmountToBurn = MathUpgradeable + .min(tAmountToSlash, stakingProviderStruct.tStake) + .toUint96(); stakingProviderStruct.tStake -= tAmountToBurn; tAmountToSlash -= tAmountToBurn; diff --git a/docs/rfc-1-staking-contract.adoc b/docs/rfc-1-staking-contract.adoc index 6ac11684..d3f24dea 100644 --- a/docs/rfc-1-staking-contract.adoc +++ b/docs/rfc-1-staking-contract.adoc @@ -19,10 +19,8 @@ network throughput without compromising the security of the owners’ stake. This proposal aims at implementing a minimum viable staking contract version allowing to support native T delegations in all applications developed against -this staking contract version. It means that stakers will be able to participate -in all applications developed against this staking contract version on equal rules. -The functionality of the staking contract can be further extended by the -upgradeability of the contract code. +this staking contract version. The functionality of the staking contract can be +further extended by the upgradeability of the contract code. === Terminology @@ -131,9 +129,9 @@ increase the authorization for applications. This increases the probability of b chosen for work in the application but is only effective for future checks of the authorized amount. -Stakers can only top-up their stakes with a liquid T. +Stakes can only be topped-up with liquid T. -Anyone can execute a stake top-up for a staking provider using a liquid T. +Anyone can execute a stake top-up for a staking provider using liquid T. Stake top-up does not automatically increase authorization levels for applications. Stake top-up is a one-step process and does not require any delay. @@ -308,14 +306,14 @@ delegation owner or the staking provider. ==== `unstakeNu(address stakingProvider, uint96 amount) external onlyOwnerOrStakingProvider(stakingProvider)` -Reduces cached legacy NU stake amount by `amount`. Reverts if there is at least -one authorization higher than the sum of remaining legacy NU stake and liquid T -stake for that provider or if amount is higher than the cached legacy stake -amount. If succeeded, the legacy NU stake can be partially or fully undelegated -on the legacy staking contract. This function allows to unstake from NU staking -contract while sill being able to operate in T network and earning rewards based -on the liquid T staked. Can be called only by the delegation owner or the -staking provider. +Sets to 0 the amount of T that is cached from the legacy NU staking contract. +Reverts if there is at least one authorization higher than the sum of remaining +legacy NU stake and native T stake for that staking provider or if the unstaked +amount is higher than the cached legacy stake amount. If succeeded, the legacy +NU stake can be partially or fully undelegated on the legacy NU staking contract. +This function allows to unstake from NU staking contract while still being able +to operate in T network and earning rewards based on the native T staked. +Can be called only by the stake owner or the staking provider. ==== `unstakeAll(address stakingProvider) external onlyOwnerOrStakingProvider(stakingProvider)` @@ -402,7 +400,7 @@ and 30 T worth of NU all staked, and the maximum application authorization is * 0 T if KEEP stake type specified i.e. min = 40 T max - (10 T) = 30 T * 10 T if NU stake type specified i.e. min = 40 T max - (10 T) = 30 T -* 0 T if T stake type specified i.e. min = 40 T max = 40 T < 0 T +* 0 T if T stake type specified i.e. min = 40 T max = 40 T In other words, the minimum stake amount for the specified stake type is the minimum amount of stake of the given type needed