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

delvtech / hyperdrive / 8517843340

02 Apr 2024 05:21AM UTC coverage: 92.214%. First build
8517843340

Pull #906

github

web-flow
Merge 650223444 into cbc93bbc2
Pull Request #906: fix unsafe routes in _distributeExcessIdleSafe

13 of 16 new or added lines in 3 files covered. (81.25%)

1658 of 1798 relevant lines covered (92.21%)

415800.84 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,242✔
14
            revert IHyperdrive.UnsafeCastToUint112();
×
15
        }
16
        y = uint112(x);
37,242✔
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,221,510✔
24
            revert IHyperdrive.UnsafeCastToUint128();
410✔
25
        }
26
        y = uint128(x);
3,221,100✔
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))) {
727,056✔
34
            revert IHyperdrive.UnsafeCastToInt128();
×
35
        }
36
        y = int128(int256(x));
727,056✔
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,258✔
44
            revert IHyperdrive.UnsafeCastToInt128();
×
45
        }
46
        y = int128(x);
149,258✔
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,634,400✔
54
            revert IHyperdrive.UnsafeCastToInt256();
×
55
        }
56
        y = int256(x);
37,634,400✔
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

© 2026 Coveralls, Inc