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

delvtech / hyperdrive / 8732730472

18 Apr 2024 05:12AM UTC coverage: 93.378% (+0.04%) from 93.337%
8732730472

Pull #989

github

web-flow
Merge e5c94423d into 78a1b5959
Pull Request #989: Metadata Functions

2 of 2 new or added lines in 2 files covered. (100.0%)

52 existing lines in 7 files now uncovered.

1805 of 1933 relevant lines covered (93.38%)

383731.12 hits per line

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

73.91
/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 { IERC4626 } from "../../interfaces/IERC4626.sol";
7
import { IHyperdrive } from "../../interfaces/IHyperdrive.sol";
8
import { IHyperdriveDeployerCoordinator } from "../../interfaces/IHyperdriveDeployerCoordinator.sol";
9
import { ONE } from "../../libraries/FixedPointMath.sol";
10
import { HyperdriveDeployerCoordinator } from "../HyperdriveDeployerCoordinator.sol";
11

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

21
    /// @notice The deployer coordinator's name.
22
    string public constant override name =
23
        "ERC4626HyperdriveDeployerCoordinator";
24

25
    /// @notice The deployer coordinator's version.
26
    string public constant override version = "v1.0.0";
27

28
    /// @notice Instantiates the deployer coordinator.
29
    /// @param _factory The factory that this deployer will be registered with.
30
    /// @param _coreDeployer The core deployer.
31
    /// @param _target0Deployer The target0 deployer.
32
    /// @param _target1Deployer The target1 deployer.
33
    /// @param _target2Deployer The target2 deployer.
34
    /// @param _target3Deployer The target3 deployer.
35
    /// @param _target4Deployer The target4 deployer.
36
    constructor(
37
        address _factory,
38
        address _coreDeployer,
39
        address _target0Deployer,
40
        address _target1Deployer,
41
        address _target2Deployer,
42
        address _target3Deployer,
43
        address _target4Deployer
44
    )
45
        HyperdriveDeployerCoordinator(
46
            _factory,
47
            _coreDeployer,
48
            _target0Deployer,
49
            _target1Deployer,
50
            _target2Deployer,
51
            _target3Deployer,
52
            _target4Deployer
53
        )
54
    {}
55

56
    /// @dev Prepares the coordinator for initialization by drawing funds from
57
    ///      the LP, if necessary.
58
    /// @param _hyperdrive The Hyperdrive instance that is being initialized.
59
    /// @param _lp The LP that is initializing the pool.
60
    /// @param _contribution The amount of capital to supply. The units of this
61
    ///        quantity are either base or vault shares, depending on the value
62
    ///        of `_options.asBase`.
63
    /// @param _options The options that configure how the initialization is
64
    ///        settled.
65
    /// @return The value that should be sent in the initialize transaction.
66
    function _prepareInitialize(
67
        IHyperdrive _hyperdrive,
68
        address _lp,
69
        uint256 _contribution,
70
        IHyperdrive.Options memory _options
71
    ) internal override returns (uint256) {
72
        // If base is the deposit asset, the initialization will be paid in the
73
        // base token.
74
        address token;
3,182✔
75
        if (_options.asBase) {
1,591✔
76
            token = _hyperdrive.baseToken();
3,182✔
77
        }
78
        // Otherwise, the initialization will be paid in vault shares.
79
        else {
UNCOV
80
            token = _hyperdrive.vaultSharesToken();
×
81
        }
82

83
        // Take custody of the contribution and approve Hyperdrive to pull the
84
        // tokens.
85
        ERC20(token).safeTransferFrom(_lp, address(this), _contribution);
3,182✔
86
        ERC20(token).forceApprove(address(_hyperdrive), _contribution);
3,182✔
87

88
        // NOTE: Return zero since this yield source isn't payable.
89
        return 0;
3,182✔
90
    }
91

92
    /// @dev Prevents the contract from receiving ether.
93
    function _checkMessageValue() internal view override {
94
        if (msg.value != 0) {
3,182✔
UNCOV
95
            revert IHyperdriveDeployerCoordinator.NotPayable();
×
96
        }
97
    }
98

99
    /// @notice Checks the pool configuration to ensure that it is valid.
100
    /// @param _deployConfig The deploy configuration of the Hyperdrive pool.
101
    function _checkPoolConfig(
102
        IHyperdrive.PoolDeployConfig memory _deployConfig
103
    ) internal view override {
104
        // Perform the default checks.
105
        super._checkPoolConfig(_deployConfig);
19,092✔
106

107
        // Ensure that the vault shares token address is non-zero.
108
        if (address(_deployConfig.vaultSharesToken) == address(0)) {
38,184✔
UNCOV
109
            revert IHyperdriveDeployerCoordinator.InvalidVaultSharesToken();
×
110
        }
111

112
        // Ensure that the base token address is properly configured.
113
        if (
114
            address(_deployConfig.baseToken) !=
28,638✔
115
            IERC4626(address(_deployConfig.vaultSharesToken)).asset()
19,092✔
116
        ) {
UNCOV
117
            revert IHyperdriveDeployerCoordinator.InvalidBaseToken();
×
118
        }
119

120
        // Ensure that the minimum share reserves are large enough to meet the
121
        // minimum requirements for safety.
122
        //
123
        // NOTE: Some pools may require larger minimum share reserves to be
124
        // considered safe. This is just a sanity check.
125
        if (
126
            _deployConfig.minimumShareReserves <
19,092✔
127
            10 ** (_deployConfig.baseToken.decimals() - 4)
19,092✔
128
        ) {
UNCOV
129
            revert IHyperdriveDeployerCoordinator.InvalidMinimumShareReserves();
×
130
        }
131

132
        // Ensure that the minimum transaction amount is large enough to meet
133
        // the minimum requirements for safety.
134
        //
135
        // NOTE: Some pools may require larger minimum transaction amounts to be
136
        // considered safe. This is just a sanity check.
137
        if (
138
            _deployConfig.minimumTransactionAmount <
19,092✔
139
            10 ** (_deployConfig.baseToken.decimals() - 4)
19,092✔
140
        ) {
UNCOV
141
            revert IHyperdriveDeployerCoordinator
×
142
                .InvalidMinimumTransactionAmount();
143
        }
144
    }
145

146
    /// @dev Gets the initial vault share price of the Hyperdrive pool.
147
    /// @param _deployConfig The deploy config that will be used to deploy the
148
    ///        pool.
149
    /// @return The initial vault share price of the Hyperdrive pool.
150
    function _getInitialVaultSharePrice(
151
        IHyperdrive.PoolDeployConfig memory _deployConfig,
152
        bytes memory // unused extra data
153
    ) internal view override returns (uint256) {
154
        // Return the vault's current share price.
155
        return
3,182✔
156
            IERC4626(address(_deployConfig.vaultSharesToken)).convertToAssets(
3,182✔
157
                ONE
158
            );
159
    }
160
}
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