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

delvtech / hyperdrive / 8511828111

01 Apr 2024 06:13PM UTC coverage: 92.334%. First build
8511828111

Pull #911

github

web-flow
Merge 0006ac3ae into 5ff6cce24
Pull Request #911: calculateSharesDeltaGivenBondsDeltaDerivativeSafe edge case

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

1650 of 1787 relevant lines covered (92.33%)

418086.65 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,154✔
14
            revert IHyperdrive.UnsafeCastToUint112();
×
15
        }
16
        y = uint112(x);
37,154✔
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,224,916✔
24
            revert IHyperdrive.UnsafeCastToUint128();
412✔
25
        }
26
        y = uint128(x);
3,224,504✔
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,290✔
34
            revert IHyperdrive.UnsafeCastToInt128();
×
35
        }
36
        y = int128(int256(x));
729,290✔
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)) {
148,912✔
44
            revert IHyperdrive.UnsafeCastToInt128();
×
45
        }
46
        y = int128(x);
148,912✔
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,566,764✔
54
            revert IHyperdrive.UnsafeCastToInt256();
×
55
        }
56
        y = int256(x);
37,566,764✔
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