Skip to content

Commit

Permalink
refactor: reserveRatioThresholdBP ⇒ rebalanceThresholdBP
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Feb 26, 2025
1 parent 081444b commit aa92ca3
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 55 deletions.
10 changes: 5 additions & 5 deletions contracts/0.8.25/vaults/Dashboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ contract Dashboard is Permissions {

/**
* @notice Returns the reserve ratio of the vault in basis points
* @return The reserve ratio as a uint16
* @return The reserve ratio in basis points as a uint16
*/
function reserveRatioBP() public view returns (uint16) {
return vaultSocket().reserveRatioBP;
}

/**
* @notice Returns the threshold reserve ratio of the vault in basis points.
* @return The threshold reserve ratio as a uint16.
* @notice Returns the rebalance threshold of the vault in basis points.
* @return The rebalance threshold in basis points as a uint16.
*/
function thresholdReserveRatioBP() external view returns (uint16) {
return vaultSocket().reserveRatioThresholdBP;
function rebalanceThresholdBP() external view returns (uint16) {
return vaultSocket().rebalanceThresholdBP;
}

/**
Expand Down
28 changes: 14 additions & 14 deletions contracts/0.8.25/vaults/VaultHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ abstract contract VaultHub is PausableUntilWithRoles {
uint96 shareLimit;
/// @notice minimal share of ether that is reserved for each stETH minted
uint16 reserveRatioBP;
/// @notice if vault's reserve decreases to this threshold ratio, it should be force rebalanced
uint16 reserveRatioThresholdBP;
/// @notice if vault's reserve decreases to this threshold, it should be force rebalanced
uint16 rebalanceThresholdBP;
/// @notice treasury fee in basis points
uint16 treasuryFeeBP;
/// @notice if true, vault is disconnected and fee is not accrued
Expand Down Expand Up @@ -135,38 +135,38 @@ abstract contract VaultHub is PausableUntilWithRoles {
return $.sockets[$.vaultIndex[_vault]];
}

/// @notice checks if the vault is healthy by comparing its valuation against minted shares
/// @dev A vault is considered healthy when its valuation is sufficient to cover the current value of minted shares
/// @notice checks if the vault is healthy by comparing its projected valuation after applying rebalance threshold
/// against the current value of minted shares
/// @param _vault vault address
/// @return true if vault is healthy, false otherwise
function isVaultHealthy(address _vault) public view returns (bool) {
VaultSocket storage socket = _connectedSocket(_vault);
if (socket.sharesMinted == 0) return true;

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

/// @notice connects a vault to the hub
/// @param _vault vault address
/// @param _shareLimit maximum number of stETH shares that can be minted by the vault
/// @param _reserveRatioBP minimum Reserve ratio in basis points
/// @param _reserveRatioThresholdBP reserve ratio that makes possible to force rebalance on the vault (in basis points)
/// @param _reserveRatioBP minimum reserve ratio in basis points
/// @param _rebalanceThresholdBP threshold to force rebalance on the vault in basis points
/// @param _treasuryFeeBP treasury fee in basis points
/// @dev msg.sender must have VAULT_MASTER_ROLE
function connectVault(
address _vault,
uint256 _shareLimit,
uint256 _reserveRatioBP,
uint256 _reserveRatioThresholdBP,
uint256 _rebalanceThresholdBP,
uint256 _treasuryFeeBP
) 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 (_reserveRatioThresholdBP == 0) revert ZeroArgument("_reserveRatioThresholdBP");
if (_reserveRatioThresholdBP > _reserveRatioBP) revert ReserveRatioThresholdTooHigh(_vault, _reserveRatioThresholdBP, _reserveRatioBP);
if (_rebalanceThresholdBP == 0) revert ZeroArgument("_rebalanceThresholdBP");
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 All @@ -182,7 +182,7 @@ abstract contract VaultHub is PausableUntilWithRoles {
0, // sharesMinted
uint96(_shareLimit),
uint16(_reserveRatioBP),
uint16(_reserveRatioThresholdBP),
uint16(_rebalanceThresholdBP),
uint16(_treasuryFeeBP),
false // pendingDisconnect
);
Expand All @@ -191,7 +191,7 @@ abstract contract VaultHub is PausableUntilWithRoles {

IStakingVault(_vault).lock(CONNECT_DEPOSIT);

emit VaultConnected(_vault, _shareLimit, _reserveRatioBP, _reserveRatioThresholdBP, _treasuryFeeBP);
emit VaultConnected(_vault, _shareLimit, _reserveRatioBP, _rebalanceThresholdBP, _treasuryFeeBP);
}

/// @notice updates share limit for the vault
Expand Down Expand Up @@ -542,7 +542,7 @@ abstract contract VaultHub is PausableUntilWithRoles {
if (isVaultHealthy(_vault)) revert AlreadyHealthy(_vault);
}

event VaultConnected(address indexed vault, uint256 capShares, uint256 minReserveRatio, uint256 reserveRatioThreshold, 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 All @@ -564,7 +564,7 @@ abstract contract VaultHub is PausableUntilWithRoles {
error TooManyVaults();
error ShareLimitTooHigh(address vault, uint256 capShares, uint256 maxCapShares);
error ReserveRatioTooHigh(address vault, uint256 reserveRatioBP, uint256 maxReserveRatioBP);
error ReserveRatioThresholdTooHigh(address vault, uint256 reserveRatioThresholdBP, uint256 maxReserveRatioBP);
error RebalanceThresholdTooHigh(address vault, uint256 rebalanceThresholdBP, uint256 maxRebalanceThresholdBP);
error TreasuryFeeTooHigh(address vault, uint256 treasuryFeeBP, uint256 maxTreasuryFeeBP);
error ExternalSharesCapReached(address vault, uint256 capShares, uint256 maxMintableExternalShares);
error InsufficientValuationToMint(address vault, uint256 valuation);
Expand Down
22 changes: 11 additions & 11 deletions test/0.8.25/vaults/dashboard/dashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe("Dashboard.sol", () => {
sharesMinted: 555n,
shareLimit: 1000n,
reserveRatioBP: 1000n,
reserveRatioThresholdBP: 800n,
rebalanceThresholdBP: 800n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand All @@ -193,7 +193,7 @@ describe("Dashboard.sol", () => {
expect(await dashboard.shareLimit()).to.equal(sockets.shareLimit);
expect(await dashboard.sharesMinted()).to.equal(sockets.sharesMinted);
expect(await dashboard.reserveRatioBP()).to.equal(sockets.reserveRatioBP);
expect(await dashboard.thresholdReserveRatioBP()).to.equal(sockets.reserveRatioThresholdBP);
expect(await dashboard.rebalanceThresholdBP()).to.equal(sockets.rebalanceThresholdBP);
expect(await dashboard.treasuryFeeBP()).to.equal(sockets.treasuryFeeBP);
});
});
Expand All @@ -218,7 +218,7 @@ describe("Dashboard.sol", () => {
shareLimit: 1000000000n,
sharesMinted: 555n,
reserveRatioBP: 1000n,
reserveRatioThresholdBP: 800n,
rebalanceThresholdBP: 800n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand All @@ -240,7 +240,7 @@ describe("Dashboard.sol", () => {
shareLimit: 100n,
sharesMinted: 0n,
reserveRatioBP: 1000n,
reserveRatioThresholdBP: 800n,
rebalanceThresholdBP: 800n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand All @@ -260,7 +260,7 @@ describe("Dashboard.sol", () => {
shareLimit: 1000000000n,
sharesMinted: 555n,
reserveRatioBP: 10_000n,
reserveRatioThresholdBP: 800n,
rebalanceThresholdBP: 800n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand All @@ -280,7 +280,7 @@ describe("Dashboard.sol", () => {
shareLimit: 10000000n,
sharesMinted: 555n,
reserveRatioBP: 0n,
reserveRatioThresholdBP: 0n,
rebalanceThresholdBP: 0n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand Down Expand Up @@ -308,7 +308,7 @@ describe("Dashboard.sol", () => {
shareLimit: 10000000n,
sharesMinted: 0n,
reserveRatioBP: 1000n,
reserveRatioThresholdBP: 800n,
rebalanceThresholdBP: 800n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand All @@ -334,7 +334,7 @@ describe("Dashboard.sol", () => {
shareLimit: 10000000n,
sharesMinted: 900n,
reserveRatioBP: 1000n,
reserveRatioThresholdBP: 800n,
rebalanceThresholdBP: 800n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand All @@ -357,7 +357,7 @@ describe("Dashboard.sol", () => {
shareLimit: 10000000n,
sharesMinted: 10000n,
reserveRatioBP: 1000n,
reserveRatioThresholdBP: 800n,
rebalanceThresholdBP: 800n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand All @@ -378,7 +378,7 @@ describe("Dashboard.sol", () => {
shareLimit: 10000000n,
sharesMinted: 500n,
reserveRatioBP: 1000n,
reserveRatioThresholdBP: 800n,
rebalanceThresholdBP: 800n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand All @@ -402,7 +402,7 @@ describe("Dashboard.sol", () => {
shareLimit: 500n,
sharesMinted: 500n,
reserveRatioBP: 1000n,
reserveRatioThresholdBP: 800n,
rebalanceThresholdBP: 800n,
treasuryFeeBP: 500n,
pendingDisconnect: false,
};
Expand Down
10 changes: 5 additions & 5 deletions test/0.8.25/vaults/vaultFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ describe("VaultFactory.sol", () => {
const config1 = {
shareLimit: 10n,
minReserveRatioBP: 500n,
thresholdReserveRatioBP: 20n,
rebalanceThresholdBP: 20n,
treasuryFeeBP: 500n,
};
const config2 = {
shareLimit: 20n,
minReserveRatioBP: 200n,
thresholdReserveRatioBP: 20n,
rebalanceThresholdBP: 20n,
treasuryFeeBP: 600n,
};

Expand Down Expand Up @@ -242,7 +242,7 @@ describe("VaultFactory.sol", () => {
await vault1.getAddress(),
config1.shareLimit,
config1.minReserveRatioBP,
config1.thresholdReserveRatioBP,
config1.rebalanceThresholdBP,
config1.treasuryFeeBP,
),
).to.revertedWithCustomError(accounting, "VaultProxyNotAllowed");
Expand All @@ -259,7 +259,7 @@ describe("VaultFactory.sol", () => {
await vault1.getAddress(),
config1.shareLimit,
config1.minReserveRatioBP,
config1.thresholdReserveRatioBP,
config1.rebalanceThresholdBP,
config1.treasuryFeeBP,
);

Expand Down Expand Up @@ -289,7 +289,7 @@ describe("VaultFactory.sol", () => {
await vault2.getAddress(),
config2.shareLimit,
config2.minReserveRatioBP,
config2.thresholdReserveRatioBP,
config2.rebalanceThresholdBP,
config2.treasuryFeeBP,
),
).to.not.revertedWithCustomError(accounting, "VaultProxyNotAllowed");
Expand Down
Loading

0 comments on commit aa92ca3

Please sign in to comment.