Skip to content

Commit

Permalink
Merge pull request #63 from symbioticfi/stage
Browse files Browse the repository at this point in the history
Stage
  • Loading branch information
1kresh authored Oct 15, 2024
2 parents 5996d26 + a79e12c commit f27663f
Show file tree
Hide file tree
Showing 45 changed files with 2,093 additions and 747 deletions.
16 changes: 14 additions & 2 deletions script/deploy/Vault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {IBaseDelegator} from "../../src/interfaces/delegator/IBaseDelegator.sol"
import {INetworkRestakeDelegator} from "../../src/interfaces/delegator/INetworkRestakeDelegator.sol";
import {IFullRestakeDelegator} from "../../src/interfaces/delegator/IFullRestakeDelegator.sol";
import {IOperatorSpecificDelegator} from "../../src/interfaces/delegator/IOperatorSpecificDelegator.sol";
import {IBaseSlasher} from "../../src/interfaces/slasher/IBaseSlasher.sol";
import {ISlasher} from "../../src/interfaces/slasher/ISlasher.sol";
import {IVetoSlasher} from "../../src/interfaces/slasher/IVetoSlasher.sol";

contract VaultScript is Script {
Expand Down Expand Up @@ -74,8 +76,18 @@ contract VaultScript is Script {
}

bytes memory slasherParams;
if (slasherIndex == 1) {
slasherParams = abi.encode(IVetoSlasher.InitParams({vetoDuration: vetoDuration, resolverSetEpochsDelay: 3}));
if (slasherIndex == 0) {
slasherParams = abi.encode(
abi.encode(ISlasher.InitParams({baseParams: IBaseSlasher.BaseParams({isBurnerHook: false})}))
);
} else if (slasherIndex == 1) {
slasherParams = abi.encode(
IVetoSlasher.InitParams({
baseParams: IBaseSlasher.BaseParams({isBurnerHook: false}),
vetoDuration: vetoDuration,
resolverSetEpochsDelay: 3
})
);
}

(address vault_, address delegator_, address slasher_) = IVaultConfigurator(vaultConfigurator).create(
Expand Down
2 changes: 2 additions & 0 deletions src/contracts/common/MigratableEntity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ abstract contract MigratableEntity is
function _initialize(uint64, /* initialVersion */ address, /* owner */ bytes memory /* data */ ) internal virtual {}

function _migrate(uint64, /* oldVersion */ uint64, /* newVersion */ bytes calldata /* data */ ) internal virtual {}

uint256[10] private __gap;
}
5 changes: 2 additions & 3 deletions src/contracts/common/MigratablesFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ contract MigratablesFactory is Registry, Ownable, IMigratablesFactory {
function create(uint64 version, address owner_, bytes calldata data) external returns (address entity_) {
entity_ = address(
new MigratableEntityProxy{salt: keccak256(abi.encode(totalEntities(), version, owner_, data))}(
implementation(version),
abi.encodeWithSelector(IMigratableEntity.initialize.selector, version, owner_, data)
implementation(version), abi.encodeCall(IMigratableEntity.initialize, (version, owner_, data))
)
);

Expand All @@ -110,7 +109,7 @@ contract MigratablesFactory is Registry, Ownable, IMigratablesFactory {
}

IMigratableEntityProxy(entity_).upgradeToAndCall(
implementation(newVersion), abi.encodeWithSelector(IMigratableEntity.migrate.selector, newVersion, data)
implementation(newVersion), abi.encodeCall(IMigratableEntity.migrate, (newVersion, data))
);

emit Migrate(entity_, newVersion);
Expand Down
7 changes: 6 additions & 1 deletion src/contracts/common/StaticDelegateCallable.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.25;

abstract contract StaticDelegateCallable {
import {IStaticDelegateCallable} from "../../interfaces/common/IStaticDelegateCallable.sol";

abstract contract StaticDelegateCallable is IStaticDelegateCallable {
/**
* @inheritdoc IStaticDelegateCallable
*/
function staticDelegateCall(address target, bytes calldata data) external {
(bool success, bytes memory returndata) = target.delegatecall(data);
bytes memory revertData = abi.encode(success, returndata);
Expand Down
36 changes: 19 additions & 17 deletions src/contracts/delegator/BaseDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Subnetwork} from "../libraries/Subnetwork.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";

contract BaseDelegator is
abstract contract BaseDelegator is
Entity,
StaticDelegateCallable,
AccessControlUpgradeable,
Expand All @@ -25,11 +25,6 @@ contract BaseDelegator is
using Subnetwork for bytes32;
using Subnetwork for address;

/**
* @inheritdoc IBaseDelegator
*/
uint64 public constant VERSION = 1;

/**
* @inheritdoc IBaseDelegator
*/
Expand Down Expand Up @@ -94,6 +89,13 @@ contract BaseDelegator is
OPERATOR_NETWORK_OPT_IN_SERVICE = operatorNetworkOptInService;
}

/**
* @inheritdoc IBaseDelegator
*/
function VERSION() external pure returns (uint64) {
return 1;
}

/**
* @inheritdoc IBaseDelegator
*/
Expand Down Expand Up @@ -164,6 +166,10 @@ contract BaseDelegator is
function setHook(
address hook_
) external nonReentrant onlyRole(HOOK_SET_ROLE) {
if (hook == hook_) {
revert AlreadySet();
}

hook = hook_;

emit SetHook(hook_);
Expand All @@ -175,19 +181,18 @@ contract BaseDelegator is
function onSlash(
bytes32 subnetwork,
address operator,
uint256 slashedAmount,
uint256 amount,
uint48 captureTimestamp,
bytes memory data
) external nonReentrant {
if (IVault(vault).slasher() != msg.sender) {
if (msg.sender != IVault(vault).slasher()) {
revert NotSlasher();
}

address hook_ = hook;
if (hook_ != address(0)) {
bytes memory calldata_ = abi.encodeWithSelector(
IDelegatorHook.onSlash.selector, subnetwork, operator, slashedAmount, captureTimestamp, data
);
bytes memory calldata_ =
abi.encodeCall(IDelegatorHook.onSlash, (subnetwork, operator, amount, captureTimestamp, data));

if (gasleft() < HOOK_RESERVE + HOOK_GAS_LIMIT * 64 / 63) {
revert InsufficientHookGas();
Expand All @@ -198,7 +203,7 @@ contract BaseDelegator is
}
}

emit OnSlash(subnetwork, operator, slashedAmount);
emit OnSlash(subnetwork, operator, amount, captureTimestamp);
}

function _initialize(
Expand All @@ -214,7 +219,7 @@ contract BaseDelegator is

vault = vault_;

IBaseDelegator.BaseParams memory baseParams = __initialize(vault_, data_);
BaseParams memory baseParams = __initialize(vault_, data_);

hook = baseParams.hook;

Expand All @@ -237,8 +242,5 @@ contract BaseDelegator is

function _setMaxNetworkLimit(bytes32 subnetwork, uint256 amount) internal virtual {}

function __initialize(
address vault_,
bytes memory data
) internal virtual returns (IBaseDelegator.BaseParams memory) {}
function __initialize(address vault_, bytes memory data) internal virtual returns (BaseParams memory) {}
}
16 changes: 10 additions & 6 deletions src/contracts/delegator/FullRestakeDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ contract FullRestakeDelegator is BaseDelegator, IFullRestakeDelegator {
revert ExceedsMaxNetworkLimit();
}

if (networkLimit(subnetwork) == amount) {
revert AlreadySet();
}

_networkLimit[subnetwork].push(Time.timestamp(), amount);

emit SetNetworkLimit(subnetwork, amount);
Expand All @@ -105,6 +109,10 @@ contract FullRestakeDelegator is BaseDelegator, IFullRestakeDelegator {
address operator,
uint256 amount
) external onlyRole(OPERATOR_NETWORK_LIMIT_SET_ROLE) {
if (operatorNetworkLimit(subnetwork, operator) == amount) {
revert AlreadySet();
}

_operatorNetworkLimit[subnetwork][operator].push(Time.timestamp(), amount);

emit SetOperatorNetworkLimit(subnetwork, operator, amount);
Expand Down Expand Up @@ -161,23 +169,19 @@ contract FullRestakeDelegator is BaseDelegator, IFullRestakeDelegator {
revert ZeroAddressRoleHolder();
}

if (hasRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolders[i])) {
if (!_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolders[i])) {
revert DuplicateRoleHolder();
}

_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolders[i]);
}

for (uint256 i; i < params.operatorNetworkLimitSetRoleHolders.length; ++i) {
if (params.operatorNetworkLimitSetRoleHolders[i] == address(0)) {
revert ZeroAddressRoleHolder();
}

if (hasRole(OPERATOR_NETWORK_LIMIT_SET_ROLE, params.operatorNetworkLimitSetRoleHolders[i])) {
if (!_grantRole(OPERATOR_NETWORK_LIMIT_SET_ROLE, params.operatorNetworkLimitSetRoleHolders[i])) {
revert DuplicateRoleHolder();
}

_grantRole(OPERATOR_NETWORK_LIMIT_SET_ROLE, params.operatorNetworkLimitSetRoleHolders[i]);
}

return params.baseParams;
Expand Down
20 changes: 12 additions & 8 deletions src/contracts/delegator/NetworkRestakeDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ contract NetworkRestakeDelegator is BaseDelegator, INetworkRestakeDelegator {
revert ExceedsMaxNetworkLimit();
}

if (networkLimit(subnetwork) == amount) {
revert AlreadySet();
}

_networkLimit[subnetwork].push(Time.timestamp(), amount);

emit SetNetworkLimit(subnetwork, amount);
Expand All @@ -127,9 +131,13 @@ contract NetworkRestakeDelegator is BaseDelegator, INetworkRestakeDelegator {
address operator,
uint256 shares
) external onlyRole(OPERATOR_NETWORK_SHARES_SET_ROLE) {
uint256 operatorNetworkShares_ = operatorNetworkShares(subnetwork, operator);
if (operatorNetworkShares_ == shares) {
revert AlreadySet();
}

_totalOperatorNetworkShares[subnetwork].push(
Time.timestamp(),
totalOperatorNetworkShares(subnetwork) - operatorNetworkShares(subnetwork, operator) + shares
Time.timestamp(), totalOperatorNetworkShares(subnetwork) - operatorNetworkShares_ + shares
);
_operatorNetworkShares[subnetwork][operator].push(Time.timestamp(), shares);

Expand Down Expand Up @@ -194,23 +202,19 @@ contract NetworkRestakeDelegator is BaseDelegator, INetworkRestakeDelegator {
revert ZeroAddressRoleHolder();
}

if (hasRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolders[i])) {
if (!_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolders[i])) {
revert DuplicateRoleHolder();
}

_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolders[i]);
}

for (uint256 i; i < params.operatorNetworkSharesSetRoleHolders.length; ++i) {
if (params.operatorNetworkSharesSetRoleHolders[i] == address(0)) {
revert ZeroAddressRoleHolder();
}

if (hasRole(OPERATOR_NETWORK_SHARES_SET_ROLE, params.operatorNetworkSharesSetRoleHolders[i])) {
if (!_grantRole(OPERATOR_NETWORK_SHARES_SET_ROLE, params.operatorNetworkSharesSetRoleHolders[i])) {
revert DuplicateRoleHolder();
}

_grantRole(OPERATOR_NETWORK_SHARES_SET_ROLE, params.operatorNetworkSharesSetRoleHolders[i]);
}

return params.baseParams;
Expand Down
8 changes: 5 additions & 3 deletions src/contracts/delegator/OperatorSpecificDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ contract OperatorSpecificDelegator is BaseDelegator, IOperatorSpecificDelegator
revert ExceedsMaxNetworkLimit();
}

if (networkLimit(subnetwork) == amount) {
revert AlreadySet();
}

_networkLimit[subnetwork].push(Time.timestamp(), amount);

emit SetNetworkLimit(subnetwork, amount);
Expand Down Expand Up @@ -139,11 +143,9 @@ contract OperatorSpecificDelegator is BaseDelegator, IOperatorSpecificDelegator
revert ZeroAddressRoleHolder();
}

if (hasRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolders[i])) {
if (!_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolders[i])) {
revert DuplicateRoleHolder();
}

_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolders[i]);
}

operator = params.operator;
Expand Down
24 changes: 8 additions & 16 deletions src/contracts/hints/DelegatorHints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ contract NetworkRestakeDelegatorHints is Hints, NetworkRestakeDelegator {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
delegator,
abi.encodeWithSelector(
NetworkRestakeDelegatorHints.networkLimitHintInternal.selector, subnetwork, timestamp
)
abi.encodeCall(NetworkRestakeDelegatorHints.networkLimitHintInternal, (subnetwork, timestamp))
),
(bool, uint32)
);
Expand All @@ -137,11 +135,8 @@ contract NetworkRestakeDelegatorHints is Hints, NetworkRestakeDelegator {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
delegator,
abi.encodeWithSelector(
NetworkRestakeDelegatorHints.operatorNetworkSharesHintInternal.selector,
subnetwork,
operator,
timestamp
abi.encodeCall(
NetworkRestakeDelegatorHints.operatorNetworkSharesHintInternal, (subnetwork, operator, timestamp)
)
),
(bool, uint32)
Expand All @@ -167,8 +162,8 @@ contract NetworkRestakeDelegatorHints is Hints, NetworkRestakeDelegator {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
delegator,
abi.encodeWithSelector(
NetworkRestakeDelegatorHints.totalOperatorNetworkSharesHintInternal.selector, subnetwork, timestamp
abi.encodeCall(
NetworkRestakeDelegatorHints.totalOperatorNetworkSharesHintInternal, (subnetwork, timestamp)
)
),
(bool, uint32)
Expand Down Expand Up @@ -243,10 +238,7 @@ contract FullRestakeDelegatorHints is Hints, FullRestakeDelegator {
) public view returns (bytes memory) {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
delegator,
abi.encodeWithSelector(
FullRestakeDelegatorHints.networkLimitHintInternal.selector, subnetwork, timestamp
)
delegator, abi.encodeCall(FullRestakeDelegatorHints.networkLimitHintInternal, (subnetwork, timestamp))
),
(bool, uint32)
);
Expand All @@ -273,8 +265,8 @@ contract FullRestakeDelegatorHints is Hints, FullRestakeDelegator {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
delegator,
abi.encodeWithSelector(
FullRestakeDelegatorHints.operatorNetworkLimitHintInternal.selector, subnetwork, operator, timestamp
abi.encodeCall(
FullRestakeDelegatorHints.operatorNetworkLimitHintInternal, (subnetwork, operator, timestamp)
)
),
(bool, uint32)
Expand Down
5 changes: 2 additions & 3 deletions src/contracts/hints/Hints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ abstract contract Hints {
}

function _selfStaticDelegateCall(address target, bytes memory dataInternal) internal view returns (bytes memory) {
(, bytes memory returnDataInternal) = target.staticcall(
abi.encodeWithSelector(StaticDelegateCallable.staticDelegateCall.selector, address(this), dataInternal)
);
(, bytes memory returnDataInternal) =
target.staticcall(abi.encodeCall(StaticDelegateCallable.staticDelegateCall, (address(this), dataInternal)));
(bool success, bytes memory returnData) = abi.decode(returnDataInternal, (bool, bytes));
if (!success) {
if (returnData.length == 0) revert();
Expand Down
3 changes: 1 addition & 2 deletions src/contracts/hints/OptInServiceHints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ contract OptInServiceHints is Hints, OptInService {
) external view returns (bytes memory) {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
optInService,
abi.encodeWithSelector(OptInServiceHints.optInHintInternal.selector, who, where, timestamp)
optInService, abi.encodeCall(OptInServiceHints.optInHintInternal, (who, where, timestamp))
),
(bool, uint32)
);
Expand Down
Loading

0 comments on commit f27663f

Please sign in to comment.