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

Internal review #21

Closed
wants to merge 366 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
366 commits
Select commit Hold shift + click to select a range
eac4724
feat: opt in and out of strategy rewards
haythemsellami May 29, 2024
b34d179
fix
haythemsellami May 29, 2024
079fc00
chore: lint
haythemsellami May 29, 2024
8656756
feat: claimStrategyReward()
haythemsellami May 29, 2024
3173f75
Merge pull request #13 from euler-xyz/feat/fees
haythemsellami May 29, 2024
aa9c869
Merge branch 'main' into feat/opt-in-strategy-rewards
haythemsellami May 29, 2024
266e804
chore: add natspec
haythemsellami May 30, 2024
700111d
test:
haythemsellami May 30, 2024
fdfdc17
chore: lint
haythemsellami May 30, 2024
ced8cc3
Merge pull request #14 from euler-xyz/feat/opt-in-strategy-rewards
haythemsellami May 30, 2024
10a6db8
feat: socialize negative yield
haythemsellami May 30, 2024
61a19e3
fix and tests'
haythemsellami May 31, 2024
5c4746b
decrease totalAllocated
haythemsellami May 31, 2024
034c2e5
fix
haythemsellami Jun 3, 2024
0262537
more gulping tests
haythemsellami Jun 3, 2024
0ce8f65
clean
haythemsellami Jun 3, 2024
d55d61b
more tests
haythemsellami Jun 3, 2024
970ead0
clean
haythemsellami Jun 3, 2024
69f74df
Merge pull request #15 from euler-xyz/feat/negative-yield-socialization
haythemsellami Jun 4, 2024
9545b5f
Add revert case
haythemsellami Jun 4, 2024
62cef9e
Push to withdrawalQueue
haythemsellami Jun 4, 2024
2eb3b23
Check that strategy is ERC4626
haythemsellami Jun 4, 2024
3de4aba
use SafeCast; other fixes
haythemsellami Jun 4, 2024
396afda
refactor _withdraw()
haythemsellami Jun 4, 2024
3320087
use max functions; ignore balance tracker hooks in self-transfer
haythemsellami Jun 4, 2024
c065a0d
update timestamp check
haythemsellami Jun 4, 2024
8ea4e4d
fix
haythemsellami Jun 5, 2024
f76a87a
fix
haythemsellami Jun 5, 2024
7d6186b
Merge pull request #17 from euler-xyz/fix/k-review
haythemsellami Jun 5, 2024
9956613
feat: add events
haythemsellami Jun 6, 2024
648affd
fix build
haythemsellami Jun 6, 2024
019ff45
add more events
haythemsellami Jun 6, 2024
6052b0d
Merge pull request #18 from euler-xyz/events
haythemsellami Jun 6, 2024
e5f9f3a
feat: init cap impl
haythemsellami Jun 7, 2024
e171136
add tests
haythemsellami Jun 10, 2024
2877e68
test: more tests
haythemsellami Jun 10, 2024
6e8192a
chore: natspec
haythemsellami Jun 10, 2024
40e0a02
Merge pull request #19 from euler-xyz/feat/balance-cap
haythemsellami Jun 10, 2024
fe7d604
feat: init hooks
haythemsellami Jun 10, 2024
c1fde1e
chore: lint
haythemsellami Jun 10, 2024
68457f0
feat: hooks implementation
haythemsellami Jun 10, 2024
981f2a2
chore: clean & rename
haythemsellami Jun 10, 2024
a09c8a3
test: init tests
haythemsellami Jun 10, 2024
43455a0
tests
haythemsellami Jun 11, 2024
3b0fa7f
chore: natspec
haythemsellami Jun 11, 2024
3bab3fa
chore: add reference
haythemsellami Jun 11, 2024
c8ab40b
add Rebalancer.sol
haythemsellami Jun 11, 2024
707ed8f
remove modifier
haythemsellami Jun 11, 2024
6791fad
more refactoring
haythemsellami Jun 11, 2024
a9631b7
Merge pull request #20 from euler-xyz/feat/hooks
haythemsellami Jun 11, 2024
7982101
Merge branch 'main' into reduce-bytecode-size
haythemsellami Jun 11, 2024
fdd19a2
chore: add bytecode size checks to CI
haythemsellami Jun 11, 2024
60356e3
move event
haythemsellami Jun 11, 2024
88daa43
remove rebalance hook
haythemsellami Jun 12, 2024
32e39cf
refactor
haythemsellami Jun 12, 2024
a436765
add event
haythemsellami Jun 12, 2024
b0f8889
remove cachedBalanceTracker
haythemsellami Jun 12, 2024
43f60e6
remove duplicate params
haythemsellami Jun 12, 2024
f591ebf
minor gas opt; remove account status check
haythemsellami Jun 12, 2024
b29462b
more fixes
haythemsellami Jun 12, 2024
ec792d7
clean
haythemsellami Jun 12, 2024
aa11e27
Merge pull request #22 from euler-xyz/reduce-bytecode-size
haythemsellami Jun 12, 2024
f3c2cf5
Merge branch 'main' into k-review2
haythemsellami Jun 12, 2024
6b7636e
refactor setHooksConfig()
haythemsellami Jun 12, 2024
b38c925
feat: pack hooks config in uint256
haythemsellami Jun 13, 2024
f5c5bd1
uncomment asserts
haythemsellami Jun 13, 2024
e43cff0
refactor
haythemsellami Jun 13, 2024
c048e42
revert on duplicate initial strategies
haythemsellami Jun 13, 2024
b0232f3
Merge pull request #24 from euler-xyz/k-review2
haythemsellami Jun 13, 2024
199ca17
accrue performance fee in underlying asset
haythemsellami Jun 14, 2024
d1329a3
lint
haythemsellami Jun 14, 2024
42832ad
use > instead of !=
haythemsellami Jun 14, 2024
82d3431
test: add asserts
haythemsellami Jun 14, 2024
46fc6e9
Merge pull request #25 from euler-xyz/update-performance-fee
haythemsellami Jun 14, 2024
a605265
refactor
haythemsellami Jun 14, 2024
81f619c
add files
haythemsellami Jun 14, 2024
f7886c3
forge install: openzeppelin-contracts-upgradeable
haythemsellami Jun 17, 2024
d019379
refactor
haythemsellami Jun 17, 2024
9ebd543
forge install: openzeppelin-contracts
haythemsellami Jun 17, 2024
0d8133c
unstructured storage
haythemsellami Jun 17, 2024
2ed5a5f
working version
haythemsellami Jun 17, 2024
8785df0
working version
haythemsellami Jun 17, 2024
9dd3080
working version
haythemsellami Jun 18, 2024
529aad6
working version
haythemsellami Jun 18, 2024
d6cbb57
working version
haythemsellami Jun 18, 2024
18756aa
working version
haythemsellami Jun 18, 2024
3282709
bytecode under limit
haythemsellami Jun 18, 2024
c6f29f2
clean
haythemsellami Jun 18, 2024
6e1a8fd
chore: rename roleS
haythemsellami Jun 18, 2024
133865d
add access control & last touches
haythemsellami Jun 18, 2024
7eaf524
Merge pull request #27 from euler-xyz/feat/clones
haythemsellami Jun 18, 2024
c4d83c2
chore: uncomment tests
haythemsellami Jun 18, 2024
680dd20
chore: natspec and renames
haythemsellami Jun 19, 2024
a475294
chore: renames
haythemsellami Jun 19, 2024
4c3c078
Merge pull request #26 from euler-xyz/refactor/withdraw
haythemsellami Jun 19, 2024
75fcb7f
fix RewardStreams integration
haythemsellami Jun 19, 2024
de41b89
clean
haythemsellami Jun 19, 2024
d864756
add natspec and use()
haythemsellami Jun 19, 2024
b09b8d8
clean
haythemsellami Jun 19, 2024
0c66c13
Merge pull request #28 from euler-xyz/fix/reward-streams-integration
haythemsellami Jun 19, 2024
da33430
update withdraw and redeem
haythemsellami Jun 20, 2024
5c726a5
Merge pull request #29 from euler-xyz/improve/withdraw
haythemsellami Jun 20, 2024
4a415dd
refactor
haythemsellami Jun 21, 2024
cf47798
feat: net yield/loss
haythemsellami Jun 23, 2024
54c5135
refactor
haythemsellami Jun 24, 2024
2661030
refactor and add tests
haythemsellami Jun 25, 2024
00c75b0
clean
haythemsellami Jun 25, 2024
59e8da5
clean
haythemsellami Jun 25, 2024
854f5e2
clean
haythemsellami Jun 25, 2024
293dc42
clean
haythemsellami Jun 25, 2024
1c6f7ff
Merge pull request #30 from euler-xyz/improve/harvest
haythemsellami Jun 27, 2024
c454c6e
rename
haythemsellami Jun 27, 2024
49fc1eb
separate core from plugin
haythemsellami Jun 27, 2024
b146b63
Merge pull request #31 from euler-xyz/chore/rename
haythemsellami Jun 27, 2024
e09ae62
remove dependency to the EVC
haythemsellami Jun 27, 2024
7a63756
feat: add setters for plugins
haythemsellami Jul 1, 2024
e4eb399
Merge pull request #32 from euler-xyz/plugins/setters
haythemsellami Jul 1, 2024
624b79e
forge install: erc4626-tests
haythemsellami Jul 1, 2024
5fbd9d8
test: a16z erc4626 property tests
haythemsellami Jul 1, 2024
bfbe585
clean
haythemsellami Jul 1, 2024
76bef1d
Merge pull request #33 from euler-xyz/test/a16z-tests
haythemsellami Jul 1, 2024
f8269f8
init basic invariants setup
haythemsellami Jul 1, 2024
c28a76c
improve setup; more invariants; fixes
haythemsellami Jul 2, 2024
28a1622
chore: add invariants run to github actions
haythemsellami Jul 2, 2024
980d117
more invariants; no removing strategy with allocated amount
haythemsellami Jul 2, 2024
d32af2a
lint:
haythemsellami Jul 2, 2024
1f23c58
fix CI
haythemsellami Jul 2, 2024
9c91401
more invariants; fix: reset cap when removing strategy
haythemsellami Jul 2, 2024
6ee42bc
lint
haythemsellami Jul 2, 2024
361e930
invariants
haythemsellami Jul 3, 2024
95a5896
more invariants
haythemsellami Jul 3, 2024
4a9c003
add gulp to handler
haythemsellami Jul 3, 2024
e61207f
fix: minor comments from certora
haythemsellami Jul 3, 2024
bb260c2
forge install: properties
haythemsellami Jul 3, 2024
6ef8f03
add echidna properties tests
haythemsellami Jul 3, 2024
e0d0e5c
update echidna config
haythemsellami Jul 3, 2024
49e5891
update echidna config
haythemsellami Jul 3, 2024
24db103
update echidna config
haythemsellami Jul 3, 2024
e8ed3a9
update echidna config
haythemsellami Jul 3, 2024
54fc8ff
update echidna config
haythemsellami Jul 3, 2024
183e275
update echidna config
haythemsellami Jul 3, 2024
8ee4b59
update echidna config
haythemsellami Jul 3, 2024
3eba2f3
update
haythemsellami Jul 3, 2024
25a2739
update
haythemsellami Jul 4, 2024
327729e
invariants: gulp
haythemsellami Jul 4, 2024
788a096
update config
haythemsellami Jul 4, 2024
22552d5
Merge pull request #34 from euler-xyz/invariants-test
haythemsellami Jul 4, 2024
9369073
rename to Euler Aggregation Vault
haythemsellami Jul 4, 2024
9f7e14e
Merge pull request #35 from euler-xyz/rename
haythemsellami Jul 4, 2024
0994bab
gulp only if min amount is minted
haythemsellami Jul 5, 2024
6b7546f
add invariant
haythemsellami Jul 5, 2024
4bda9ba
gulp fuzzing
haythemsellami Jul 5, 2024
59c4590
Merge pull request #36 from euler-xyz/fix/min-amount-to-gulp
haythemsellami Jul 5, 2024
85a99db
test: gulp fuzzing
haythemsellami Jul 5, 2024
0d16a98
add invariant and comments
haythemsellami Jul 5, 2024
cb4951b
feat: whitelisted withdrawal queue
haythemsellami Jul 8, 2024
298c6ab
fix
haythemsellami Jul 8, 2024
79788a7
clean; add events
haythemsellami Jul 8, 2024
d0d1c96
add slither
haythemsellami Jul 8, 2024
d889ad0
clean
haythemsellami Jul 8, 2024
a88bc5a
clean
haythemsellami Jul 8, 2024
384afb8
Merge pull request #37 from euler-xyz/feat/whitelisted-withdrawal-que…
haythemsellami Jul 8, 2024
1fc4174
chore: delete slither.db.json
haythemsellami Jul 9, 2024
04e1fea
clean; add invariants tests
haythemsellami Jul 9, 2024
d29a1ef
Merge pull request #38 from euler-xyz/clean
haythemsellami Jul 10, 2024
da4f193
feat: do not harvest or rebalance in-active strategies
haythemsellami Jul 10, 2024
9c43041
chore: lint
haythemsellami Jul 10, 2024
735fdd0
circuit-breaker
haythemsellami Jul 10, 2024
2faacf8
chore: lint
haythemsellami Jul 10, 2024
3aeadbf
merge strategy added and remover into strategy operator
haythemsellami Jul 10, 2024
9522d10
add startegy status
haythemsellami Jul 10, 2024
20bfc1c
refactor
haythemsellami Jul 11, 2024
bafa48e
deduct losses when set strategy in emergency mode
haythemsellami Jul 12, 2024
1093fd8
fix
haythemsellami Jul 12, 2024
2abe33a
refactor
haythemsellami Jul 12, 2024
80b8a19
improve invariants
haythemsellami Jul 12, 2024
cff5495
lint
haythemsellami Jul 12, 2024
3b2ff39
more tests
haythemsellami Jul 12, 2024
599a5a2
rename to StrategyModule; add tests
haythemsellami Jul 15, 2024
15c965f
chore: lint
haythemsellami Jul 15, 2024
6708cb0
set allocated to maxWithdraw()
haythemsellami Jul 16, 2024
c993480
Merge pull request #39 from euler-xyz/feat/circuit-breaker
haythemsellami Jul 17, 2024
f7cc381
fix fuzz tests
haythemsellami Jul 17, 2024
5a30dbb
fix role setup
haythemsellami Jul 17, 2024
18bb998
remove --sizes from CI
haythemsellami Jul 17, 2024
efa5eda
test: voting power invariant
haythemsellami Jul 18, 2024
fc2fcad
Rebalance module
haythemsellami Jul 18, 2024
ba90148
refactor: remove Rebalancer plugin and add Rebalance module
haythemsellami Jul 19, 2024
3fe8e39
clean
haythemsellami Jul 19, 2024
299949e
update modifiers order
haythemsellami Jul 19, 2024
daaa6bd
add _gulp() into Shared.sol
haythemsellami Jul 19, 2024
55ea44f
remove whitelisting of WithdrawalQueue
haythemsellami Jul 21, 2024
f61b867
Refactor factory
haythemsellami Jul 21, 2024
0c95eb2
chore: add echidna to CI
haythemsellami Jul 21, 2024
94b5414
add gulping
haythemsellami Jul 22, 2024
585bce3
fix
haythemsellami Jul 22, 2024
0ab9e1c
update
haythemsellami Jul 22, 2024
45ff916
fix invariant_votingPower
haythemsellami Jul 22, 2024
c3fd0d1
fix
haythemsellami Jul 22, 2024
ba95957
chore: update CI
haythemsellami Jul 23, 2024
668c73e
chore: update CI
haythemsellami Jul 23, 2024
f9fe32a
chore: update CI
haythemsellami Jul 23, 2024
2e52990
chore: update CI
haythemsellami Jul 23, 2024
fce8181
chore: update CI
haythemsellami Jul 23, 2024
f53a553
use default testLimit
haythemsellami Jul 23, 2024
6af81ca
Refactor factory
haythemsellami Jul 23, 2024
4bc449c
refactor
haythemsellami Jul 23, 2024
4c93aec
fit Strategy struct in one slot
haythemsellami Jul 23, 2024
d8b9144
refactor
haythemsellami Jul 24, 2024
07f0cd4
Merge pull request #43 from euler-xyz/fix/refactor-codebase
haythemsellami Jul 24, 2024
5052879
add sizes check to CI
haythemsellami Jul 24, 2024
5507358
clean
haythemsellami Jul 24, 2024
2e0e155
Merge pull request #41 from euler-xyz/feat/erc20votes
haythemsellami Jul 24, 2024
d8b61d5
Merge branch 'main' into chore/add-echidna-CI
haythemsellami Jul 24, 2024
db658b2
Merge pull request #44 from euler-xyz/chore/add-echidna-CI
haythemsellami Jul 24, 2024
d581e67
Remove plugin
haythemsellami Jul 25, 2024
8a5283a
import WithdrawalQueueModule
haythemsellami Jul 25, 2024
bde1183
clean
haythemsellami Jul 25, 2024
7392b00
refactor
haythemsellami Jul 25, 2024
a632098
refactor hooks storage
haythemsellami Jul 25, 2024
d74f60e
Merge pull request #45 from euler-xyz/remove-plugin
haythemsellami Jul 25, 2024
3de0031
Refactor _deductLoss()
haythemsellami Jul 25, 2024
a18db08
clean
haythemsellami Jul 26, 2024
4ee8e24
lint
haythemsellami Jul 26, 2024
44b7b47
clean
haythemsellami Jul 26, 2024
9a6c460
clean
haythemsellami Jul 26, 2024
b808a39
Merge pull request #46 from euler-xyz/refactor-deduct-loss
haythemsellami Jul 26, 2024
fcade52
Feat: mint fee shares
haythemsellami Jul 30, 2024
5e3f1bd
fix test:
haythemsellami Jul 30, 2024
7c26e98
fix invariants
haythemsellami Jul 30, 2024
5c05f3d
fix
haythemsellami Jul 30, 2024
b8f1162
fix
haythemsellami Jul 30, 2024
1237522
fix
haythemsellami Jul 30, 2024
a50bfef
fix
haythemsellami Jul 30, 2024
7751a08
fix
haythemsellami Jul 30, 2024
7041292
fix
haythemsellami Jul 30, 2024
cf6851c
Merge pull request #48 from euler-xyz/fix/ci
haythemsellami Jul 31, 2024
25ea7d0
chore: commentS
haythemsellami Jul 31, 2024
2bfb7a9
Merge pull request #47 from euler-xyz/feat/mint-fee
haythemsellami Jul 31, 2024
53de3ac
Change performanceFee to uint96
haythemsellami Jul 31, 2024
a0c696f
feat: harvest cooldown
haythemsellami Aug 1, 2024
f4c2caf
remove gulp after withdraW
haythemsellami Aug 1, 2024
e660347
improve invariants
haythemsellami Aug 1, 2024
1a5ee69
update test:
haythemsellami Aug 5, 2024
ea8f01e
Merge pull request #49 from euler-xyz/feat/harvest-interval
haythemsellami Aug 5, 2024
1fe9f9d
chore: update EVC dependency
haythemsellami Aug 5, 2024
9be83cd
feat: EVC integration
haythemsellami Aug 5, 2024
542d1d3
Add onlyEVCAccountOwner() modifier
haythemsellami Aug 6, 2024
4fcc7fe
chore: update dependency
haythemsellami Aug 6, 2024
4f3c54b
Merge pull request #50 from euler-xyz/evc-integration
haythemsellami Aug 6, 2024
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
15 changes: 13 additions & 2 deletions src/core/Dispatch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@ import {RewardsModule} from "./module/Rewards.sol";
import {StrategyModule} from "./module/Strategy.sol";
import {FeeModule} from "./module/Fee.sol";
import {RebalanceModule} from "./module/Rebalance.sol";
import {WithdrawalQueueModule} from "./module/WithdrawalQueue.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, FeeModule, StrategyModule, RebalanceModule {
abstract contract Dispatch is
RewardsModule,
HooksModule,
FeeModule,
StrategyModule,
RebalanceModule,
WithdrawalQueueModule
{
address public immutable rewardsModule;
address public immutable hooksModule;
address public immutable feeModule;
address public immutable strategyModule;
address public immutable rebalanceModule;
address public immutable withdrawalQueueModule;

/// @dev Constructor.
/// @param _rewardsModule Address of Rewards module.
Expand All @@ -31,13 +40,15 @@ abstract contract Dispatch is RewardsModule, HooksModule, FeeModule, StrategyMod
address _hooksModule,
address _feeModule,
address _strategyModule,
address _rebalanceModule
address _rebalanceModule,
address _withdrawalQueueModule
) {
rewardsModule = _rewardsModule;
hooksModule = _hooksModule;
feeModule = _feeModule;
strategyModule = _strategyModule;
rebalanceModule = _rebalanceModule;
withdrawalQueueModule = _withdrawalQueueModule;
}

// Modifier proxies the function call to a module and low-level returns the result
Expand Down
147 changes: 65 additions & 82 deletions src/core/EulerAggregationVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IBalanceTracker} from "reward-streams/interfaces/IBalanceTracker.sol";
import {IEulerAggregationVault} from "./interface/IEulerAggregationVault.sol";
import {IWithdrawalQueue} from "./interface/IWithdrawalQueue.sol";
// contracts
import {Dispatch} from "./Dispatch.sol";
import {
Expand Down Expand Up @@ -49,6 +48,8 @@ contract EulerAggregationVault is
bytes32 public constant STRATEGY_OPERATOR_ADMIN = keccak256("STRATEGY_OPERATOR_ADMIN");
bytes32 public constant AGGREGATION_VAULT_MANAGER = keccak256("AGGREGATION_VAULT_MANAGER");
bytes32 public constant AGGREGATION_VAULT_MANAGER_ADMIN = keccak256("AGGREGATION_VAULT_MANAGER_ADMIN");
bytes32 public constant WITHDRAWAL_QUEUE_MANAGER = keccak256("WITHDRAWAL_QUEUE_MANAGER");
bytes32 public constant WITHDRAWAL_QUEUE_MANAGER_ADMIN = keccak256("WITHDRAWAL_QUEUE_MANAGER_ADMIN");

/// @dev Constructor.
constructor(ConstructorParams memory _constructorParams)
Expand All @@ -57,7 +58,8 @@ contract EulerAggregationVault is
_constructorParams.hooksModule,
_constructorParams.feeModule,
_constructorParams.strategyModule,
_constructorParams.rebalanceModule
_constructorParams.rebalanceModule,
_constructorParams.withdrawalQueueModule
)
{}

Expand All @@ -72,7 +74,6 @@ contract EulerAggregationVault is

AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();
$.locked = REENTRANCYLOCK__UNLOCKED;
$.withdrawalQueue = _initParams.withdrawalQueuePlugin;
$.balanceTracker = _initParams.balanceTracker;
$.strategies[address(0)] = IEulerAggregationVault.Strategy({
allocated: 0,
Expand All @@ -89,8 +90,7 @@ contract EulerAggregationVault is
_setRoleAdmin(GUARDIAN, GUARDIAN_ADMIN);
_setRoleAdmin(STRATEGY_OPERATOR, STRATEGY_OPERATOR_ADMIN);
_setRoleAdmin(AGGREGATION_VAULT_MANAGER, AGGREGATION_VAULT_MANAGER_ADMIN);

IWithdrawalQueue(_initParams.withdrawalQueuePlugin).init(_initParams.aggregationVaultOwner);
_setRoleAdmin(WITHDRAWAL_QUEUE_MANAGER, WITHDRAWAL_QUEUE_MANAGER_ADMIN);
}

/// @dev See {FeeModule-setFeeRecipient}.
Expand Down Expand Up @@ -188,8 +188,17 @@ contract EulerAggregationVault is
/// @dev See {RewardsModule-disableBalanceForwarder}.
function disableBalanceForwarder() external override use(rewardsModule) {}

/// @dev See {RebalanceModule-rebalance}.
function rebalance(address[] calldata _strategies) external override use(rebalanceModule) {}

/// @dev See {WithdrawalQueue-reorderWithdrawalQueue}.
function reorderWithdrawalQueue(uint8 _index1, uint8 _index2)
external
override
onlyRole(WITHDRAWAL_QUEUE_MANAGER)
use(withdrawalQueueModule)
{}

/// @notice Harvest all the strategies. Any positive yiled should be gupled by calling gulp() after harvesting.
/// @dev This function will loop through the strategies following the withdrawal queue order and harvest all.
/// @dev Harvest yield and losses will be aggregated and only net yield/loss will be accounted.
Expand All @@ -200,7 +209,7 @@ contract EulerAggregationVault is
}

/// @notice update accrued interest
function updateInterestAccrued() external {
function updateInterestAccrued() external nonReentrant {
return _updateInterestAccrued();
}

Expand All @@ -209,53 +218,6 @@ contract EulerAggregationVault is
_gulp();
}

/// @notice Execute a withdraw from a strategy.
/// @dev Can only be called from the WithdrawalQueue contract.
/// @param _strategy Strategy's address.
/// @param _withdrawAmount Amount to withdraw.
function executeStrategyWithdraw(address _strategy, uint256 _withdrawAmount) external returns (uint256) {
_isCallerWithdrawalQueue();

AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();

if ($.strategies[_strategy].status != IEulerAggregationVault.StrategyStatus.Active) return 0;

// Update allocated assets
$.strategies[_strategy].allocated -= uint120(_withdrawAmount);
$.totalAllocated -= _withdrawAmount;

// Do actual withdraw from strategy
IERC4626(_strategy).withdraw(_withdrawAmount, address(this), address(this));

return _withdrawAmount;
}

/// @notice Execute a withdraw from the AggregationVault
/// @dev This function should be called and can only be called by the WithdrawalQueue.
/// @param _caller Withdraw call initiator.
/// @param _receiver Receiver of the withdrawn asset.
/// @param _owner Owner of shares to withdraw against.
/// @param _assets Amount of asset to withdraw.
/// @param _shares Amount of shares to withdraw against.
function executeAggregationVaultWithdraw(
address _caller,
address _receiver,
address _owner,
uint256 _assets,
uint256 _shares
) external {
_isCallerWithdrawalQueue();

if (_receiver == address(this)) revert Errors.CanNotReceiveWithdrawnAsset();

AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();
$.totalAssetsDeposited -= _assets;

super._withdraw(_caller, _receiver, _owner, _assets, _shares);

_gulp();
}

/// @notice Get strategy params.
/// @param _strategy strategy's address
/// @return Strategy struct
Expand All @@ -272,7 +234,7 @@ contract EulerAggregationVault is
}

/// @notice Get saving rate data.
/// @return avsr AggregationVaultSavingRate struct.
/// @return AggregationVaultSavingRate struct.
function getAggregationVaultSavingRate() external view returns (AggregationVaultSavingRate memory) {
AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();
AggregationVaultSavingRate memory avsr = AggregationVaultSavingRate({
Expand Down Expand Up @@ -308,23 +270,23 @@ contract EulerAggregationVault is
return $.totalAssetsDeposited;
}

/// @notice Get the WithdrawalQueue plugin address.
/// @return address Withdrawal queue address.
function withdrawalQueue() external view returns (address) {
AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();

return $.withdrawalQueue;
}

/// @notice Get the performance fee config.
/// @return adddress Fee recipient.
/// @return uint256 Fee percentage.
function performanceFeeConfig() external view returns (address, uint256) {
function performanceFeeConfig() external view virtual returns (address, uint256) {
AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();

return ($.feeRecipient, $.performanceFee);
}

/// @notice Return the withdrawal queue length.
/// @return uint256 length.
function withdrawalQueue() external view virtual returns (address[] memory) {
AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();

return $.withdrawalQueue;
}

/// @dev See {IERC4626-deposit}.
/// @dev Call DEPOSIT hook if enabled.
function deposit(uint256 _assets, address _receiver) public override nonReentrant returns (uint256) {
Expand Down Expand Up @@ -393,10 +355,8 @@ contract EulerAggregationVault is
/// @notice get the total assets allocatable
/// @dev the total assets allocatable is the amount of assets deposited into the aggregator + assets already deposited into strategies
/// @return uint256 total assets
function totalAssetsAllocatable() public view returns (uint256) {
AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();

return IERC20(asset()).balanceOf(address(this)) + $.totalAllocated;
function totalAssetsAllocatable() external view returns (uint256) {
return _totalAssetsAllocatable();
}

/// @dev See {IERC4626-_deposit}.
Expand All @@ -417,9 +377,42 @@ contract EulerAggregationVault is
AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();
uint256 assetsRetrieved = IERC20(asset()).balanceOf(address(this));

IWithdrawalQueue($.withdrawalQueue).callWithdrawalQueue(
_caller, _receiver, _owner, _assets, _shares, assetsRetrieved
);
if (assetsRetrieved < _assets) {
uint256 numStrategies = $.withdrawalQueue.length;
for (uint256 i; i < numStrategies; ++i) {
IERC4626 strategy = IERC4626($.withdrawalQueue[i]);

if ($.strategies[address(strategy)].status != IEulerAggregationVault.StrategyStatus.Active) continue;

uint256 underlyingBalance = strategy.maxWithdraw(address(this));
uint256 desiredAssets = _assets - assetsRetrieved;
uint256 withdrawAmount = (underlyingBalance > desiredAssets) ? desiredAssets : underlyingBalance;

// Update allocated assets
$.strategies[address(strategy)].allocated -= uint120(withdrawAmount);
$.totalAllocated -= withdrawAmount;

// Do actual withdraw from strategy
IERC4626(address(strategy)).withdraw(withdrawAmount, address(this), address(this));

// update _availableAssets
assetsRetrieved += withdrawAmount;

if (assetsRetrieved >= _assets) {
break;
}
}
}

if (assetsRetrieved < _assets) {
revert Errors.NotEnoughAssets();
}

$.totalAssetsDeposited -= _assets;

super._withdraw(_caller, _receiver, _owner, _assets, _shares);

_gulp();
}

/// @dev Loop through stratgies, aggregate positive yield and loss and account for net amount.
Expand All @@ -430,13 +423,10 @@ contract EulerAggregationVault is

AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();

(address[] memory withdrawalQueueArray, uint256 length) =
IWithdrawalQueue($.withdrawalQueue).getWithdrawalQueueArray();

uint256 totalYield;
uint256 totalLoss;
for (uint256 i; i < length; ++i) {
(uint256 yield, uint256 loss) = _executeHarvest(withdrawalQueueArray[i]);
for (uint256 i; i < $.withdrawalQueue.length; ++i) {
(uint256 yield, uint256 loss) = _executeHarvest($.withdrawalQueue[i]);

totalYield += yield;
totalLoss += loss;
Expand Down Expand Up @@ -539,11 +529,4 @@ contract EulerAggregationVault is
balanceTracker.balanceTrackerHook(to, super.balanceOf(to), false);
}
}

/// @dev Check if caller is WithdrawalQueue address, if not revert.
function _isCallerWithdrawalQueue() internal view {
AggregationVaultStorage storage $ = Storage._getAggregationVaultStorage();

if (msg.sender != $.withdrawalQueue) revert Errors.NotWithdrawaQueue();
}
}
14 changes: 7 additions & 7 deletions src/core/EulerAggregationVaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract EulerAggregationVaultFactory {
address public immutable feeModule;
address public immutable strategyModule;
address public immutable rebalanceModule;
address public immutable withdrawalQueueModule;
/// aggregation vault implementation address
address public immutable aggregationVaultImpl;

Expand All @@ -34,11 +35,10 @@ contract EulerAggregationVaultFactory {
address feeModuleImpl;
address strategyModuleImpl;
address rebalanceModuleImpl;
address withdrawalQueueModuleImpl;
}

event DeployEulerAggregationVault(
address indexed _owner, address _aggregationVault, address indexed _withdrawalQueueImpl, address indexed _asset
);
event DeployEulerAggregationVault(address indexed _owner, address _aggregationVault, address indexed _asset);

/// @notice Constructor.
/// @param _factoryParams FactoryParams struct.
Expand All @@ -49,14 +49,16 @@ contract EulerAggregationVaultFactory {
feeModule = Clones.clone(_factoryParams.feeModuleImpl);
strategyModule = Clones.clone(_factoryParams.strategyModuleImpl);
rebalanceModule = Clones.clone(_factoryParams.rebalanceModuleImpl);
withdrawalQueueModule = Clones.clone(_factoryParams.withdrawalQueueModuleImpl);

IEulerAggregationVault.ConstructorParams memory aggregationVaultConstructorParams = IEulerAggregationVault
.ConstructorParams({
rewardsModule: rewardsModule,
hooksModule: hooksModule,
feeModule: feeModule,
strategyModule: strategyModule,
rebalanceModule: rebalanceModule
rebalanceModule: rebalanceModule,
withdrawalQueueModule: withdrawalQueueModule
});
aggregationVaultImpl = address(new EulerAggregationVault(aggregationVaultConstructorParams));
}
Expand All @@ -71,7 +73,6 @@ contract EulerAggregationVaultFactory {
/// @param _initialCashAllocationPoints The amount of points to initally allocate for cash reserve.
/// @return eulerAggregationVault The address of the new deployed aggregation vault.
function deployEulerAggregationVault(
address _withdrawalQueueImpl,
address _asset,
string memory _name,
string memory _symbol,
Expand All @@ -82,7 +83,6 @@ contract EulerAggregationVaultFactory {
IEulerAggregationVault.InitParams memory aggregationVaultInitParams = IEulerAggregationVault.InitParams({
aggregationVaultOwner: msg.sender,
asset: _asset,
withdrawalQueuePlugin: Clones.clone(_withdrawalQueueImpl),
balanceTracker: balanceTracker,
name: _name,
symbol: _symbol,
Expand All @@ -92,7 +92,7 @@ contract EulerAggregationVaultFactory {

aggregationVaults.push(address(eulerAggregationVault));

emit DeployEulerAggregationVault(msg.sender, address(eulerAggregationVault), _withdrawalQueueImpl, _asset);
emit DeployEulerAggregationVault(msg.sender, address(eulerAggregationVault), _asset);

return eulerAggregationVault;
}
Expand Down
Loading
Loading