• 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

50.0
/contracts/src/libraries/MorphoSharesMath.sol
1
/// SPDX-License-Identifier: Apache-2.0
2
pragma solidity 0.8.20;
3

4
import { FixedPointMath } from "./FixedPointMath.sol";
5

6
/// @title SharesMathLib
7
/// @author Morpho Labs
8
/// @custom:contact security@morpho.org
9
/// @notice Shares management library.
10
/// @dev This implementation mitigates share price manipulations, using OpenZeppelin's method of virtual shares:
11
/// https://docs.openzeppelin.com/contracts/4.x/erc4626#inflation-attack.
12
library MorphoSharesMath {
13
    using FixedPointMath for uint256;
14

15
    /// @dev The number of virtual shares has been chosen low enough to prevent overflows, and high enough to ensure
16
    /// high precision computations.
17
    /// @dev Virtual shares can never be redeemed for the assets they are entitled to, but it is assumed the share price
18
    /// stays low enough not to inflate these assets to a significant value.
19
    /// @dev Warning: The assets to which virtual borrow shares are entitled behave like unrealizable bad debt.
20
    uint256 internal constant VIRTUAL_SHARES = 1e6;
21

22
    /// @dev A number of virtual assets of 1 enforces a conversion rate between shares and assets when a market is
23
    /// empty.
24
    uint256 internal constant VIRTUAL_ASSETS = 1;
25

26
    /// @dev Calculates the value of `assets` quoted in shares, rounding down.
27
    function toSharesDown(
28
        uint256 assets,
29
        uint256 totalAssets,
30
        uint256 totalShares
31
    ) internal pure returns (uint256) {
32
        return
2✔
33
            assets.mulDivDown(
2✔
34
                totalShares + VIRTUAL_SHARES,
35
                totalAssets + VIRTUAL_ASSETS
36
            );
37
    }
38

39
    /// @dev Calculates the value of `shares` quoted in assets, rounding down.
40
    function toAssetsDown(
41
        uint256 shares,
42
        uint256 totalAssets,
43
        uint256 totalShares
44
    ) internal pure returns (uint256) {
45
        return
4✔
46
            shares.mulDivDown(
4✔
47
                totalAssets + VIRTUAL_ASSETS,
48
                totalShares + VIRTUAL_SHARES
49
            );
50
    }
51

52
    /// @dev Calculates the value of `assets` quoted in shares, rounding up.
53
    function toSharesUp(
54
        uint256 assets,
55
        uint256 totalAssets,
56
        uint256 totalShares
57
    ) internal pure returns (uint256) {
NEW
58
        return
×
NEW
59
            assets.mulDivUp(
×
60
                totalShares + VIRTUAL_SHARES,
61
                totalAssets + VIRTUAL_ASSETS
62
            );
63
    }
64

65
    /// @dev Calculates the value of `shares` quoted in assets, rounding up.
66
    function toAssetsUp(
67
        uint256 shares,
68
        uint256 totalAssets,
69
        uint256 totalShares
70
    ) internal pure returns (uint256) {
NEW
71
        return
×
NEW
72
            shares.mulDivUp(
×
73
                totalAssets + VIRTUAL_ASSETS,
74
                totalShares + VIRTUAL_SHARES
75
            );
76
    }
77
}
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