• 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

45.83
/contracts/src/instances/morpho/MorphoBase.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 { Id, IMorpho, Market, MarketParams, Position } from "../../interfaces/IMorpho.sol";
8
import { IHyperdrive } from "../../interfaces/IHyperdrive.sol";
9
import { HyperdriveBase } from "../../internal/HyperdriveBase.sol";
10
import { MorphoSharesMath } from "../../libraries/MorphoSharesMath.sol";
11
import { MorphoParamsLib } from "../../libraries/MorphoParamsLib.sol";
12

13
import "forge-std/console2.sol";
14

15
/// @author DELV
16
/// @title MorphoBase
17
/// @notice The base contract for the Morpho Hyperdrive implementation.
18
/// @dev This Hyperdrive implementation is designed to work with standard
19
///      Morpho vaults. Non-standard implementations may not work correctly
20
///      and should be carefully checked.
21
/// @custom:disclaimer The language used in this code is for coding convenience
22
///                    only, and is not intended to, and does not, have any
23
///                    particular legal or regulatory significance.
24
abstract contract MorphoBase is HyperdriveBase {
25
    using SafeERC20 for ERC20;
26
    using MorphoSharesMath for uint256;
27
    using MorphoParamsLib for MarketParams;
28

29
    IMorpho internal immutable _morpho;
30
    MarketParams internal _marketParams;
31

32
    /// @notice Instantiates the ezETH Hyperdrive base contract.
33
    /// @param __morpho The Morpho contract.
34
    /// @param __marketParams The Morpho market information.
35
    constructor(IMorpho __morpho, MarketParams memory __marketParams) {
36
        _morpho = __morpho;
12✔
37
        _marketParams = __marketParams;
12✔
38
    }
39

40
    /// Yield Source ///
41

42
    /// @dev Accepts a deposit from the user in base.
43
    /// @param _baseAmount The base amount to deposit.
44
    /// @return The shares that were minted in the deposit.
45
    /// @return The amount of ETH to refund. Since this yield source isn't
46
    ///         payable, this is always zero.
47
    function _depositWithBase(
48
        uint256 _baseAmount,
49
        bytes calldata // unused
50
    ) internal override returns (uint256, uint256) {
51
        // Take custody of the deposit in base.
52
        ERC20(address(_marketParams.loanToken)).safeTransferFrom(
2✔
53
            msg.sender,
54
            address(this),
55
            _baseAmount
56
        );
57

58
        ERC20(_marketParams.loanToken).forceApprove(
2✔
59
            address(_morpho),
60
            _baseAmount + 1
61
        );
62

63
        (, uint256 sharesSupplied) = _morpho.supply(
3✔
64
            _marketParams,
65
            _baseAmount,
66
            0,
67
            address(this),
68
            hex""
69
        );
70

71
        return (sharesSupplied, 0);
2✔
72
    }
73

74
    /// @dev Process a deposit in vault shares.
75
    /// @param _shareAmount The vault shares amount to deposit.
76
    function _depositWithShares(
77
        uint256 _shareAmount,
78
        bytes calldata // unused _extraData
79
    ) internal override {
NEW
80
        revert IHyperdrive.UnsupportedToken();
×
81

82
        // // Take custody of the deposit in base.
83
        // ERC20(address(_marketParams.loanToken)).safeTransferFrom(
84
        //     msg.sender,
85
        //     address(this),
86
        //     _baseAmount
87
        // );
88

89
        // ERC20(marketParams.loanToken).forceApprove(
90
        //     address(_morpho),
91
        //     _baseAmount + 1
92
        // );
93

94
        // (, uint256 sharesSupplied) = _morpho.supply(
95
        //     _marketParams,
96
        //     0,
97
        //     _shareAmount,
98
        //     msg.sender,
99
        //     hex""
100
        // );
101

102
        // return (sharesSupplied, 0);
103
    }
104

105
    /// @dev Process a withdrawal in base and send the proceeds to the
106
    ///      destination.
107

108
    /// @param _shareAmount The amount of vault shares to withdraw.
109
    /// @param _destination The destination of the withdrawal.
110
    /// @return amountWithdrawn The amount of base withdrawn.
111
    function _withdrawWithBase(
112
        uint256 _shareAmount,
113
        address _destination,
114
        bytes calldata // unused
115
    ) internal override returns (uint256) {
NEW
116
        (uint256 amountWithdrawn, ) = _morpho.withdraw(
×
117
            _marketParams,
118
            0,
119
            _shareAmount, // TODO _shareAmount is in 36 decimals
120
            address(this), // onBalf of hyperdrive
121
            msg.sender // credit to user
122
        );
123

124
        return amountWithdrawn;
×
125
    }
126

127
    /// @dev Process a withdrawal in vault shares and send the proceeds to the
128
    ///      destination.
129
    /// @param _shareAmount The amount of vault shares to withdraw.
130
    /// @param _destination The destination of the withdrawal.
131
    function _withdrawWithShares(
132
        uint256 _shareAmount,
133
        address _destination,
134
        bytes calldata // unused
135
    ) internal override {
NEW
136
        revert IHyperdrive.UnsupportedToken();
×
137
    }
138

139
    /// @dev Convert an amount of vault shares to an amount of base.
140
    /// @param _shareAmount The vault shares amount.
141
    /// @return The base amount.
142
    function _convertToBase(
143
        uint256 _shareAmount
144
    ) internal view override returns (uint256) {
145
        Id marketId = _marketParams.id();
3✔
146
        Market memory market = _morpho.market(marketId);
3✔
147

148
        return
2✔
149
            _shareAmount.toAssetsDown(
2✔
150
                market.totalSupplyAssets,
151
                market.totalSupplyShares
152
            );
153
    }
154

155
    /// @dev Convert an amount of base to an amount of vault shares.
156
    /// @param _baseAmount The base amount.
157
    /// @return The vault shares amount.
158
    function _convertToShares(
159
        uint256 _baseAmount
160
    ) internal view override returns (uint256) {
NEW
161
        Id marketId = _marketParams.id();
×
NEW
162
        Market memory market = _morpho.market(marketId);
×
163

164
        // rounding down for withdraws
165
        return
×
NEW
166
            _baseAmount.toSharesDown(
×
167
                market.totalSupplyAssets,
168
                market.totalSupplyShares
169
            );
170
    }
171

172
    /// @dev Gets the total amount of shares held by the pool in the yield
173
    ///      source.
174
    /// @return shareAmount The total amount of shares.
175
    function _totalShares() internal view override returns (uint256) {
NEW
176
        Id marketId = _marketParams.id();
×
NEW
177
        Market memory market = _morpho.market(marketId);
×
178

NEW
179
        Position memory position = _morpho.position(marketId, address(this));
×
NEW
180
        return position.supplyShares;
×
181
    }
182

183
    /// @dev We override the message value check since this integration is
184
    ///      not payable.
185
    function _checkMessageValue() internal view override {
186
        if (msg.value != 0) {
2✔
187
            revert IHyperdrive.NotPayable();
×
188
        }
189
    }
190
}
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