diff --git a/contracts/ethereum/docs/index.md b/contracts/ethereum/docs/index.md index 1e0ef7ed1..df31ceaa5 100644 --- a/contracts/ethereum/docs/index.md +++ b/contracts/ethereum/docs/index.md @@ -2,6 +2,14 @@ ## CasimirManager +### upkeepRegistrationMinimum + +```solidity +uint256 upkeepRegistrationMinimum +``` + +Minimum balance for upkeep registration (0.1 LINK) + ### finalizableCompletedExits ```solidity @@ -26,6 +34,14 @@ modifier onlyOracle() _Validate the caller is the manager oracle_ +### onlyOracleOrUpkeep + +```solidity +modifier onlyOracleOrUpkeep() +``` + +_Validate the caller is the oracle or upkeep_ + ### onlyRegistry ```solidity @@ -75,7 +91,7 @@ _Validate a distribution_ ### constructor ```solidity -constructor(address _oracleAddress, address beaconDepositAddress, address linkFunctionsAddress, address linkRegistrarAddress, uint32 linkSubscriptionId, address linkTokenAddress, address ssvNetworkAddress, address ssvNetworkViewsAddress, address ssvTokenAddress, address swapFactoryAddress, address swapRouterAddress, address wethTokenAddress) public +constructor(address _oracleAddress, address beaconDepositAddress, address linkFunctionsAddress, address linkRegistrarAddress, address linkRegistryAddress, address linkTokenAddress, address ssvNetworkAddress, address ssvNetworkViewsAddress, address ssvTokenAddress, address swapFactoryAddress, address swapRouterAddress, address wethTokenAddress) public ``` Constructor @@ -88,7 +104,7 @@ Constructor | beaconDepositAddress | address | The Beacon deposit address | | linkFunctionsAddress | address | The Chainlink functions oracle address | | linkRegistrarAddress | address | The Chainlink keeper registrar address | -| linkSubscriptionId | uint32 | The Chainlink functions subscription ID | +| linkRegistryAddress | address | The Chainlink keeper registry address | | linkTokenAddress | address | The Chainlink token address | | ssvNetworkAddress | address | The SSV network address | | ssvNetworkViewsAddress | address | The SSV network views address | @@ -152,7 +168,7 @@ Deposit recovered balance for a given pool from an operator ### depositClusterBalance ```solidity -function depositClusterBalance(struct ISSVNetworkCore.Cluster cluster, uint256 amount) external +function depositClusterBalance(uint64[] operatorIds, struct ISSVNetworkCore.Cluster cluster, uint256 feeAmount, bool processed) external ``` Deposit to a cluster balance @@ -161,22 +177,25 @@ Deposit to a cluster balance | Name | Type | Description | | ---- | ---- | ----------- | -| cluster | struct ISSVNetworkCore.Cluster | The cluster | -| amount | uint256 | The amount to deposit | +| operatorIds | uint64[] | The operator IDs | +| cluster | struct ISSVNetworkCore.Cluster | The SSV cluster snapshot | +| feeAmount | uint256 | The fee amount to deposit | +| processed | bool | Whether the fee amount is already processed | ### depositUpkeepBalance ```solidity -function depositUpkeepBalance(uint256 amount) external +function depositUpkeepBalance(uint256 feeAmount, bool processed) external ``` -Deposit upkeep balance +Deposit to the upkeep balance #### Parameters | Name | Type | Description | | ---- | ---- | ----------- | -| amount | uint256 | The amount to deposit | +| feeAmount | uint256 | The fee amount to deposit | +| processed | bool | Whether the fee amount is already processed | ### depositReservedFees @@ -186,6 +205,20 @@ function depositReservedFees() external payable Deposit reserved fees +### withdrawReservedFees + +```solidity +function withdrawReservedFees(uint256 amount) external +``` + +Withdraw a given amount of reserved fees + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| amount | uint256 | The amount of fees to withdraw | + ### rebalanceStake ```solidity @@ -248,7 +281,7 @@ Fulfill a given count of pending withdrawals ### initiateDeposit ```solidity -function initiateDeposit(bytes32 depositDataRoot, bytes publicKey, bytes signature, bytes withdrawalCredentials, uint64[] operatorIds, bytes shares, struct ISSVNetworkCore.Cluster cluster, uint256 feeAmount) external +function initiateDeposit(bytes32 depositDataRoot, bytes publicKey, bytes signature, bytes withdrawalCredentials, uint64[] operatorIds, bytes shares, struct ISSVNetworkCore.Cluster cluster, uint256 feeAmount, bool processed) external ``` Initiate the next ready pool @@ -263,8 +296,9 @@ Initiate the next ready pool | withdrawalCredentials | bytes | The withdrawal credentials | | operatorIds | uint64[] | The operator IDs | | shares | bytes | The operator shares | -| cluster | struct ISSVNetworkCore.Cluster | | -| feeAmount | uint256 | The fee amount | +| cluster | struct ISSVNetworkCore.Cluster | The SSV cluster snapshot | +| feeAmount | uint256 | The fee amount to deposit | +| processed | bool | | ### activateDeposits @@ -311,16 +345,16 @@ Request reports for a given count of completed exits ### reportForcedExits ```solidity -function reportForcedExits(uint32 poolId) external +function reportForcedExits(uint32[] poolIds) external ``` -Report a pool unexpected exit +Report pool forced (unrequested) exits #### Parameters | Name | Type | Description | | ---- | ---- | ----------- | -| poolId | uint32 | The pool ID | +| poolIds | uint32[] | The pool IDs | ### reportCompletedExit @@ -338,6 +372,65 @@ Report a completed exit | blamePercents | uint32[] | The operator blame percents (0 if balance is 32 ether) | | cluster | struct ISSVNetworkCore.Cluster | The SSV cluster snapshot | +### reportReshare + +```solidity +function reportReshare(uint32 poolId, uint64[] operatorIds, uint64[] oldOperatorIds, uint64 newOperatorId, uint64 oldOperatorId, bytes shares, struct ISSVNetworkCore.Cluster cluster, struct ISSVNetworkCore.Cluster oldCluster, uint256 feeAmount, bool processed) external +``` + +Report a reshare + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| poolId | uint32 | The pool ID | +| operatorIds | uint64[] | The operator IDs | +| oldOperatorIds | uint64[] | The old operator IDs | +| newOperatorId | uint64 | The new operator ID | +| oldOperatorId | uint64 | The old operator ID | +| shares | bytes | The operator shares | +| cluster | struct ISSVNetworkCore.Cluster | The SSV cluster snapshot | +| oldCluster | struct ISSVNetworkCore.Cluster | The old SSV cluster snapshot | +| feeAmount | uint256 | The fee amount to deposit | +| processed | bool | Whether the fee amount is already processed | + +### withdrawUpkeepBalance + +```solidity +function withdrawUpkeepBalance() external +``` + +Cancel upkeep and withdraw the upkeep balance + +### withdrawLINKBalance + +```solidity +function withdrawLINKBalance(uint256 amount) external +``` + +Withdraw a given amount from the LINK balance + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| amount | uint256 | The amount to withdraw | + +### withdrawSSVBalance + +```solidity +function withdrawSSVBalance(uint256 amount) external +``` + +Withdraw a given amount from the SSV balance + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| amount | uint256 | The amount to withdraw | + ### setFunctionsAddress ```solidity @@ -748,6 +841,20 @@ Get the registry address | ---- | ---- | ----------- | | registryAddress | address | The registry address | +### getUpkeepId + +```solidity +function getUpkeepId() external view returns (uint256) +``` + +Get the upkeep ID + +#### Return Values + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | uint256 | upkeepId The upkeep ID | + ### getUpkeepAddress ```solidity @@ -762,6 +869,20 @@ Get the upkeep address | ---- | ---- | ----------- | | upkeepAddress | address | The upkeep address | +### getUpkeepBalance + +```solidity +function getUpkeepBalance() external view returns (uint256 upkeepBalance) +``` + +Get the upkeep balance + +#### Return Values + +| Name | Type | Description | +| ---- | ---- | ----------- | +| upkeepBalance | uint256 | The upkeep balance | + ### getSweptBalance ```solidity @@ -882,13 +1003,13 @@ uint256 minimumCollateralDeposit uint256 totalCollateral ``` -### onlyPool +### onlyOwnerOrPool ```solidity -modifier onlyPool(uint32 poolId) +modifier onlyOwnerOrPool(uint32 poolId) ``` -_Validate the caller is the authorized pool_ +_Validate the caller is owner or the authorized pool_ ### constructor @@ -1067,7 +1188,7 @@ Fulfillment gas limit ### constructor ```solidity -constructor(address linkFunctionsAddress, address linkRegistrarAddress, uint64 _linkSubscriptionId, address linkTokenAddress) public +constructor(address linkFunctionsAddress) public ``` Constructor @@ -1077,15 +1198,6 @@ Constructor | Name | Type | Description | | ---- | ---- | ----------- | | linkFunctionsAddress | address | The functions oracle contract address | -| linkRegistrarAddress | address | The keeper registrar address | -| _linkSubscriptionId | uint64 | The functions subscription ID | -| linkTokenAddress | address | The LINK token address | - -### registerUpkeep - -```solidity -function registerUpkeep(struct KeeperRegistrarInterface.RegistrationParams params) public -``` ### generateRequest @@ -1106,7 +1218,7 @@ Generate a new Functions.Request(off-chain, saving gas) ### setRequest ```solidity -function setRequest(uint32 _fulfillGasLimit, uint64 linkSubscriptionId, bytes _requestCBOR) external +function setRequest(uint32 _fulfillGasLimit, uint64 _linkSubscriptionId, bytes _requestCBOR) external ``` Set the bytes representing the CBOR-encoded Functions.Request @@ -1116,7 +1228,7 @@ Set the bytes representing the CBOR-encoded Functions.Request | Name | Type | Description | | ---- | ---- | ----------- | | _fulfillGasLimit | uint32 | Maximum amount of gas used to call the client contract's `handleOracleFulfillment` function | -| linkSubscriptionId | uint64 | The functions billing subscription ID used to pay for Functions requests | +| _linkSubscriptionId | uint64 | The functions billing subscription ID used to pay for Functions requests | | _requestCBOR | bytes | Bytes representing the CBOR-encoded Functions.Request | ### checkUpkeep @@ -1383,13 +1495,13 @@ function depositReservedFees() external payable ### depositClusterBalance ```solidity -function depositClusterBalance(struct ISSVNetworkCore.Cluster cluster, uint256 amount) external +function depositClusterBalance(uint64[] operatorIds, struct ISSVNetworkCore.Cluster cluster, uint256 feeAmount, bool processed) external ``` ### depositUpkeepBalance ```solidity -function depositUpkeepBalance(uint256 amount) external +function depositUpkeepBalance(uint256 feeAmount, bool processed) external ``` ### rebalanceStake @@ -1419,7 +1531,7 @@ function fulfillWithdrawals(uint256 count) external ### initiateDeposit ```solidity -function initiateDeposit(bytes32 depositDataRoot, bytes publicKey, bytes signature, bytes withdrawalCredentials, uint64[] operatorIds, bytes shares, struct ISSVNetworkCore.Cluster cluster, uint256 feeAmount) external +function initiateDeposit(bytes32 depositDataRoot, bytes publicKey, bytes signature, bytes withdrawalCredentials, uint64[] operatorIds, bytes shares, struct ISSVNetworkCore.Cluster cluster, uint256 feeAmount, bool processed) external ``` ### activateDeposits @@ -1446,6 +1558,24 @@ function requestCompletedExitReports(uint256 count) external function reportCompletedExit(uint256 poolIndex, uint32[] blamePercents, struct ISSVNetworkCore.Cluster cluster) external ``` +### reportReshare + +```solidity +function reportReshare(uint32 poolId, uint64[] operatorIds, uint64[] oldOperatorIds, uint64 newOperatorId, uint64 oldOperatorId, bytes shares, struct ISSVNetworkCore.Cluster cluster, struct ISSVNetworkCore.Cluster oldCluster, uint256 feeAmount, bool processed) external +``` + +### withdrawLINKBalance + +```solidity +function withdrawLINKBalance(uint256 amount) external +``` + +### withdrawSSVBalance + +```solidity +function withdrawSSVBalance(uint256 amount) external +``` + ### setFunctionsAddress ```solidity @@ -1596,12 +1726,24 @@ function getPoolDetails(uint32 poolId) external view returns (struct ICasimirMan function getRegistryAddress() external view returns (address) ``` +### getUpkeepId + +```solidity +function getUpkeepId() external view returns (uint256) +``` + ### getUpkeepAddress ```solidity function getUpkeepAddress() external view returns (address) ``` +### getUpkeepBalance + +```solidity +function getUpkeepBalance() external view returns (uint256 upkeepBalance) +``` + ## ICasimirPool ### PoolConfig diff --git a/contracts/ethereum/src/CasimirManager.sol b/contracts/ethereum/src/CasimirManager.sol index c15c60da1..a07d56deb 100644 --- a/contracts/ethereum/src/CasimirManager.sol +++ b/contracts/ethereum/src/CasimirManager.sol @@ -902,12 +902,17 @@ contract CasimirManager is ICasimirManager, Ownable, ReentrancyGuard { ) external onlyOracle { ICasimirPool pool = ICasimirPool(poolAddresses[poolId]); ICasimirPool.PoolConfig memory poolConfig = pool.getConfig(); - require( poolConfig.status == ICasimirPool.PoolStatus.PENDING || poolConfig.status == ICasimirPool.PoolStatus.ACTIVE, "Pool not active" ); + require( + poolConfig.reshares < 2, + "Pool already reshared twice" + ); + + pool.setReshares(poolConfig.reshares + 1); registry.removeOperatorPool(oldOperatorId, poolId, 0); registry.addOperatorPool(newOperatorId, poolId); diff --git a/contracts/ethereum/src/CasimirPool.sol b/contracts/ethereum/src/CasimirPool.sol index 0932b144c..8b8c073df 100644 --- a/contracts/ethereum/src/CasimirPool.sol +++ b/contracts/ethereum/src/CasimirPool.sol @@ -65,6 +65,10 @@ contract CasimirPool is ICasimirPool, Ownable, ReentrancyGuard { config.operatorIds = operatorIds; } + function setReshares(uint256 reshares) external onlyOwner { + config.reshares = reshares; + } + function setStatus(PoolStatus status) external onlyOwner { config.status = status; } diff --git a/contracts/ethereum/src/interfaces/ICasimirPool.sol b/contracts/ethereum/src/interfaces/ICasimirPool.sol index 05bc4b971..3c94e8228 100644 --- a/contracts/ethereum/src/interfaces/ICasimirPool.sol +++ b/contracts/ethereum/src/interfaces/ICasimirPool.sol @@ -11,6 +11,7 @@ interface ICasimirPool { uint32 poolId; bytes publicKey; uint64[] operatorIds; + uint256 reshares; PoolStatus status; } @@ -33,6 +34,8 @@ interface ICasimirPool { function setOperatorIds(uint64[] memory operatorIds) external; + function setReshares(uint256 reshares) external; + function setStatus(PoolStatus status) external; function getBalance() external view returns (uint256);