Skip to content

Commit 1ff4664

Browse files
Improve code formatting
1 parent e708444 commit 1ff4664

6 files changed

+347
-275
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,5 +437,5 @@ and a few more for the non-liquid variant.
437437

438438
To generate and view the comprehensive NatSpec documentation, run
439439
```bash
440-
forge doc --serve --open
440+
forge doc --serve --open --port 3001
441441
```

src/BaseDelegation.sol

+158-130
Large diffs are not rendered by default.

src/IDelegation.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ interface IDelegation {
5353

5454
/**
5555
* @notice Transfer all outstanding commissions to the configured receiver.
56-
* Must be called by the contract owner.
56+
* It must be called by the contract owner.
5757
*/
5858
function collectCommission() external;
5959

src/LiquidDelegation.sol

+66-46
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ import {NonRebasingLST} from "src/NonRebasingLST.sol";
99
bytes32 constant LIQUID_VARIANT = 0xfa57cbed4b267d0bc9f2cbdae86b4d1d23ca818308f873af9c968a23afadfd00;
1010

1111
/**
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.
1819
*
1920
* @dev The contract is registered as the reward address of all validators in the
2021
* staking pool, i.e. its balance can increase in every block. Since this does not
2122
* happen in form of transactions, the {receive} function will not notice it.
2223
*/
24+
// solhint-disable comprehensive-interface
2325
contract LiquidDelegation is IDelegation, BaseDelegation {
2426

2527
// ************************************************************************
@@ -29,10 +31,11 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
2931
// ************************************************************************
3032

3133
/**
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`.
3639
*/
3740
/// @custom:storage-location erc7201:zilliqa.storage.LiquidDelegation
3841
struct LiquidDelegationStorage {
@@ -70,7 +73,11 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
7073
/**
7174
* @dev Initialize the base contracts and create the LST token contract.
7275
*/
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 {
7481
__BaseDelegation_init(initialOwner);
7582
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage();
7683
$.lst = address(new NonRebasingLST(name, symbol));
@@ -105,19 +112,25 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
105112
}
106113

107114
/// @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
110121
taxRewards();
111122
_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
113125
_addToPool(blsPubKey, controlAddress);
114126
}
115127

116128
/// @inheritdoc BaseDelegation
117129
function leavePool(bytes calldata blsPubKey) public override {
118130
if (!_preparedToLeave(blsPubKey))
119131
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
121134
taxRewards();
122135
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage();
123136
uint256 amount = _unstake(NonRebasingLST($.lst).balanceOf(_msgSender()), _msgSender());
@@ -138,17 +151,19 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
138151

139152
/**
140153
* @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.
144157
*/
145158
function stake() public override(BaseDelegation, IDelegation) payable whenNotPaused {
146159
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
149163
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
152167
$.taxedRewards += msg.value;
153168
taxRewards();
154169
$.taxedRewards -= msg.value;
@@ -160,13 +175,14 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
160175
}
161176

162177
/**
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).
165180
*
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`.
168183
*
169-
* Revert with {DelegatedAmountTooLow} containing the `value` lower than {MIN_DELEGATION}.
184+
* Revert with {DelegatedAmountTooLow} containing the `value` lower
185+
* than {MIN_DELEGATION}.
170186
*/
171187
function _stake(uint256 value, address staker) internal {
172188
require(value >= MIN_DELEGATION, DelegatedAmountTooLow(value));
@@ -182,32 +198,35 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
182198

183199
/**
184200
* @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.
188204
*/
189205
function unstake(uint256 shares)
190206
public
191207
override(BaseDelegation, IDelegation)
192208
whenNotPaused
193209
returns(uint256 amount)
194210
{
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
197214
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
199217
taxRewards();
200218
amount = _unstake(shares, _msgSender());
201219
_enqueueWithdrawal(amount);
202220
_decreaseDeposit(amount);
203221
}
204222

205223
/**
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).
208227
*
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.
211230
*/
212231
function _unstake(uint256 shares, address staker) internal returns(uint256 amount) {
213232
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage();
@@ -221,7 +240,8 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
221240
}
222241

223242
/**
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.
225245
*/
226246
function getPrice() public view returns(uint256 amount) {
227247
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage();
@@ -234,13 +254,13 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
234254
}
235255

236256
/**
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.
239259
*
240260
* Emit {CommissionPaid} containing the receiver address and the amount transferred.
241261
*
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.
244264
*/
245265
function taxRewards() internal {
246266
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage();
@@ -260,17 +280,17 @@ contract LiquidDelegation is IDelegation, BaseDelegation {
260280
/**
261281
* @inheritdoc IDelegation
262282
*
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.
265285
*/
266286
function stakeRewards() public override(BaseDelegation, IDelegation) onlyOwner {
267287
require(_isActivated(), StakingPoolNotActivated());
268288
_stakeRewards();
269289
}
270290

271291
/**
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.
274294
*/
275295
function _stakeRewards() internal {
276296
LiquidDelegationStorage storage $ = _getLiquidDelegationStorage();

0 commit comments

Comments
 (0)