• 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

77.78
/contracts/src/deployers/aave/AaveHyperdriveDeployerCoordinator.sol
1
// SPDX-License-Identifier: Apache-2.0
2
pragma solidity 0.8.20;
3

4
import { IPool } from "aave/interfaces/IPool.sol";
5
import { ERC20 } from "openzeppelin/token/ERC20/ERC20.sol";
6
import { SafeERC20 } from "openzeppelin/token/ERC20/utils/SafeERC20.sol";
7
import { AaveConversions } from "../../instances/aave/AaveConversions.sol";
8
import { IAaveHyperdriveDeployerCoordinator } from "../../interfaces/IAaveHyperdriveDeployerCoordinator.sol";
9
import { IAToken } from "../../interfaces/IAToken.sol";
10
import { IERC20 } from "../../interfaces/IERC20.sol";
11
import { IHyperdrive } from "../../interfaces/IHyperdrive.sol";
12
import { IHyperdriveDeployerCoordinator } from "../../interfaces/IHyperdriveDeployerCoordinator.sol";
13
import { AAVE_HYPERDRIVE_DEPLOYER_COORDINATOR_KIND } from "../../libraries/Constants.sol";
14
import { FixedPointMath } from "../../libraries/FixedPointMath.sol";
15
import { ONE } from "../../libraries/FixedPointMath.sol";
16
import { HyperdriveDeployerCoordinator } from "../HyperdriveDeployerCoordinator.sol";
17

18
/// @author DELV
19
/// @title AaveHyperdriveDeployerCoordinator
20
/// @notice The deployer coordinator for the AaveHyperdrive
21
///         implementation.
22
/// @custom:disclaimer The language used in this code is for coding convenience
23
///                    only, and is not intended to, and does not, have any
24
///                    particular legal or regulatory significance.
25
contract AaveHyperdriveDeployerCoordinator is
26
    HyperdriveDeployerCoordinator,
27
    IAaveHyperdriveDeployerCoordinator
28
{
29
    using FixedPointMath for uint256;
30
    using SafeERC20 for ERC20;
31

32
    /// @notice The deployer coordinator's kind.
33
    string
34
        public constant
35
        override(
36
            HyperdriveDeployerCoordinator,
37
            IHyperdriveDeployerCoordinator
38
        ) kind = AAVE_HYPERDRIVE_DEPLOYER_COORDINATOR_KIND;
39

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

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

99
            // AToken transfers are in base, so we need to convert from
100
            // shares to base.
101
            _contribution = convertToBase(
20✔
102
                IERC20(baseToken),
103
                IAToken(token).POOL(),
104
                _contribution
105
            );
106
        }
107

108
        // Take custody of the contribution and approve Hyperdrive to pull the
109
        // tokens.
110
        ERC20(token).safeTransferFrom(_lp, address(this), _contribution);
21✔
111
        ERC20(token).forceApprove(address(_hyperdrive), _contribution);
21✔
112

113
        // This yield source isn't payable, so we should always send 0 value.
114
        return 0;
21✔
115
    }
116

117
    /// @notice Convert an amount of vault shares to an amount of base.
118
    /// @param _baseToken The base token.
119
    /// @param _vault The Aave vault.
120
    /// @param _shareAmount The vault shares amount.
121
    /// @return The base amount.
122
    function convertToBase(
123
        IERC20 _baseToken,
124
        IPool _vault,
125
        uint256 _shareAmount
126
    ) public view returns (uint256) {
127
        return AaveConversions.convertToBase(_baseToken, _vault, _shareAmount);
41✔
128
    }
129

130
    /// @notice Convert an amount of base to an amount of vault shares.
131
    /// @param _baseToken The base token.
132
    /// @param _vault The Aave vault.
133
    /// @param _baseAmount The base amount.
134
    /// @return The vault shares amount.
135
    function convertToShares(
136
        IERC20 _baseToken,
137
        IPool _vault,
138
        uint256 _baseAmount
139
    ) public view returns (uint256) {
NEW
140
        return AaveConversions.convertToShares(_baseToken, _vault, _baseAmount);
×
141
    }
142

143
    /// @dev We override the message value check since this integration is
144
    ///      not payable.
145
    function _checkMessageValue() internal view override {
146
        if (msg.value != 0) {
21✔
NEW
147
            revert IHyperdriveDeployerCoordinator.NotPayable();
×
148
        }
149
    }
150

151
    /// @notice Checks the pool configuration to ensure that it is valid.
152
    /// @param _deployConfig The deploy configuration of the Hyperdrive pool.
153
    function _checkPoolConfig(
154
        IHyperdrive.PoolDeployConfig memory _deployConfig
155
    ) internal view override {
156
        // Perform the default checks.
157
        super._checkPoolConfig(_deployConfig);
126✔
158

159
        // Ensure that the vault shares token address is non-zero.
160
        if (address(_deployConfig.vaultSharesToken) == address(0)) {
126✔
NEW
161
            revert IHyperdriveDeployerCoordinator.InvalidVaultSharesToken();
×
162
        }
163

164
        // Ensure that the base token address is properly configured.
165
        if (
166
            address(_deployConfig.baseToken) !=
126✔
167
            IAToken(address(_deployConfig.vaultSharesToken))
126✔
168
                .UNDERLYING_ASSET_ADDRESS()
169
        ) {
NEW
170
            revert IHyperdriveDeployerCoordinator.InvalidBaseToken();
×
171
        }
172

173
        // Ensure that the minimum share reserves are large enough to meet the
174
        // minimum requirements for safety.
175
        //
176
        // NOTE: Some pools may require larger minimum share reserves to be
177
        // considered safe. This is just a sanity check.
178
        if (
179
            _deployConfig.minimumShareReserves <
126✔
180
            10 ** (_deployConfig.baseToken.decimals() - 3)
126✔
181
        ) {
NEW
182
            revert IHyperdriveDeployerCoordinator.InvalidMinimumShareReserves();
×
183
        }
184

185
        // Ensure that the minimum transaction amount is large enough to meet
186
        // the minimum requirements for safety.
187
        //
188
        // NOTE: Some pools may require larger minimum transaction amounts to be
189
        // considered safe. This is just a sanity check.
190
        if (
191
            _deployConfig.minimumTransactionAmount <
126✔
192
            10 ** (_deployConfig.baseToken.decimals() - 3)
126✔
193
        ) {
NEW
194
            revert IHyperdriveDeployerCoordinator
×
195
                .InvalidMinimumTransactionAmount();
196
        }
197
    }
198

199
    /// @dev Gets the initial vault share price of the Hyperdrive pool.
200
    /// @param _deployConfig The deploy config that will be used to deploy the
201
    ///        pool.
202
    /// @return The initial vault share price of the Hyperdrive pool.
203
    function _getInitialVaultSharePrice(
204
        IHyperdrive.PoolDeployConfig memory _deployConfig, // unused _deployConfig
205
        bytes memory // unused _extraData
206
    ) internal view override returns (uint256) {
207
        // We calculate the vault share price by converting 1e18 vault shares to
208
        // aTokens.
209
        return
21✔
210
            convertToBase(
21✔
211
                _deployConfig.baseToken,
212
                IAToken(address(_deployConfig.vaultSharesToken)).POOL(),
213
                ONE
214
            );
215
    }
216
}
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