Skip to content

Commit

Permalink
feat: remove locator call from vaulthub constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeday committed Mar 3, 2025
1 parent ae75131 commit 715a0fd
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 21 deletions.
46 changes: 31 additions & 15 deletions contracts/0.8.25/vaults/VaultHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,24 @@ contract VaultHub is PausableUntilWithRoles {
address public immutable ACCOUNTING;

/// @param _locator Lido Locator contract
/// @param _lido Lido stETH contract
/// @param _accounting Accounting contract
/// @param _connectedVaultsLimit Maximum number of vaults that can be connected simultaneously
/// @param _relativeShareLimitBP Maximum share limit relative to TVL in basis points
constructor(ILidoLocator _locator, address _accounting, uint256 _connectedVaultsLimit, uint256 _relativeShareLimitBP) {
constructor(
ILidoLocator _locator,
address _lido,
address _accounting,
uint256 _connectedVaultsLimit,
uint256 _relativeShareLimitBP
) {
if (_connectedVaultsLimit == 0) revert ZeroArgument("_connectedVaultsLimit");
if (_relativeShareLimitBP == 0) revert ZeroArgument("_relativeShareLimitBP");
if (_relativeShareLimitBP > TOTAL_BASIS_POINTS) revert RelativeShareLimitBPTooHigh(_relativeShareLimitBP, TOTAL_BASIS_POINTS);
if (_relativeShareLimitBP > TOTAL_BASIS_POINTS)
revert RelativeShareLimitBPTooHigh(_relativeShareLimitBP, TOTAL_BASIS_POINTS);

LIDO_LOCATOR = _locator;
STETH = IStETH(_locator.lido());
STETH = IStETH(_lido);
ACCOUNTING = _accounting;
CONNECTED_VAULTS_LIMIT = _connectedVaultsLimit;
RELATIVE_SHARE_LIMIT_BP = _relativeShareLimitBP;
Expand Down Expand Up @@ -157,9 +165,9 @@ contract VaultHub is PausableUntilWithRoles {
VaultSocket storage socket = _connectedSocket(_vault);
if (socket.sharesMinted == 0) return true;

return (
IStakingVault(_vault).valuation() * (TOTAL_BASIS_POINTS - socket.rebalanceThresholdBP) / TOTAL_BASIS_POINTS
) >= STETH.getPooledEthBySharesRoundUp(socket.sharesMinted);
return
((IStakingVault(_vault).valuation() * (TOTAL_BASIS_POINTS - socket.rebalanceThresholdBP)) /
TOTAL_BASIS_POINTS) >= STETH.getPooledEthBySharesRoundUp(socket.sharesMinted);
}

/// @notice connects a vault to the hub
Expand All @@ -178,9 +186,11 @@ contract VaultHub is PausableUntilWithRoles {
) external onlyRole(VAULT_MASTER_ROLE) {
if (_vault == address(0)) revert ZeroArgument("_vault");
if (_reserveRatioBP == 0) revert ZeroArgument("_reserveRatioBP");
if (_reserveRatioBP > TOTAL_BASIS_POINTS) revert ReserveRatioTooHigh(_vault, _reserveRatioBP, TOTAL_BASIS_POINTS);
if (_reserveRatioBP > TOTAL_BASIS_POINTS)
revert ReserveRatioTooHigh(_vault, _reserveRatioBP, TOTAL_BASIS_POINTS);
if (_rebalanceThresholdBP == 0) revert ZeroArgument("_rebalanceThresholdBP");
if (_rebalanceThresholdBP > _reserveRatioBP) revert RebalanceThresholdTooHigh(_vault, _rebalanceThresholdBP, _reserveRatioBP);
if (_rebalanceThresholdBP > _reserveRatioBP)
revert RebalanceThresholdTooHigh(_vault, _rebalanceThresholdBP, _reserveRatioBP);
if (_treasuryFeeBP > TOTAL_BASIS_POINTS) revert TreasuryFeeTooHigh(_vault, _treasuryFeeBP, TOTAL_BASIS_POINTS);
if (vaultsCount() == CONNECTED_VAULTS_LIMIT) revert TooManyVaults();
_checkShareLimitUpperBound(_vault, _shareLimit);
Expand Down Expand Up @@ -377,11 +387,7 @@ contract VaultHub is PausableUntilWithRoles {
/// @param _refundRecipient The address that will receive the refund for transaction costs
/// @dev When the vault becomes unhealthy, anyone can force its validators to exit the beacon chain
/// This returns the vault's deposited ETH back to vault's balance and allows to rebalance the vault
function forceValidatorExit(
address _vault,
bytes calldata _pubkeys,
address _refundRecipient
) external payable {
function forceValidatorExit(address _vault, bytes calldata _pubkeys, address _refundRecipient) external payable {
if (msg.value == 0) revert ZeroArgument("msg.value");
if (_vault == address(0)) revert ZeroArgument("_vault");
if (_pubkeys.length == 0) revert ZeroArgument("_pubkeys");
Expand Down Expand Up @@ -419,7 +425,11 @@ contract VaultHub is PausableUntilWithRoles {
uint256 _preTotalShares,
uint256 _preTotalPooledEther,
uint256 _sharesToMintAsFees
) public view returns (uint256[] memory lockedEther, uint256[] memory treasuryFeeShares, uint256 totalTreasuryFeeShares) {
)
public
view
returns (uint256[] memory lockedEther, uint256[] memory treasuryFeeShares, uint256 totalTreasuryFeeShares)
{
/// HERE WILL BE ACCOUNTING DRAGON

// \||/
Expand Down Expand Up @@ -568,7 +578,13 @@ contract VaultHub is PausableUntilWithRoles {
if (isVaultHealthy(_vault)) revert AlreadyHealthy(_vault);
}

event VaultConnected(address indexed vault, uint256 capShares, uint256 minReserveRatio, uint256 rebalanceThreshold, uint256 treasuryFeeBP);
event VaultConnected(
address indexed vault,
uint256 capShares,
uint256 minReserveRatio,
uint256 rebalanceThreshold,
uint256 treasuryFeeBP
);
event ShareLimitUpdated(address indexed vault, uint256 newShareLimit);
event VaultDisconnected(address indexed vault);
event MintedSharesOnVault(address indexed vault, uint256 amountOfShares);
Expand Down
1 change: 1 addition & 0 deletions lib/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ async function getLocatorConfig(locatorAddress: string) {
"oracleDaemonConfig",
"accounting",
"wstETH",
"predepositGuarantee",
"vaultHub",
] as (keyof LidoLocator.ConfigStruct)[];

Expand Down
1 change: 1 addition & 0 deletions scripts/scratch/steps/0090-deploy-non-aragon-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export async function main() {

const vaultHub = await deployBehindOssifiableProxy(Sk.vaultHub, "VaultHub", proxyContractsOwner, deployer, [
locator.address,
lidoAddress,
accounting.address,
vaultHubParams.connectedVaultsLimit,
vaultHubParams.relativeShareLimitBP,
Expand Down
1 change: 1 addition & 0 deletions test/0.8.25/vaults/vaultFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe("VaultFactory.sol", () => {
// Accounting
vaultHubImpl = await ethers.deployContract("VaultHub", [
locator,
steth,
ZeroAddress,
VAULTS_CONNECTED_VAULTS_LIMIT,
VAULTS_RELATIVE_SHARE_LIMIT_BP,
Expand Down
3 changes: 2 additions & 1 deletion test/0.8.25/vaults/vaultHub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ describe("VaultHub.sol", () => {
// VaultHub
vaultHubImpl = await ethers.deployContract("VaultHub", [
locator,
ZeroAddress,
await locator.lido(),
await locator.accounting(),
VAULTS_CONNECTED_VAULTS_LIMIT,
VAULTS_RELATIVE_SHARE_LIMIT_BP,
]);
Expand Down
10 changes: 9 additions & 1 deletion test/0.8.25/vaults/vaulthub/contracts/VaultHub__Harness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ contract VaultHub__Harness is VaultHub {
address _locator,
uint256 _connectedVaultsLimit,
uint256 _relativeShareLimitBP
) VaultHub(ILidoLocator(_locator), address(0), _connectedVaultsLimit, _relativeShareLimitBP) {}
)
VaultHub(
ILidoLocator(_locator),
ILidoLocator(_locator).lido(),
ILidoLocator(_locator).accounting(),
_connectedVaultsLimit,
_relativeShareLimitBP
)
{}

function mock__calculateVaultsRebase(
uint256 _postTotalShares,
Expand Down
3 changes: 2 additions & 1 deletion test/0.8.25/vaults/vaulthub/vaulthub.hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ describe("VaultHub.sol:hub", () => {

const vaultHubImpl = await ethers.deployContract("VaultHub", [
locator,
ZeroAddress,
await locator.lido(),
await locator.accounting(),
VAULTS_CONNECTED_VAULTS_LIMIT,
VAULTS_RELATIVE_SHARE_LIMIT_BP,
]);
Expand Down
4 changes: 2 additions & 2 deletions test/0.8.25/vaults/vaulthub/vaulthub.pausable.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from "chai";
import { ZeroAddress } from "ethers";
import { ethers } from "hardhat";

import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
Expand Down Expand Up @@ -31,7 +30,8 @@ describe("VaultHub.sol:pausableUntil", () => {

const vaultHubImpl = await ethers.deployContract("VaultHub", [
locator,
ZeroAddress,
await locator.lido(),
await locator.accounting(),
VAULTS_CONNECTED_VAULTS_LIMIT,
VAULTS_RELATIVE_SHARE_LIMIT_BP,
]);
Expand Down
3 changes: 2 additions & 1 deletion test/0.8.9/accounting.handleOracleReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { certainAddress, ether, impersonate } from "lib";

import { deployLidoLocator, updateLidoLocatorImplementation } from "test/deploy";
import { VAULTS_CONNECTED_VAULTS_LIMIT, VAULTS_RELATIVE_SHARE_LIMIT_BP } from "test/suite";

describe("Accounting.sol:report", () => {
let deployer: HardhatEthersSigner;

Expand Down Expand Up @@ -75,7 +76,7 @@ describe("Accounting.sol:report", () => {

const vaultHubImpl = await ethers.deployContract(
"VaultHub",
[locator, accounting, VAULTS_CONNECTED_VAULTS_LIMIT, VAULTS_RELATIVE_SHARE_LIMIT_BP],
[locator, lido, accounting, VAULTS_CONNECTED_VAULTS_LIMIT, VAULTS_RELATIVE_SHARE_LIMIT_BP],
deployer,
);
const vaultHubProxy = await ethers.deployContract(
Expand Down

0 comments on commit 715a0fd

Please sign in to comment.