Skip to content

Commit

Permalink
chore: better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Feb 24, 2025
1 parent 9c22cdf commit b4c79b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions contracts/0.8.25/vaults/VaultHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ abstract contract VaultHub is PausableUntilWithRoles {
/// the reserve ratio threshold.
/// @param _vault vault address
/// @return true if vault is healthy, false otherwise
function isHealthy(address _vault) public view returns (bool) {
function isVaultHealthy(address _vault) public view returns (bool) {
VaultSocket storage socket = _connectedSocket(_vault);
if (socket.sharesMinted == 0) return true;

Expand Down Expand Up @@ -541,7 +541,7 @@ abstract contract VaultHub is PausableUntilWithRoles {
}

function _requireUnhealthy(address _vault) internal view {
if (isHealthy(_vault)) revert AlreadyHealthy(_vault);
if (isVaultHealthy(_vault)) revert AlreadyHealthy(_vault);
}

event VaultConnected(address indexed vault, uint256 capShares, uint256 minReserveRatio, uint256 reserveRatioThreshold, uint256 treasuryFeeBP);
Expand Down
2 changes: 1 addition & 1 deletion test/0.8.25/vaults/vaulthub/vaulthub.forceExit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe("VaultHub.sol:forceExit", () => {

await demoVault.report(valuation - penalty, valuation, rebase.lockedEther[1]);

expect(await vaultHub.isHealthy(demoVaultAddress)).to.be.false;
expect(await vaultHub.isVaultHealthy(demoVaultAddress)).to.be.false;

await expect(vaultHub.forceValidatorExit(demoVaultAddress, SAMPLE_PUBKEY, feeRecipient, { value: FEE }))
.to.emit(vaultHub, "ForceValidatorExitTriggered")
Expand Down
45 changes: 24 additions & 21 deletions test/0.8.25/vaults/vaulthub/vaulthub.hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,12 @@ describe("VaultHub.sol:hub", () => {
});
});

context("isHealthy", () => {
context("isVaultHealthy", () => {
it("reverts if vault is not connected", async () => {
await expect(vaultHub.isHealthy(randomAddress())).to.be.revertedWithCustomError(vaultHub, "NotConnectedToHub");
await expect(vaultHub.isVaultHealthy(randomAddress())).to.be.revertedWithCustomError(
vaultHub,
"NotConnectedToHub",
);
});

it("returns true if the vault has no shares minted", async () => {
Expand All @@ -262,7 +265,7 @@ describe("VaultHub.sol:hub", () => {

await vault.fund({ value: ether("1") });

expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true);
});

// Looks like fuzzing but it's not [:}
Expand Down Expand Up @@ -301,7 +304,7 @@ describe("VaultHub.sol:hub", () => {

await vault.report(valuation - slashed, valuation, BigIntMath.max(mintable, ether("1")));

const actualHealthy = await vaultHub.isHealthy(vaultAddress);
const actualHealthy = await vaultHub.isVaultHealthy(vaultAddress);
try {
expect(actualHealthy).to.equal(expectedHealthy);
} catch (error) {
Expand Down Expand Up @@ -334,16 +337,16 @@ describe("VaultHub.sol:hub", () => {
await vaultHub.connect(user).mintShares(vaultAddress, user, ether("0.25"));

await vault.report(ether("1"), ether("1"), ether("1")); // normal report
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true);

await vault.report(ether("0.5") + 1n, ether("1"), ether("1")); // above the threshold
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true);

await vault.report(ether("0.5"), ether("1"), ether("1")); // at the threshold
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true);

await vault.report(ether("0.5") - 1n, ether("1"), ether("1")); // below the threshold
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(false);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(false);
});

it("returns correct value for different share rates", async () => {
Expand All @@ -361,28 +364,28 @@ describe("VaultHub.sol:hub", () => {
await vaultHub.connect(user).mintShares(vaultAddress, user, sharesToMint);

await vault.report(ether("1"), ether("1"), ether("1")); // normal report
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true); // valuation is enough
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true); // valuation is enough

// Burn some shares to make share rate fractional
const burner = await impersonate(await locator.burner(), ether("1"));
await lido.connect(whale).transfer(burner, ether("100"));
await lido.connect(burner).burnShares(ether("100"));

await vault.report(ether("1"), ether("1"), ether("1")); // normal report
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(false); // old valuation is not enough
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(false); // old valuation is not enough

const lockedEth = await lido.getPooledEthBySharesRoundUp(sharesToMint);
// For 50% reserve ratio, we need valuation to be 2x of locked ETH to be healthy
const report = lockedEth * 2n;

await vault.report(report - 1n, ether("1"), ether("1")); // below the threshold
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(false);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(false);

await vault.report(report, ether("1"), ether("1")); // at the threshold
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true);

await vault.report(report + 1n, ether("1"), ether("1")); // above the threshold
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true);
});

it("returns correct value for smallest possible reserve ratio", async () => {
Expand All @@ -401,7 +404,7 @@ describe("VaultHub.sol:hub", () => {
await vaultHub.connect(user).mintShares(vaultAddress, user, sharesToMint);

await vault.report(ether("1"), ether("1"), ether("1")); // normal report
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true); // valuation is enough
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true); // valuation is enough

// Burn some shares to make share rate fractional
const burner = await impersonate(await locator.burner(), ether("1"));
Expand All @@ -413,13 +416,13 @@ describe("VaultHub.sol:hub", () => {
const report = (lockedEth * 10000n) / 9999n;

await vault.report(report - 1n, ether("1"), ether("1")); // below the threshold
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(false);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(false);

await vault.report(report, ether("1"), ether("1")); // at the threshold
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(false); // XXX: rounding issue, should be true
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(false); // XXX: rounding issue, should be true

await vault.report(report + 1n, ether("1"), ether("1")); // above the threshold
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true);
});

it("returns correct value for minimal shares amounts", async () => {
Expand All @@ -435,18 +438,18 @@ describe("VaultHub.sol:hub", () => {
await vaultHub.connect(user).mintShares(vaultAddress, user, 1n);

await vault.report(ether("1"), ether("1"), ether("1"));
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true);

await vault.report(2n, ether("1"), ether("1")); // Minimal valuation to be healthy with 1 share (50% reserve ratio)
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true);

await vault.report(1n, ether("1"), ether("1")); // Below minimal required valuation
expect(await vaultHub.isHealthy(vaultAddress)).to.equal(false);
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(false);

await lido.connect(user).transferShares(await locator.accounting(), 1n);
await vaultHub.connect(user).burnShares(vaultAddress, 1n);

expect(await vaultHub.isHealthy(vaultAddress)).to.equal(true); // Should be healthy with no shares
expect(await vaultHub.isVaultHealthy(vaultAddress)).to.equal(true); // Should be healthy with no shares
});
});

Expand Down

0 comments on commit b4c79b6

Please sign in to comment.