diff --git a/contracts/staking/IStaking.sol b/contracts/staking/IStaking.sol index b6282958..cb843785 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 diff --git a/contracts/staking/TokenStaking.sol b/contracts/staking/TokenStaking.sol index 1aea088e..90946e5c 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. @@ -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..b27967af 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)`