• 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/lseth/LsETHHyperdriveDeployerCoordinator.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 { LsETHConversions } from "../../instances/lseth/LsETHConversions.sol";
7
import { IERC20 } from "../../interfaces/IERC20.sol";
8
import { IHyperdrive } from "../../interfaces/IHyperdrive.sol";
9
import { IHyperdriveDeployerCoordinator } from "../../interfaces/IHyperdriveDeployerCoordinator.sol";
10
import { ILsETHHyperdriveDeployerCoordinator } from "../../interfaces/ILsETHHyperdriveDeployerCoordinator.sol";
11
import { IRiverV1 } from "../../interfaces/IRiverV1.sol";
12
import { ETH, LSETH_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 LsETHHyperdriveDeployerCoordinator
18
/// @notice The deployer coordinator for the LsETHHyperdrive 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 LsETHHyperdriveDeployerCoordinator is
23
    HyperdriveDeployerCoordinator,
24
    ILsETHHyperdriveDeployerCoordinator
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 = LSETH_HYPERDRIVE_DEPLOYER_COORDINATOR_KIND;
36

37
    /// @dev The LsETH contract.
38
    IRiverV1 internal immutable river;
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 _river The LsETH 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
        IRiverV1 _river
60
    )
61
        HyperdriveDeployerCoordinator(
62
            _name,
63
            _factory,
64
            _coreDeployer,
65
            _target0Deployer,
66
            _target1Deployer,
67
            _target2Deployer,
68
            _target3Deployer,
69
            _target4Deployer
70
        )
71
    {
72
        river = _river;
×
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
        // Depositing as base is disallowed.
92
        if (_options.asBase) {
20✔
93
            revert IHyperdrive.UnsupportedToken();
×
94
        }
95

96
        // Transfer vault shares from the LP and approve the
97
        // Hyperdrive pool.
98
        ERC20(address(river)).safeTransferFrom(
20✔
99
            _lp,
100
            address(this),
101
            _contribution
102
        );
103
        ERC20(address(river)).forceApprove(address(_hyperdrive), _contribution);
20✔
104

105
        // NOTE: Return zero since this yield source isn't payable.
106
        return 0;
20✔
107
    }
108

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

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

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

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

147
        // Ensure that the base token address is properly configured.
148
        if (address(_deployConfig.baseToken) != ETH) {
126✔
149
            revert IHyperdriveDeployerCoordinator.InvalidBaseToken();
×
150
        }
151

152
        // Ensure that the vault shares token address is properly configured.
153
        if (address(_deployConfig.vaultSharesToken) != address(river)) {
126✔
154
            revert IHyperdriveDeployerCoordinator.InvalidVaultSharesToken();
×
155
        }
156

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

165
        // Ensure that the minimum transaction amount are equal to 1e15. This
166
        // value has been tested to prevent precision issues.
167
        if (_deployConfig.minimumTransactionAmount != 1e15) {
126✔
168
            revert IHyperdriveDeployerCoordinator
×
169
                .InvalidMinimumTransactionAmount();
170
        }
171
    }
172

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