Skip to content

Commit

Permalink
Restructure the readme, add more solhint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
DrZoltanFazekas committed Dec 18, 2024
1 parent 0cdf822 commit a1db3ed
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 73 deletions.
15 changes: 14 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
"func-visibility": ["warn", {"ignoreConstructors": true}],
"gas-custom-errors": "off",
"no-empty-blocks": "off",
"no-complex-fallback": "off"
"no-complex-fallback": "off",
"interface-starts-with-i": "warn",
"func-param-name-mixedcase": "warn",
"modifier-name-mixedcase": "warn",
"gas-calldata-parameters": "warn",
"gas-indexed-events": "warn",
"gas-length-in-loops": "warn",
"comprehensive-interface": "warn",
"gas-increment-by-one": "off",
"private-vars-leading-underscore": ["off", {"strict": false}],
"named-parameters-mapping": "off",
"foundry-test-functions": ["off"],
"imports-order": "off",
"max-line-length": ["off", 120]
}
}
124 changes: 70 additions & 54 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/BaseDelegation.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.26;

import {Delegation} from "src/Delegation.sol";
import {IDelegation} from "src/IDelegation.sol";
import {WithdrawalQueue} from "src/WithdrawalQueue.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {ERC165Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol";

abstract contract BaseDelegation is Delegation, PausableUpgradeable, Ownable2StepUpgradeable, UUPSUpgradeable, ERC165Upgradeable {
abstract contract BaseDelegation is IDelegation, PausableUpgradeable, Ownable2StepUpgradeable, UUPSUpgradeable, ERC165Upgradeable {

using WithdrawalQueue for WithdrawalQueue.Fifo;

Expand Down
2 changes: 1 addition & 1 deletion src/Delegation.sol → src/IDelegation.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.26;

interface Delegation {
interface IDelegation {

// data can store additional information e.g. liquid staking tokens
event Staked(address indexed delegator, uint256 amount, bytes data);
Expand Down
8 changes: 4 additions & 4 deletions test/BaseDelegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.26;
import {BlsVerifyPrecompile} from "test/BlsVerifyPrecompile.t.sol";
import {BaseDelegation} from "src/BaseDelegation.sol";
import {WithdrawalQueue} from "src/WithdrawalQueue.sol";
import {Delegation} from "src/Delegation.sol";
import {IDelegation} from "src/IDelegation.sol";
import {Deposit} from "@zilliqa/zq2/deposit_v3.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Test} from "forge-std/Test.sol";
Expand Down Expand Up @@ -179,7 +179,7 @@ abstract contract BaseDelegationTest is Test {
false,
address(delegation)
);
emit Delegation.Staked(
emit IDelegation.Staked(
stakers[0],
depositAmount,
""
Expand All @@ -201,7 +201,7 @@ abstract contract BaseDelegationTest is Test {
vm.roll(block.number + Deposit(delegation.DEPOSIT_CONTRACT()).blocksPerEpoch() * 2);
}

function claimsAfterManyUnstakings(BaseDelegation delegation, uint64 steps) public {
function claimsAfterManyUnstakings(BaseDelegation delegation, uint64 steps) internal {
uint256 i;
uint256 x;

Expand Down Expand Up @@ -229,7 +229,7 @@ abstract contract BaseDelegationTest is Test {
false,
address(delegation)
);
emit Delegation.Staked(
emit IDelegation.Staked(
stakers[i-1],
steps * x * 1 ether,
""
Expand Down
1 change: 1 addition & 0 deletions test/BlsVerifyPrecompile.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.26;

contract BlsVerifyPrecompile {

// solhint-disable foundry-test-functions
function blsVerify(bytes memory, bytes memory, bytes memory) public pure returns(bool) {
return true;
}
Expand Down
11 changes: 6 additions & 5 deletions test/LiquidDelegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {LiquidDelegationV2} from "src/LiquidDelegationV2.sol";
import {NonRebasingLST} from "src/NonRebasingLST.sol";
import {BaseDelegation} from "src/BaseDelegation.sol";
import {WithdrawalQueue} from "src/WithdrawalQueue.sol";
import {Delegation} from "src/Delegation.sol";
import {IDelegation} from "src/IDelegation.sol";
import {Deposit} from "@zilliqa/zq2/deposit_v3.sol";
import {Console} from "src/Console.sol";
import {Vm} from "forge-std/Test.sol";
import {console} from "forge-std/console.sol";

/* solhint-disable func-name-mixedcase */
contract LiquidDelegationTest is BaseDelegationTest {
LiquidDelegationV2 internal delegation;
NonRebasingLST internal lst;
Expand Down Expand Up @@ -54,7 +55,7 @@ contract LiquidDelegationTest is BaseDelegationTest {
uint256 rewardsBeforeUnstaking,
uint256 blocksUntil,
DepositMode mode
) public {
) internal {
delegation = LiquidDelegationV2(proxy);
lst = NonRebasingLST(delegation.getLST());

Expand Down Expand Up @@ -113,7 +114,7 @@ contract LiquidDelegationTest is BaseDelegationTest {
false,
address(delegation)
);
emit Delegation.Staked(
emit IDelegation.Staked(
stakers[0],
delegatedAmount,
abi.encode(lst.totalSupply() * delegatedAmount / (delegation.getStake() + delegation.getRewards()))
Expand Down Expand Up @@ -197,7 +198,7 @@ contract LiquidDelegationTest is BaseDelegationTest {
false,
address(delegation)
);
emit Delegation.Unstaked(
emit IDelegation.Unstaked(
stakers[0],
(delegation.getStake() + delegation.getRewards()) * lst.balanceOf(stakers[0]) / lst.totalSupply(),
abi.encode(lst.balanceOf(stakers[0]))
Expand Down Expand Up @@ -279,7 +280,7 @@ contract LiquidDelegationTest is BaseDelegationTest {
false,
address(delegation)
);
emit Delegation.Claimed(
emit IDelegation.Claimed(
stakers[0],
unstakedAmount,
""
Expand Down
13 changes: 7 additions & 6 deletions test/NonLiquidDelegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {NonLiquidDelegation} from "src/NonLiquidDelegation.sol";
import {NonLiquidDelegationV2} from "src/NonLiquidDelegationV2.sol";
import {BaseDelegation} from "src/BaseDelegation.sol";
import {WithdrawalQueue} from "src/WithdrawalQueue.sol";
import {Delegation} from "src/Delegation.sol";
import {IDelegation} from "src/IDelegation.sol";
import {Deposit} from "@zilliqa/zq2/deposit_v3.sol";
import {Console} from "src/Console.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {console} from "forge-std/console.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

/* solhint-disable func-name-mixedcase */
contract NonLiquidDelegationTest is BaseDelegationTest {
using SafeCast for int256;

Expand Down Expand Up @@ -113,7 +114,7 @@ contract NonLiquidDelegationTest is BaseDelegationTest {
uint256 rewardsBeforeStaking,
uint256 rewardsAccruedAfterEach,
DepositMode mode
) public {
) internal {
uint64 steps = withdrawalInSteps;
uint256[] memory stakerIndicesBeforeWithdrawals = abi.decode(_stakerIndicesBeforeWithdrawals, (uint256[]));
int256[] memory relativeAmountsBeforeWithdrawals = abi.decode(_relativeAmountsBeforeWithdrawals, (int256[]));
Expand Down Expand Up @@ -500,7 +501,7 @@ contract NonLiquidDelegationTest is BaseDelegationTest {
false,
address(delegation)
);
emit Delegation.Staked(
emit IDelegation.Staked(
stakers[i-1],
x * 1 ether,
""
Expand All @@ -522,7 +523,7 @@ contract NonLiquidDelegationTest is BaseDelegationTest {
false,
address(delegation)
);
emit Delegation.Unstaked(
emit IDelegation.Unstaked(
stakers[i-1],
x * 1 ether,
""
Expand Down Expand Up @@ -567,7 +568,7 @@ contract NonLiquidDelegationTest is BaseDelegationTest {
false,
address(delegation)
);
emit Delegation.Claimed(
emit IDelegation.Claimed(
stakers[i-1],
steps / 8 * x * 1 ether,
""
Expand Down Expand Up @@ -613,7 +614,7 @@ contract NonLiquidDelegationTest is BaseDelegationTest {
false,
address(delegation)
);
emit Delegation.Staked(
emit IDelegation.Staked(
stakers[i-1],
x * 1 ether,
""
Expand Down

0 comments on commit a1db3ed

Please sign in to comment.