Skip to content

Commit

Permalink
Merge branch 'main' into stage-27062023
Browse files Browse the repository at this point in the history
  • Loading branch information
mtabasco committed Aug 2, 2023
2 parents fa3b2b2 + 470fc45 commit 435b2a8
Show file tree
Hide file tree
Showing 36 changed files with 310 additions and 168 deletions.
108 changes: 108 additions & 0 deletions .openzeppelin/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,114 @@
}
}
}
},
"400b4079d3549b56702f7dfadb688c5395e64dd3211c072e6f584ae7ae02f79f": {
"address": "0xE2d1Cf93CD4D5E0EEEF1b33ca51Bb82c829A1b75",
"txHash": "0x5c1c55b3073cc2579fd426616636484a188f1205a4278dc37063bc891c397494",
"layout": {
"solcVersion": "0.8.18",
"storage": [
{
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "t_uint8",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:62",
"retypedFrom": "bool"
},
{
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "t_bool",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:67"
},
{
"label": "__gap",
"offset": 0,
"slot": "1",
"type": "t_array(t_uint256)50_storage",
"contract": "ERC1967UpgradeUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol:197"
},
{
"label": "__gap",
"offset": 0,
"slot": "51",
"type": "t_array(t_uint256)50_storage",
"contract": "UUPSUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:107"
},
{
"label": "__gap",
"offset": 0,
"slot": "101",
"type": "t_array(t_uint256)50_storage",
"contract": "ContextUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36"
},
{
"label": "_owner",
"offset": 0,
"slot": "151",
"type": "t_address",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22"
},
{
"label": "__gap",
"offset": 0,
"slot": "152",
"type": "t_array(t_uint256)49_storage",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94"
},
{
"label": "_pendingOwner",
"offset": 0,
"slot": "201",
"type": "t_address",
"contract": "Ownable2StepUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol:27"
},
{
"label": "__gap",
"offset": 0,
"slot": "202",
"type": "t_array(t_uint256)49_storage",
"contract": "Ownable2StepUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol:70"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_array(t_uint256)49_storage": {
"label": "uint256[49]",
"numberOfBytes": "1568"
},
"t_array(t_uint256)50_storage": {
"label": "uint256[50]",
"numberOfBytes": "1600"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
}
}
}
}
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SSV Network Smart Contracts

### Intro | [Architecture](./docs/architecture.md) | [Setup](./docs/setup.md) | [Tasks](./docs/tasks.md) | [Local development](./docs/local-dev.md)
### Intro | [Architecture](./docs/architecture.md) | [Setup](./docs/setup.md) | [Tasks](./docs/tasks.md) | [Local development](./docs/local-dev.md) | [Roles](./docs/roles.md)

This repository contains the Solidity smart contracts for the SSV Network. The SSV Network is a decentralized network for the operation of Ethereum validators. It allows for secure, scalable, and decentralized staking on the Ethereum blockchain. The key elements of this system are represented through several Ethereum smart contracts, all of which are outlined below.

Expand All @@ -10,6 +10,7 @@ The documentation is divided into different sections:
- **Setup** The basic setup of the repository to be able to compile the contracts, run tests, etc.
- **Tasks** Detailed instructions to run useful tools, deploy, and upgrade the contracts.
- **Local development** Guide to setup the local environment to work with the contracts.
- **Roles** Detailed information about the privileged roles in the system.

## SSV Documentation

Expand Down
18 changes: 12 additions & 6 deletions contracts/SSVNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import "./libraries/Types.sol";
import "./libraries/CoreLib.sol";
import "./libraries/SSVStorage.sol";
import "./libraries/SSVStorageProtocol.sol";
import "./libraries/OperatorLib.sol";
import "./libraries/ClusterLib.sol";
import "./libraries/RegisterAuth.sol";

import "./SSVProxy.sol";
Expand All @@ -34,7 +32,6 @@ contract SSVNetwork is
SSVProxy
{
using Types256 for uint256;
using ClusterLib for Cluster;

/****************/
/* Initializers */
Expand Down Expand Up @@ -98,6 +95,11 @@ contract SSVNetwork is
sp.operatorMaxFeeIncrease = operatorMaxFeeIncrease_;
}

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

/*****************/
/* UUPS required */
/*****************/
Expand Down Expand Up @@ -150,7 +152,7 @@ contract SSVNetwork is
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS]);
}

function withdrawOperatorEarnings(uint64 operatorId) external override {
function withdrawAllOperatorEarnings(uint64 operatorId) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS]);
}

Expand Down Expand Up @@ -186,7 +188,7 @@ contract SSVNetwork is
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_CLUSTERS]);
}

function liquidate(address owner, uint64[] calldata operatorIds, ISSVNetworkCore.Cluster memory cluster) external {
function liquidate(address clusterOwner, uint64[] calldata operatorIds, ISSVNetworkCore.Cluster memory cluster) external {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_CLUSTERS]);
}

Expand All @@ -199,7 +201,7 @@ contract SSVNetwork is
}

function deposit(
address owner,
address clusterOwner,
uint64[] calldata operatorIds,
uint256 amount,
ISSVNetworkCore.Cluster memory cluster
Expand Down Expand Up @@ -243,6 +245,10 @@ contract SSVNetwork is
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_DAO]);
}

function getVersion() external pure override returns (string memory version) {
return CoreLib.getVersion();
}

/*******************************/
/* Upgrade Modules Function */
/*******************************/
Expand Down
24 changes: 12 additions & 12 deletions contracts/SSVNetworkViews.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract SSVNetworkViews is UUPSUpgradeable, Ownable2StepUpgradeable, ISSVViews

// @dev reserve storage space for future new state variables in base contract
// slither-disable-next-line shadowing-state
uint256[50] private__gap;
uint256[50] private __gap;

function _authorizeUpgrade(address) internal override onlyOwner {}

Expand All @@ -39,8 +39,8 @@ contract SSVNetworkViews is UUPSUpgradeable, Ownable2StepUpgradeable, ISSVViews
/* Validator External View Functions */
/*************************************/

function getValidator(address owner, bytes calldata publicKey) external view override returns (bool active) {
return ssvNetwork.getValidator(owner, publicKey);
function getValidator(address clusterOwner, bytes calldata publicKey) external view override returns (bool active) {
return ssvNetwork.getValidator(clusterOwner, publicKey);
}

/************************************/
Expand All @@ -51,7 +51,7 @@ contract SSVNetworkViews is UUPSUpgradeable, Ownable2StepUpgradeable, ISSVViews
return ssvNetwork.getOperatorFee(operatorId);
}

function getOperatorDeclaredFee(uint64 operatorId) external view override returns (uint256, uint64, uint64) {
function getOperatorDeclaredFee(uint64 operatorId) external view override returns (bool, uint256, uint64, uint64) {
return ssvNetwork.getOperatorDeclaredFee(operatorId);
}

Expand All @@ -64,27 +64,27 @@ contract SSVNetworkViews is UUPSUpgradeable, Ownable2StepUpgradeable, ISSVViews
/***********************************/

function isLiquidatable(
address owner,
address clusterOwner,
uint64[] calldata operatorIds,
Cluster memory cluster
) external view override returns (bool) {
return ssvNetwork.isLiquidatable(owner, operatorIds, cluster);
return ssvNetwork.isLiquidatable(clusterOwner, operatorIds, cluster);
}

function isLiquidated(
address owner,
address clusterOwner,
uint64[] calldata operatorIds,
Cluster memory cluster
) external view override returns (bool) {
return ssvNetwork.isLiquidated(owner, operatorIds, cluster);
return ssvNetwork.isLiquidated(clusterOwner, operatorIds, cluster);
}

function getBurnRate(
address owner,
address clusterOwner,
uint64[] calldata operatorIds,
Cluster memory cluster
) external view returns (uint256) {
return ssvNetwork.getBurnRate(owner, operatorIds, cluster);
return ssvNetwork.getBurnRate(clusterOwner, operatorIds, cluster);
}

/***********************************/
Expand All @@ -96,11 +96,11 @@ contract SSVNetworkViews is UUPSUpgradeable, Ownable2StepUpgradeable, ISSVViews
}

function getBalance(
address owner,
address clusterOwner,
uint64[] calldata operatorIds,
Cluster memory cluster
) external view override returns (uint256) {
return ssvNetwork.getBalance(owner, operatorIds, cluster);
return ssvNetwork.getBalance(clusterOwner, operatorIds, cluster);
}

/*******************************/
Expand Down
4 changes: 4 additions & 0 deletions contracts/interfaces/ISSVNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ interface ISSVNetwork {
uint64 operatorMaxFeeIncrease_
) external;

function getVersion() external pure returns (string memory version);

function setFeeRecipientAddress(address feeRecipientAddress) external;

function updateModule(SSVModules moduleId, address moduleAddress) external;

function setRegisterAuth(address userAddress, bool authOperators, bool authValidators) external;
Expand Down
8 changes: 2 additions & 6 deletions contracts/interfaces/ISSVOperators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@ interface ISSVOperators is ISSVNetworkCore {
/// @param fee The new Operator's fee (SSV)
function reduceOperatorFee(uint64 operatorId, uint256 fee) external;

/// @notice Sets the fee recipient address
/// @param feeRecipientAddress The address to receive Operator's fee
function setFeeRecipientAddress(address feeRecipientAddress) external;

/// @notice Withdraws operator earnings
/// @param operatorId The ID of the operator
/// @param tokenAmount The amount of tokens to withdraw (SSV)
function withdrawOperatorEarnings(uint64 operatorId, uint256 tokenAmount) external;

/// @notice Withdraws all operator earnings
/// @param operatorId The ID of the operator
function withdrawOperatorEarnings(uint64 operatorId) external;
function withdrawAllOperatorEarnings(uint64 operatorId) external;

/**
* @dev Emitted when a new operator has been added.
Expand All @@ -72,7 +68,7 @@ interface ISSVOperators is ISSVNetworkCore {
event OperatorWhitelistUpdated(uint64 indexed operatorId, address whitelisted);
event OperatorFeeDeclared(address indexed owner, uint64 indexed operatorId, uint256 blockNumber, uint256 fee);

event OperatorFeeCancellationDeclared(address indexed owner, uint64 indexed operatorId);
event OperatorFeeDeclarationCancelled(address indexed owner, uint64 indexed operatorId);
/**
* @dev Emitted when an operator's fee is updated.
* @param owner Operator's owner.
Expand Down
17 changes: 9 additions & 8 deletions contracts/interfaces/ISSVViews.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ interface ISSVViews is ISSVNetworkCore {
/// @notice Gets the validator status
/// @param owner The address of the validator's owner
/// @param publicKey The public key of the validator
/// @return A boolean indicating if the validator is active
function getValidator(address owner, bytes calldata publicKey) external view returns (bool);
/// @return active A boolean indicating if the validator is active. If it does not exist, returns false.
function getValidator(address owner, bytes calldata publicKey) external view returns (bool active);

/// @notice Gets the operator fee
/// @param operatorId The ID of the operator
/// @return The fee associated with the operator (SSV)
function getOperatorFee(uint64 operatorId) external view returns (uint256);

/// @return fee The fee associated with the operator (SSV). If the operator does not exist, the returned value is 0.
function getOperatorFee(uint64 operatorId) external view returns (uint256 fee);
/// @notice Gets the declared operator fee
/// @param operatorId The ID of the operator
/// @return isFeeDeclared A boolean indicating if the fee is declared
/// @return fee The declared operator fee (SSV)
/// @return approvalBeginTime The time when the fee approval process begins
/// @return approvalEndTime The time when the fee approval process ends
function getOperatorDeclaredFee(uint64 operatorId) external view returns (uint256 fee, uint64 approvalBeginTime, uint64 approvalEndTime);
function getOperatorDeclaredFee(uint64 operatorId) external view returns (bool isFeeDeclared, uint256 fee, uint64 approvalBeginTime, uint64 approvalEndTime);

/// @notice Gets operator details by ID
/// @param operatorId The ID of the operator
Expand Down Expand Up @@ -52,8 +53,8 @@ interface ISSVViews is ISSVNetworkCore {

/// @notice Gets operator earnings
/// @param operatorId The ID of the operator
/// @return The earnings associated with the operator (SSV)
function getOperatorEarnings(uint64 operatorId) external view returns (uint256);
/// @return earnings The earnings associated with the operator (SSV)
function getOperatorEarnings(uint64 operatorId) external view returns (uint256 earnings);

/// @notice Gets the balance of the cluster
/// @param owner The owner address of the cluster
Expand Down
1 change: 0 additions & 1 deletion contracts/libraries/ClusterLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.18;

import "../interfaces/ISSVNetworkCore.sol";
import "./SSVStorage.sol";
import "./SSVStorageProtocol.sol";
import "./Types.sol";

library ClusterLib {
Expand Down
4 changes: 2 additions & 2 deletions contracts/libraries/CoreLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ pragma solidity 0.8.18;
import "./SSVStorage.sol";

library CoreLib {
event ModuleUpgraded(SSVModules moduleId, address moduleAddress);
event ModuleUpgraded(SSVModules indexed moduleId, address moduleAddress);

function getVersion() internal pure returns (string memory) {
return "v1.0.0";
return "v1.0.0.rc3";
}

function transferBalance(address to, uint256 amount) internal {
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/OperatorLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ library OperatorLib {
uint32 deltaValidatorCount,
StorageData storage s
) internal returns (uint64 clusterIndex, uint64 burnRate) {
for (uint i; i < operatorIds.length; ) {
for (uint256 i; i < operatorIds.length; ) {
uint64 operatorId = operatorIds[i];
ISSVNetworkCore.Operator storage operator = s.operators[operatorId];
if (operator.snapshot.block != 0) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/ProtocolLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.18;

import "../interfaces/ISSVNetworkCore.sol";
import "../SSVNetwork.sol";
import "./Types.sol";
import "./SSVStorageProtocol.sol";

library ProtocolLib {
Expand Down
Loading

0 comments on commit 435b2a8

Please sign in to comment.