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
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
4cd4e20
add msg.sender to depositLpToken
ez7212 Apr 23, 2022
3f849f7
add user param to depositLpToken
ez7212 Apr 23, 2022
f0b50e4
add address param
ez7212 Apr 23, 2022
6a18b22
initial commit
ez7212 Apr 23, 2022
2e9152e
initial commit
ez7212 Apr 23, 2022
6edefca
inital commit
ez7212 Apr 23, 2022
d676eea
fix IVault directory
ez7212 Apr 28, 2022
f608078
new directory for vault interfaces
ez7212 Apr 28, 2022
f6d1280
import only RocketStorage and add withdrawal check
ez7212 Apr 28, 2022
210d35f
update solidity version
ez7212 May 3, 2022
962ae49
update solidity version and remove comment
ez7212 May 3, 2022
7543bac
move withdraw check to getAmountEth
ez7212 May 3, 2022
87920b3
rearrange params
ez7212 May 3, 2022
2f39bbd
change vault balance getter function
ez7212 May 3, 2022
4cca37b
initial commit
ez7212 May 3, 2022
609ce9a
add forking config
ez7212 May 4, 2022
03bd301
add rocket vault deployment
ez7212 May 4, 2022
dfa61c0
rocket test initial commit
ez7212 May 4, 2022
ba2a92d
fix comment
ez7212 May 4, 2022
d65f23d
Merge branch 'main' into feat/rocketvault
Oozyx May 4, 2022
8d364a5
fix getAddress parameter
ez7212 May 4, 2022
9eeb1b7
all tests for rocket vault
ez7212 May 4, 2022
6aa821f
Merge branch 'feat/rocketvault' of https://github.com/FukuNFT/fuku-nf…
ez7212 May 4, 2022
4140092
set forking to true
ez7212 May 5, 2022
99a0629
Skip tests if not fork
Oozyx May 5, 2022
0bec6bd
Network fork set to false
Oozyx May 5, 2022
17c9df2
Remove vault coverage
Oozyx May 5, 2022
ff5bfdf
Add test variables
Oozyx May 6, 2022
559aac6
Add feature info
Oozyx May 9, 2022
63c5039
initial commit
ez7212 May 11, 2022
e3e9c51
initial commit
ez7212 May 11, 2022
cda310b
initial commit
ez7212 May 11, 2022
a0e3fe2
initial commit
ez7212 May 11, 2022
6b3a1bf
add _data param
ez7212 May 13, 2022
c50c92d
changed file name
ez7212 May 13, 2022
f2c79eb
removed
ez7212 May 13, 2022
4f8ca96
move BaseDelegate code here
ez7212 May 13, 2022
f753bf5
add _data param and make deposit/withdraw changes
ez7212 May 13, 2022
713f2aa
fix import and storage interface
ez7212 May 13, 2022
a9e7089
initial commit
ez7212 May 13, 2022
d6268e9
initial commit
ez7212 May 13, 2022
766d4d9
add comment
ez7212 May 13, 2022
f8082f6
change interface names
ez7212 May 17, 2022
2552e9f
fix param description and order
ez7212 May 17, 2022
6b9c84f
fix imports
ez7212 May 17, 2022
2c7d253
fix imports, param order, and add vault storage creation
ez7212 May 17, 2022
de0a184
remove initialize and ownable
ez7212 May 17, 2022
da6db33
add comment
ez7212 May 17, 2022
0934d39
add address encoding
ez7212 May 18, 2022
51ca073
change bytes32 param to address
ez7212 May 18, 2022
cbcbb49
change bytes32 to bytes
ez7212 May 18, 2022
756c841
add bytes param
ez7212 May 18, 2022
5c22445
add bytes param
ez7212 May 18, 2022
d86864f
add receive function
ez7212 May 18, 2022
1125200
add bytes decoder and getter for current implementation
ez7212 May 18, 2022
49dcc9b
import interface and change bytes to address
ez7212 May 18, 2022
538d306
add userData for tests to pass
ez7212 May 18, 2022
059e8c7
add userData for tests to pass
ez7212 May 18, 2022
81fee31
add delegate testing
ez7212 May 18, 2022
1ea26d2
more tests
ez7212 May 19, 2022
3ba4746
Refactor suggestions
Oozyx May 19, 2022
418e5fb
remove unneeded functions
ez7212 May 19, 2022
d8ce179
change implementation functions to ownership
ez7212 May 19, 2022
090ec87
Merge branch 'feat/rocket-delegate-mechanism' of https://github.com/F…
ez7212 May 19, 2022
d4bac30
add getVaultOptionalData helper
ez7212 May 23, 2022
953ab23
multiple user withdraw tests
ez7212 May 23, 2022
2da5cac
minor changes
Oozyx May 24, 2022
9d25759
rocket vault without creating new vault storage
ez7212 May 24, 2022
d1d78a9
upgrade rocket vault and ensure withdrawals work
ez7212 May 24, 2022
0c89801
Use fixture constant
Oozyx May 25, 2022
0ca165f
change impersonate deposit amt
ez7212 May 25, 2022
c383576
Use RocketPoolVaultStorage interface
Oozyx May 25, 2022
beb594b
Remove text file
Oozyx May 25, 2022
82ea2e4
Merge pull request #26 from FukuNFT/feat/rocket-delegate-mechanism
Oozyx May 25, 2022
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
2 changes: 1 addition & 1 deletion contracts/interfaces/vaults/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ interface IVault {
/**
* @dev Deposits LP token directly into vault
*
* @param user The user depositing
* @param amount The amount of LP tokens to deposit
* @param user The user depositing
*/
function depositLpToken(uint256 amount, address user) external;

Expand Down
16 changes: 16 additions & 0 deletions contracts/interfaces/vaults/RocketVaultInterface.sol
Original file line number Diff line number Diff line change
@@ -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

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

function depositEther() external payable;
function withdrawEther(uint256 _amount) external;
function depositToken(string memory _networkContractName, IERC20 _tokenAddress, uint256 _amount) external;
function withdrawToken(address _withdrawalAddress, IERC20 _tokenAddress, uint256 _amount) external;
function balanceOfToken(string memory _networkContractName, IERC20 _tokenAddress) external view returns (uint256);
function transferToken(string memory _networkContractName, IERC20 _tokenAddress, uint256 _amount) external;
function burnToken(ERC20Burnable _tokenAddress, uint256 _amount) external;
}
14 changes: 7 additions & 7 deletions contracts/vaults/RocketPoolVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BaseVault } from "./BaseVault.sol";
import { RocketDepositPoolInterface } from "../interfaces/vaults/RocketDepositPoolInterface.sol";
import { RocketTokenRETHInterface } from "../interfaces/vaults/RocketTokenRETHInterface.sol";
import { RocketStorageInterface } from "../interfaces/vaults/RocketStorageInterface.sol";
import { RocketVaultInterface } from "../interfaces/vaults/RocketVaultInterface.sol";

contract RocketVault is BaseVault {
// stores state for Rocket Protocol
Expand Down Expand Up @@ -43,9 +44,6 @@ contract RocketVault is BaseVault {
// Load contracts
address rethAddress = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketETHToken")));
RocketTokenRETHInterface rETH = RocketTokenRETHInterface(rethAddress);

// check that rocketVault has enough ETH to handle withdrawal
uint256 amountToWithdraw = rETH.getEthValue(lpTokenAmount);

// Redeem rETH for ETH and send to recipient
uint256 balanceBefore = address(this).balance;
Expand Down Expand Up @@ -78,18 +76,20 @@ contract RocketVault is BaseVault {
}

function getAmountETH(uint256 lpTokenAmount) external view override returns (uint256) {
// Load rocketVault address and rETH contract
address rocketVault = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketVault")));
// Load rocketVault and rETH contracts
address rocketVaultAddress = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketVault")));
RocketVaultInterface rocketVault = RocketVaultInterface(rocketVaultAddress);
address rethAddress = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketETHToken")));
RocketTokenRETHInterface rETH = RocketTokenRETHInterface(rethAddress);

uint256 ethAmount = rETH.getEthValue(lpTokenAmount);

// check if rocket vault has enough to withdraw, if not return rocket vault balance
if (rocketVault.balance >= ethAmount) {
uint256 vaultBalance = rocketVault.balanceOf("rocketDepositPool");
if (vaultBalance >= ethAmount) {
return ethAmount;
} else {
return rocketVault.balance;
return vaultBalance;
}
}

Expand Down
10 changes: 10 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ require("hardhat-deploy-ethers");
require("hardhat-gas-reporter");
require("dotenv").config();

const MAINNET_URL = process.env.MAINNET_URL ? process.env.MAINNET_URL : "";

module.exports = {
networks: {
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

},
},
},
solidity: {
version: "0.8.4",
settings: {
Expand Down
13 changes: 13 additions & 0 deletions test/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,28 @@ const fixture = deployments.createFixture(async () => {
// create vault names
const vaultNames = {
empty: "0xeeeeeeeeeeeeeeeeeeeeeeee",
rocketVault: "0xeeeeeeeeeeeeeeeeeeeeeeed"
};

// rocket pool addresses for deployment
const rocketAddresses = {
rocketStorage: "0x1d8f8f00cfa6758d7bE78336684788Fb0ee0Fa46"
}

// create and register vault
const EmptyVault = await ethers.getContractFactory("EmptyVault");
const emptyVault = await EmptyVault.deploy(diamond.address);
await emptyVault.deployed();
tx = await vaultManagement.registerVault(vaultNames.empty, emptyVault.address);
await tx.wait();

// create and register rocket vault
const RocketVault = await ethers.getContractFactory("RocketVault");
const rocketVault = await RocketVault.deploy(diamond.address, rocketAddresses.rocketStorage);
await rocketVault.deployed();
tx = await vaultManagement.registerVault(vaultNames.rocketVault, rocketVault.address);
await tx.wait();

return {
diamond,
diamondCut,
Expand Down
41 changes: 41 additions & 0 deletions test/vaults/RocketVault.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { ethers } = require("hardhat");
const { expect } = require("chai");

const { fixture } = require("../fixture");

describe("Rocket Vault", async () => {
// fixture values
let deployer, user;
let vaultAccounting;
let vaultManagement;
let vaultNames;

// vault parameters
let depositAmount;
let expectedEthAmount;
let expectedLpToken;
let expectedLpTokenAmount;
let rocketVault;

beforeEach(async () => {
// initialize fixture values
({ vaultAccounting, vaultManagement, vaultNames } = await fixture());
[deployer, user] = await ethers.getSigners();

// initialize vault parameters
depositAmount = ethers.utils.parseEther("1.0");
expectedEthAmount = ethers.utils.parseEther("1.0");
expectedLpToken = "0xae78736Cd615f374D3085123A210448E74Fc6393"; // rETH token address
rocketVault = await ethers.getContractAt("IVault", await vaultManagement.getVault(vaultNames.rocketVault));
expectedLpTokenAmount = await rocketVault.getAmountLpTokens(depositAmount); //gets rETH amount equivalent to 1 ETH
});

it("Should reflect correct conversion from lp tokens to ETH", async () => {
expect(await rocketVault.getAmountETH(expectedLpTokenAmount)).to.be.equal(expectedEthAmount);
});

it("Should reflect correct conversion from ETH to lp tokens", async () => {
expect(await rocketVault.getAmountLpTokens(expectedEthAmount)).to.be.equal(expectedLpTokenAmount);
});

});