• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

delvtech / hyperdrive / 9928368899

14 Jul 2024 01:43PM UTC coverage: 92.237%. First build
9928368899

Pull #1081

github

jalextowle
Added a getter for Aave's vault
Pull Request #1081: Added an Aave integration

120 of 143 new or added lines in 33 files covered. (83.92%)

2115 of 2293 relevant lines covered (92.24%)

376490.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.23
/contracts/src/deployers/erc4626/ERC4626HyperdriveDeployerCoordinator.sol
1
// SPDX-License-Identifier: Apache-2.0
2
pragma solidity 0.8.20;
3

4
import { ERC20 } from "openzeppelin/token/ERC20/ERC20.sol";
5
import { SafeERC20 } from "openzeppelin/token/ERC20/utils/SafeERC20.sol";
6
import { ERC4626Conversions } from "../../instances/erc4626/ERC4626Conversions.sol";
7
import { IERC20 } from "../../interfaces/IERC20.sol";
8
import { IERC4626 } from "../../interfaces/IERC4626.sol";
9
import { IERC4626HyperdriveDeployerCoordinator } from "../../interfaces/IERC4626HyperdriveDeployerCoordinator.sol";
10
import { IHyperdrive } from "../../interfaces/IHyperdrive.sol";
11
import { IHyperdriveDeployerCoordinator } from "../../interfaces/IHyperdriveDeployerCoordinator.sol";
12
import { ERC4626_HYPERDRIVE_DEPLOYER_COORDINATOR_KIND } from "../../libraries/Constants.sol";
13
import { ONE } from "../../libraries/FixedPointMath.sol";
14
import { HyperdriveDeployerCoordinator } from "../HyperdriveDeployerCoordinator.sol";
15

16
/// @author DELV
17
/// @title ERC4626HyperdriveDeployerCoordinator
18
/// @notice The deployer coordinator for the ERC4626Hyperdrive implementation.
19
/// @custom:disclaimer The language used in this code is for coding convenience
20
///                    only, and is not intended to, and does not, have any
21
///                    particular legal or regulatory significance.
22
contract ERC4626HyperdriveDeployerCoordinator is
23
    HyperdriveDeployerCoordinator,
24
    IERC4626HyperdriveDeployerCoordinator
25
{
26
    using SafeERC20 for ERC20;
27

28
    /// @notice The deployer coordinator's kind.
29
    string
30
        public constant
31
        override(
32
            HyperdriveDeployerCoordinator,
33
            IHyperdriveDeployerCoordinator
34
        ) kind = ERC4626_HYPERDRIVE_DEPLOYER_COORDINATOR_KIND;
35

36
    /// @notice Instantiates the deployer coordinator.
37
    /// @param _name The deployer coordinator's name.
38
    /// @param _factory The factory that this deployer will be registered with.
39
    /// @param _coreDeployer The core deployer.
40
    /// @param _target0Deployer The target0 deployer.
41
    /// @param _target1Deployer The target1 deployer.
42
    /// @param _target2Deployer The target2 deployer.
43
    /// @param _target3Deployer The target3 deployer.
44
    /// @param _target4Deployer The target4 deployer.
45
    constructor(
46
        string memory _name,
47
        address _factory,
48
        address _coreDeployer,
49
        address _target0Deployer,
50
        address _target1Deployer,
51
        address _target2Deployer,
52
        address _target3Deployer,
53
        address _target4Deployer
54
    )
55
        HyperdriveDeployerCoordinator(
56
            _name,
57
            _factory,
58
            _coreDeployer,
59
            _target0Deployer,
60
            _target1Deployer,
61
            _target2Deployer,
62
            _target3Deployer,
63
            _target4Deployer
64
        )
65
    {}
66

67
    /// @dev Prepares the coordinator for initialization by drawing funds from
68
    ///      the LP, if necessary.
69
    /// @param _hyperdrive The Hyperdrive instance that is being initialized.
70
    /// @param _lp The LP that is initializing the pool.
71
    /// @param _contribution The amount of capital to supply. The units of this
72
    ///        quantity are either base or vault shares, depending on the value
73
    ///        of `_options.asBase`.
74
    /// @param _options The options that configure how the initialization is
75
    ///        settled.
76
    /// @return The value that should be sent in the initialize transaction.
77
    function _prepareInitialize(
78
        IHyperdrive _hyperdrive,
79
        address _lp,
80
        uint256 _contribution,
81
        IHyperdrive.Options memory _options
82
    ) internal override returns (uint256) {
83
        // If base is the deposit asset, the initialization will be paid in the
84
        // base token.
85
        address token;
1,644✔
86
        if (_options.asBase) {
1,644✔
87
            token = _hyperdrive.baseToken();
1,644✔
88
        }
89
        // Otherwise, the initialization will be paid in vault shares.
90
        else {
91
            token = _hyperdrive.vaultSharesToken();
×
92
        }
93

94
        // Take custody of the contribution and approve Hyperdrive to pull the
95
        // tokens.
96
        ERC20(token).safeTransferFrom(_lp, address(this), _contribution);
1,644✔
97
        ERC20(token).forceApprove(address(_hyperdrive), _contribution);
1,644✔
98

99
        // NOTE: Return zero since this yield source isn't payable.
100
        return 0;
1,644✔
101
    }
102

103
    /// @notice Convert an amount of vault shares to an amount of base.
104
    /// @param _vaultSharesToken The vault shares asset.
105
    /// @param _shareAmount The vault shares amount.
106
    /// @return The base amount.
107
    function convertToBase(
108
        IERC20 _vaultSharesToken,
109
        uint256 _shareAmount
110
    ) public view returns (uint256) {
111
        return
1,644✔
112
            ERC4626Conversions.convertToBase(_vaultSharesToken, _shareAmount);
1,644✔
113
    }
114

115
    /// @notice Convert an amount of base to an amount of vault shares.
116
    /// @param _vaultSharesToken The vault shares asset.
117
    /// @param _baseAmount The base amount.
118
    /// @return The vault shares amount.
119
    function convertToShares(
120
        IERC20 _vaultSharesToken,
121
        uint256 _baseAmount
122
    ) public view returns (uint256) {
NEW
123
        return
×
NEW
124
            ERC4626Conversions.convertToShares(_vaultSharesToken, _baseAmount);
×
125
    }
126

127
    /// @dev We override the message value check since this integration is
128
    ///      not payable.
129
    function _checkMessageValue() internal view override {
130
        if (msg.value != 0) {
1,644✔
131
            revert IHyperdriveDeployerCoordinator.NotPayable();
×
132
        }
133
    }
134

135
    /// @notice Checks the pool configuration to ensure that it is valid.
136
    /// @param _deployConfig The deploy configuration of the Hyperdrive pool.
137
    function _checkPoolConfig(
138
        IHyperdrive.PoolDeployConfig memory _deployConfig
139
    ) internal view override {
140
        // Perform the default checks.
141
        super._checkPoolConfig(_deployConfig);
9,864✔
142

143
        // Ensure that the vault shares token address is non-zero.
144
        if (address(_deployConfig.vaultSharesToken) == address(0)) {
9,864✔
145
            revert IHyperdriveDeployerCoordinator.InvalidVaultSharesToken();
×
146
        }
147

148
        // Ensure that the base token address is properly configured.
149
        if (
150
            address(_deployConfig.baseToken) !=
9,864✔
151
            IERC4626(address(_deployConfig.vaultSharesToken)).asset()
9,864✔
152
        ) {
153
            revert IHyperdriveDeployerCoordinator.InvalidBaseToken();
×
154
        }
155

156
        // Ensure that the minimum share reserves are large enough to meet the
157
        // minimum requirements for safety.
158
        //
159
        // NOTE: Some pools may require larger minimum share reserves to be
160
        // considered safe. This is just a sanity check.
161
        if (
162
            _deployConfig.minimumShareReserves <
9,864✔
163
            10 ** (_deployConfig.baseToken.decimals() - 3)
9,864✔
164
        ) {
165
            revert IHyperdriveDeployerCoordinator.InvalidMinimumShareReserves();
×
166
        }
167

168
        // Ensure that the minimum transaction amount is large enough to meet
169
        // the minimum requirements for safety.
170
        //
171
        // NOTE: Some pools may require larger minimum transaction amounts to be
172
        // considered safe. This is just a sanity check.
173
        if (
174
            _deployConfig.minimumTransactionAmount <
9,864✔
175
            10 ** (_deployConfig.baseToken.decimals() - 3)
9,864✔
176
        ) {
177
            revert IHyperdriveDeployerCoordinator
×
178
                .InvalidMinimumTransactionAmount();
179
        }
180
    }
181

182
    /// @dev Gets the initial vault share price of the Hyperdrive pool.
183
    /// @param _deployConfig The deploy config that will be used to deploy the
184
    ///        pool.
185
    /// @return The initial vault share price of the Hyperdrive pool.
186
    function _getInitialVaultSharePrice(
187
        IHyperdrive.PoolDeployConfig memory _deployConfig,
188
        bytes memory // unused extra data
189
    ) internal view override returns (uint256) {
190
        return convertToBase(_deployConfig.vaultSharesToken, ONE);
1,644✔
191
    }
192
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc