Skip to content

Commit

Permalink
fix: rename long name to Delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
mymphe committed Nov 29, 2024
1 parent 481979d commit ce82205
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Dashboard} from "./Dashboard.sol";
import {Math256} from "contracts/common/lib/Math256.sol";

/**
* @title StVaultOwnerWithDelegation
* @title Delegation
* @notice This contract serves as an owner for `StakingVault` with additional delegation capabilities.
* It extends `Dashboard` and implements `IReportReceiver`.
* The contract provides administrative functions for managing the staking vault,
Expand All @@ -26,7 +26,7 @@ import {Math256} from "contracts/common/lib/Math256.sol";
* @notice The term "fee" is used to express the fee percentage as basis points, e.g. 5%,
* while "due" is the actual amount of the fee, e.g. 1 ether
*/
contract StVaultOwnerWithDelegation is Dashboard, IReportReceiver {
contract Delegation is Dashboard, IReportReceiver {
// ==================== Constants ====================

uint256 private constant BP_BASE = 10000; // Basis points base (100%)
Expand All @@ -45,15 +45,15 @@ contract StVaultOwnerWithDelegation is Dashboard, IReportReceiver {
* - vote on ownership transfer
* - vote on performance fee changes
*/
bytes32 public constant MANAGER_ROLE = keccak256("Vault.StVaultOwnerWithDelegation.ManagerRole");
bytes32 public constant MANAGER_ROLE = keccak256("Vault.Delegation.ManagerRole");

/**
* @notice Role for the staker.
* Staker can:
* - fund the vault
* - withdraw from the vault
*/
bytes32 public constant STAKER_ROLE = keccak256("Vault.StVaultOwnerWithDelegation.StakerRole");
bytes32 public constant STAKER_ROLE = keccak256("Vault.Delegation.StakerRole");

/** @notice Role for the operator
* Operator can:
Expand All @@ -62,22 +62,22 @@ contract StVaultOwnerWithDelegation is Dashboard, IReportReceiver {
* - vote on ownership transfer
* - set the Key Master role
*/
bytes32 public constant OPERATOR_ROLE = keccak256("Vault.StVaultOwnerWithDelegation.OperatorRole");
bytes32 public constant OPERATOR_ROLE = keccak256("Vault.Delegation.OperatorRole");

/**
* @notice Role for the key master.
* Key master can:
* - deposit validators to the beacon chain
*/
bytes32 public constant KEY_MASTER_ROLE = keccak256("Vault.StVaultOwnerWithDelegation.KeyMasterRole");
bytes32 public constant KEY_MASTER_ROLE = keccak256("Vault.Delegation.KeyMasterRole");

/**
* @notice Role for the token master.
* Token master can:
* - mint stETH tokens
* - burn stETH tokens
*/
bytes32 public constant TOKEN_MASTER_ROLE = keccak256("Vault.StVaultOwnerWithDelegation.TokenMasterRole");
bytes32 public constant TOKEN_MASTER_ROLE = keccak256("Vault.Delegation.TokenMasterRole");

/**
* @notice Role for the Lido DAO.
Expand All @@ -86,7 +86,7 @@ contract StVaultOwnerWithDelegation is Dashboard, IReportReceiver {
* - set the operator role
* - vote on ownership transfer
*/
bytes32 public constant LIDO_DAO_ROLE = keccak256("Vault.StVaultOwnerWithDelegation.LidoDAORole");
bytes32 public constant LIDO_DAO_ROLE = keccak256("Vault.Delegation.LidoDAORole");

// ==================== State Variables ====================

Expand Down
59 changes: 28 additions & 31 deletions contracts/0.8.25/vaults/VaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IStakingVault} from "./interfaces/IStakingVault.sol";

pragma solidity 0.8.25;

interface IStVaultOwnerWithDelegation {
interface IDelegation {
struct InitializationParams {
uint256 managementFee;
uint256 performanceFee;
Expand Down Expand Up @@ -37,59 +37,56 @@ interface IStVaultOwnerWithDelegation {
}

contract VaultFactory is UpgradeableBeacon {
address public immutable stVaultOwnerWithDelegationImpl;
address public immutable delegationImpl;

/// @param _owner The address of the VaultFactory owner
/// @param _stakingVaultImpl The address of the StakingVault implementation
/// @param _stVaultOwnerWithDelegationImpl The address of the StVaultOwnerWithDelegation implementation
/// @param _delegationImpl The address of the Delegation implementation
constructor(
address _owner,
address _stakingVaultImpl,
address _stVaultOwnerWithDelegationImpl
address _delegationImpl
) UpgradeableBeacon(_stakingVaultImpl, _owner) {
if (_stVaultOwnerWithDelegationImpl == address(0)) revert ZeroArgument("_stVaultOwnerWithDelegation");
if (_delegationImpl == address(0)) revert ZeroArgument("_delegation");

stVaultOwnerWithDelegationImpl = _stVaultOwnerWithDelegationImpl;
delegationImpl = _delegationImpl;
}

/// @notice Creates a new StakingVault and StVaultOwnerWithDelegation contracts
/// @notice Creates a new StakingVault and Delegation contracts
/// @param _stakingVaultParams The params of vault initialization
/// @param _initializationParams The params of vault initialization
function createVault(
bytes calldata _stakingVaultParams,
IStVaultOwnerWithDelegation.InitializationParams calldata _initializationParams,
IDelegation.InitializationParams calldata _initializationParams,
address _lidoAgent
) external returns (IStakingVault vault, IStVaultOwnerWithDelegation stVaultOwnerWithDelegation) {
) external returns (IStakingVault vault, IDelegation delegation) {
if (_initializationParams.manager == address(0)) revert ZeroArgument("manager");
if (_initializationParams.operator == address(0)) revert ZeroArgument("operator");

vault = IStakingVault(address(new BeaconProxy(address(this), "")));

stVaultOwnerWithDelegation = IStVaultOwnerWithDelegation(Clones.clone(stVaultOwnerWithDelegationImpl));
delegation = IDelegation(Clones.clone(delegationImpl));

stVaultOwnerWithDelegation.initialize(address(this), address(vault));
delegation.initialize(address(this), address(vault));

stVaultOwnerWithDelegation.grantRole(stVaultOwnerWithDelegation.LIDO_DAO_ROLE(), _lidoAgent);
stVaultOwnerWithDelegation.grantRole(stVaultOwnerWithDelegation.MANAGER_ROLE(), _initializationParams.manager);
stVaultOwnerWithDelegation.grantRole(
stVaultOwnerWithDelegation.OPERATOR_ROLE(),
_initializationParams.operator
);
stVaultOwnerWithDelegation.grantRole(stVaultOwnerWithDelegation.DEFAULT_ADMIN_ROLE(), msg.sender);
delegation.grantRole(delegation.LIDO_DAO_ROLE(), _lidoAgent);
delegation.grantRole(delegation.MANAGER_ROLE(), _initializationParams.manager);
delegation.grantRole(delegation.OPERATOR_ROLE(), _initializationParams.operator);
delegation.grantRole(delegation.DEFAULT_ADMIN_ROLE(), msg.sender);

stVaultOwnerWithDelegation.grantRole(stVaultOwnerWithDelegation.MANAGER_ROLE(), address(this));
stVaultOwnerWithDelegation.setManagementFee(_initializationParams.managementFee);
stVaultOwnerWithDelegation.setPerformanceFee(_initializationParams.performanceFee);
delegation.grantRole(delegation.MANAGER_ROLE(), address(this));
delegation.setManagementFee(_initializationParams.managementFee);
delegation.setPerformanceFee(_initializationParams.performanceFee);

//revoke roles from factory
stVaultOwnerWithDelegation.revokeRole(stVaultOwnerWithDelegation.MANAGER_ROLE(), address(this));
stVaultOwnerWithDelegation.revokeRole(stVaultOwnerWithDelegation.DEFAULT_ADMIN_ROLE(), address(this));
stVaultOwnerWithDelegation.revokeRole(stVaultOwnerWithDelegation.LIDO_DAO_ROLE(), address(this));
delegation.revokeRole(delegation.MANAGER_ROLE(), address(this));
delegation.revokeRole(delegation.DEFAULT_ADMIN_ROLE(), address(this));
delegation.revokeRole(delegation.LIDO_DAO_ROLE(), address(this));

vault.initialize(address(stVaultOwnerWithDelegation), _stakingVaultParams);
vault.initialize(address(delegation), _stakingVaultParams);

emit VaultCreated(address(stVaultOwnerWithDelegation), address(vault));
emit StVaultOwnerWithDelegationCreated(msg.sender, address(stVaultOwnerWithDelegation));
emit VaultCreated(address(delegation), address(vault));
emit DelegationCreated(msg.sender, address(delegation));
}

/**
Expand All @@ -100,11 +97,11 @@ contract VaultFactory is UpgradeableBeacon {
event VaultCreated(address indexed owner, address indexed vault);

/**
* @notice Event emitted on a StVaultOwnerWithDelegation creation
* @param admin The address of the StVaultOwnerWithDelegation admin
* @param stVaultOwnerWithDelegation The address of the created StVaultOwnerWithDelegation
* @notice Event emitted on a Delegation creation
* @param admin The address of the Delegation admin
* @param delegation The address of the created Delegation
*/
event StVaultOwnerWithDelegationCreated(address indexed admin, address indexed stVaultOwnerWithDelegation);
event DelegationCreated(address indexed admin, address indexed delegation);

error ZeroArgument(string);
}
28 changes: 14 additions & 14 deletions lib/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
OssifiableProxy,
OssifiableProxy__factory,
StakingVault,
StVaultOwnerWithDelegation,
Delegation,
VaultFactory,
} from "typechain-types";

import { findEventsWithInterfaces } from "lib";

import { IStVaultOwnerWithDelegation } from "../typechain-types/contracts/0.8.25/vaults/VaultFactory.sol/VaultFactory";
import StVaultOwnerWithDelegationInitializationParamsStruct = IStVaultOwnerWithDelegation.InitializationParamsStruct;
import { IDelegation } from "../typechain-types/contracts/0.8.25/vaults/VaultFactory.sol/VaultFactory";
import DelegationInitializationParamsStruct = IDelegation.InitializationParamsStruct;

interface ProxifyArgs<T> {
impl: T;
Expand Down Expand Up @@ -44,7 +44,7 @@ interface CreateVaultResponse {
tx: ContractTransactionResponse;
proxy: BeaconProxy;
vault: StakingVault;
stVaultOwnerWithDelegation: StVaultOwnerWithDelegation;
delegation: Delegation;
}

export async function createVaultProxy(
Expand All @@ -53,7 +53,7 @@ export async function createVaultProxy(
_lidoAgent: HardhatEthersSigner,
): Promise<CreateVaultResponse> {
// Define the parameters for the struct
const initializationParams: StVaultOwnerWithDelegationInitializationParamsStruct = {
const initializationParams: DelegationInitializationParamsStruct = {
managementFee: 100n,
performanceFee: 200n,
manager: await _owner.getAddress(),
Expand All @@ -71,28 +71,28 @@ export async function createVaultProxy(
const event = events[0];
const { vault } = event.args;

const stVaultOwnerWithDelegationEvents = findEventsWithInterfaces(
const delegationEvents = findEventsWithInterfaces(
receipt,
"StVaultOwnerWithDelegationCreated",
"DelegationCreated",
[vaultFactory.interface],
);

if (stVaultOwnerWithDelegationEvents.length === 0) throw new Error("StVaultOwnerWithDelegation creation event not found");
if (delegationEvents.length === 0) throw new Error("Delegation creation event not found");

const { stVaultOwnerWithDelegation: stVaultOwnerWithDelegationAddress } = stVaultOwnerWithDelegationEvents[0].args;
const { delegation: delegationAddress } = delegationEvents[0].args;

const proxy = (await ethers.getContractAt("BeaconProxy", vault, _owner)) as BeaconProxy;
const stakingVault = (await ethers.getContractAt("StakingVault", vault, _owner)) as StakingVault;
const stVaultOwnerWithDelegation = (await ethers.getContractAt(
"StVaultOwnerWithDelegation",
stVaultOwnerWithDelegationAddress,
const delegation = (await ethers.getContractAt(
"Delegation",
delegationAddress,
_owner,
)) as StVaultOwnerWithDelegation;
)) as Delegation;

return {
tx,
proxy,
vault: stakingVault,
stVaultOwnerWithDelegation,
delegation,
};
}
2 changes: 1 addition & 1 deletion lib/state-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export enum Sk {
// Vaults
stakingVaultImpl = "stakingVaultImpl",
stakingVaultFactory = "stakingVaultFactory",
stVaultOwnerWithDelegationImpl = "stVaultOwnerWithDelegationImpl",
delegationImpl = "delegationImpl",
}

export function getAddress(contractKey: Sk, state: DeploymentState): string {
Expand Down
4 changes: 2 additions & 2 deletions scripts/scratch/steps/0145-deploy-vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export async function main() {
]);
const impAddress = await imp.getAddress();

// Deploy StVaultOwnerWithDelegation implementation contract
const room = await deployWithoutProxy(Sk.stVaultOwnerWithDelegationImpl, "StVaultOwnerWithDelegation", deployer, [lidoAddress]);
// Deploy Delegation implementation contract
const room = await deployWithoutProxy(Sk.delegationImpl, "Delegation", deployer, [lidoAddress]);
const roomAddress = await room.getAddress();

// Deploy VaultFactory contract
Expand Down
Loading

0 comments on commit ce82205

Please sign in to comment.