-
Notifications
You must be signed in to change notification settings - Fork 4
/
PeriodicAllocationPerfFeeMetaVault.sol
237 lines (212 loc) · 8.44 KB
/
PeriodicAllocationPerfFeeMetaVault.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
//Libs
import { SameAssetUnderlyingsAbstractVault } from "../allocate/SameAssetUnderlyingsAbstractVault.sol";
import { AssetPerShareAbstractVault } from "../allocate/AssetPerShareAbstractVault.sol";
import { PeriodicAllocationAbstractVault } from "../allocate/PeriodicAllocationAbstractVault.sol";
import { PerfFeeAbstractVault } from "../fee/PerfFeeAbstractVault.sol";
import { FeeAdminAbstractVault } from "../fee/FeeAdminAbstractVault.sol";
import { AbstractVault } from "../AbstractVault.sol";
import { VaultManagerRole } from "../../shared/VaultManagerRole.sol";
import { InitializableToken } from "../../tokens/InitializableToken.sol";
/**
* @notice EIP-4626 vault that periodically invests 3CRV in the underlying vaults and charge performance fees
* @author mStable
* @dev VERSION: 1.0
* DATE: 2022-05-27
*/
contract PeriodicAllocationPerfFeeMetaVault is
PeriodicAllocationAbstractVault,
PerfFeeAbstractVault,
Initializable
{
/// @param _nexus Address of the Nexus contract that resolves protocol modules and roles.
/// @param _asset Address of the vault's underlying asset which is one of DAI/USDC/USDT
constructor(address _nexus, address _asset) AbstractVault(_asset) VaultManagerRole(_nexus) {}
/// @notice have to override this function
/// @dev dummy function
function _initialize(address dummy)
internal
virtual
override(FeeAdminAbstractVault, VaultManagerRole)
{}
/**
* @param _name Name of Vault token
* @param _symbol Symbol of vault token
* @param _vaultManager Trusted account that can perform vault operations. eg rebalance.
* @param _performanceFee Performance fee to be charged
* @param _feeReceiver Account that receives fees in the form of vault shares.
* @param _underlyingVaults The underlying vaults address to invest into.
* @param _sourceParams Params related to sourcing of assets
* @param _assetPerShareUpdateThreshold threshold amount of transfers to/from for assetPerShareUpdate
* @param _assetToBurn amount of assets that will be deposited and corresponding shares locked permanently
*/
function initialize(
string calldata _name,
string calldata _symbol,
address _vaultManager,
uint24 _performanceFee,
address _feeReceiver,
address[] memory _underlyingVaults,
AssetSourcingParams memory _sourceParams,
uint256 _assetPerShareUpdateThreshold,
uint256 _assetToBurn
) external initializer {
require(
_sourceParams.singleSourceVaultIndex < _underlyingVaults.length,
"Invalid source vault index"
);
// Set the vault's decimals to the same as the reference asset.
uint8 decimals_ = InitializableToken(address(_asset)).decimals();
InitializableToken._initialize(_name, _symbol, decimals_);
// Initialize contracts
VaultManagerRole._initialize(_vaultManager);
PerfFeeAbstractVault._initialize(_performanceFee);
SameAssetUnderlyingsAbstractVault._initialize(_underlyingVaults);
AssetPerShareAbstractVault._initialize();
PeriodicAllocationAbstractVault._initialize(_sourceParams, _assetPerShareUpdateThreshold);
FeeAdminAbstractVault._initialize(_feeReceiver);
AbstractVault._initialize(_assetToBurn);
}
/*///////////////////////////////////////////////////////////////
DEPOSIT/MINT
//////////////////////////////////////////////////////////////*/
/// @dev use PeriodicAllocationAbstractVault implementation.
function _deposit(uint256 assets, address receiver)
internal
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 shares)
{
return PeriodicAllocationAbstractVault._deposit(assets, receiver);
}
/// @dev use PeriodicAllocationAbstractVault implementation.
function _previewDeposit(uint256 assets)
internal
view
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 shares)
{
return PeriodicAllocationAbstractVault._previewDeposit(assets);
}
/// @dev use PeriodicAllocationAbstractVault implementation.
function _mint(uint256 shares, address receiver)
internal
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 assets)
{
return PeriodicAllocationAbstractVault._mint(shares, receiver);
}
/// @dev use PeriodicAllocationAbstractVault implementation.
function _previewMint(uint256 shares)
internal
view
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 assets)
{
return PeriodicAllocationAbstractVault._previewMint(shares);
}
/*///////////////////////////////////////////////////////////////
WITHDRAW/REDEEM
//////////////////////////////////////////////////////////////*/
/// @dev use PeriodicAllocationAbstractVault implementation.
function _withdraw(
uint256 assets,
address receiver,
address owner
)
internal
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 shares)
{
return PeriodicAllocationAbstractVault._withdraw(assets, receiver, owner);
}
/// @dev use PeriodicAllocationAbstractVault implementation.
function _previewWithdraw(uint256 assets)
internal
view
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 shares)
{
return PeriodicAllocationAbstractVault._previewWithdraw(assets);
}
/// @dev use PeriodicAllocationAbstractVault implementation.
function _redeem(
uint256 shares,
address receiver,
address owner
)
internal
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 assets)
{
return PeriodicAllocationAbstractVault._redeem(shares, receiver, owner);
}
/// @dev use PeriodicAllocationAbstractVault implementation.
function _previewRedeem(uint256 shares)
internal
view
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 assets)
{
return PeriodicAllocationAbstractVault._previewRedeem(shares);
}
/*///////////////////////////////////////////////////////////////
CONVERTIONS
//////////////////////////////////////////////////////////////*/
/// @dev use PeriodicAllocationAbstractVault implementation.
function _convertToAssets(uint256 shares, bool isRoundUp)
internal
view
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 assets)
{
return PeriodicAllocationAbstractVault._convertToAssets(shares, isRoundUp);
}
/// @dev use PeriodicAllocationAbstractVault implementation.
function _convertToShares(uint256 assets, bool isRoundUp)
internal
view
virtual
override(AbstractVault, PeriodicAllocationAbstractVault)
returns (uint256 shares)
{
return PeriodicAllocationAbstractVault._convertToShares(assets, isRoundUp);
}
/***************************************
Vault Hooks
****************************************/
function _afterDepositHook(
uint256 assets,
uint256,
address,
bool
) internal virtual override {
// Assets are held in the vault after deposit and mint so this hook is not needed.
// Assets are deposited using the `settle` function to the underlying
}
function _beforeWithdrawHook(
uint256 assets,
uint256,
address,
bool
) internal virtual override {
// Assets are withdrawn from the underlying using the `sourceAssets` function if there are not enough assets in this vault.
}
/***************************************
Internal Hooks
****************************************/
/// @dev update assetPerShare after charging performance fees
function _afterChargePerformanceFee() internal virtual override {
_updateAssetPerShare();
}
}