Skip to content

Commit

Permalink
217: Test fixes
Browse files Browse the repository at this point in the history
Fixes for NodeELRewardVault.t

Fixes for solidity formatting:
 - bracketSpacing
 - double quote
 - no tabs

Fixes test_withdraw in NodeELRewardVault.t.sol

Pass operator address as argument to NodeRegistryMock

rebase changes from mainnet_V0

fixing hoax prank issues

ValidatorWithdrawalVaultTest is passing

PermissionlessNodeRegistryTest.test_markReadyToDepositValidator is passing

PermissionlessNodeRegistryTest.test_getAllActiveValidatorsWithZeroPageNumber is passing

PermissionlessNodeRegistryTest.test_getAllActiveValidators is passing

PermissionlessPoolTest.test_setCommisionFeesWithInvalidInput is passing

PermissionedPoolTest.test_StakeUserETHToBeaconChain is passing

OperatorRewardsCollectorTest passing

All tests passing
  • Loading branch information
jac18281828 committed Apr 5, 2024
1 parent b305c1b commit 891f3f6
Show file tree
Hide file tree
Showing 63 changed files with 1,408 additions and 1,473 deletions.
27 changes: 11 additions & 16 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@
"JuanBlanco.solidity"
]
}
},
"containerEnv": {
"PRIVATE_KEY": "${localEnv:PRIVATE_KEY}",
"PUBLIC_KEY": "${localEnv:PUBLIC_KEY}",
"RPC_URL": "${localEnv:RPC_URL}",
"OPG_URL": "${localEnv:OPG_URL}",
"OPS_URL": "${localEnv:OPS_URL}",
"ARS_URL": "${localEnv:ARS_URL}",
"HOLESKY_URL": "${localEnv:HOLESKY_URL}",
"ETHERSCAN_API_KEY": "${localEnv:ETHERSCAN_API_KEY}"
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "cat /etc/os-release",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}
}
32 changes: 32 additions & 0 deletions .github/workflows/ci-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Dev Image CI

on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- "*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and Push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64
push: false
build-args: |
VERSION=latest
18 changes: 14 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 120
}
"semi": true,
"singleQuote": false,
"printWidth": 120,
"useTabs": false,
"bracketSpacing": true,
"plugins": [
"prettier-plugin-solidity"
],
"overrides": [
{
"files": "*.sol"
}
]
}
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ RUN npm ci
RUN npm run prettier:check
# RUN slither .
# RUN npm run lint
# RUN forge test -vvv
RUN forge test -v
RUN forge coverage
RUN forge geiger --check contracts/*.sol contracts/*/*.sol
16 changes: 8 additions & 8 deletions contracts/Auction.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.16;

import './library/UtilLib.sol';
import "./library/UtilLib.sol";

import '../contracts/interfaces/SDCollateral/IAuction.sol';
import '../contracts/interfaces/IStaderStakePoolManager.sol';
import "../contracts/interfaces/SDCollateral/IAuction.sol";
import "../contracts/interfaces/IStaderStakePoolManager.sol";

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

contract Auction is IAuction, AccessControlUpgradeable, ReentrancyGuardUpgradeable {
IStaderConfig public override staderConfig;
Expand Down Expand Up @@ -97,7 +97,7 @@ contract Auction is IAuction, AccessControlUpgradeable, ReentrancyGuardUpgradeab
if (lotItem.ethExtracted) revert AlreadyClaimed();

lotItem.ethExtracted = true;
IStaderStakePoolManager(staderConfig.getStakePoolManager()).receiveEthFromAuction{value: ethAmount}();
IStaderStakePoolManager(staderConfig.getStakePoolManager()).receiveEthFromAuction{ value: ethAmount }();
emit ETHClaimed(lotId, staderConfig.getStakePoolManager(), ethAmount);
}

Expand Down Expand Up @@ -126,7 +126,7 @@ contract Auction is IAuction, AccessControlUpgradeable, ReentrancyGuardUpgradeab
lotItem.bids[msg.sender] -= withdrawalAmount;

// send the funds
(bool success, ) = payable(msg.sender).call{value: withdrawalAmount}('');
(bool success, ) = payable(msg.sender).call{ value: withdrawalAmount }("");
if (!success) revert ETHWithdrawFailed();

emit BidWithdrawn(lotId, msg.sender, withdrawalAmount);
Expand Down
22 changes: 9 additions & 13 deletions contracts/ETHx.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.16;
import './library/UtilLib.sol';
import "./library/UtilLib.sol";

import './interfaces/IStaderConfig.sol';
import "./interfaces/IStaderConfig.sol";

import '@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";

/**
* @title ETHx token Contract
Expand All @@ -18,8 +18,8 @@ contract ETHx is Initializable, ERC20Upgradeable, PausableUpgradeable, AccessCon
event UpdatedStaderConfig(address indexed _staderConfig);

IStaderConfig public staderConfig;
bytes32 public constant MINTER_ROLE = keccak256('MINTER_ROLE');
bytes32 public constant BURNER_ROLE = keccak256('BURNER_ROLE');
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
Expand All @@ -30,7 +30,7 @@ contract ETHx is Initializable, ERC20Upgradeable, PausableUpgradeable, AccessCon
UtilLib.checkNonZeroAddress(_admin);
UtilLib.checkNonZeroAddress(_staderConfig);

__ERC20_init('ETHx', 'ETHx');
__ERC20_init("ETHx", "ETHx");
__Pausable_init();
__AccessControl_init();

Expand Down Expand Up @@ -74,11 +74,7 @@ contract ETHx is Initializable, ERC20Upgradeable, PausableUpgradeable, AccessCon
_unpause();
}

function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override whenNotPaused {
function _beforeTokenTransfer(address from, address to, uint256 amount) internal override whenNotPaused {
super._beforeTokenTransfer(from, to, amount);
}

Expand Down
18 changes: 9 additions & 9 deletions contracts/NodeELRewardVault.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.16;

import './library/UtilLib.sol';
import "./library/UtilLib.sol";

import './interfaces/IPoolUtils.sol';
import './interfaces/IVaultProxy.sol';
import './interfaces/INodeRegistry.sol';
import './interfaces/INodeELRewardVault.sol';
import './interfaces/IStaderStakePoolManager.sol';
import './interfaces/IOperatorRewardsCollector.sol';
import "./interfaces/IPoolUtils.sol";
import "./interfaces/IVaultProxy.sol";
import "./interfaces/INodeRegistry.sol";
import "./interfaces/INodeELRewardVault.sol";
import "./interfaces/IStaderStakePoolManager.sol";
import "./interfaces/IOperatorRewardsCollector.sol";

contract NodeELRewardVault is INodeELRewardVault {
constructor() {}
Expand All @@ -33,11 +33,11 @@ contract NodeELRewardVault is INodeELRewardVault {
.calculateRewardShare(poolId, totalRewards);

// Distribute rewards
IStaderStakePoolManager(staderConfig.getStakePoolManager()).receiveExecutionLayerRewards{value: userShare}();
IStaderStakePoolManager(staderConfig.getStakePoolManager()).receiveExecutionLayerRewards{ value: userShare }();
// slither-disable-next-line arbitrary-send-eth
UtilLib.sendValue(payable(staderConfig.getStaderTreasury()), protocolShare);
address operator = UtilLib.getOperatorAddressByOperatorId(poolId, operatorId, staderConfig);
IOperatorRewardsCollector(staderConfig.getOperatorRewardsCollector()).depositFor{value: operatorShare}(
IOperatorRewardsCollector(staderConfig.getOperatorRewardsCollector()).depositFor{ value: operatorShare }(
operator
);

Expand Down
35 changes: 20 additions & 15 deletions contracts/OperatorRewardsCollector.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.16;

import './library/UtilLib.sol';
import "./library/UtilLib.sol";

import './interfaces/INodeRegistry.sol';
import './interfaces/INodeELRewardVault.sol';
import './interfaces/IPermissionlessNodeRegistry.sol';
import './interfaces/IOperatorRewardsCollector.sol';
import './interfaces/IStaderConfig.sol';
import './interfaces/ISDUtilityPool.sol';
import './interfaces/SDCollateral/ISDCollateral.sol';
import './interfaces/IWETH.sol';
import '../contracts/interfaces/IStaderOracle.sol';
import "./interfaces/INodeRegistry.sol";
import "./interfaces/INodeELRewardVault.sol";
import "./interfaces/IPermissionlessNodeRegistry.sol";
import "./interfaces/IOperatorRewardsCollector.sol";
import "./interfaces/IStaderConfig.sol";
import "./interfaces/ISDUtilityPool.sol";
import "./interfaces/SDCollateral/ISDCollateral.sol";
import "./interfaces/IWETH.sol";
import "../contracts/interfaces/IStaderOracle.sol";

import '@openzeppelin/contracts/utils/math/Math.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

contract OperatorRewardsCollector is IOperatorRewardsCollector, AccessControlUpgradeable {
IStaderConfig public staderConfig;
Expand Down Expand Up @@ -46,16 +46,22 @@ contract OperatorRewardsCollector is IOperatorRewardsCollector, AccessControlUpg
emit DepositedFor(msg.sender, _receiver, msg.value);
}

event log_uint256(string message, uint256 value);

/**
* @notice Claims payouts for an operator, repaying any outstanding liquidations and transferring any remaining balance to the operator's rewards address.
* @dev This function first checks for any unpaid liquidations for the operator and repays them if necessary. Then, it transfers any remaining balance to the operator's reward address.
*/
function claim() external {
claimLiquidation(msg.sender);

emit log_uint256("withdrawableInEth(msg.sender)", withdrawableInEth(msg.sender));

uint256 amount = balances[msg.sender] > withdrawableInEth(msg.sender)
? withdrawableInEth(msg.sender)
: balances[msg.sender];

emit log_uint256("claim amount", amount);
_claim(msg.sender, amount);
}

Expand Down Expand Up @@ -145,7 +151,7 @@ contract OperatorRewardsCollector is IOperatorRewardsCollector, AccessControlUpg
operatorLiquidation.totalAmountInEth - operatorLiquidation.totalFeeInEth
);

weth.deposit{value: wETHDeposit}();
weth.deposit{ value: wETHDeposit }();
if (weth.transferFrom(address(this), operatorLiquidation.liquidator, wETHDeposit) == false)
revert WethTransferFailed();
balances[operator] -= wETHDeposit;
Expand All @@ -157,7 +163,7 @@ contract OperatorRewardsCollector is IOperatorRewardsCollector, AccessControlUpg
sdUtilityPool.completeLiquidation(operator);
} else {
// Transfer WETH to liquidator and ETH to treasury
weth.deposit{value: operatorLiquidation.totalAmountInEth - operatorLiquidation.totalFeeInEth}();
weth.deposit{ value: operatorLiquidation.totalAmountInEth - operatorLiquidation.totalFeeInEth }();
if (
weth.transferFrom(
address(this),
Expand All @@ -182,7 +188,6 @@ contract OperatorRewardsCollector is IOperatorRewardsCollector, AccessControlUpg
*/
function _claim(address operator, uint256 amount) internal {
uint256 maxWithdrawableInEth = withdrawableInEth(operator);

if (amount > maxWithdrawableInEth || amount > balances[operator]) revert InsufficientBalance();

balances[operator] -= amount;
Expand Down
20 changes: 8 additions & 12 deletions contracts/Penalty.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.16;

import './library/UtilLib.sol';
import "./library/UtilLib.sol";

import './interfaces/IPenalty.sol';
import './interfaces/IRatedV1.sol';
import './interfaces/IStaderOracle.sol';
import './interfaces/IStaderConfig.sol';
import "./interfaces/IPenalty.sol";
import "./interfaces/IRatedV1.sol";
import "./interfaces/IStaderOracle.sol";
import "./interfaces/IStaderConfig.sol";

import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

contract Penalty is IPenalty, AccessControlUpgradeable, ReentrancyGuardUpgradeable {
IStaderConfig public staderConfig;
Expand All @@ -28,11 +28,7 @@ contract Penalty is IPenalty, AccessControlUpgradeable, ReentrancyGuardUpgradeab
_disableInitializers();
}

function initialize(
address _admin,
address _staderConfig,
address _ratedOracleAddress
) external initializer {
function initialize(address _admin, address _staderConfig, address _ratedOracleAddress) external initializer {
UtilLib.checkNonZeroAddress(_admin);
UtilLib.checkNonZeroAddress(_staderConfig);
UtilLib.checkNonZeroAddress(_ratedOracleAddress);
Expand Down
Loading

0 comments on commit 891f3f6

Please sign in to comment.