Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vault] Dashboard recovery #908

Open
wants to merge 1 commit into
base: feat/dashboard-ux-updates
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion contracts/0.8.25/vaults/Dashboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,19 @@
_rebalanceVault(_ether);
}

/**
* @notice recovers ERC20 tokens or ether from the vault
* @param _token Address of the token to recover, 0 for ether
*/
function recover(address _token) external payable virtual onlyRole(DEFAULT_ADMIN_ROLE) {
if (_token == address(0)) {
payable(msg.sender).transfer(address(this).balance);
} else {
bool success = IERC20(_token).transfer(msg.sender, IERC20(_token).balanceOf(address(this)));
if (!success) revert("ERC20: Transfer failed");
}
}
Comment on lines +416 to +423

Check failure

Code scanning / Slither

Functions that send Ether to arbitrary destinations High


// ==================== Internal Functions ====================

/**
Expand Down Expand Up @@ -502,7 +515,8 @@
* @param _valuation custom vault valuation
*/
function _totalMintableShares(uint256 _valuation) internal view returns (uint256) {
uint256 maxMintableStETH = (_valuation * (TOTAL_BASIS_POINTS - vaultSocket().reserveRatioBP)) / TOTAL_BASIS_POINTS;
uint256 maxMintableStETH = (_valuation * (TOTAL_BASIS_POINTS - vaultSocket().reserveRatioBP)) /
TOTAL_BASIS_POINTS;
return Math256.min(STETH.getSharesByPooledEth(maxMintableStETH), vaultSocket().shareLimit);
}

Expand Down
39 changes: 39 additions & 0 deletions test/0.8.25/vaults/dashboard/dashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -992,4 +992,43 @@ describe("Dashboard", () => {
.withArgs(amount);
});
});

context("recover", async () => {
const amount = ether("1");

before(async () => {
const wethContract = weth.connect(vaultOwner);

await wethContract.deposit({ value: amount });

await vaultOwner.sendTransaction({ to: dashboard.getAddress(), value: amount });
await wethContract.transfer(dashboard.getAddress(), amount);

expect(await ethers.provider.getBalance(dashboard.getAddress())).to.equal(amount);
expect(await wethContract.balanceOf(dashboard.getAddress())).to.equal(amount);
});

it("allows only admin to recover", async () => {
await expect(dashboard.connect(stranger).recover(ZeroAddress)).to.be.revertedWithCustomError(
dashboard,
"AccessControlUnauthorizedAccount",
);
});

it("recovers all ether", async () => {
const preBalance = await ethers.provider.getBalance(vaultOwner);
const tx = await dashboard.recover(ZeroAddress);
const { gasUsed, gasPrice } = (await ethers.provider.getTransactionReceipt(tx.hash))!;

expect(await ethers.provider.getBalance(dashboard.getAddress())).to.equal(0);
expect(await ethers.provider.getBalance(vaultOwner)).to.equal(preBalance + amount - gasUsed * gasPrice);
});

it("recovers all weth", async () => {
const preBalance = await weth.balanceOf(vaultOwner);
await dashboard.recover(weth.getAddress());
expect(await weth.balanceOf(dashboard.getAddress())).to.equal(0);
expect(await weth.balanceOf(vaultOwner)).to.equal(preBalance + amount);
});
});
});
Loading