• 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

65.0
/contracts/src/deployers/reth/RETHHyperdriveDeployerCoordinator.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 { RETHConversions } from "../../instances/reth/RETHConversions.sol";
7
import { IERC20 } from "../../interfaces/IERC20.sol";
8
import { IHyperdrive } from "../../interfaces/IHyperdrive.sol";
9
import { IHyperdriveDeployerCoordinator } from "../../interfaces/IHyperdriveDeployerCoordinator.sol";
10
import { IRETHHyperdriveDeployerCoordinator } from "../../interfaces/IRETHHyperdriveDeployerCoordinator.sol";
11
import { IRocketTokenRETH } from "../../interfaces/IRocketTokenRETH.sol";
12
import { ETH, RETH_HYPERDRIVE_DEPLOYER_COORDINATOR_KIND } from "../../libraries/Constants.sol";
13
import { FixedPointMath, ONE } from "../../libraries/FixedPointMath.sol";
14
import { HyperdriveDeployerCoordinator } from "../HyperdriveDeployerCoordinator.sol";
15

16
/// @author DELV
17
/// @title RETHHyperdriveDeployerCoordinator
18
/// @notice The deployer coordinator for the RETHHyperdrive 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 RETHHyperdriveDeployerCoordinator is
23
    HyperdriveDeployerCoordinator,
24
    IRETHHyperdriveDeployerCoordinator
25
{
26
    using SafeERC20 for ERC20;
27
    using FixedPointMath for uint256;
28

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

37
    /// @dev The Rocket Token RETH contract.
38
    IRocketTokenRETH internal immutable rocketTokenReth;
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
    /// @param _rocketTokenReth The rETH token contract.
50
    constructor(
51
        string memory _name,
52
        address _factory,
53
        address _coreDeployer,
54
        address _target0Deployer,
55
        address _target1Deployer,
56
        address _target2Deployer,
57
        address _target3Deployer,
58
        address _target4Deployer,
59
        IRocketTokenRETH _rocketTokenReth
60
    )
61
        HyperdriveDeployerCoordinator(
62
            _name,
63
            _factory,
64
            _coreDeployer,
65
            _target0Deployer,
66
            _target1Deployer,
67
            _target2Deployer,
68
            _target3Deployer,
69
            _target4Deployer
70
        )
71
    {
72
        rocketTokenReth = _rocketTokenReth;
×
73
    }
74

75
    /// @dev Prepares the coordinator for initialization by drawing funds from
76
    ///      the LP, if necessary.
77
    /// @param _hyperdrive The Hyperdrive instance that is being initialized.
78
    /// @param _lp The LP that is initializing the pool.
79
    /// @param _contribution The amount of capital to supply. The units of this
80
    ///        quantity are either base or vault shares, depending on the value
81
    ///        of `_options.asBase`.
82
    /// @param _options The options that configure how the initialization is
83
    ///        settled.
84
    /// @return The value that should be sent in the initialize transaction.
85
    function _prepareInitialize(
86
        IHyperdrive _hyperdrive,
87
        address _lp,
88
        uint256 _contribution,
89
        IHyperdrive.Options memory _options
90
    ) internal override returns (uint256) {
91
        // If base is the deposit asset, revert because depositing as base
92
        // is not supported for the rETH integration.
93
        if (_options.asBase) {
20✔
94
            revert IHyperdrive.UnsupportedToken();
×
95
        }
96

97
        // Otherwise, transfer vault shares from the LP and approve the
98
        // Hyperdrive pool.
99
        ERC20(address(rocketTokenReth)).safeTransferFrom(
20✔
100
            _lp,
101
            address(this),
102
            _contribution
103
        );
104
        ERC20(address(rocketTokenReth)).forceApprove(
20✔
105
            address(_hyperdrive),
106
            _contribution
107
        );
108

109
        // NOTE: Return zero since this yield source isn't payable.
110
        return 0;
20✔
111
    }
112

113
    /// @notice Convert an amount of vault shares to an amount of base.
114
    /// @param _vaultSharesToken The vault shares asset.
115
    /// @param _shareAmount The vault shares amount.
116
    /// @return The base amount.
117
    function convertToBase(
118
        IERC20 _vaultSharesToken,
119
        uint256 _shareAmount
120
    ) public view returns (uint256) {
121
        return RETHConversions.convertToBase(_vaultSharesToken, _shareAmount);
21✔
122
    }
123

124
    /// @notice Convert an amount of base to an amount of vault shares.
125
    /// @param _vaultSharesToken The vault shares asset.
126
    /// @param _baseAmount The base amount.
127
    /// @return The vault shares amount.
128
    function convertToShares(
129
        IERC20 _vaultSharesToken,
130
        uint256 _baseAmount
131
    ) public view returns (uint256) {
NEW
132
        return RETHConversions.convertToShares(_vaultSharesToken, _baseAmount);
×
133
    }
134

135
    /// @dev We override the message value check since this integration is
136
    ///      not payable.
137
    function _checkMessageValue() internal view override {
138
        if (msg.value != 0) {
21✔
139
            revert IHyperdrive.NotPayable();
1✔
140
        }
141
    }
142

143
    /// @notice Checks the pool configuration to ensure that it is valid.
144
    /// @param _deployConfig The deploy configuration of the Hyperdrive pool.
145
    function _checkPoolConfig(
146
        IHyperdrive.PoolDeployConfig memory _deployConfig
147
    ) internal view override {
148
        // Perform the default checks.
149
        super._checkPoolConfig(_deployConfig);
126✔
150

151
        // Ensure that the base token address is properly configured.
152
        if (address(_deployConfig.baseToken) != ETH) {
126✔
153
            revert IHyperdriveDeployerCoordinator.InvalidBaseToken();
×
154
        }
155

156
        // Ensure that the vault shares token address is properly configured.
157
        if (
158
            address(_deployConfig.vaultSharesToken) != address(rocketTokenReth)
126✔
159
        ) {
160
            revert IHyperdriveDeployerCoordinator.InvalidVaultSharesToken();
×
161
        }
162

163
        // Ensure that the minimum share reserves are equal to 1e15. This value
164
        // has been tested to prevent arithmetic overflows in the
165
        // `_updateLiquidity` function when the share reserves are as high as
166
        // 200 million.
167
        if (_deployConfig.minimumShareReserves != 1e15) {
126✔
168
            revert IHyperdriveDeployerCoordinator.InvalidMinimumShareReserves();
×
169
        }
170

171
        // Ensure that the minimum transaction amount are equal to 1e15. This
172
        // value has been tested to prevent precision issues.
173
        if (_deployConfig.minimumTransactionAmount != 1e15) {
126✔
174
            revert IHyperdriveDeployerCoordinator
×
175
                .InvalidMinimumTransactionAmount();
176
        }
177
    }
178

179
    /// @dev Gets the initial vault share price of the Hyperdrive pool.
180
    /// @param _deployConfig The deploy configuration of the Hyperdrive pool.
181
    /// @return The initial vault share price of the Hyperdrive pool.
182
    function _getInitialVaultSharePrice(
183
        IHyperdrive.PoolDeployConfig memory _deployConfig,
184
        bytes memory // unused extra data
185
    ) internal view override returns (uint256) {
186
        return convertToBase(_deployConfig.vaultSharesToken, ONE);
21✔
187
    }
188
}
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