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

Stage #63

Merged
merged 42 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
be1117a
Revert "Merge pull request #44 from symbioticfi/global-cumul"
1kresh Oct 3, 2024
b2044d8
fix: adapt tokenized vault's tests
1kresh Oct 3, 2024
92c65a8
feat: provide more data to the hook
1kresh Oct 3, 2024
235a86d
feat: improve data for hook
1kresh Oct 14, 2024
b76b86d
refactor: rename type_ to slasherType at extra data for the hook
1kresh Oct 14, 2024
68ccc6d
fix: cover resolvers' set -> unset -> set cases
1kresh Oct 4, 2024
8ed7ff2
style: add IStaticDelegateCallable
1kresh Oct 3, 2024
f3bec1c
fix: dev -> notice for burner()
1kresh Oct 3, 2024
af9628b
fix: add account param to slashableBalanceOf()
1kresh Oct 3, 2024
c2ffae9
fix: limit can be fulfilled without risk
1kresh Oct 2, 2024
2e7fd2e
fix: update docstring
1kresh Oct 3, 2024
d225636
fix: optimize _upperBinaryLookup
1kresh Oct 4, 2024
d1c52ed
fix: optimize checkpoints push & make it return proper values
1kresh Oct 4, 2024
ede4810
refactor: remove redundant event
1kresh Oct 7, 2024
e6a46bf
fix: make upperLookupRecentCheckpoint return valid value
1kresh Oct 7, 2024
9ed36c2
feat: "already set" revert for hook
1kresh Oct 14, 2024
1c1eeec
feat: add "abstract" to contracts
1kresh Oct 14, 2024
63e8c88
feat: "already set" reverts on delegations
1kresh Oct 14, 2024
3e9b8b0
feat: add gap to migratable entity
1kresh Oct 14, 2024
1e9fcc6
refactor: make VERSION external only
1kresh Oct 14, 2024
b33738d
feat: use encodeCall instead of encodeWithSelector
1kresh Oct 14, 2024
4274712
fix: adapt hints contracts to new resolvers checks
1kresh Oct 14, 2024
bf3c8fe
fix: make slashedAmount = 0 case consistent with instant slasher
1kresh Oct 7, 2024
27e6cba
fix: statemind - remove redundant hasRole checks
1kresh Oct 14, 2024
ef59705
refactor: statemind - remove redundant error
1kresh Oct 14, 2024
8dda1d3
feat: remove limiting checks on deposit limit / deposit whitelist
1kresh Oct 14, 2024
def15e0
feat: make vault onSlash() return real slashed amount
1kresh Oct 14, 2024
c1942e0
fix: add "already set" revert to operator-specific delegator
1kresh Oct 14, 2024
77ddd76
fix: statemind - remove redundant hasRole checks for operator-specifi…
1kresh Oct 14, 2024
cb13875
feat: add call to burner
1kresh Oct 15, 2024
d6d90ba
refactor: slashedAmount -> amount for calls
1kresh Oct 15, 2024
95d7660
feat: add burner-hook flag
1kresh Oct 15, 2024
73a5609
Merge pull request #56 from symbioticfi/revert-global-cumulative
1kresh Oct 15, 2024
fc875c6
Merge pull request #57 from symbioticfi/fix-docstrings
1kresh Oct 15, 2024
8ba03c5
Merge pull request #58 from symbioticfi/resolvers-change-improve
1kresh Oct 15, 2024
4f3b001
Merge branch 'stage' into fixes-cantina
1kresh Oct 15, 2024
d60b3e2
Merge pull request #61 from symbioticfi/fixes-cantina
1kresh Oct 15, 2024
97c54cc
Merge branch 'stage' into fixes-statemind
1kresh Oct 15, 2024
cc39da8
Merge pull request #60 from symbioticfi/fixes-statemind
1kresh Oct 15, 2024
b0a5eb9
Merge branch 'stage' into burner-hook
1kresh Oct 15, 2024
35df819
Merge pull request #62 from symbioticfi/burner-hook
1kresh Oct 15, 2024
a79e12c
fix: adapt gas limit for tests
1kresh Oct 15, 2024
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
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
Loading