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

[Draft] Vaults UX suggestions #893

Draft
wants to merge 8 commits into
base: feat/vaults
Choose a base branch
from
Draft

Conversation

DiRaiks
Copy link
Contributor

@DiRaiks DiRaiks commented Dec 6, 2024

A short summary of the changes.

Context

  • It would be very convenient to have a view on VaultHub that will allow us to get Vaults by the Owner's address
    • Why is it necessary - in theory, there can be a lot of Vaults. To display all the user's Vaults on the UI, we need to get all the Vaults and then make a request for each one to get the Owner's address
  • View on maxMintableShares - external - to show how much stETH Vault allows to mint
  • canMint(uint256 depositSize) - a view that will return how much you can mint from the deposit amount - an exact number.
    • Needed when calculating the amount and for sending the number to the mint() method
  • canWithdraw() - similar to canMint
  • Deposit ETH/WETH
  • Withdrawal ETH/WETH
  • Mint stETH/wstETH
  • Burn + Permit

Problem

What problem this PR solves, link relevant issue if it exists

Solution

Your proposed solution

@DiRaiks DiRaiks requested a review from a team as a code owner December 6, 2024 11:34
@DiRaiks DiRaiks marked this pull request as draft December 6, 2024 11:34
/// @notice Returns all vaults owned by a given address
/// @param _owner Address of the owner
/// @return An array of vaults owned by the given address
function vaultsByOwner(address _owner) external view returns (IHubVault[] memory) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the correctness of this method, but such a method will be very useful

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe needs vaultsIndexesByOwner and then this method around it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that Vaults are created without an owner, and then the owner and other roles are added. And it seems to me that storing another array in memory that will be updated frequently may be a bad decision.
If this is not the case, then it makes sense to have an additional owner field in the VaultSocket structure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe needs vaultsIndexesByOwner and then this method around it.

We can't maintain the correctness of such index, because the owner can be changed in the vault, independently.

contracts/0.8.25/vaults/Dashboard.sol Show resolved Hide resolved
contracts/0.8.25/vaults/VaultHub.sol Outdated Show resolved Hide resolved
/// @notice Returns all vaults owned by a given address
/// @param _owner Address of the owner
/// @return An array of vaults owned by the given address
function vaultsByOwner(address _owner) external view returns (IHubVault[] memory) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the owner is the dashboard contract, how are you planning to use it?

* @notice Funds the staking vault with wrapped ether. Approvals for the passed amounts should be done before.
* @param _wethAmount Amount of wrapped ether to fund the staking vault with
*/
function fundByWeth(uint256 _wethAmount) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing transferFrom?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

contracts/0.8.25/vaults/Dashboard.sol Outdated Show resolved Hide resolved
@@ -159,6 +233,15 @@ contract Dashboard is AccessControlEnumerable {
_withdraw(_recipient, _ether);
}

/**
* @notice Withdraws stETH tokens from the staking vault to wrapped ether. Approvals for the passed amounts should be done before.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't get what it should do. RN, ether is still on the dashboard contract. Should it be transferred to msg.sender or some other recepient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@folkyatina The idea is to send to the fundByWeth method the amount of WETH that needs to be "unwrap" to the ETH and then fund Vault
WETH withdraw method https://github.com/gnosis/canonical-weth/blob/master/contracts/WETH9.sol#L38

Now I understand that it seems that this code will not work correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

wstETH.permit(msg.sender, address(this), _wstETHPermit.value, _wstETHPermit.deadline, _wstETHPermit.v, _wstETHPermit.r, _wstETHPermit.s);

wstETH.transferFrom(msg.sender, address(this), _tokens);
stETH.approve(address(wstETH), _tokens);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need approve for unwrap.

* @param _wstETHPermit data required for the wstETH.permit() method to set the allowance
*/
function burnWstETHWithPermit(uint256 _tokens, PermitInput calldata _wstETHPermit) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
wstETH.permit(msg.sender, address(this), _wstETHPermit.value, _wstETHPermit.deadline, _wstETHPermit.v, _wstETHPermit.r, _wstETHPermit.s);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs check for allowance to prevent ddos. See updated WQ contract.

@tamtamchik tamtamchik added solidity issues/tasks related to smart contract code next-upgrade Things to pickup for the next protocol upgrade vaults labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next-upgrade Things to pickup for the next protocol upgrade solidity issues/tasks related to smart contract code vaults
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants