-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathERC4626UpgradeableSafe.sol
43 lines (36 loc) · 1.77 KB
/
ERC4626UpgradeableSafe.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
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;
import {ERC4626Upgradeable, ERC20Upgradeable, IERC20MetadataUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
/// @title ERC4626UpgradeableSafe.
/// @author Morpho Labs.
/// @custom:contact [email protected]
/// @notice ERC4626 Tokenized Vault abstract upgradeable implementation tweaking OZ's implementation to make it safer at initialization.
abstract contract ERC4626UpgradeableSafe is ERC4626Upgradeable {
/// CONSTRUCTOR ///
/// @dev The contract automatically disables initializers when deployed so that nobody can highjack the implementation contract.
constructor() {
_disableInitializers();
}
/// INITIALIZER ///
function __ERC4626UpgradeableSafe_init(
IERC20MetadataUpgradeable _asset,
uint256 _initialDeposit
) internal onlyInitializing {
__ERC4626_init_unchained(_asset);
__ERC4626UpgradeableSafe_init_unchained(_initialDeposit);
}
function __ERC4626UpgradeableSafe_init_unchained(uint256 _initialDeposit)
internal
onlyInitializing
{
// Sacrifice an initial seed of shares to ensure a healthy amount of precision in minting shares.
// Set to 0 at your own risk.
// Caller must have approved the asset to this contract's address.
// See: https://github.com/Rari-Capital/solmate/issues/178
if (_initialDeposit > 0) deposit(_initialDeposit, address(this));
}
/// @dev This empty reserved space is put in place to allow future versions to add new
/// variables without shifting down storage in the inheritance chain.
/// See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
uint256[50] private __gap;
}