Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: David Núñez <[email protected]>
Co-authored-by: Łukasz Zimnoch <[email protected]>
  • Loading branch information
3 people committed Nov 9, 2023
1 parent 6ed49bc commit 676cb41
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 40 deletions.
26 changes: 13 additions & 13 deletions contracts/staking/IStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 10 additions & 12 deletions contracts/staking/TokenStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
28 changes: 13 additions & 15 deletions docs/rfc-1-staking-contract.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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)`

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 676cb41

Please sign in to comment.