|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import "./ClampHelper.sol"; |
| 5 | + |
| 6 | +abstract contract ClampWrapper is ClampHelper { |
| 7 | + |
| 8 | + /// @notice Clamps value to be between low and high, both inclusive |
| 9 | + function clampBetween( |
| 10 | + uint256 value, |
| 11 | + uint256 low, |
| 12 | + uint256 high |
| 13 | + ) internal returns (uint256) { |
| 14 | + return clampBetween(value, low, high, true); |
| 15 | + } |
| 16 | + |
| 17 | + /// @notice int256 version of clampBetween |
| 18 | + function clampBetween( |
| 19 | + int256 value, |
| 20 | + int256 low, |
| 21 | + int256 high |
| 22 | + ) internal returns (int256) { |
| 23 | + return clampBetween(value, low, high, true); |
| 24 | + } |
| 25 | + |
| 26 | + /// @notice clamps a to be less than b |
| 27 | + function clampLt(uint256 a, uint256 b) internal returns (uint256) { |
| 28 | + return clampLt(a, b); |
| 29 | + } |
| 30 | + |
| 31 | + /// @notice int256 version of clampLt |
| 32 | + function clampLt(int256 a, int256 b) internal returns (int256) { |
| 33 | + return clampLt(a, b, true); |
| 34 | + } |
| 35 | + |
| 36 | + /// @notice clamps a to be less than or equal to b |
| 37 | + function clampLte(uint256 a, uint256 b) internal returns (uint256) { |
| 38 | + return clampLte(a, b, true); |
| 39 | + } |
| 40 | + |
| 41 | + /// @notice int256 version of clampLte |
| 42 | + function clampLte(int256 a, int256 b) internal returns (int256) { |
| 43 | + return clampLte(a, b, true); |
| 44 | + } |
| 45 | + |
| 46 | + /// @notice clamps a to be greater than b |
| 47 | + function clampGt(uint256 a, uint256 b) internal returns (uint256) { |
| 48 | + return clampGt(a, b, true); |
| 49 | + } |
| 50 | + |
| 51 | + /// @notice int256 version of clampGt |
| 52 | + function clampGt(int256 a, int256 b) internal returns (int256) { |
| 53 | + return clampGt(a, b, true); |
| 54 | + } |
| 55 | + |
| 56 | + /// @notice clamps a to be greater than or equal to b |
| 57 | + function clampGte(uint256 a, uint256 b) internal returns (uint256) { |
| 58 | + return clampGte(a, b, true); |
| 59 | + } |
| 60 | + |
| 61 | + /// @notice int256 version of clampGte |
| 62 | + function clampGte(int256 a, int256 b) internal returns (int256) { |
| 63 | + return clampGte(a, b, true); |
| 64 | + } |
| 65 | +} |
0 commit comments