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

Rocket Pool Vault #18

Open
wants to merge 74 commits into
base: main
Choose a base branch
from
Open

Rocket Pool Vault #18

wants to merge 74 commits into from

Conversation

ez7212
Copy link

@ez7212 ez7212 commented Apr 23, 2022

  • added a "user" parameter to depositLpToken to call transferFrom

pending issues:

  • RocketPool deposit limit is 2k ETH in pool
  • RocketPool doesn't allow withdrawals unless there is ETH available in the pool
  • should we add these checks in RocketPoolVault or VaultAccounting?

@ez7212
Copy link
Author

ez7212 commented Apr 26, 2022

i might've put the interfaces into the wrong folder so lmk if there's a better location

Copy link
Collaborator

@Oozyx Oozyx left a comment

Choose a reason for hiding this comment

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

I would also create a new folder in interfaces. call it vaults or something and put the interfaces related to vaults in there.

@@ -0,0 +1,15 @@
pragma solidity 0.8.0;

// SPDX-License-Identifier: GPL-3.0-only
Copy link
Collaborator

Choose a reason for hiding this comment

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

Goes above pragma solidity

Copy link
Author

Choose a reason for hiding this comment

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

fixed


interface RocketDepositPoolInterface {
function getBalance() external view returns (uint256);
function getExcessBalance() external view returns (uint256);
Copy link
Collaborator

Choose a reason for hiding this comment

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

New line in between each function. Keep same style as other interface files.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@@ -0,0 +1,17 @@
pragma solidity 0.8.0;

// SPDX-License-Identifier: GPL-3.0-only
Copy link
Collaborator

Choose a reason for hiding this comment

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

Above pragma solidity


interface RocketTokenRETHInterface is IERC20 {
function getEthValue(uint256 _rethAmount) external view returns (uint256);
function getRethValue(uint256 _ethAmount) external view returns (uint256);
Copy link
Collaborator

Choose a reason for hiding this comment

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

new lines


contract RocketVault is BaseVault {

RocketDepositPoolInterface depositPool;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add comments to explain what these variables are

@Oozyx Oozyx changed the base branch from feat/tokenomics to main April 28, 2022 13:45
RocketTokenRETHInterface rETH;

constructor (address _diamond, address _rETHAddress, address _depositPool) BaseVault(_diamond) {
depositPool = RocketDepositPoolInterface(_depositPool);
Copy link
Collaborator

Choose a reason for hiding this comment

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

After looking at the docs, you should only store the RocketStorageInterface address, and use it to get the current addresses of the rocketdepositpool and rockettokenreth

}

function getAmountETH(uint256 lpTokenAmount) external view override returns (uint256) {
return rETH.getEthValue(lpTokenAmount);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There may be a limit to how much could be withdrawn. I think to avoid having bids that can't be covered (not enough excess ETH in the pool to withdraw), we should make a check that takes this in consideration

Copy link
Author

Choose a reason for hiding this comment

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

added
should we also add a check for depositing (if the rocket vault is not accepting more ETH) and 24 hr check after depositing?
I believe rocket already has these checks in place, but wondering if we need them on our side too

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think we need to add checks for depositing. If it does revert I don't think it's a big deal. Mainly on the withdraw we want to avoid reverting.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see the check for the withdraw limit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nvm

@@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

wrong solidity version (should be ^0.8.0)


interface RocketStorageInterface {

// Getters
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove comment

@@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

wrong solidity version

@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

wrong solidity version

}

function getAmountETH(uint256 lpTokenAmount) external view override returns (uint256) {
return rETH.getEthValue(lpTokenAmount);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think we need to add checks for depositing. If it does revert I don't think it's a big deal. Mainly on the withdraw we want to avoid reverting.

}

function getAmountETH(uint256 lpTokenAmount) external view override returns (uint256) {
return rETH.getEthValue(lpTokenAmount);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see the check for the withdraw limit?

}

function getAmountETH(uint256 lpTokenAmount) external view override returns (uint256) {
return rETH.getEthValue(lpTokenAmount);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nvm

address rethAddress = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketETHToken")));
RocketTokenRETHInterface rETH = RocketTokenRETHInterface(rethAddress);

// check that rocketVault has enough ETH to handle withdrawal
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this check should be in the getAmountEth function. Reason is because we use this function when checking if a bid is valid (enough eth in vaults to cover bid). With this change we will not be displaying bids if rocket pool limits the withdrawal amount

Copy link
Author

@ez7212 ez7212 May 2, 2022

Choose a reason for hiding this comment

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

Yea makes sense. I'll move the check to getAmountEth

The withdraw function in vaultAccountingFacet doesn't call getAmountEth though. If a user wants to withdraw from the vault, I'm guessing its ok that it reverts too? Since we only want to avoid reverting when a bid is actually accepted

Copy link
Author

@ez7212 ez7212 May 3, 2022

Choose a reason for hiding this comment

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

Moved the check to getAmountEth. I currently have it as an if statement where if rocket vault doesn't have enough eth to match the eth amount result, it returns the rocket vault balance. This may mess up the userETHBalance function in VaultAccountingFacet though.

If I have a require(rocketVault.balance >= ethAmount, "not enough ETH to withdraw"), I'm assuming it would revert sometimes. Wondering what you think is the best way to go about this

Copy link
Collaborator

Choose a reason for hiding this comment

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

The userETHBalance function calls the vault's getAmountETH function, so this should be good.

@Oozyx
Copy link
Collaborator

Oozyx commented May 2, 2022

Also need to add tests for this. Would probably be similar to how we test the vaults in the old repo. Mainnet fork for the rocket pool testing. I'll get the testing started with the empty vault.

uint256 ethAmount = rETH.getEthValue(lpTokenAmount);

// check if rocket vault has enough to withdraw, if not return rocket vault balance
if (rocketVault.balance >= ethAmount) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

fixed

address rethAddress = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketETHToken")));
RocketTokenRETHInterface rETH = RocketTokenRETHInterface(rethAddress);

// check that rocketVault has enough ETH to handle withdrawal
Copy link
Collaborator

Choose a reason for hiding this comment

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

The userETHBalance function calls the vault's getAmountETH function, so this should be good.

@@ -12,9 +12,10 @@ interface IVault {
/**
* @dev Deposits LP token directly into vault
*
* @param user The user depositing
Copy link
Collaborator

Choose a reason for hiding this comment

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

params are not in order

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@Oozyx
Copy link
Collaborator

Oozyx commented May 4, 2022

Also you didn't run prettier. You should set it up so it automatically applies when saving.
Here are the settings I use in VSCode:
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.rulers": [120],
"editor.tabSize": 2,

@@ -0,0 +1,16 @@
pragma solidity ^0.8.0;

// SPDX-License-Identifier: GPL-3.0-only
Copy link
Collaborator

Choose a reason for hiding this comment

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

Goes above pragma solidity

pragma solidity ^0.8.0;

// SPDX-License-Identifier: GPL-3.0-only
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Import {IERC20} from ...

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

interface RocketVaultInterface {
function balanceOf(string memory _networkContractName) external view returns (uint256);
Copy link
Collaborator

Choose a reason for hiding this comment

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

New lines in between each function

hardhat: {
forking: {
url: MAINNET_URL,
enabled: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make this false by default

Copy link
Collaborator

Choose a reason for hiding this comment

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

I merged main so this should be fixed


module.exports = {
networks: {
hardhat: {
forking: {
url: MAINNET_URL,
enabled: true,
// enabled: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't comment out, set enabled to false

@@ -152,7 +152,7 @@ contract BidMarketFacet is IBidMarket {
// update user balance
vs.userVaultBalances[bidInfo.bidder][bidInfo.bidInput.vault] -= bidLPTokenAmount;
// withdraw funds from vault
uint256 ethReturned = vault.withdraw(bidLPTokenAmount, payable(this));
uint256 ethReturned = vault.withdraw(bidLPTokenAmount, payable(this), abi.encode(bidInfo.bidder));
Copy link
Collaborator

Choose a reason for hiding this comment

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

use vaultlibutils for optional data

Copy link
Author

Choose a reason for hiding this comment

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

we're encoding the bidder's address instead of msg.sender here. how would I go about adding this to the vaultLibUtils?

@@ -156,7 +156,7 @@ contract OptionMarketFacet is IOptionMarket, IERC721Receiver {
// update user balance
vs.userVaultBalances[option.bidder][option.optionInput.bidInput.vault] -= premiumLPTokenAmount;
// withdraw the premium from bidder's vault
uint256 ethReturned = vault.withdraw(premiumLPTokenAmount, payable(this));
uint256 ethReturned = vault.withdraw(premiumLPTokenAmount, payable(this), abi.encode(option.bidder));
Copy link
Collaborator

Choose a reason for hiding this comment

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

use vaultlibutils for optional data

@@ -244,7 +244,11 @@ contract OptionMarketFacet is IOptionMarket, IERC721Receiver {
// update user balance
vs.userVaultBalances[option.bidder][option.optionInput.bidInput.vault] -= strikeLPTokenAmount;
// withdraw the strike amount from bidder's vault
uint256 ethReturned = vault.withdraw(strikeLPTokenAmount, payable(oms.acceptedOptions[optionId].seller));
uint256 ethReturned = vault.withdraw(
Copy link
Collaborator

Choose a reason for hiding this comment

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

use vaultlibutils for optional data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants