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

delvtech / hyperdrive / 9179140169

21 May 2024 05:53PM UTC coverage: 88.259% (-2.8%) from 91.088%
9179140169

push

github

cashd
wip

16 of 32 new or added lines in 4 files covered. (50.0%)

77 existing lines in 15 files now uncovered.

1774 of 2010 relevant lines covered (88.26%)

371757.72 hits per line

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

0.0
/contracts/src/instances/reth/RETHBase.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 { HyperdriveBase } from "../../internal/HyperdriveBase.sol";
7
import { IHyperdrive } from "../../interfaces/IHyperdrive.sol";
8
import { IRocketTokenRETH } from "../../interfaces/IRocketTokenRETH.sol";
9

10
/// @author DELV
11
/// @title RETHHyperdrive
12
/// @notice The base contract for the rETH Hyperdrive implementation.
13
/// @dev Rocket Pool has it's own notion of shares to account for the accrual of
14
///      interest on the ether pooled in the Rocket Pool protocol. Instead of
15
///      maintaining a balance of shares, this integration can simply use Rocket Pool
16
///      shares directly.
17
/// @custom:disclaimer The language used in this code is for coding convenience
18
///                    only, and is not intended to, and does not, have any
19
///                    particular legal or regulatory significance.
20
abstract contract RETHBase is HyperdriveBase {
21
    using SafeERC20 for ERC20;
22

23
    /// Yield Source ///
24

25
    function _depositWithBase(
26
        uint256, // unused
27
        bytes calldata // unused
28
    ) internal pure override returns (uint256, uint256) {
29
        // Deposits with ETH is not supported because of accounting
30
        // issues due to the Rocket Pool deposit fee.
UNCOV
31
        revert IHyperdrive.UnsupportedToken();
×
32
    }
33

34
    /// @dev Process a deposit in vault shares.
35
    /// @param _shareAmount The vault shares amount to deposit.
36
    function _depositWithShares(
37
        uint256 _shareAmount,
38
        bytes calldata // unused
39
    ) internal override {
40
        // Transfer rETH shares into the contract.
UNCOV
41
        ERC20(address(_vaultSharesToken)).safeTransferFrom(
×
42
            msg.sender,
43
            address(this),
44
            _shareAmount
45
        );
46
    }
47

48
    /// @dev Process a withdrawal in base and send the proceeds to the
49
    ///      destination.
50
    /// @param _shareAmount The amount of vault shares to withdraw.
51
    /// @param _destination The destination of the withdrawal.
52
    /// @return amountWithdrawn The amount of base withdrawn.
53
    function _withdrawWithBase(
54
        uint256 _shareAmount,
55
        address _destination,
56
        bytes calldata // unused
57
    ) internal override returns (uint256 amountWithdrawn) {
58
        // Burning rETH shares in exchange for ether.
59
        // Ether proceeds are credited to this contract.
UNCOV
60
        IRocketTokenRETH(address(_vaultSharesToken)).burn(_shareAmount);
×
61

62
        // Amount of ETH that was withdrawn from the yield source and
63
        // will be sent to the destination address.
UNCOV
64
        amountWithdrawn = address(this).balance;
×
65

66
        // Return withdrawn ether to the destination.
UNCOV
67
        (bool success, ) = payable(_destination).call{ value: amountWithdrawn }(
×
68
            ""
69
        );
UNCOV
70
        if (!success) {
×
71
            revert IHyperdrive.TransferFailed();
×
72
        }
73
    }
74

75
    /// @dev Process a withdrawal in vault shares and send the proceeds to the
76
    ///      destination.
77
    /// @param _shareAmount The amount of vault shares to withdraw.
78
    /// @param _destination The destination of the withdrawal.
79
    function _withdrawWithShares(
80
        uint256 _shareAmount,
81
        address _destination,
82
        bytes calldata // unused
83
    ) internal override {
84
        // Transfer the rETH shares to the destination.
UNCOV
85
        ERC20(address(_vaultSharesToken)).safeTransfer(
×
86
            _destination,
87
            _shareAmount
88
        );
89
    }
90

91
    /// @dev Convert an amount of vault shares to an amount of base.
92
    /// @param _shareAmount The vault shares amount.
93
    /// @return baseAmount The base amount.
94
    function _convertToBase(
95
        uint256 _shareAmount
96
    ) internal view override returns (uint256) {
UNCOV
97
        return
×
UNCOV
98
            IRocketTokenRETH(address(_vaultSharesToken)).getEthValue(
×
99
                _shareAmount
100
            );
101
    }
102

103
    /// @dev Convert an amount of base to an amount of vault shares.
104
    /// @param _baseAmount The base amount.
105
    /// @return shareAmount The vault shares amount.
106
    function _convertToShares(
107
        uint256 _baseAmount
108
    ) internal view override returns (uint256) {
UNCOV
109
        return
×
UNCOV
110
            IRocketTokenRETH(address(_vaultSharesToken)).getRethValue(
×
111
                _baseAmount
112
            );
113
    }
114

115
    /// @dev Gets the total amount of shares held by the pool in the yield
116
    ///      source.
117
    /// @return shareAmount The total amount of shares.
118
    function _totalShares()
119
        internal
120
        view
121
        override
122
        returns (uint256 shareAmount)
123
    {
UNCOV
124
        return _vaultSharesToken.balanceOf(address(this));
×
125
    }
126

127
    /// @dev Disallows the contract to receive ether, when opening positions.
128
    function _checkMessageValue() internal view override {
UNCOV
129
        if (msg.value != 0) {
×
UNCOV
130
            revert IHyperdrive.NotPayable();
×
131
        }
132
    }
133

134
    /// @dev Allows ether to be received only from the Rocket Pool rETH
135
    ///      token contract. Supports withdrawing as ethers from this
136
    ///      yield source.
137
    receive() external payable {
138
        if (msg.sender != address(_vaultSharesToken)) {
139
            revert IHyperdrive.TransferFailed();
140
        }
141
    }
142
}
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