generated from ZeframLou/foundry-template
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathAaveV3ERC4626Factory.sol
83 lines (67 loc) · 3.27 KB
/
AaveV3ERC4626Factory.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
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.13;
import {ERC20} from "solmate/tokens/ERC20.sol";
import {ERC4626} from "solmate/mixins/ERC4626.sol";
import {IPool} from "./external/IPool.sol";
import {AaveV3ERC4626} from "./AaveV3ERC4626.sol";
import {ERC4626Factory} from "../base/ERC4626Factory.sol";
import {IRewardsController} from "./external/IRewardsController.sol";
/// @title AaveV3ERC4626Factory
/// @author zefram.eth
/// @notice Factory for creating AaveV3ERC4626 contracts
contract AaveV3ERC4626Factory is ERC4626Factory {
/// -----------------------------------------------------------------------
/// Errors
/// -----------------------------------------------------------------------
/// @notice Thrown when trying to deploy an AaveV3ERC4626 vault using an asset without an aToken
error AaveV3ERC4626Factory__ATokenNonexistent();
/// -----------------------------------------------------------------------
/// Immutable params
/// -----------------------------------------------------------------------
/// @notice The Aave Pool contract
IPool public immutable lendingPool;
/// @notice The address that will receive the liquidity mining rewards (if any)
address public immutable rewardRecipient;
/// @notice The Aave RewardsController contract
IRewardsController public immutable rewardsController;
/// -----------------------------------------------------------------------
/// Constructor
/// -----------------------------------------------------------------------
constructor(IPool lendingPool_, address rewardRecipient_, IRewardsController rewardsController_) {
lendingPool = lendingPool_;
rewardRecipient = rewardRecipient_;
rewardsController = rewardsController_;
}
/// -----------------------------------------------------------------------
/// External functions
/// -----------------------------------------------------------------------
/// @inheritdoc ERC4626Factory
function createERC4626(ERC20 asset) external virtual override returns (ERC4626 vault) {
IPool.ReserveData memory reserveData = lendingPool.getReserveData(address(asset));
address aTokenAddress = reserveData.aTokenAddress;
if (aTokenAddress == address(0)) {
revert AaveV3ERC4626Factory__ATokenNonexistent();
}
vault = new AaveV3ERC4626{salt: bytes32(0)}(
asset, ERC20(aTokenAddress), lendingPool, rewardRecipient, rewardsController
);
emit CreateERC4626(asset, vault);
}
/// @inheritdoc ERC4626Factory
function computeERC4626Address(ERC20 asset) external view virtual override returns (ERC4626 vault) {
IPool.ReserveData memory reserveData = lendingPool.getReserveData(address(asset));
address aTokenAddress = reserveData.aTokenAddress;
vault = ERC4626(
_computeCreate2Address(
keccak256(
abi.encodePacked(
// Deployment bytecode:
type(AaveV3ERC4626).creationCode,
// Constructor arguments:
abi.encode(asset, ERC20(aTokenAddress), lendingPool, rewardRecipient, rewardsController)
)
)
)
);
}
}