Skip to content

Commit

Permalink
Merge pull request #42 from symbioticfi/change-init
Browse files Browse the repository at this point in the history
Change init process
  • Loading branch information
1kresh authored Sep 26, 2024
2 parents 327bf64 + 1145628 commit 2d6162e
Show file tree
Hide file tree
Showing 35 changed files with 1,066 additions and 1,072 deletions.
30 changes: 15 additions & 15 deletions script/deploy/Vault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ contract VaultScript is Script {
IVaultConfigurator.InitParams({
version: IMigratablesFactory(IVaultConfigurator(vaultConfigurator).VAULT_FACTORY()).lastVersion(),
owner: owner,
vaultParams: IVault.InitParams({
collateral: address(collateral),
delegator: address(0),
slasher: address(0),
burner: address(0xdEaD),
epochDuration: epochDuration,
depositWhitelist: depositWhitelist,
isDepositLimit: depositLimit != 0,
depositLimit: depositLimit,
defaultAdminRoleHolder: owner,
depositWhitelistSetRoleHolder: owner,
depositorWhitelistRoleHolder: owner,
isDepositLimitSetRoleHolder: owner,
depositLimitSetRoleHolder: owner
}),
vaultParams: abi.encode(
IVault.InitParams({
collateral: address(collateral),
burner: address(0xdEaD),
epochDuration: epochDuration,
depositWhitelist: depositWhitelist,
isDepositLimit: depositLimit != 0,
depositLimit: depositLimit,
defaultAdminRoleHolder: owner,
depositWhitelistSetRoleHolder: owner,
depositorWhitelistRoleHolder: owner,
isDepositLimitSetRoleHolder: owner,
depositLimitSetRoleHolder: owner
})
),
delegatorIndex: delegatorIndex,
delegatorParams: delegatorIndex == 0
? abi.encode(
Expand Down
28 changes: 8 additions & 20 deletions src/contracts/VaultConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,18 @@ contract VaultConfigurator is IVaultConfigurator {
*/
function create(
InitParams memory params
) public returns (address, address, address) {
if (params.vaultParams.delegator != address(0) || params.vaultParams.slasher != address(0)) {
revert DirtyInitParams();
}

address vault =
VaultFactory(VAULT_FACTORY).create(params.version, params.owner, false, abi.encode(params.vaultParams));

params.vaultParams.delegator = DelegatorFactory(DELEGATOR_FACTORY).create(
params.delegatorIndex, true, abi.encode(vault, params.delegatorParams)
);

bytes memory slasherData;
if (params.withSlasher) {
slasherData = abi.encode(vault, params.slasherParams);
params.vaultParams.slasher = SlasherFactory(SLASHER_FACTORY).create(params.slasherIndex, false, slasherData);
}
) public returns (address vault, address delegator, address slasher) {
vault = VaultFactory(VAULT_FACTORY).create(params.version, params.owner, params.vaultParams);

Vault(vault).initialize(params.version, params.owner, abi.encode(params.vaultParams));
delegator =
DelegatorFactory(DELEGATOR_FACTORY).create(params.delegatorIndex, abi.encode(vault, params.delegatorParams));

if (params.withSlasher) {
BaseSlasher(params.vaultParams.slasher).initialize(slasherData);
slasher =
SlasherFactory(SLASHER_FACTORY).create(params.slasherIndex, abi.encode(vault, params.slasherParams));
}

return (vault, params.vaultParams.delegator, params.vaultParams.slasher);
Vault(vault).setDelegator(delegator);
Vault(vault).setSlasher(slasher);
}
}
14 changes: 0 additions & 14 deletions src/contracts/common/Entity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,13 @@ abstract contract Entity is Initializable, IEntity {
*/
uint64 public immutable TYPE;

modifier initialized() {
if (!isInitialized()) {
revert NotInitialized();
}
_;
}

constructor(address factory, uint64 type_) {
_disableInitializers();

FACTORY = factory;
TYPE = type_;
}

/**
* @inheritdoc IEntity
*/
function isInitialized() public view returns (bool) {
return _getInitializedVersion() != 0;
}

/**
* @inheritdoc IEntity
*/
Expand Down
6 changes: 2 additions & 4 deletions src/contracts/common/Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,11 @@ contract Factory is Registry, Ownable, IFactory {
/**
* @inheritdoc IFactory
*/
function create(uint64 type_, bool withInitialize, bytes calldata data) external returns (address entity_) {
function create(uint64 type_, bytes calldata data) external returns (address entity_) {
entity_ = implementation(type_).cloneDeterministic(keccak256(abi.encode(totalEntities(), type_, data)));

_addEntity(entity_);

if (withInitialize) {
IEntity(entity_).initialize(data);
}
IEntity(entity_).initialize(data);
}
}
23 changes: 1 addition & 22 deletions src/contracts/common/MigratableEntity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,8 @@ abstract contract MigratableEntity is
*/
address public immutable FACTORY;

address private immutable SELF;

modifier initialized() {
if (!isInitialized()) {
revert NotInitialized();
}
_;
}

modifier notInitialized() {
if (isInitialized()) {
if (_getInitializedVersion() != 0) {
revert AlreadyInitialized();
}

Expand All @@ -42,14 +33,6 @@ abstract contract MigratableEntity is
_disableInitializers();

FACTORY = factory;
SELF = address(this);
}

/**
* @inheritdoc IMigratableEntity
*/
function isInitialized() public view returns (bool) {
return _getInitializedVersion() != 0;
}

/**
Expand All @@ -67,10 +50,6 @@ abstract contract MigratableEntity is
address owner_,
bytes calldata data
) external notInitialized reinitializer(initialVersion) {
if (SELF != IMigratablesFactory(FACTORY).implementation(initialVersion)) {
revert InvalidInitialVersion();
}

__ReentrancyGuard_init();

if (owner_ != address(0)) {
Expand Down
11 changes: 2 additions & 9 deletions src/contracts/common/MigratablesFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,11 @@ contract MigratablesFactory is Registry, Ownable, IMigratablesFactory {
/**
* @inheritdoc IMigratablesFactory
*/
function create(
uint64 version,
address owner_,
bool withInitialize,
bytes calldata data
) external returns (address entity_) {
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),
withInitialize
? abi.encodeWithSelector(IMigratableEntity.initialize.selector, version, owner_, data)
: new bytes(0)
abi.encodeWithSelector(IMigratableEntity.initialize.selector, version, owner_, data)
)
);

Expand Down
6 changes: 3 additions & 3 deletions src/contracts/delegator/BaseDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ contract BaseDelegator is
/**
* @inheritdoc IBaseDelegator
*/
function setMaxNetworkLimit(uint96 identifier, uint256 amount) external initialized nonReentrant {
function setMaxNetworkLimit(uint96 identifier, uint256 amount) external nonReentrant {
if (!IRegistry(NETWORK_REGISTRY).isEntity(msg.sender)) {
revert NotNetwork();
}
Expand All @@ -163,7 +163,7 @@ contract BaseDelegator is
*/
function setHook(
address hook_
) external initialized nonReentrant onlyRole(HOOK_SET_ROLE) {
) external nonReentrant onlyRole(HOOK_SET_ROLE) {
hook = hook_;

emit SetHook(hook_);
Expand All @@ -178,7 +178,7 @@ contract BaseDelegator is
uint256 slashedAmount,
uint48 captureTimestamp,
bytes memory data
) external initialized nonReentrant {
) external nonReentrant {
if (IVault(vault).slasher() != msg.sender) {
revert NotSlasher();
}
Expand Down
7 changes: 2 additions & 5 deletions src/contracts/delegator/FullRestakeDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ contract FullRestakeDelegator is BaseDelegator, IFullRestakeDelegator {
/**
* @inheritdoc IFullRestakeDelegator
*/
function setNetworkLimit(
bytes32 subnetwork,
uint256 amount
) external initialized onlyRole(NETWORK_LIMIT_SET_ROLE) {
function setNetworkLimit(bytes32 subnetwork, uint256 amount) external onlyRole(NETWORK_LIMIT_SET_ROLE) {
if (amount > maxNetworkLimit[subnetwork]) {
revert ExceedsMaxNetworkLimit();
}
Expand All @@ -107,7 +104,7 @@ contract FullRestakeDelegator is BaseDelegator, IFullRestakeDelegator {
bytes32 subnetwork,
address operator,
uint256 amount
) external initialized onlyRole(OPERATOR_NETWORK_LIMIT_SET_ROLE) {
) external onlyRole(OPERATOR_NETWORK_LIMIT_SET_ROLE) {
_operatorNetworkLimit[subnetwork][operator].push(Time.timestamp(), amount);

emit SetOperatorNetworkLimit(subnetwork, operator, amount);
Expand Down
7 changes: 2 additions & 5 deletions src/contracts/delegator/NetworkRestakeDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ contract NetworkRestakeDelegator is BaseDelegator, INetworkRestakeDelegator {
/**
* @inheritdoc INetworkRestakeDelegator
*/
function setNetworkLimit(
bytes32 subnetwork,
uint256 amount
) external initialized onlyRole(NETWORK_LIMIT_SET_ROLE) {
function setNetworkLimit(bytes32 subnetwork, uint256 amount) external onlyRole(NETWORK_LIMIT_SET_ROLE) {
if (amount > maxNetworkLimit[subnetwork]) {
revert ExceedsMaxNetworkLimit();
}
Expand All @@ -129,7 +126,7 @@ contract NetworkRestakeDelegator is BaseDelegator, INetworkRestakeDelegator {
bytes32 subnetwork,
address operator,
uint256 shares
) external initialized onlyRole(OPERATOR_NETWORK_SHARES_SET_ROLE) {
) external onlyRole(OPERATOR_NETWORK_SHARES_SET_ROLE) {
_totalOperatorNetworkShares[subnetwork].push(
Time.timestamp(),
totalOperatorNetworkShares(subnetwork) - operatorNetworkShares(subnetwork, operator) + shares
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/slasher/Slasher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract Slasher is BaseSlasher, ISlasher {
uint256 amount,
uint48 captureTimestamp,
bytes calldata hints
) external initialized nonReentrant onlyNetworkMiddleware(subnetwork) returns (uint256 slashedAmount) {
) external nonReentrant onlyNetworkMiddleware(subnetwork) returns (uint256 slashedAmount) {
SlashHints memory slashHints;
if (hints.length > 0) {
slashHints = abi.decode(hints, (SlashHints));
Expand Down
15 changes: 4 additions & 11 deletions src/contracts/slasher/VetoSlasher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher {
uint256 amount,
uint48 captureTimestamp,
bytes calldata hints
) external initialized nonReentrant onlyNetworkMiddleware(subnetwork) returns (uint256 slashIndex) {
) external nonReentrant onlyNetworkMiddleware(subnetwork) returns (uint256 slashIndex) {
RequestSlashHints memory requestSlashHints;
if (hints.length > 0) {
requestSlashHints = abi.decode(hints, (RequestSlashHints));
Expand Down Expand Up @@ -126,7 +126,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher {
function executeSlash(
uint256 slashIndex,
bytes calldata hints
) external initialized nonReentrant returns (uint256 slashedAmount) {
) external nonReentrant returns (uint256 slashedAmount) {
ExecuteSlashHints memory executeSlashHints;
if (hints.length > 0) {
executeSlashHints = abi.decode(hints, (ExecuteSlashHints));
Expand Down Expand Up @@ -189,7 +189,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher {
/**
* @inheritdoc IVetoSlasher
*/
function vetoSlash(uint256 slashIndex, bytes calldata hints) external initialized nonReentrant {
function vetoSlash(uint256 slashIndex, bytes calldata hints) external nonReentrant {
VetoSlashHints memory vetoSlashHints;
if (hints.length > 0) {
vetoSlashHints = abi.decode(hints, (VetoSlashHints));
Expand Down Expand Up @@ -227,11 +227,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher {
emit VetoSlash(slashIndex, msg.sender);
}

function setResolver(
uint96 identifier,
address resolver_,
bytes calldata hints
) external initialized nonReentrant {
function setResolver(uint96 identifier, address resolver_, bytes calldata hints) external nonReentrant {
SetResolverHints memory setResolverHints;
if (hints.length > 0) {
setResolverHints = abi.decode(hints, (SetResolverHints));
Expand Down Expand Up @@ -261,9 +257,6 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher {
(InitParams memory params) = abi.decode(data, (InitParams));

uint48 epochDuration = IVault(vault_).epochDuration();
if (!IVault(vault_).isInitialized()) {
revert VaultNotInitialized();
}
if (params.vetoDuration >= epochDuration) {
revert InvalidVetoDuration();
}
Expand Down
Loading

0 comments on commit 2d6162e

Please sign in to comment.