Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fee abstraction PoC #253

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions contracts/SSVNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ contract SSVNetwork is
/* Operator External Functions */
/*******************************/

function registerOperator(bytes calldata publicKey, uint256 fee) external override returns (uint64 id) {
function registerOperator(
bytes calldata publicKey,
uint256 fee,
IERC20 feeToken
) external override returns (uint64 id) {
if (!RegisterAuth.load().authorization[msg.sender].registerOperator) revert NotAuthorized();

_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS]);
Expand Down Expand Up @@ -173,6 +177,8 @@ contract SSVNetwork is
uint64[] memory operatorIds,
bytes calldata sharesData,
uint256 amount,
IERC20 feeToken,
uint256 ssvAmount,
ISSVNetworkCore.Cluster memory cluster
) external override {
if (!RegisterAuth.load().authorization[msg.sender].registerValidator) revert NotAuthorized();
Expand All @@ -188,13 +194,19 @@ contract SSVNetwork is
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_CLUSTERS]);
}

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

function reactivate(
uint64[] calldata operatorIds,
uint256 amount,
IERC20 feeToken,
ISSVNetworkCore.Cluster memory cluster
) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_CLUSTERS]);
Expand All @@ -204,6 +216,7 @@ contract SSVNetwork is
address clusterOwner,
uint64[] calldata operatorIds,
uint256 amount,
IERC20 feeToken,
ISSVNetworkCore.Cluster memory cluster
) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_CLUSTERS]);
Expand Down
47 changes: 43 additions & 4 deletions contracts/interfaces/ISSVClusters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface ISSVClusters is ISSVNetworkCore {
uint64[] memory operatorIds,
bytes calldata sharesData,
uint256 amount,
IERC20 feeToken,
uint256 ssvAmount,
Cluster memory cluster
) external;

Expand All @@ -32,6 +34,8 @@ interface ISSVClusters is ISSVNetworkCore {
/// @param owner The owner of the cluster
/// @param operatorIds Array of IDs of operators managing the cluster
/// @param cluster Cluster to be liquidated
function liquidate(address owner, uint64[] memory operatorIds, IERC20 feeToken, Cluster memory cluster) external;

function liquidate(address owner, uint64[] memory operatorIds, Cluster memory cluster) external;

/// @notice Reactivates a cluster
Expand All @@ -40,16 +44,37 @@ interface ISSVClusters is ISSVNetworkCore {
/// @param cluster Cluster to be reactivated
function reactivate(uint64[] memory operatorIds, uint256 amount, Cluster memory cluster) external;

function reactivate(
uint64[] calldata operatorIds,
uint256 feeAmount,
IERC20 feeToken,
uint256 ssvAmount,
Cluster memory cluster
) external;

/******************************/
/* Balance External Functions */
/******************************/

/// @notice Deposits tokens into a cluster
/// @param owner The owner of the cluster
/// @param clusterOwner The owner of the cluster
/// @param operatorIds Array of IDs of operators managing the cluster
/// @param amount Amount of SSV tokens to be deposited
/// @param ssvAmount Amount of SSV tokens to be deposited
/// @param cluster Cluster where the deposit will be made
function deposit(address owner, uint64[] memory operatorIds, uint256 amount, Cluster memory cluster) external;
function depositClusterBalance(
address clusterOwner,
uint64[] calldata operatorIds,
uint256 ssvAmount,
Cluster memory cluster
) external;

function depositClusterBalance(
address clusterOwner,
uint64[] calldata operatorIds,
uint256 feeAmount,
IERC20 feeToken,
Cluster memory cluster
) external;

/// @notice Withdraws tokens from a cluster
/// @param operatorIds Array of IDs of operators managing the cluster
Expand Down Expand Up @@ -80,5 +105,19 @@ interface ISSVClusters is ISSVNetworkCore {

event ClusterWithdrawn(address indexed owner, uint64[] operatorIds, uint256 value, Cluster cluster);

event ClusterDeposited(address indexed owner, uint64[] operatorIds, uint256 value, Cluster cluster);
event ClusterDeposited(
address indexed owner,
uint64[] operatorIds,
IERC20 feeToken,
uint256 value,
Cluster cluster
);

event ClusterTokenDeposited(
address indexed owner,
uint64[] operatorIds,
IERC20 feeToken,
uint256 value,
Cluster cluster
);
}
2 changes: 0 additions & 2 deletions contracts/interfaces/ISSVNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import "./ISSVViews.sol";

import {SSVModules} from "../libraries/SSVStorage.sol";

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface ISSVNetwork {
function initialize(
IERC20 token_,
Expand Down
10 changes: 10 additions & 0 deletions contracts/interfaces/ISSVNetworkCore.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface ISSVNetworkCore {

Check warning on line 6 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Contract has 30 states declarations but allowed no more than 15
/***********/
/* Structs */
/***********/
Expand All @@ -28,6 +30,8 @@
bool whitelisted;
/// @dev The state snapshot of the operator
Snapshot snapshot;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explore to include it with the operator key

/// @dev The token used for fees
IERC20 feeToken;
}

/// @notice Represents a request to change an operator's fee
Expand All @@ -54,15 +58,20 @@
uint256 balance;
}

struct Account {
/// @dev Total account validators
uint32 validatorCount;
uint64 ssvBalance;
}
/**********/
/* Errors */
/**********/

error CallerNotOwner(); // 0x5cd83192

Check warning on line 70 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Variable name must be in mixedCase

Check warning on line 70 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Explicitly mark visibility of state
error CallerNotWhitelisted(); // 0x8c6e5d71

Check warning on line 71 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Variable name must be in mixedCase

Check warning on line 71 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Explicitly mark visibility of state
error FeeTooLow(); // 0x732f9413

Check warning on line 72 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Variable name must be in mixedCase

Check warning on line 72 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Explicitly mark visibility of state
error FeeExceedsIncreaseLimit(); // 0x958065d9

Check warning on line 73 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Variable name must be in mixedCase

Check warning on line 73 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Explicitly mark visibility of state
error NoFeeDeclared(); // 0x1d226c30

Check warning on line 74 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Variable name must be in mixedCase
error ApprovalNotWithinTimeframe(); // 0x97e4b518
error OperatorDoesNotExist(); // 0x961e3e8c
error InsufficientBalance(); // 0xf4d678b8
Expand All @@ -87,4 +96,5 @@
error OperatorAlreadyExists(); // 0x289c9494
error TargetModuleDoesNotExist(); // 0x8f9195fb
error MaxValueExceeded(); // 0x91aa3017
error FeeTokenMismatch();
}
2 changes: 1 addition & 1 deletion contracts/interfaces/ISSVOperators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ISSVOperators is ISSVNetworkCore {
/// @notice Registers a new operator
/// @param publicKey The public key of the operator
/// @param fee The operator's fee (SSV)
function registerOperator(bytes calldata publicKey, uint256 fee) external returns (uint64);
function registerOperator(bytes calldata publicKey, uint256 fee, IERC20 feeToken) external returns (uint64);

/// @notice Removes an existing operator
/// @param operatorId The ID of the operator to be removed
Expand Down
Loading
Loading