@@ -9,17 +9,19 @@ import {NonRebasingLST} from "src/NonRebasingLST.sol";
9
9
bytes32 constant LIQUID_VARIANT = 0xfa57cbed4b267d0bc9f2cbdae86b4d1d23ca818308f873af9c968a23afadfd00 ;
10
10
11
11
/**
12
- * @notice The liquid variant of the stake delegation contract. It uses {NonRebasingLST}
13
- * as liquid staking token implementation. Every time users stake ZIL they receive the
14
- * corresponding amount of liquid staking tokens depending on the current token price.
15
- * The liquid staking token is non-rebasing, i.e. the token balances are not adjusted
16
- * to reflect the rewards earned by the staking pool. Instead, the taxed rewards, i.e.
17
- * the rewards after deducting the commission are included in the token price.
12
+ * @notice The liquid variant of the stake delegation contract that uses a
13
+ * {NonRebasingLST} as liquid staking token. Every time users stake ZIL they
14
+ * receive the corresponding amount of liquid staking tokens depending on the
15
+ * current token price. The liquid staking token is non-rebasing, i.e. the token
16
+ * balances are not adjusted to reflect the rewards earned by the staking pool.
17
+ * Instead, the taxed rewards, i.e. the rewards after deducting the commission
18
+ * are included in the token price.
18
19
*
19
20
* @dev The contract is registered as the reward address of all validators in the
20
21
* staking pool, i.e. its balance can increase in every block. Since this does not
21
22
* happen in form of transactions, the {receive} function will not notice it.
22
23
*/
24
+ // solhint-disable comprehensive-interface
23
25
contract LiquidDelegation is IDelegation , BaseDelegation {
24
26
25
27
// ************************************************************************
@@ -29,10 +31,11 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
29
31
// ************************************************************************
30
32
31
33
/**
32
- * @dev `lst` is the address of the {NonRebasingLST} token issued by the {LiquidDelegation}.
33
- * `taxedRewards` is the amount of rewards accrued that the {LiquidDelegation} contract is
34
- * aware of and has already deducted the commission from. The contract balance is higher
35
- * if new (untaxed) rewards have been added to it since the last update of `taxedRewards`.
34
+ * @dev `lst` stores the address of the {NonRebasingLST} token issued by the
35
+ * {LiquidDelegation}. `taxedRewards` is the amount of rewards accrued that
36
+ * the {LiquidDelegation} contract is aware of and has already deducted the
37
+ * commission from. The contract balance is higher if new (untaxed) rewards
38
+ * have been added to it since the last update of `taxedRewards`.
36
39
*/
37
40
/// @custom:storage-location erc7201:zilliqa.storage.LiquidDelegation
38
41
struct LiquidDelegationStorage {
@@ -70,7 +73,11 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
70
73
/**
71
74
* @dev Initialize the base contracts and create the LST token contract.
72
75
*/
73
- function initialize (address initialOwner , string calldata name , string calldata symbol ) public initializer {
76
+ function initialize (
77
+ address initialOwner ,
78
+ string calldata name ,
79
+ string calldata symbol
80
+ ) public initializer {
74
81
__BaseDelegation_init (initialOwner);
75
82
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage ();
76
83
$.lst = address (new NonRebasingLST (name, symbol));
@@ -105,19 +112,25 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
105
112
}
106
113
107
114
/// @inheritdoc BaseDelegation
108
- function joinPool (bytes calldata blsPubKey , address controlAddress ) public override onlyOwner {
109
- // deduct the commission from the yet untaxed rewards before calculating the number of shares
115
+ function joinPool (
116
+ bytes calldata blsPubKey ,
117
+ address controlAddress
118
+ ) public override onlyOwner {
119
+ // deduct the commission from the yet untaxed rewards
120
+ // before calculating the number of shares
110
121
taxRewards ();
111
122
_stake (getDeposit (blsPubKey), controlAddress);
112
- // increases the deposited stake hence it must be called after calculating the shares
123
+ // increases the deposited stake hence it must
124
+ // be called after calculating the shares
113
125
_addToPool (blsPubKey, controlAddress);
114
126
}
115
127
116
128
/// @inheritdoc BaseDelegation
117
129
function leavePool (bytes calldata blsPubKey ) public override {
118
130
if (! _preparedToLeave (blsPubKey))
119
131
return ;
120
- // deduct the commission from the yet untaxed rewards before calculating the amount
132
+ // deduct the commission from the yet untaxed rewards
133
+ // before calculating the amount
121
134
taxRewards ();
122
135
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage ();
123
136
uint256 amount = _unstake (NonRebasingLST ($.lst).balanceOf (_msgSender ()), _msgSender ());
@@ -138,17 +151,19 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
138
151
139
152
/**
140
153
* @inheritdoc IDelegation
141
- * @dev Deduct the commission from the yet untaxed rewards before calculating the number of liquid
142
- * staking tokens corresponsing to the delegated amount. Increase the deposit of the validators in
143
- * the staking pool by the delegated amount.
154
+ * @dev Deduct the commission from the yet untaxed rewards before calculating the
155
+ * number of liquid staking tokens corresponsing to the delegated amount. Increase
156
+ * the deposit of the validators in the staking pool by the delegated amount.
144
157
*/
145
158
function stake () public override (BaseDelegation, IDelegation) payable whenNotPaused {
146
159
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage ();
147
- // if we are in the fundraising phase getRewards() would return 0 and taxedRewards would
148
- // be greater i.e. the commission calculated in taxRewards() would be negative, therefore
160
+ // if we are in the fundraising phase getRewards() would return 0 and
161
+ // taxedRewards would be greater i.e. the commission calculated in
162
+ // taxRewards() would be negative, therefore
149
163
if (_isActivated ()) {
150
- // the amount just delegated is now part of the rewards since it was added to the balance
151
- // therefore add it to the taxed rewards too to avoid commission and remove it after taxing
164
+ // the amount just delegated is now part of the rewards since
165
+ // it was added to the balance therefore add it to the taxed
166
+ // rewards too to avoid commission and remove it after taxing
152
167
$.taxedRewards += msg .value ;
153
168
taxRewards ();
154
169
$.taxedRewards -= msg .value ;
@@ -160,13 +175,14 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
160
175
}
161
176
162
177
/**
163
- * @dev Calculate the shares of the `staker` based on the delegated `value` and mint the
164
- * corresponding amount of liquid staking tokens (LST).
178
+ * @dev Calculate the shares of the `staker` based on the delegated `value`
179
+ * and mint the corresponding amount of liquid staking tokens (LST).
165
180
*
166
- * Emit {Staked} containing the `staker` address, the `value` staked, and the corresponding
167
- * amount of LST minted to the `staker`.
181
+ * Emit {Staked} containing the `staker` address, the `value` staked, and
182
+ * the corresponding amount of LST minted to the `staker`.
168
183
*
169
- * Revert with {DelegatedAmountTooLow} containing the `value` lower than {MIN_DELEGATION}.
184
+ * Revert with {DelegatedAmountTooLow} containing the `value` lower
185
+ * than {MIN_DELEGATION}.
170
186
*/
171
187
function _stake (uint256 value , address staker ) internal {
172
188
require (value >= MIN_DELEGATION, DelegatedAmountTooLow (value));
@@ -182,32 +198,35 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
182
198
183
199
/**
184
200
* @inheritdoc IDelegation
185
- * @dev Deduct the commission from the yet untaxed rewards before calculating the amount
186
- * corresponding to the unstaked liquid staking tokens. Decrease the deposit of the validators
187
- * in the staking pool by the calculated amount.
201
+ * @dev Deduct the commission from the yet untaxed rewards before calculating
202
+ * the amount corresponding to the unstaked liquid staking tokens. Decrease
203
+ * the deposit of the validators in the staking pool by the calculated amount.
188
204
*/
189
205
function unstake (uint256 shares )
190
206
public
191
207
override (BaseDelegation, IDelegation)
192
208
whenNotPaused
193
209
returns (uint256 amount )
194
210
{
195
- // if we are in the fundraising phase getRewards() would return 0 and taxedRewards would
196
- // be greater i.e. the commission calculated in taxRewards() would be negative, therefore
211
+ // if we are in the fundraising phase getRewards() would return 0 and
212
+ // taxedRewards would be greater i.e. the commission calculated in
213
+ // taxRewards() would be negative, therefore
197
214
if (_isActivated ())
198
- // deduct the commission from the yet untaxed rewards before calculating the amount
215
+ // deduct the commission from the yet untaxed rewards
216
+ // before calculating the amount
199
217
taxRewards ();
200
218
amount = _unstake (shares, _msgSender ());
201
219
_enqueueWithdrawal (amount);
202
220
_decreaseDeposit (amount);
203
221
}
204
222
205
223
/**
206
- * @dev Calculate and return the `amount` of ZIL corresponding to the unstaked `shares` i.e.
207
- * liquid staking tokens of the `staker` and burn the unstaked liquid staking tokens (LST).
224
+ * @dev Calculate and return the `amount` of ZIL corresponding to the unstaked
225
+ * `shares` i.e. liquid staking tokens of the `staker` and burn the unstaked
226
+ * liquid staking tokens (LST).
208
227
*
209
- * Emit {Unstaked} containing the `staker` address, the amount of ZIL unstaked, and the
210
- * number of LST `shares` burned.
228
+ * Emit {Unstaked} containing the `staker` address, the amount of ZIL unstaked,
229
+ * and the number of LST `shares` burned.
211
230
*/
212
231
function _unstake (uint256 shares , address staker ) internal returns (uint256 amount ) {
213
232
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage ();
@@ -221,7 +240,8 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
221
240
}
222
241
223
242
/**
224
- * @dev Return the amount of ZIL equivalent to 10**18 shares of the liquid staking token supply.
243
+ * @dev Return the amount of ZIL equivalent to 10**18 shares of the liquid
244
+ * staking token supply.
225
245
*/
226
246
function getPrice () public view returns (uint256 amount ) {
227
247
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage ();
@@ -234,13 +254,13 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
234
254
}
235
255
236
256
/**
237
- * @dev Deduct the commission from the yet untaxed rewards and transfer it to the configured
238
- * commission receiver address.
257
+ * @dev Deduct the commission from the yet untaxed rewards and transfer it to
258
+ * the configured commission receiver address.
239
259
*
240
260
* Emit {CommissionPaid} containing the receiver address and the amount transferred.
241
261
*
242
- * Revert with {TransferFailed} containing the reciever address and the amount to be
243
- * transferred if the transfer failed.
262
+ * Revert with {TransferFailed} containing the reciever address and the amount
263
+ * to be transferred if the transfer failed.
244
264
*/
245
265
function taxRewards () internal {
246
266
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage ();
@@ -260,17 +280,17 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
260
280
/**
261
281
* @inheritdoc IDelegation
262
282
*
263
- * @dev Revert with {StakingPoolNotActivated} if the staking pool has not earned
264
- * any rewards yet.
283
+ * @dev Revert with {StakingPoolNotActivated} if the staking pool has not
284
+ * earned any rewards yet.
265
285
*/
266
286
function stakeRewards () public override (BaseDelegation, IDelegation) onlyOwner {
267
287
require (_isActivated (), StakingPoolNotActivated ());
268
288
_stakeRewards ();
269
289
}
270
290
271
291
/**
272
- * @dev Stake only the portion of the taxed rewards that are not needed for covering
273
- * the pending withdrawals.
292
+ * @dev Stake only the portion of the taxed rewards that are not needed for
293
+ * covering the pending withdrawals.
274
294
*/
275
295
function _stakeRewards () internal {
276
296
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage ();
0 commit comments