Skip to content

Commit 9dbc4f9

Browse files
committed
Add slashing of rewards
1 parent b65aa4f commit 9dbc4f9

File tree

15 files changed

+331
-76
lines changed

15 files changed

+331
-76
lines changed

docs/autogen/src/src/UVN/L1/StakingMiddleware.sol/contract.StakingMiddleware.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# StakingMiddleware
2-
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/24150a287633bc355fa0bd43e8e420b312a5ca02/src/UVN/L1/StakingMiddleware.sol)
2+
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/b65aa4f5b827097e05d9ccfdf4601e76462b77b0/src/UVN/L1/StakingMiddleware.sol)
33

44
**Inherits:**
5-
[ProtocolRewardDistributor](/src/UVN/L1/StakingMiddleware/ProtocolRewardDistributor.sol/abstract.ProtocolRewardDistributor.md), [SlashingManager](/src/UVN/L1/StakingMiddleware/SlashingManager.sol/abstract.SlashingManager.md), [IStakingMiddleware](/src/interfaces/UVN/L1/IStakingMiddleware.sol/interface.IStakingMiddleware.md)
5+
[SlashingManager](/src/UVN/L1/StakingMiddleware/SlashingManager.sol/abstract.SlashingManager.md), [IStakingMiddleware](/src/interfaces/UVN/L1/IStakingMiddleware.sol/interface.IStakingMiddleware.md)
66

77

88
## State Variables
@@ -22,8 +22,11 @@ constructor(
2222
address initialAdmin,
2323
IUniStaker unistaker_,
2424
uint256 withdrawalDelay_,
25+
address slashingBeneficiary_,
2526
IDelegationManager delegationManager_
26-
) UniStakerWrapper(unistaker_) StakingMiddlewareParams(initialAdmin, withdrawalDelay_, delegationManager_);
27+
)
28+
UniStakerWrapper(unistaker_)
29+
StakingMiddlewareParams(initialAdmin, withdrawalDelay_, slashingBeneficiary_, delegationManager_);
2730
```
2831

2932
### updateGovernanceDelegatee
@@ -68,3 +71,10 @@ function withdrawFromUniStaker() external;
6871
function alterGovernanceDelegatee(address newGovernanceDelegatee) external;
6972
```
7073

74+
### deselectOperator
75+
76+
77+
```solidity
78+
function deselectOperator() public override;
79+
```
80+

docs/autogen/src/src/UVN/L1/StakingMiddleware/ProtocolRewardDistributor.sol/abstract.ProtocolRewardDistributor.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ProtocolRewardDistributor
2-
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/dbd11eeb90f59abe0099dfbb1022b6093132bf21/src/UVN/L1/StakingMiddleware/ProtocolRewardDistributor.sol)
2+
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/b65aa4f5b827097e05d9ccfdf4601e76462b77b0/src/UVN/L1/StakingMiddleware/ProtocolRewardDistributor.sol)
33

44
**Inherits:**
55
[UniStakerWrapper](/src/UVN/L1/StakingMiddleware/UniStakerWrapper.sol/contract.UniStakerWrapper.md), [IProtocolRewardDistributor](/src/interfaces/UVN/L1/StakingMiddleware/IProtocolRewardDistributor.sol/interface.IProtocolRewardDistributor.md)
@@ -16,21 +16,21 @@ uint256 private constant PRECISION = 1e27;
1616
### _globalRewardCheckpoint
1717

1818
```solidity
19-
uint256 private _globalRewardCheckpoint;
19+
uint256 internal _globalRewardCheckpoint;
2020
```
2121

2222

2323
### _rewardCheckpointOf
2424

2525
```solidity
26-
mapping(address account => uint256 checkpoint) private _rewardCheckpointOf;
26+
mapping(address account => uint256 checkpoint) internal _rewardCheckpointOf;
2727
```
2828

2929

3030
### _earnedRewardsOf
3131

3232
```solidity
33-
mapping(address account => uint256 earnedRewards) private _earnedRewardsOf;
33+
mapping(address account => uint256 earnedRewards) internal _earnedRewardsOf;
3434
```
3535

3636

@@ -39,21 +39,21 @@ mapping(address account => uint256 earnedRewards) private _earnedRewardsOf;
3939

4040

4141
```solidity
42-
function withdrawRewards(address to) external returns (uint256 reward);
42+
function withdrawRewards(address to) public virtual returns (uint256 reward);
4343
```
4444

4545
### rewardsOf
4646

4747

4848
```solidity
49-
function rewardsOf(address account) public view returns (uint256);
49+
function rewardsOf(address account) public view virtual returns (uint256);
5050
```
5151

52-
### _updateRewardIndex
52+
### _updateGlobalRewardCheckpoint
5353

5454

5555
```solidity
56-
function _updateRewardIndex() internal;
56+
function _updateGlobalRewardCheckpoint() internal returns (uint256 newGlobalRewardCheckpoint);
5757
```
5858

5959
### _updateRewardCheckpoint
@@ -63,10 +63,24 @@ function _updateRewardIndex() internal;
6363
function _updateRewardCheckpoint(address account) internal;
6464
```
6565

66-
### _calculateRewardSinceLastCheckpoint
66+
### _getNewGlobalRewardCheckpoint
6767

6868

6969
```solidity
70-
function _calculateRewardSinceLastCheckpoint(address account) internal view returns (uint256);
70+
function _getNewGlobalRewardCheckpoint(uint256 reward) internal view returns (uint256);
71+
```
72+
73+
### _calculateRewardUntil
74+
75+
76+
```solidity
77+
function _calculateRewardUntil(address account, uint256 checkpoint) internal view returns (uint256);
78+
```
79+
80+
### _calculateRewardFromTo
81+
82+
83+
```solidity
84+
function _calculateRewardFromTo(uint256 balance, uint256 from, uint256 to) internal pure returns (uint256);
7185
```
7286

docs/autogen/src/src/UVN/L1/StakingMiddleware/SlashingManager.sol/abstract.SlashingManager.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# SlashingManager
2-
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/24150a287633bc355fa0bd43e8e420b312a5ca02/src/UVN/L1/StakingMiddleware/SlashingManager.sol)
2+
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/b65aa4f5b827097e05d9ccfdf4601e76462b77b0/src/UVN/L1/StakingMiddleware/SlashingManager.sol)
33

44
**Inherits:**
5-
[OperatorManager](/src/UVN/L1/StakingMiddleware/OperatorManager.sol/abstract.OperatorManager.md)
5+
[ProtocolRewardDistributor](/src/UVN/L1/StakingMiddleware/ProtocolRewardDistributor.sol/abstract.ProtocolRewardDistributor.md), [OperatorManager](/src/UVN/L1/StakingMiddleware/OperatorManager.sol/abstract.OperatorManager.md)
66

77

88
## State Variables
@@ -39,7 +39,14 @@ function selectOperator(address operator) public override;
3939

4040

4141
```solidity
42-
function deselectOperator() public override;
42+
function deselectOperator() public virtual override;
43+
```
44+
45+
### withdrawRewards
46+
47+
48+
```solidity
49+
function withdrawRewards(address to) public override returns (uint256 reward);
4350
```
4451

4552
### slashAmount
@@ -77,6 +84,13 @@ function isDelegatorSlashed(address delegator) external view returns (bool);
7784
function delegatorStake(address delegator) public view override returns (uint96);
7885
```
7986

87+
### rewardsOf
88+
89+
90+
```solidity
91+
function rewardsOf(address delegator) public view override returns (uint256);
92+
```
93+
8094
### _slash
8195

8296

@@ -86,12 +100,16 @@ function _slash(address operator, uint96 remainingPercentage) internal;
86100

87101
### _calculateSlashing
88102

103+
*iterates over slashing occurrences by the operator a delegator has selected. For every slashing instance, it calculates the new stake based on the total percentage of the total delegated stake slashed.*
104+
105+
*In case a delegator has deposited their tokens into UniStaker, to ensure they do not accrue rewards for slashed stake, rewards are also adjusted by the slashed amount. As the slashed stake remains in the UniStaker contract until slashing is applied, the slashed stake is treated as a deposit by the slashing beneficiary, meaning the slashing beneficiary accrues the rewards for the slashed stake instead of the delegator until slashing is applied and the underlying stake is withdrawn.*
106+
89107

90108
```solidity
91-
function _calculateSlashing(address delegator, uint256 n)
109+
function _calculateSlashing(address delegator, uint256 n, uint256 globalCheckpoint)
92110
internal
93111
view
94-
returns (uint96 newStake, bytes32 delegatorHead);
112+
returns (uint96 newStake, bytes32 delegatorHead, uint256 newRewards, uint256 slashedRewards, uint256 newCheckpoint);
95113
```
96114

97115
### _isDelegatorSlashed
@@ -114,6 +132,8 @@ function SLASHER_ROLE() public view returns (bytes32);
114132
```solidity
115133
struct SlashingInstance {
116134
uint96 remainingPercentage;
135+
uint40 timestamp;
136+
uint256 rewardCheckpoint;
117137
bytes32 next;
118138
}
119139
```

docs/autogen/src/src/UVN/L1/StakingMiddleware/StakingMiddlewareParams.sol/contract.StakingMiddlewareParams.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# StakingMiddlewareParams
2-
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/6b285bfe59012065422d5d75fc08ddb0d2404ce9/src/UVN/L1/StakingMiddleware/StakingMiddlewareParams.sol)
2+
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/b65aa4f5b827097e05d9ccfdf4601e76462b77b0/src/UVN/L1/StakingMiddleware/StakingMiddlewareParams.sol)
33

44
**Inherits:**
55
[IStakingMiddlewareParams](/src/interfaces/UVN/L1/StakingMiddleware/IStakingMiddlewareParams.sol/interface.IStakingMiddlewareParams.md), AccessControl
@@ -20,10 +20,17 @@ uint256 private _withdrawalDelay;
2020
```
2121

2222

23+
### _slashingBeneficiary
24+
25+
```solidity
26+
address private _slashingBeneficiary;
27+
```
28+
29+
2330
### _delegationManager
2431

2532
```solidity
26-
IDelegationManager private _delegationManager;
33+
IDelegationManager private immutable _delegationManager;
2734
```
2835

2936

@@ -32,7 +39,12 @@ IDelegationManager private _delegationManager;
3239

3340

3441
```solidity
35-
constructor(address initialAdmin, uint256 withdrawalDelay_, IDelegationManager delegationManager_);
42+
constructor(
43+
address initialAdmin,
44+
uint256 withdrawalDelay_,
45+
address slashingBeneficiary_,
46+
IDelegationManager delegationManager_
47+
);
3648
```
3749

3850
### withdrawalDelay
@@ -42,6 +54,13 @@ constructor(address initialAdmin, uint256 withdrawalDelay_, IDelegationManager d
4254
function withdrawalDelay() public view returns (uint256);
4355
```
4456

57+
### slashingBeneficiary
58+
59+
60+
```solidity
61+
function slashingBeneficiary() public view returns (address);
62+
```
63+
4564
### delegationManager
4665

4766

@@ -56,11 +75,11 @@ function delegationManager() public view returns (IDelegationManager);
5675
function updateWithdrawalDelay(uint256 withdrawalDelay_) external onlyRole(PARAMS_SETTER_ROLE);
5776
```
5877

59-
### updateDelegationManager
78+
### updateSlashingBeneficiary
6079

6180

6281
```solidity
63-
function updateDelegationManager(IDelegationManager delegationManager_) external onlyRole(PARAMS_SETTER_ROLE);
82+
function updateSlashingBeneficiary(address slashingBeneficiary_) external onlyRole(PARAMS_SETTER_ROLE);
6483
```
6584

6685
### _setWithdrawalDelay
@@ -70,10 +89,10 @@ function updateDelegationManager(IDelegationManager delegationManager_) external
7089
function _setWithdrawalDelay(uint256 withdrawalDelay_) internal;
7190
```
7291

73-
### _updateDelegationManager
92+
### _setSlashingBeneficiary
7493

7594

7695
```solidity
77-
function _updateDelegationManager(IDelegationManager delegationManager_) internal;
96+
function _setSlashingBeneficiary(address slashingBeneficiary_) internal;
7897
```
7998

docs/autogen/src/src/UVN/L1/StakingMiddleware/UniStakerWrapper.sol/contract.UniStakerWrapper.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# UniStakerWrapper
2-
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/6b285bfe59012065422d5d75fc08ddb0d2404ce9/src/UVN/L1/StakingMiddleware/UniStakerWrapper.sol)
2+
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/b65aa4f5b827097e05d9ccfdf4601e76462b77b0/src/UVN/L1/StakingMiddleware/UniStakerWrapper.sol)
33

44

55
## State Variables
@@ -53,6 +53,13 @@ function _depositIntoUniStaker(uint96 amount, address delegatee) internal return
5353
function _withdrawFromUniStaker(uint96 amount) internal;
5454
```
5555

56+
### _withdrawFromUniStaker
57+
58+
59+
```solidity
60+
function _withdrawFromUniStaker(address delegator, uint96 amount) internal;
61+
```
62+
5663
### _stakedBalanceOf
5764

5865

@@ -64,7 +71,7 @@ function _stakedBalanceOf(address delegator) internal view returns (uint96);
6471

6572

6673
```solidity
67-
function _totalAmountStaked() internal view returns (uint256);
74+
function _totalAmountStaked() internal view returns (uint96);
6875
```
6976

7077
### _isDepositedIntoUniStaker

docs/autogen/src/src/interfaces/UVN/L1/StakingMiddleware/IStakingMiddlewareParams.sol/interface.IStakingMiddlewareParams.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# IStakingMiddlewareParams
2-
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/5b98eecce12fe90fe24abd37da1a3642b02cfbd3/src/interfaces/UVN/L1/StakingMiddleware/IStakingMiddlewareParams.sol)
2+
[Git Source](https://github.com/Uniswap/unichain-contracts/blob/b65aa4f5b827097e05d9ccfdf4601e76462b77b0/src/interfaces/UVN/L1/StakingMiddleware/IStakingMiddlewareParams.sol)
33

44

55
## Functions
@@ -18,6 +18,21 @@ function updateWithdrawalDelay(uint256 withdrawalDelay) external;
1818
|`withdrawalDelay`|`uint256`|The new withdrawal delay in seconds|
1919

2020

21+
### updateSlashingBeneficiary
22+
23+
Updates the slashing beneficiary that receives slashed stake and rewards
24+
25+
26+
```solidity
27+
function updateSlashingBeneficiary(address slashingBeneficiary) external;
28+
```
29+
**Parameters**
30+
31+
|Name|Type|Description|
32+
|----|----|-----------|
33+
|`slashingBeneficiary`|`address`|The new slashing beneficiary|
34+
35+
2136
### withdrawalDelay
2237

2338
The delay before a user can withdraw their stake or change their operator
@@ -33,6 +48,21 @@ function withdrawalDelay() external view returns (uint256);
3348
|`<none>`|`uint256`|The withdrawal delay in seconds|
3449

3550

51+
### slashingBeneficiary
52+
53+
The slashing beneficiary that receives slashed stake and rewards
54+
55+
56+
```solidity
57+
function slashingBeneficiary() external view returns (address);
58+
```
59+
**Returns**
60+
61+
|Name|Type|Description|
62+
|----|----|-----------|
63+
|`<none>`|`address`|The slashing beneficiary|
64+
65+
3666
### PARAMS_SETTER_ROLE
3767

3868
The role that can set parameters
@@ -49,3 +79,9 @@ function PARAMS_SETTER_ROLE() external view returns (bytes32);
4979
event WithdrawalDelayUpdated(uint256 oldWithdrawalDelay, uint256 newWithdrawalDelay);
5080
```
5181

82+
### SlashingBeneficiaryUpdated
83+
84+
```solidity
85+
event SlashingBeneficiaryUpdated(address oldSlashingBeneficiary, address newSlashingBeneficiary);
86+
```
87+

0 commit comments

Comments
 (0)