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

delvtech / hyperdrive / 8530993764

02 Apr 2024 11:53PM UTC coverage: 92.329%. First build
8530993764

Pull #929

github

web-flow
Merge 6ce4d71e8 into aee13fb9e
Pull Request #929: stricter fee check rounding

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

1649 of 1786 relevant lines covered (92.33%)

418190.57 hits per line

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

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

4
import { IHyperdrive } from "../interfaces/IHyperdrive.sol";
5

6
/// @notice Safe unsigned integer casting library that reverts on overflow.
7
/// @author Inspired by OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeCast.sol)
8
library SafeCast {
9
    /// @notice This function safely casts a uint256 to a uint112.
10
    /// @param x The uint256 to cast to uint112.
11
    /// @return y The uint112 casted from x.
12
    function toUint112(uint256 x) internal pure returns (uint112 y) {
13
        if (!(x < 1 << 112)) {
37,218✔
14
            revert IHyperdrive.UnsafeCastToUint112();
×
15
        }
16
        y = uint112(x);
37,218✔
17
    }
18

19
    /// @notice This function safely casts a uint256 to a uint128.
20
    /// @param x The uint256 to cast to uint128.
21
    /// @return y The uint128 casted from x.
22
    function toUint128(uint256 x) internal pure returns (uint128 y) {
23
        if (!(x < 1 << 128)) {
3,223,888✔
24
            revert IHyperdrive.UnsafeCastToUint128();
410✔
25
        }
26
        y = uint128(x);
3,223,478✔
27
    }
28

29
    /// @notice This function safely casts an uint256 to an int128.
30
    /// @param x The uint256 to cast to int128.
31
    /// @return y The int128 casted from x.
32
    function toInt128(uint256 x) internal pure returns (int128 y) {
33
        if (!(x <= uint128(type(int128).max))) {
729,148✔
34
            revert IHyperdrive.UnsafeCastToInt128();
×
35
        }
36
        y = int128(int256(x));
729,148✔
37
    }
38

39
    /// @notice This function safely casts an int256 to an int128.
40
    /// @param x The int256 to cast to int128.
41
    /// @return y The int128 casted from x.
42
    function toInt128(int256 x) internal pure returns (int128 y) {
43
        if (!(x >= type(int128).min && x <= type(int128).max)) {
149,264✔
44
            revert IHyperdrive.UnsafeCastToInt128();
×
45
        }
46
        y = int128(x);
149,264✔
47
    }
48

49
    /// @notice This function safely casts an uint256 to an int256.
50
    /// @param x The uint256 to cast to int256.
51
    /// @return y The int256 casted from x.
52
    function toInt256(uint256 x) internal pure returns (int256 y) {
53
        if (!(x <= uint256(type(int256).max))) {
37,555,116✔
54
            revert IHyperdrive.UnsafeCastToInt256();
×
55
        }
56
        y = int256(x);
37,555,116✔
57
    }
58
}
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