Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e8a57bd
feat(vault): remove rebalance and _setCacheNextBestStrategy
NouDaimon Sep 22, 2022
4190952
feat(refactor): move strategies to vault storage, store strategy meta…
NouDaimon Sep 27, 2022
2354639
feat(config): update earn protocol configuration
NouDaimon Sep 27, 2022
33af74e
feat(rename): rename InvestStrategyRegitsry => StrategyRegistry
NouDaimon Sep 29, 2022
7726921
feat(strategyregistry): move withdrawal buffers to vault storage
NouDaimon Sep 29, 2022
998faeb
feat(strategies): expose add/remove strategy and remove unrequired fu…
NouDaimon Sep 30, 2022
d3052e4
feat(test): tests for multi-strat | WIP
NouDaimon Sep 30, 2022
8f75937
feat(strategyregistry): remove all invest strategy registry references
NouDaimon Oct 4, 2022
e8a4d0e
feat(bytecode): remove unrequired internals to save space
NouDaimon Oct 4, 2022
4b22894
feat(bytecode): remove compute strategy hash function
NouDaimon Oct 4, 2022
3b3528b
feat(vaultactions): add natspec and check to vaultwithdraw/deposit
NouDaimon Oct 4, 2022
60289b5
Merge branch 'feat/harvest' into feat/multi-strat
NouDaimon Oct 4, 2022
64b68a6
feat(modifiers): new vault-specific modifier contract for bytecode size
NouDaimon Oct 5, 2022
7d53819
feat(vault): add checks, remove unneeded libraries, remove unneeded t…
NouDaimon Oct 6, 2022
2232d00
chore(earn-protocol-config): bump up module
dhruvinparikh Oct 17, 2022
c67ceec
Merge branch 'master' into feat/multi-strat
dhruvinparikh Oct 18, 2022
f1a97a5
Merge branch 'master' into feat/multi-strat
dhruvinparikh Oct 20, 2022
eda72c5
Merge branch 'master' into feat/multi-strat
dhruvinparikh Nov 24, 2022
849a73c
feat(submodule): update earn-protocol-config
dhruvinparikh Nov 24, 2022
a1aaaa4
feat(weiroll): add libraries
dhruvinparikh Nov 29, 2022
c8d9207
feat(weiroll): test deposit
dhruvinparikh Nov 30, 2022
8c7f378
feat(vaultweiroll): test user withdraw and vault withdraw
dhruvinparikh Dec 1, 2022
bd3bc80
feat(vaultweiroll): add outputindex
dhruvinparikh Dec 6, 2022
d90dff8
chore(submodules): update earn-protocol-configuration
dhruvinparikh Dec 6, 2022
5a87d5f
Merge branch 'weiroll' into feat/multi-strat
dhruvinparikh Dec 6, 2022
67ff73a
feat(vault.sol): weiroll
dhruvinparikh Dec 7, 2022
3a5b951
refactor(vault.sol): reduce bytecodesize
dhruvinparikh Dec 7, 2022
77db8a0
feat(vault.sol): user withdraw from strategies proportionally
dhruvinparikh Dec 7, 2022
4611bd1
feat(adapter): add compound adapter
dhruvinparikh Dec 10, 2022
cbe7318
feat(adapter): add AaveV2Adapter
dhruvinparikh Dec 10, 2022
043ac0e
refactor(harvest): use v6 type
dhruvinparikh Dec 12, 2022
5973e24
Merge branch 'master' into feat/multi-strat
dhruvinparikh Dec 12, 2022
376bbdf
feat(strategymanager): add strategy managet class and required interface
dhruvinparikh Dec 14, 2022
1ca01aa
feat(strategy-manager): add read plans
dhruvinparikh Dec 14, 2022
ee6dde9
refactor(strategy-manager): change argument types
dhruvinparikh Dec 15, 2022
95d4203
feat(test): save strategy testing
dhruvinparikh Dec 17, 2022
4ddff06
refactor(opusdc-save): add approvals
dhruvinparikh Dec 17, 2022
d0fba4b
feat(test): add vault withdraw and deposit assertions
dhruvinparikh Dec 19, 2022
ff0a2f3
refactor(harvest): split by multi sig role
dhruvinparikh Dec 20, 2022
72a160c
test(strategies): deposit / withdraw eth
dhruvinparikh Dec 21, 2022
dea80a8
test(strategies): save except USDT
dhruvinparikh Dec 22, 2022
48be89f
test(strategies): refactor output index
dhruvinparikh Dec 23, 2022
7463278
refactor(test): split helper contracts
dhruvinparikh Jan 2, 2023
e06fe2e
feat(adapter): convex and curve
dhruvinparikh Jan 10, 2023
9fb5776
feat(test): fix curve adapter tests
dhruvinparikh Jan 11, 2023
fc3a03b
feat(test): convex strategies
dhruvinparikh Jan 12, 2023
bff3025
feat(strategy): test frax
dhruvinparikh Jan 16, 2023
d4e0612
test(strategy): mim and steth strat
dhruvinparikh Jan 20, 2023
6389a73
test(vault_spec): fix some test
dhruvinparikh Jan 30, 2023
6cddfcb
feat(2_vault_spec): refactor
dhruvinparikh Feb 1, 2023
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 .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ typechain/
specification_docs/
deployments/
contracts/protocol/earn-protocol-configuration
contracts/protocol/adapters
contracts/protocol/adapters/avalanche
contracts/protocol/adapters/defi-adapters
contracts/protocol/adapters/ethereum/curve-crypto-pool-adapter
contracts/protocol/adapters/ethereum/curve-metapool-gauge-adapter
contracts/protocol/adapters/ethereum/curve-metapool-swap-adapter
contracts/protocol/adapters/ethereum/newo-staking-adapter
contracts/protocol/adapters/ethereum/sushi-bar-adapter
contracts/protocol/adapters/ethereum/sushiswap-masterchefv2-adapter-ethereum
contracts/protocol/adapters/ethereum/team-defi-adapters
contracts/protocol/adapters/polygon
contracts/protocol/adapters/swap-adapters
contracts/protocol/adapters/uniswapV2PoolAdapter
contracts/utils/optyfi-oracle
tenderly-actions/
helpers/types/
deployments/

# files
.solcover.js
10 changes: 7 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@
[submodule "contracts/protocol/adapters/swap-adapters"]
path = contracts/protocol/adapters/swap-adapters
url = git@github.com:Opty-Fi/swap-adapters.git
[submodule "contracts/protocol/earn-protocol-configuration"]
path = contracts/protocol/earn-protocol-configuration
url = git@github.com:Opty-Fi/earn-protocol-configuration.git
[submodule "contracts/protocol/adapters/ethereum/team-defi-adapters"]
path = contracts/protocol/adapters/ethereum/team-defi-adapters
url = git@github.com:Opty-Fi/team-defi-adapters.git
[submodule "contracts/protocol/earn-protocol-configuration"]
path = contracts/protocol/earn-protocol-configuration
url = git@github.com:Opty-Fi/earn-protocol-configuration.git
branch = feat/multi-strat
[submodule "contracts/utils/optyfi-oracle"]
path = contracts/utils/optyfi-oracle
url = git@github.com:Opty-Fi/optyfi-oracle.git
16 changes: 15 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,22 @@
**/typechain
**/specification_docs
contracts/protocol/earn-protocol-configuration
contracts/protocol/adapters
contracts/protocol/adapters/avalanche
contracts/protocol/adapters/defi-adapters
contracts/protocol/adapters/ethereum/curve-crypto-pool-adapter
contracts/protocol/adapters/ethereum/curve-metapool-gauge-adapter
contracts/protocol/adapters/ethereum/curve-metapool-swap-adapter
contracts/protocol/adapters/ethereum/newo-staking-adapter
contracts/protocol/adapters/ethereum/sushi-bar-adapter
contracts/protocol/adapters/ethereum/sushiswap-masterchefv2-adapter-ethereum
contracts/protocol/adapters/ethereum/team-defi-adapters
contracts/protocol/adapters/polygon
contracts/protocol/adapters/swap-adapters
contracts/protocol/adapters/uniswapV2PoolAdapter
**out/
helpers/types/
deployments/
contracts/utils/optyfi-oracle

# files
*.env
Expand Down
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"plugins": ["prettier"],
"rules": {
"code-complexity": ["error", 11],
"compiler-version": ["error", "^0.6.12"],
"compiler-version": ["error", ">=0.6.12"],
"const-name-snakecase": "off",
"constructor-syntax": "error",
"func-visibility": ["error", { "ignoreConstructors": true }],
Expand Down
14 changes: 13 additions & 1 deletion .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@ contracts/utils/
contracts/dependencies/
contracts/mocks/
contracts/protocol/earn-protocol-configuration
contracts/protocol/adapters
contracts/protocol/adapters/avalanche
contracts/protocol/adapters/defi-adapters
contracts/protocol/adapters/ethereum/curve-crypto-pool-adapter
contracts/protocol/adapters/ethereum/curve-metapool-gauge-adapter
contracts/protocol/adapters/ethereum/curve-metapool-swap-adapter
contracts/protocol/adapters/ethereum/newo-staking-adapter
contracts/protocol/adapters/ethereum/sushi-bar-adapter
contracts/protocol/adapters/ethereum/sushiswap-masterchefv2-adapter-ethereum
contracts/protocol/adapters/ethereum/team-defi-adapters
contracts/protocol/adapters/polygon
contracts/protocol/adapters/swap-adapters
contracts/protocol/adapters/uniswapV2PoolAdapter
contracts/utils/optyfi-oracle
119 changes: 53 additions & 66 deletions contracts/interfaces/opty/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ interface IVault {
* @param _active If true, the Vault goes into Emergency Shutdown. If false, the Vault
* goes back into Normal Operation
*/
function setEmergencyShutdown(bool _active) external;
function setEmergencyShutdown(bool _active) external payable;

/**
* @notice activates or deactivates vault mode where all strategies
Expand All @@ -119,16 +119,7 @@ interface IVault {
* @param _unpaused If true, the vault goes into unpause mode. If false(default), the vault
* goes into pause mode
*/
function setUnpaused(bool _unpaused) external;

/**
* @notice Withdraw the underlying asset of vault from previous strategy if any,
* claims and swaps the reward tokens for the underlying token
* performs batch minting of shares for users deposited previously without rebalance,
* deposits the assets into the new strategy if any or holds the same in the vault
* @dev the vault will be charged to compensate gas fees if operator calls this function
*/
function rebalance() external;
function setUnpaused(bool _unpaused) external payable;

/**
* @notice Deposit underlying tokens to the vault
Expand Down Expand Up @@ -159,43 +150,40 @@ interface IVault {
) external returns (uint256);

/**
* @notice function to deposit whole balance of underlying token to current strategy
* @notice deposits underlying tokens to a strategy from the vault
* @param _strategyHash hash of strategy to deposit to
* @param _depositValueUT the amount of underlying token to deposit
*/
function vaultDepositAllToStrategy() external;
function vaultDepositSomeToStrategy(bytes32 _strategyHash, uint256 _depositValueUT) external payable;

/**
* @notice withdraws LP tokens from a strategy from the vault
* @param _strategyHash hash of the strategy to withdraw from
* @param _withdrawAmountLP the amount of LP to withdraw
*/
function vaultWithdrawSomeFromStrategy(bytes32 _strategyHash, uint256 _withdrawAmountLP) external payable;

/**
* @notice A function to be called in case vault needs to claim and harvest tokens in case a strategy
* provides multiple reward tokens
* @param _codes Array of encoded data in bytes which acts as code to execute
* @param _commands list of values that encode single
* operation for the VM to take
* @param _state list of elements to call a smart contract function
* specified in the command via delegatecall
*/
function adminCall(bytes[] memory _codes) external;
function adminCall(bytes32[] memory _commands, bytes[] memory _state) external payable;

/**
* @notice function to claim the whole balance of reward tokens
* @param _liquidityPool Liquidity pool's contract address from where to claim the reward token
*/
function claimRewardToken(address _liquidityPool) external;

/**
* @notice function to swap the vault's entire balance of reward token for the vault's underlying token
* @param _rewardToken address of the reward token to harvest
* @param _dex swap router
* @param _isUniV3 whether router is uniswapV3 or not
* @param _minimumUnderlyingTokenAmount minimum underlying after swap that must be received
* for the transaction to not revert
* @param _deadline swap deadline
* @param _path token path for uniswapV2 and its forks
* @param _pathUniV3 path for uniswapV3
*/
function harvest(
address _rewardToken,
address _dex,
bool _isUniV3,
uint256 _minimumUnderlyingTokenAmount,
uint256 _deadline,
address[] memory _path,
bytes memory _pathUniV3
) external;
* @param _strategyHash keccak256 hash of the strategy
*/
function claimRewardToken(bytes32 _strategyHash) external payable;

/**
* @notice function to swap the vault's reward token for the vault's underlying token
* @param _strategyHash keccak256 hash of the strategy
*/
function harvestRewards(bytes32 _strategyHash) external payable;

/**
* @notice Allow passing a signed message to approve spending
Expand All @@ -219,6 +207,18 @@ interface IVault {
bytes32 _s
) external;

/**
* @notice adds a strategy to the vault
* @param _strategyHash hash of strategy
*/
function addStrategy(bytes32 _strategyHash) external;

/**
* @notice removes a strategy from the vault
* @param _strategyHash hash of strategy
*/
function removeStrategy(bytes32 _strategyHash) external;

/**
* @notice Provide the allowances for the spenders to spent vault owned tokens
* @dev the length of tokens and spenders should be same
Expand Down Expand Up @@ -326,38 +326,13 @@ interface IVault {
*/
function calcWithdrawalFeeUT(uint256 _userWithdrawUT) external view returns (uint256);

/**
* @notice Returns next best invest strategy that the vault will execute on next rebalance
* @return the strategy metadata
*/
function getNextBestInvestStrategy() external view returns (DataTypes.StrategyStep[] memory);

/**
* @notice function to compute the balance of lptoken of the vault
* in the last step of the strategy
* @param _strategySteps array of strategy step tuple
* @param _strategyHash keccak256 hash of the strategyHash
* @return balance in lptoken
*/
function getLastStrategyStepBalanceLP(DataTypes.StrategyStep[] memory _strategySteps)
external
view
returns (uint256);

/**
* @notice retireves current strategy metadata
* @return array of strategy steps
*/
function getInvestStrategySteps() external view returns (DataTypes.StrategyStep[] memory);

/**
* @dev function to compute the keccak256 hash of the strategy steps
* @param _investStrategySteps metadata for invest strategy
* @return keccak256 hash of the invest strategy and underlying tokens hash
*/
function computeInvestStrategyHash(DataTypes.StrategyStep[] memory _investStrategySteps)
external
view
returns (bytes32);
function getLastStrategyStepBalanceLP(bytes32 _strategyHash) external view returns (uint256);

/**
* @dev Emitted when emergency shutdown over vault is changed
Expand Down Expand Up @@ -393,4 +368,16 @@ interface IVault {
* @param caller Address of user who has called the respective function to trigger this event
*/
event LogTotalValueLockedLimitUT(uint256 indexed totalValueLockedLimitUT, address indexed caller);

/**
* @notice Emitted when a strategy is added to the vault
* @param _strategyHash the hash of the strategy added
*/
event AddStrategy(bytes32 _strategyHash);

/**
* @notice Emitted when a strategy is removed from the vault
* @param _strategyHash the hash of the strategy removed
*/
event RemoveStrategy(bytes32 _strategyHash);
}
8 changes: 8 additions & 0 deletions contracts/mocks/contracts/TestVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ contract TestVault {
uint256 _depositFee = _vault.calcDepositFeeUT(_valueUT);
return _vault.userDepositPermitted(address(this), true, _valueUT.sub(_depositFee), _depositFee, _accountsProof);
}

function pureFunctionUint256(uint256 _arg) external pure returns (uint256) {
return _arg;
}

function getERC20Balance(address _owner, ERC20 _token) external view returns (uint256) {
return _token.balanceOf(_owner);
}
}
61 changes: 61 additions & 0 deletions contracts/protocol/adapters/ethereum/AaveV1Helper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier:MIT

pragma solidity =0.8.11;

// interfaces
import { IERC20 } from "@openzeppelin/contracts-0.8.x/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts-0.8.x/token/ERC20/utils/SafeERC20.sol";
import { IWETH } from "@optyfi/defi-legos/interfaces/misc/contracts/IWETH.sol";
import { ILendingPool } from "@optyfi/defi-legos/ethereum/aave/contracts/ILendingPool.sol";
import { IAaveV1Token } from "@optyfi/defi-legos/ethereum/aave/contracts/IAaveV1Token.sol";

contract AaveV1Helper {
using SafeERC20 for IERC20;

// solhint-disable-next-line var-name-mixedcase
IWETH public immutable WETH;

// solhint-disable-next-line var-name-mixedcase
address public constant ETH = address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);

/* solhint-disable no-empty-blocks*/
constructor(IWETH _weth) {
WETH = _weth;
}

/* solhint-enable no-empty-blocks*/

// solhint-disable-next-line func-name-mixedcase
function depositETH_AaveV1(
address _lendingPool,
address _lpToken,
uint256 _amount
) external {
uint256 _wethBalanceBefore = IERC20(address(WETH)).balanceOf(address(this));
IERC20(address(WETH)).safeTransferFrom(msg.sender, address(this), _amount);
uint256 _wethBalanceAfter = IERC20(address(WETH)).balanceOf(address(this));
uint256 _actualAmount = _wethBalanceAfter - _wethBalanceBefore;
WETH.withdraw(_actualAmount);
uint256 _balanceBeforeLP = IERC20(_lpToken).balanceOf(address(this));
ILendingPool(_lendingPool).deposit{ value: _actualAmount }(ETH, _actualAmount, uint16(0));
uint256 _balanceAfterLP = IERC20(_lpToken).balanceOf(address(this));
IERC20(_lpToken).safeTransfer(msg.sender, _balanceAfterLP - _balanceBeforeLP);
}

// solhint-disable-next-line func-name-mixedcase
function withdrawETH_AaveV1(address _lpToken, uint256 _amount) external {
uint256 _lpTokenBalanceBefore = IERC20(_lpToken).balanceOf(address(this));
IERC20(_lpToken).safeTransferFrom(msg.sender, address(this), _amount);
uint256 _lpTokenBalanceAfter = IERC20(_lpToken).balanceOf(address(this));
uint256 _actualAmount = _lpTokenBalanceAfter - _lpTokenBalanceBefore;
uint256 _balanceBeforeETH = address(this).balance;
IAaveV1Token(_lpToken).redeem(_actualAmount);
uint256 _balanceAfterETH = address(this).balance;
WETH.deposit{ value: _balanceAfterETH - _balanceBeforeETH }();
IERC20(address(WETH)).safeTransfer(msg.sender, _balanceAfterETH - _balanceBeforeETH);
}

/* solhint-disable no-empty-blocks*/
receive() external payable {}
/* solhint-enable no-empty-blocks*/
}
Loading