Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
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
23 changes: 14 additions & 9 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 @@ -185,9 +191,8 @@ contract BaseDelegator is

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, slashedAmount, captureTimestamp, data));

if (gasleft() < HOOK_RESERVE + HOOK_GAS_LIMIT * 64 / 63) {
revert InsufficientHookGas();
Expand Down
8 changes: 8 additions & 0 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
12 changes: 10 additions & 2 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
4 changes: 4 additions & 0 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
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
7 changes: 2 additions & 5 deletions src/contracts/hints/SlasherHints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ contract BaseSlasherHints is Hints, BaseSlasher {
) public view returns (bytes memory) {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
slasher,
abi.encodeWithSelector(
BaseSlasherHints.cumulativeSlashHintInternal.selector, subnetwork, operator, timestamp
)
slasher, abi.encodeCall(BaseSlasherHints.cumulativeSlashHintInternal, (subnetwork, operator, timestamp))
),
(bool, uint32)
);
Expand Down Expand Up @@ -127,7 +124,7 @@ contract VetoSlasherHints is Hints, VetoSlasher {
function resolverHint(address slasher, bytes32 subnetwork, uint48 timestamp) public view returns (bytes memory) {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
slasher, abi.encodeWithSelector(VetoSlasherHints.resolverHintInternal.selector, subnetwork, timestamp)
slasher, abi.encodeCall(VetoSlasherHints.resolverHintInternal, (subnetwork, timestamp))
),
(bool, uint32)
);
Expand Down
12 changes: 3 additions & 9 deletions src/contracts/hints/VaultHints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ contract VaultHints is Hints, Vault {

function activeStakeHint(address vault, uint48 timestamp) public view returns (bytes memory) {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
vault, abi.encodeWithSelector(VaultHints.activeStakeHintInternal.selector, timestamp)
),
_selfStaticDelegateCall(vault, abi.encodeCall(VaultHints.activeStakeHintInternal, (timestamp))),
(bool, uint32)
);

Expand All @@ -38,9 +36,7 @@ contract VaultHints is Hints, Vault {

function activeSharesHint(address vault, uint48 timestamp) public view returns (bytes memory) {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
vault, abi.encodeWithSelector(VaultHints.activeSharesHintInternal.selector, timestamp)
),
_selfStaticDelegateCall(vault, abi.encodeCall(VaultHints.activeSharesHintInternal, (timestamp))),
(bool, uint32)
);

Expand All @@ -58,9 +54,7 @@ contract VaultHints is Hints, Vault {

function activeSharesOfHint(address vault, address account, uint48 timestamp) public view returns (bytes memory) {
(bool exists, uint32 hint_) = abi.decode(
_selfStaticDelegateCall(
vault, abi.encodeWithSelector(VaultHints.activeSharesOfHintInternal.selector, account, timestamp)
),
_selfStaticDelegateCall(vault, abi.encodeCall(VaultHints.activeSharesOfHintInternal, (account, timestamp))),
(bool, uint32)
);

Expand Down
20 changes: 14 additions & 6 deletions src/contracts/libraries/Checkpoints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,18 @@ library Checkpoints {
self._values.push(0);
}

(bool exists, uint48 lastKey,) = self._trace.latestCheckpoint();

uint256 len = self._values.length;
self._trace.push(key, uint208(len));
self._values.push(value);
uint256 lastValue = latest(self);
if (exists && key == lastKey) {
self._values[len - 1] = value;
} else {
self._trace.push(key, uint208(len));
self._values.push(value);
}

return (self._values[len - 1], value);
return (lastValue, value);
}

/**
Expand Down Expand Up @@ -283,11 +290,11 @@ library Checkpoints {
uint32 hint = abi.decode(hint_, (uint32));
Checkpoint256 memory checkpoint = at(self, hint);
if (checkpoint._key == key) {
return (true, checkpoint._key, self._values[checkpoint._value], hint);
return (true, checkpoint._key, checkpoint._value, hint);
}

if (checkpoint._key < key && (hint == length(self) - 1 || at(self, hint + 1)._key > key)) {
return (true, checkpoint._key, self._values[checkpoint._value], hint);
return (true, checkpoint._key, checkpoint._value, hint);
}

return upperLookupRecentCheckpoint(self, key);
Expand Down Expand Up @@ -344,6 +351,7 @@ library Checkpoints {
}
value = self._values[idx];
self._trace._checkpoints.pop();
self._values.pop();
}

/**
Expand All @@ -355,7 +363,7 @@ library Checkpoints {
*/
function _upperBinaryLookup(
OZCheckpoints.Checkpoint208[] storage self,
uint96 key,
uint48 key,
uint256 low,
uint256 high
) private view returns (uint256) {
Expand Down
8 changes: 3 additions & 5 deletions src/contracts/vault/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau
revert InsufficientDeposit();
}

if (isDepositLimit && totalStake() + depositedAmount > depositLimit) {
if (isDepositLimit && activeStake() + depositedAmount > depositLimit) {
revert DepositLimitReached();
}

Expand Down Expand Up @@ -148,8 +148,6 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau
}

mintedShares = _withdraw(claimer, amount, burnedShares);

emit Withdraw(msg.sender, claimer, amount, burnedShares, mintedShares);
}

/**
Expand All @@ -174,8 +172,6 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau
}

mintedShares = _withdraw(claimer, withdrawnAssets, shares);

emit Redeem(msg.sender, claimer, shares, withdrawnAssets, mintedShares);
}

/**
Expand Down Expand Up @@ -405,6 +401,8 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau
withdrawals[epoch] = withdrawals_ + withdrawnAssets;
withdrawalShares[epoch] = withdrawalsShares_ + mintedShares;
withdrawalSharesOf[epoch][claimer] += mintedShares;

emit Withdraw(msg.sender, claimer, withdrawnAssets, burnedShares, mintedShares);
}

function _claim(
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/vault/VaultStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Checkpoints} from "../libraries/Checkpoints.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {Time} from "@openzeppelin/contracts/utils/types/Time.sol";

contract VaultStorage is StaticDelegateCallable, IVaultStorage {
abstract contract VaultStorage is StaticDelegateCallable, IVaultStorage {
using Checkpoints for Checkpoints.Trace256;
using SafeCast for uint256;

Expand Down
1 change: 0 additions & 1 deletion src/contracts/vault/VaultTokenized.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {IVaultTokenized} from "../../interfaces/vault/IVaultTokenized.sol";
import {IVault} from "../../interfaces/vault/IVault.sol";

import {Checkpoints} from "../libraries/Checkpoints.sol";
import {ERC4626Math} from "../libraries/ERC4626Math.sol";

import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
Expand Down
Loading
Loading