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 all 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 .solcover.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
skipFiles: ["vendor/", "test/", "interfaces/"],
skipFiles: ["vendor/", "test/", "interfaces/", "vaults/"],
};
4 changes: 2 additions & 2 deletions contracts/facets/BidMarketFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import { IBidMarket } from "../interfaces/facets/IBidMarket.sol";
import { ICryptoPunksMarket } from "../interfaces/ICryptoPunksMarket.sol";
import { IVault } from "../interfaces/IVault.sol";
import { IVault } from "../interfaces/vaults/IVault.sol";
import { LibStorage, BidMarketStorage, VaultStorage, TokenAddressStorage } from "../libraries/LibStorage.sol";
import { LibVaultUtils } from "../libraries/LibVaultUtils.sol";
import { BidInputParams, BidInfo } from "../FukuTypes.sol";
Expand Down Expand Up @@ -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?

// another safety check to make sure enough ETH was withdrawn
require(bidInfo.bidInput.amount <= ethReturned, "Didn't burn enough LP tokens");

Expand Down
10 changes: 7 additions & 3 deletions contracts/facets/OptionMarketFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import { IOptionMarket } from "../interfaces/facets/IOptionMarket.sol";
import { ICryptoPunksMarket } from "../interfaces/ICryptoPunksMarket.sol";
import { IVault } from "../interfaces/IVault.sol";
import { IVault } from "../interfaces/vaults/IVault.sol";
import { LibStorage, OptionMarketStorage, VaultStorage, TokenAddressStorage } from "../libraries/LibStorage.sol";
import { LibVaultUtils } from "../libraries/LibVaultUtils.sol";
import { OptionDuration, OptionInputParams, OptionInfo } from "../FukuTypes.sol";
Expand Down Expand Up @@ -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

// another safety check to make sure enough ETH was withdrawn
require(option.optionInput.premium <= ethReturned, "Didn't burn enough LP tokens");

Expand Down Expand Up @@ -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

strikeLPTokenAmount,
payable(oms.acceptedOptions[optionId].seller),
abi.encode(option.bidder)
);
// another safety check to make sure enough ETH was withdrawn
require(option.optionInput.bidInput.amount <= ethReturned, "Didn't burn enough LP tokens");

Expand Down
14 changes: 9 additions & 5 deletions contracts/facets/VaultAccountingFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

import { IVaultAccounting } from "../interfaces/facets/IVaultAccounting.sol";
import { IVault } from "../interfaces/IVault.sol";
import { IVault } from "../interfaces/vaults/IVault.sol";
import { LibStorage, VaultStorage, DepositsRewardsStorage, TokenAddressStorage } from "../libraries/LibStorage.sol";
import { LibVaultUtils } from "../libraries/LibVaultUtils.sol";
import { LibDiamond } from "../vendor/libraries/LibDiamond.sol";
Expand Down Expand Up @@ -51,7 +51,8 @@ contract VaultAccountingFacet is IVaultAccounting {
address vaultAddress = vs.vaultAddresses[vaultName];

// deposit into vault on behalf of sender
uint256 lpTokensAmount = IVault(vaultAddress).deposit{ value: msg.value }();
bytes memory optionalData = LibVaultUtils.getVaultOptionalData(vaultName);
uint256 lpTokensAmount = IVault(vaultAddress).deposit{ value: msg.value }(optionalData);
vs.userVaultBalances[msg.sender][vaultName] += lpTokensAmount;

emit DepositEth(msg.sender, vaultName, msg.value, lpTokensAmount);
Expand All @@ -70,7 +71,8 @@ contract VaultAccountingFacet is IVaultAccounting {
address vaultAddress = vs.vaultAddresses[vaultName];

// deposit into vault on behalf of sender
IVault(vaultAddress).depositLpToken(amount, msg.sender);
bytes memory optionalData = LibVaultUtils.getVaultOptionalData(vaultName);
IVault(vaultAddress).depositLpToken(amount, msg.sender, optionalData);
vs.userVaultBalances[msg.sender][vaultName] += amount;

emit DepositLpToken(msg.sender, vaultName, amount);
Expand All @@ -93,7 +95,8 @@ contract VaultAccountingFacet is IVaultAccounting {
// update user balance
vs.userVaultBalances[msg.sender][vaultName] -= lpTokenAmount;
// withdraw from vault and send to recipient
uint256 amountWithdrawn = IVault(vaultAddress).withdraw(lpTokenAmount, payable(msg.sender));
bytes memory optionalData = LibVaultUtils.getVaultOptionalData(vaultName);
uint256 amountWithdrawn = IVault(vaultAddress).withdraw(lpTokenAmount, payable(msg.sender), optionalData);

emit Withdraw(msg.sender, vaultName, amountWithdrawn, lpTokenAmount);
}
Expand All @@ -119,7 +122,8 @@ contract VaultAccountingFacet is IVaultAccounting {
// update user balance
vs.userVaultBalances[msg.sender][vaultName] -= lpTokenAmount;
// withdraw from vault and send to recipient
IVault(vaultAddress).withdrawLpToken(lpTokenAmount, payable(msg.sender));
bytes memory optionalData = LibVaultUtils.getVaultOptionalData(vaultName);
IVault(vaultAddress).withdrawLpToken(lpTokenAmount, payable(msg.sender), optionalData);

emit WithdrawLpToken(msg.sender, vaultName, lpTokenAmount);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/facets/VaultManagementFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

import { IVaultManagement } from "../interfaces/facets/IVaultManagement.sol";
import { IVault } from "../interfaces/IVault.sol";
import { IVault } from "../interfaces/vaults/IVault.sol";
import { LibStorage, VaultStorage } from "../libraries/LibStorage.sol";
import { LibDiamond } from "../vendor/libraries/LibDiamond.sol";

Expand Down
36 changes: 36 additions & 0 deletions contracts/interfaces/vaults/IRocketDelegate.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

interface IRocketDelegate {
/**
* @dev Deposits ETH and converts to vault's LP token
*
* @return The amount of LP tokens received from ETH deposit
*/
function deposit() external payable returns (uint256);

/**
* @dev Deposits LP token directly into vault
*
* @param amount The amount of LP tokens to deposit
* @param user The user depositing
*/
function depositLpToken(uint256 amount, address user) external;

/**
* @dev Converts LP token and withdraws as ETH
*
* @param lpTokenAmount The amount of LP tokens to withdraw before converting
* @param recipient The recipient of the converted ETH
* @return The amount of ETH withdrawn
*/
function withdraw(uint256 lpTokenAmount, address payable recipient) external returns (uint256);

/**
* @dev Withdraws LP token directly from vault
*
* @param lpTokenAmount The amount of LP tokens to withdraw
* @param recipient The recipient of the LP tokens
*/
function withdrawLpToken(uint256 lpTokenAmount, address recipient) external;
}
8 changes: 8 additions & 0 deletions contracts/interfaces/vaults/IRocketDepositPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

interface IRocketDepositPool {
function deposit() external payable;

function getUserLastDepositBlock(address _address) external view returns (uint256);
}
12 changes: 12 additions & 0 deletions contracts/interfaces/vaults/IRocketPoolVaultStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

interface IRocketPoolVaultStorage {
function setDelegateAddress(address user, address delegateAddress) external;

function getDelegateAddress(address user) external view returns (address);

function transferOwnership(address newOwner) external;

function owner() external view returns (address);
}
6 changes: 6 additions & 0 deletions contracts/interfaces/vaults/IRocketStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

interface IRocketStorage {
function getAddress(bytes32 _key) external view returns (address);
}
14 changes: 14 additions & 0 deletions contracts/interfaces/vaults/IRocketTokenRETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IRocketTokenRETH is IERC20 {
function getEthValue(uint256 _rethAmount) external view returns (uint256);

function getRethValue(uint256 _ethAmount) external view returns (uint256);

function mint(uint256 _ethAmount, address _to) external;

function burn(uint256 _rethAmount) external;
}
35 changes: 35 additions & 0 deletions contracts/interfaces/vaults/IRocketVault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity ^0.8.0;

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

interface IRocketVault {
function balanceOf(string memory _networkContractName) external view returns (uint256);

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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,50 @@ interface IVault {
/**
* @dev Deposits ETH and converts to vault's LP token
*
* @param _data Additional user data if needed
* @return The amount of LP tokens received from ETH deposit
*/
function deposit() external payable returns (uint256);
function deposit(bytes memory _data) external payable returns (uint256);

/**
* @dev Deposits LP token directly into vault
*
* @param amount The amount of LP tokens to deposit
* @param user The user depositing
* @param _data Additional user data if needed
*/
function depositLpToken(uint256 amount, address user) external;
function depositLpToken(
uint256 amount,
address user,
bytes memory _data
) external;

/**
* @dev Converts LP token and withdraws as ETH
*
* @param lpTokenAmount The amount of LP tokens to withdraw before converting
* @param recipient The recipient of the converted ETH
* @param _data Additional user data if needed
* @return The amount of ETH withdrawn
*/
function withdraw(uint256 lpTokenAmount, address payable recipient) external returns (uint256);
function withdraw(
uint256 lpTokenAmount,
address payable recipient,
bytes memory _data
) external returns (uint256);

/**
* @dev Withdraws LP token directly from vault
*
* @param lpTokenAmount The amount of LP tokens to withdraw
* @param recipient The recipient of the LP tokens
* @param _data Additional user data if needed
*/
function withdrawLpToken(uint256 lpTokenAmount, address recipient) external;
function withdrawLpToken(
uint256 lpTokenAmount,
address recipient,
bytes memory _data
) external;

/**
* @dev Transfers LP tokens to new vault
Expand Down
11 changes: 10 additions & 1 deletion contracts/libraries/LibVaultUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

import { LibStorage, VaultStorage } from "./LibStorage.sol";
import { IVault } from "../interfaces/IVault.sol";
import { IVault } from "../interfaces/vaults/IVault.sol";

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand Down Expand Up @@ -30,4 +30,13 @@ library LibVaultUtils {
return IERC20(vaultLpToken).balanceOf(vault);
}
}

function getVaultOptionalData(bytes12 vaultName) internal view returns (bytes memory optionalData) {
// todo: find alternative solution instead of hardcoding
bytes12 rocket_vault_name = 0xeeeeeeeeeeeeeeeeeeeeeeed;

if (vaultName == rocket_vault_name) {
optionalData = abi.encode(msg.sender);
}
}
}
20 changes: 16 additions & 4 deletions contracts/test/TestLpTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,31 @@ contract TestLpTokenVault is BaseVault {
lpToken = _lpToken;
}

function deposit() external payable override returns (uint256) {
function deposit(bytes memory) external payable override returns (uint256) {
revert("Disabled.");
}

function depositLpToken(uint256 amount, address user) external override {
function depositLpToken(
uint256 amount,
address user,
bytes memory
) external override {
IERC20(lpToken).transferFrom(user, address(this), amount);
}

function withdraw(uint256, address payable) external pure override returns (uint256) {
function withdraw(
uint256,
address payable,
bytes memory
) external pure override returns (uint256) {
revert("Disabled.");
}

function withdrawLpToken(uint256 lpTokenAmount, address recipient) external override {
function withdrawLpToken(
uint256 lpTokenAmount,
address recipient,
bytes memory
) external override {
IERC20(lpToken).transfer(recipient, lpTokenAmount);
}

Expand Down
Loading