-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from euler-xyz/improve/harvest
Feat: net yield/loss
- Loading branch information
Showing
26 changed files
with
663 additions
and
369 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,13 @@ import {Rewards} from "./module/Rewards.sol"; | |
import {Hooks} from "./module/Hooks.sol"; | ||
import {Fee} from "./module/Fee.sol"; | ||
import {WithdrawalQueue} from "./plugin/WithdrawalQueue.sol"; | ||
import {AggregationLayerVault} from "./AggregationLayerVault.sol"; | ||
import {AggregationLayerVault, IAggregationLayerVault} from "./AggregationLayerVault.sol"; | ||
// libs | ||
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; | ||
|
||
/// @title AggregationLayerVaultFactory contract | ||
/// @custom:security-contact [email protected] | ||
/// @author Euler Labs (https://www.eulerlabs.com/) | ||
contract AggregationLayerVaultFactory { | ||
/// core dependencies | ||
address public immutable evc; | ||
|
@@ -25,6 +28,7 @@ contract AggregationLayerVaultFactory { | |
/// @dev WithdrawalQueue plugin implementation address, need to be deployed per aggregation vault | ||
address public immutable withdrawalQueueImpl; | ||
|
||
/// @dev Init params struct. | ||
struct FactoryParams { | ||
address evc; | ||
address balanceTracker; | ||
|
@@ -36,6 +40,8 @@ contract AggregationLayerVaultFactory { | |
address withdrawalQueueImpl; | ||
} | ||
|
||
/// @notice Constructor. | ||
/// @param _factoryParams FactoryParams struct. | ||
constructor(FactoryParams memory _factoryParams) { | ||
evc = _factoryParams.evc; | ||
balanceTracker = _factoryParams.balanceTracker; | ||
|
@@ -48,6 +54,15 @@ contract AggregationLayerVaultFactory { | |
withdrawalQueueImpl = _factoryParams.withdrawalQueueImpl; | ||
} | ||
|
||
/// @notice Deploy a new aggregation layer vault. | ||
/// @dev This will clone a new WithdrawalQueue plugin instance for the aggregation layer vault. | ||
/// @dev This will use the defaut Rebalancer plugin configured in this factory. | ||
/// @dev Both plugins are possible to change by the aggregation layer vault manager. | ||
/// @param _asset Aggreation layer vault' asset address. | ||
/// @param _name Vaut name. | ||
/// @param _symbol Vault symbol. | ||
/// @param _initialCashAllocationPoints The amount of points to initally allocate for cash reserve. | ||
/// @return aggregationLayerVault The address of the new deployed aggregation layer vault. | ||
function deployEulerAggregationLayer( | ||
address _asset, | ||
string memory _name, | ||
|
@@ -67,7 +82,7 @@ contract AggregationLayerVaultFactory { | |
AggregationLayerVault aggregationLayerVault = | ||
new AggregationLayerVault(rewardsModuleAddr, hooksModuleAddr, feeModuleAddr, allocationpointsModuleAddr); | ||
|
||
AggregationLayerVault.InitParams memory aggregationVaultInitParams = AggregationLayerVault.InitParams({ | ||
IAggregationLayerVault.InitParams memory aggregationVaultInitParams = IAggregationLayerVault.InitParams({ | ||
evc: evc, | ||
balanceTracker: balanceTracker, | ||
withdrawalQueuePeriphery: address(withdrawalQueue), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,11 @@ import {Shared} from "./Shared.sol"; | |
import {HooksModule} from "./module/Hooks.sol"; | ||
import {RewardsModule} from "./module/Rewards.sol"; | ||
|
||
/// @title Dispatch contract | ||
/// @custom:security-contact [email protected] | ||
/// @author Euler Labs (https://www.eulerlabs.com/) | ||
/// @dev This contract implement the modifier to use for forwarding calls to a specific module using delegateCall. | ||
/// @dev Copied from https://github.com/euler-xyz/euler-vault-kit/blob/55d1a1fd7d572372f1c8b9f58aba0604bda3ca4f/src/EVault/Dispatch.sol. | ||
abstract contract Dispatch is RewardsModule, HooksModule { | ||
address public immutable MODULE_REWARDS; | ||
address public immutable MODULE_HOOKS; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,12 @@ import {IEVC} from "ethereum-vault-connector/utils/EVCUtil.sol"; | |
import {IHookTarget} from "evk/src/interfaces/IHookTarget.sol"; | ||
// libs | ||
import {StorageLib, AggregationVaultStorage} from "./lib/StorageLib.sol"; | ||
import {ErrorsLib} from "./lib/ErrorsLib.sol"; | ||
import {HooksLib} from "./lib/HooksLib.sol"; | ||
import {ErrorsLib as Errors} from "./lib/ErrorsLib.sol"; | ||
|
||
/// @title Shared contract | ||
/// @custom:security-contact [email protected] | ||
/// @author Euler Labs (https://www.eulerlabs.com/) | ||
contract Shared { | ||
using HooksLib for uint32; | ||
|
||
|
@@ -28,7 +31,7 @@ contract Shared { | |
modifier nonReentrant() { | ||
AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage(); | ||
|
||
if ($.locked == REENTRANCYLOCK__LOCKED) revert ErrorsLib.Reentrancy(); | ||
if ($.locked == REENTRANCYLOCK__LOCKED) revert Errors.Reentrancy(); | ||
|
||
$.locked = REENTRANCYLOCK__LOCKED; | ||
_; | ||
|
@@ -49,12 +52,12 @@ contract Shared { | |
function _setHooksConfig(address _hooksTarget, uint32 _hookedFns) internal { | ||
if (_hooksTarget != address(0) && IHookTarget(_hooksTarget).isHookTarget() != IHookTarget.isHookTarget.selector) | ||
{ | ||
revert ErrorsLib.NotHooksContract(); | ||
revert Errors.NotHooksContract(); | ||
} | ||
if (_hookedFns != 0 && _hooksTarget == address(0)) { | ||
revert ErrorsLib.InvalidHooksTarget(); | ||
revert Errors.InvalidHooksTarget(); | ||
} | ||
if (_hookedFns >= ACTIONS_COUNTER) revert ErrorsLib.InvalidHookedFns(); | ||
if (_hookedFns >= ACTIONS_COUNTER) revert Errors.InvalidHookedFns(); | ||
|
||
AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage(); | ||
$.hooksConfig = (uint256(uint160(_hooksTarget)) << 32) | uint256(_hookedFns); | ||
|
@@ -91,6 +94,6 @@ contract Shared { | |
} | ||
} | ||
|
||
revert ErrorsLib.EmptyError(); | ||
revert Errors.EmptyError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.0; | ||
|
||
interface IAggregationLayerVault { | ||
/// @dev Struct to pass init() call params. | ||
struct InitParams { | ||
address evc; | ||
address balanceTracker; | ||
address withdrawalQueuePeriphery; | ||
address rebalancerPerihpery; | ||
address aggregationVaultOwner; | ||
address asset; | ||
string name; | ||
string symbol; | ||
uint256 initialCashAllocationPoints; | ||
} | ||
|
||
/// @dev A struct that hold a strategy allocation's config | ||
/// allocated: amount of asset deposited into strategy | ||
/// allocationPoints: number of points allocated to this strategy | ||
/// active: a boolean to indice if this strategy is active or not | ||
/// cap: an optional cap in terms of deposited underlying asset. By default, it is set to 0(not activated) | ||
struct Strategy { | ||
uint120 allocated; | ||
uint120 allocationPoints; | ||
bool active; | ||
uint120 cap; | ||
} | ||
|
||
/// @dev Euler saving rate struct | ||
/// @dev Based on https://github.com/euler-xyz/euler-vault-kit/blob/master/src/Synths/EulerSavingsRate.sol | ||
/// lastInterestUpdate: last timestamo where interest was updated. | ||
/// interestSmearEnd: timestamp when the smearing of interest end. | ||
/// interestLeft: amount of interest left to smear. | ||
/// locked: if locked or not for update. | ||
struct AggregationVaultSavingRate { | ||
uint40 lastInterestUpdate; | ||
uint40 interestSmearEnd; | ||
uint168 interestLeft; | ||
uint8 locked; | ||
} | ||
|
||
function rebalance(address _strategy, uint256 _amountToRebalance, bool _isDeposit) external; | ||
function gulp() external; | ||
function harvest() external; | ||
function executeStrategyWithdraw(address _strategy, uint256 _withdrawAmount) external; | ||
function executeAggregationVaultWithdraw( | ||
address caller, | ||
address receiver, | ||
address owner, | ||
uint256 assets, | ||
uint256 shares | ||
) external; | ||
function getStrategy(address _strategy) external view returns (Strategy memory); | ||
function totalAllocationPoints() external view returns (uint256); | ||
function totalAllocated() external view returns (uint256); | ||
function totalAssetsAllocatable() external view returns (uint256); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.