Skip to content

Commit

Permalink
πŸ—‘οΈ πŸ‘·πŸ» Remove all .toUint() functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyrharper committed Feb 26, 2024
1 parent e38b9b7 commit 02aa1aa
Show file tree
Hide file tree
Showing 36 changed files with 15 additions and 364 deletions.
9 changes: 0 additions & 9 deletions src/Int128/BaseInt128/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
pragma solidity >=0.8.19;

import {BaseInt128} from "./ValueType.sol";
import {BaseUint128} from "../../Uint128/BaseUint128/ValueType.sol";
import {SafeCastI128} from "../../utils/SafeCast.sol";

using SafeCastI128 for int128;

/// @notice Wraps a int128 number into the BaseInt128 value type.
function wrap(int128 x) pure returns (BaseInt128 result) {
Expand All @@ -16,8 +12,3 @@ function wrap(int128 x) pure returns (BaseInt128 result) {
function unwrap(BaseInt128 x) pure returns (int128 result) {
result = BaseInt128.unwrap(x);
}

/// @notice Converts a BaseInt128 number into BaseUint128.
function toUint(BaseInt128 x) pure returns (BaseUint128 result) {
result = BaseUint128.wrap(unwrap(x).toUint());
}
2 changes: 1 addition & 1 deletion src/Int128/BaseInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type BaseInt128 is int128;
CASTING
//////////////////////////////////////////////////////////////*/

using {Casting.unwrap, Casting.toUint} for BaseInt128 global;
using {Casting.unwrap} for BaseInt128 global;

/*//////////////////////////////////////////////////////////////
HELPERS
Expand Down
13 changes: 0 additions & 13 deletions src/Int128/BaseQuantoPerUSDInt128/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
pragma solidity >=0.8.19;

import {BaseQuantoPerUSDInt128} from "./ValueType.sol";
import {BaseQuantoPerUSDUint128} from
"../../Uint128/BaseQuantoPerUSDUint128/ValueType.sol";
import {SafeCastI128} from "../../utils/SafeCast.sol";

using SafeCastI128 for int128;

/// @notice Wraps a int128 number into the BaseQuantoPerUSDInt128 value type.
function wrap(int128 x) pure returns (BaseQuantoPerUSDInt128 result) {
Expand All @@ -17,11 +12,3 @@ function wrap(int128 x) pure returns (BaseQuantoPerUSDInt128 result) {
function unwrap(BaseQuantoPerUSDInt128 x) pure returns (int128 result) {
result = BaseQuantoPerUSDInt128.unwrap(x);
}

/// @notice Converts a BaseQuantoPerUSDInt128 number into BaseQuantoPerUSDUint128.
function toUint(BaseQuantoPerUSDInt128 x)
pure
returns (BaseQuantoPerUSDUint128 result)
{
result = BaseQuantoPerUSDUint128.wrap(unwrap(x).toUint());
}
2 changes: 1 addition & 1 deletion src/Int128/BaseQuantoPerUSDInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type BaseQuantoPerUSDInt128 is int128;
CASTING
//////////////////////////////////////////////////////////////*/

using {Casting.unwrap, Casting.toUint} for BaseQuantoPerUSDInt128 global;
using {Casting.unwrap} for BaseQuantoPerUSDInt128 global;

/*//////////////////////////////////////////////////////////////
HELPERS
Expand Down
9 changes: 0 additions & 9 deletions src/Int128/QuantoInt128/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
pragma solidity >=0.8.19;

import {QuantoInt128} from "./ValueType.sol";
import {QuantoUint128} from "../../Uint128/QuantoUint128/ValueType.sol";
import {SafeCastI128} from "../../utils/SafeCast.sol";

using SafeCastI128 for int128;

/// @notice Wraps a int128 number into the QuantoInt128 value type.
function wrap(int128 x) pure returns (QuantoInt128 result) {
Expand All @@ -16,8 +12,3 @@ function wrap(int128 x) pure returns (QuantoInt128 result) {
function unwrap(QuantoInt128 x) pure returns (int128 result) {
result = QuantoInt128.unwrap(x);
}

/// @notice Converts a QuantoInt128 number into QuantoUint128.
function toUint(QuantoInt128 x) pure returns (QuantoUint128 result) {
result = QuantoUint128.wrap(unwrap(x).toUint());
}
2 changes: 1 addition & 1 deletion src/Int128/QuantoInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type QuantoInt128 is int128;
CASTING
//////////////////////////////////////////////////////////////*/

using {Casting.unwrap, Casting.toUint} for QuantoInt128 global;
using {Casting.unwrap} for QuantoInt128 global;

/*//////////////////////////////////////////////////////////////
HELPERS
Expand Down
9 changes: 0 additions & 9 deletions src/Int128/USDInt128/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
pragma solidity >=0.8.19;

import {USDInt128} from "./ValueType.sol";
import {USDUint128} from "../../Uint128/USDUint128/ValueType.sol";
import {SafeCastI128} from "../../utils/SafeCast.sol";

using SafeCastI128 for int128;

/// @notice Wraps a int128 number into the USDInt128 value type.
function wrap(int128 x) pure returns (USDInt128 result) {
Expand All @@ -16,8 +12,3 @@ function wrap(int128 x) pure returns (USDInt128 result) {
function unwrap(USDInt128 x) pure returns (int128 result) {
result = USDInt128.unwrap(x);
}

/// @notice Converts a USDInt128 number into USDUint128.
function toUint(USDInt128 x) pure returns (USDUint128 result) {
result = USDUint128.wrap(unwrap(x).toUint());
}
2 changes: 1 addition & 1 deletion src/Int128/USDInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type USDInt128 is int128;
CASTING
//////////////////////////////////////////////////////////////*/

using {Casting.unwrap, Casting.toUint} for USDInt128 global;
using {Casting.unwrap} for USDInt128 global;

/*//////////////////////////////////////////////////////////////
HELPERS
Expand Down
9 changes: 0 additions & 9 deletions src/Int128/USDPerBaseInt128/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
pragma solidity >=0.8.19;

import {USDPerBaseInt128} from "./ValueType.sol";
import {USDPerBaseUint128} from "../../Uint128/USDPerBaseUint128/ValueType.sol";
import {SafeCastI128} from "../../utils/SafeCast.sol";

using SafeCastI128 for int128;

/// @notice Wraps a int128 number into the USDPerBaseInt128 value type.
function wrap(int128 x) pure returns (USDPerBaseInt128 result) {
Expand All @@ -16,8 +12,3 @@ function wrap(int128 x) pure returns (USDPerBaseInt128 result) {
function unwrap(USDPerBaseInt128 x) pure returns (int128 result) {
result = USDPerBaseInt128.unwrap(x);
}

/// @notice Converts a USDPerBaseInt128 number into USDPerBaseUint128.
function toUint(USDPerBaseInt128 x) pure returns (USDPerBaseUint128 result) {
result = USDPerBaseUint128.wrap(unwrap(x).toUint());
}
2 changes: 1 addition & 1 deletion src/Int128/USDPerBaseInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type USDPerBaseInt128 is int128;
CASTING
//////////////////////////////////////////////////////////////*/

using {Casting.unwrap, Casting.toUint} for USDPerBaseInt128 global;
using {Casting.unwrap} for USDPerBaseInt128 global;

/*//////////////////////////////////////////////////////////////
HELPERS
Expand Down
13 changes: 0 additions & 13 deletions src/Int128/USDPerQuantoInt128/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
pragma solidity >=0.8.19;

import {USDPerQuantoInt128} from "./ValueType.sol";
import {USDPerQuantoUint128} from
"../../Uint128/USDPerQuantoUint128/ValueType.sol";
import {SafeCastI128} from "../../utils/SafeCast.sol";

using SafeCastI128 for int128;

/// @notice Wraps a int128 number into the USDPerQuantoInt128 value type.
function wrap(int128 x) pure returns (USDPerQuantoInt128 result) {
Expand All @@ -17,11 +12,3 @@ function wrap(int128 x) pure returns (USDPerQuantoInt128 result) {
function unwrap(USDPerQuantoInt128 x) pure returns (int128 result) {
result = USDPerQuantoInt128.unwrap(x);
}

/// @notice Converts a USDPerQuantoInt128 number into USDPerQuantoUint128.
function toUint(USDPerQuantoInt128 x)
pure
returns (USDPerQuantoUint128 result)
{
result = USDPerQuantoUint128.wrap(unwrap(x).toUint());
}
2 changes: 1 addition & 1 deletion src/Int128/USDPerQuantoInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type USDPerQuantoInt128 is int128;
CASTING
//////////////////////////////////////////////////////////////*/

using {Casting.unwrap, Casting.toUint} for USDPerQuantoInt128 global;
using {Casting.unwrap} for USDPerQuantoInt128 global;

/*//////////////////////////////////////////////////////////////
HELPERS
Expand Down
6 changes: 0 additions & 6 deletions src/Int256/BaseInt256/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity >=0.8.19;

import {BaseInt256} from "./ValueType.sol";
import {BaseInt128} from "../../Int128/BaseInt128/ValueType.sol";
import {BaseUint256} from "../../Uint256/BaseUint256/ValueType.sol";
import {SafeCastI256} from "../../utils/SafeCast.sol";

using SafeCastI256 for int256;
Expand All @@ -22,8 +21,3 @@ function unwrap(BaseInt256 x) pure returns (int256 result) {
function to128(BaseInt256 x) pure returns (BaseInt128 result) {
result = BaseInt128.wrap(unwrap(x).to128());
}

/// @notice Converts a BaseInt256 number into BaseUint256.
function toUint(BaseInt256 x) pure returns (BaseUint256 result) {
result = BaseUint256.wrap(unwrap(x).toUint());
}
2 changes: 1 addition & 1 deletion src/Int256/BaseInt256/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type BaseInt256 is int256;
CASTING
//////////////////////////////////////////////////////////////*/

using {Casting.unwrap, Casting.to128, Casting.toUint} for BaseInt256 global;
using {Casting.unwrap, Casting.to128} for BaseInt256 global;

/*//////////////////////////////////////////////////////////////
HELPERS
Expand Down
11 changes: 1 addition & 10 deletions src/Int256/BaseQuantoPerUSDInt256/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ pragma solidity >=0.8.19;
import {BaseQuantoPerUSDInt256} from "./ValueType.sol";
import {BaseQuantoPerUSDInt128} from
"../../Int128/BaseQuantoPerUSDInt128/ValueType.sol";
import {BaseQuantoPerUSDUint256} from
"../../Uint256/BaseQuantoPerUSDUint256/ValueType.sol";

import {SafeCastI256} from "../../utils/SafeCast.sol";

using SafeCastI256 for int256;
Expand All @@ -27,11 +26,3 @@ function to128(BaseQuantoPerUSDInt256 x)
{
result = BaseQuantoPerUSDInt128.wrap(unwrap(x).to128());
}

/// @notice Converts a BaseQuantoPerUSDInt256 number into BaseQuantoPerUSDUint256.
function toUint(BaseQuantoPerUSDInt256 x)
pure
returns (BaseQuantoPerUSDUint256 result)
{
result = BaseQuantoPerUSDUint256.wrap(unwrap(x).toUint());
}
3 changes: 1 addition & 2 deletions src/Int256/BaseQuantoPerUSDInt256/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ type BaseQuantoPerUSDInt256 is int256;

using {
Casting.unwrap,
Casting.to128,
Casting.toUint
Casting.to128
} for BaseQuantoPerUSDInt256 global;

/*//////////////////////////////////////////////////////////////
Expand Down
6 changes: 0 additions & 6 deletions src/Int256/QuantoInt256/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity >=0.8.19;

import {QuantoInt256} from "./ValueType.sol";
import {QuantoInt128} from "../../Int128/QuantoInt128/ValueType.sol";
import {QuantoUint256} from "../../Uint256/QuantoUint256/ValueType.sol";
import {SafeCastI256} from "../../utils/SafeCast.sol";

using SafeCastI256 for int256;
Expand All @@ -22,8 +21,3 @@ function unwrap(QuantoInt256 x) pure returns (int256 result) {
function to128(QuantoInt256 x) pure returns (QuantoInt128 result) {
result = QuantoInt128.wrap(unwrap(x).to128());
}

/// @notice Converts a QuantoInt256 number into QuantoUint256.
function toUint(QuantoInt256 x) pure returns (QuantoUint256 result) {
result = QuantoUint256.wrap(unwrap(x).toUint());
}
2 changes: 1 addition & 1 deletion src/Int256/QuantoInt256/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type QuantoInt256 is int256;
//////////////////////////////////////////////////////////////*/

using {
Casting.unwrap, Casting.to128, Casting.toUint
Casting.unwrap, Casting.to128
} for QuantoInt256 global;

/*//////////////////////////////////////////////////////////////
Expand Down
6 changes: 0 additions & 6 deletions src/Int256/USDInt256/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity >=0.8.19;

import {USDInt256} from "./ValueType.sol";
import {USDInt128} from "../../Int128/USDInt128/ValueType.sol";
import {USDUint256} from "../../Uint256/USDUint256/ValueType.sol";
import {SafeCastI256} from "../../utils/SafeCast.sol";

using SafeCastI256 for int256;
Expand All @@ -22,8 +21,3 @@ function unwrap(USDInt256 x) pure returns (int256 result) {
function to128(USDInt256 x) pure returns (USDInt128 result) {
result = USDInt128.wrap(unwrap(x).to128());
}

/// @notice Converts a USDInt256 number into USDUint256.
function toUint(USDInt256 x) pure returns (USDUint256 result) {
result = USDUint256.wrap(unwrap(x).toUint());
}
2 changes: 1 addition & 1 deletion src/Int256/USDInt256/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type USDInt256 is int256;
CASTING
//////////////////////////////////////////////////////////////*/

using {Casting.unwrap, Casting.to128, Casting.toUint} for USDInt256 global;
using {Casting.unwrap, Casting.to128} for USDInt256 global;

/*//////////////////////////////////////////////////////////////
HELPERS
Expand Down
6 changes: 0 additions & 6 deletions src/Int256/USDPerBaseInt256/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity >=0.8.19;

import {USDPerBaseInt256} from "./ValueType.sol";
import {USDPerBaseInt128} from "../../Int128/USDPerBaseInt128/ValueType.sol";
import {USDPerBaseUint256} from "../../Uint256/USDPerBaseUint256/ValueType.sol";
import {SafeCastI256} from "../../utils/SafeCast.sol";

using SafeCastI256 for int256;
Expand All @@ -22,8 +21,3 @@ function unwrap(USDPerBaseInt256 x) pure returns (int256 result) {
function to128(USDPerBaseInt256 x) pure returns (USDPerBaseInt128 result) {
result = USDPerBaseInt128.wrap(unwrap(x).to128());
}

/// @notice Converts a USDPerBaseInt256 number into USDPerBaseUint256.
function toUint(USDPerBaseInt256 x) pure returns (USDPerBaseUint256 result) {
result = USDPerBaseUint256.wrap(unwrap(x).toUint());
}
3 changes: 1 addition & 2 deletions src/Int256/USDPerBaseInt256/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ type USDPerBaseInt256 is int256;

using {
Casting.unwrap,
Casting.to128,
Casting.toUint
Casting.to128
} for USDPerBaseInt256 global;

/*//////////////////////////////////////////////////////////////
Expand Down
10 changes: 0 additions & 10 deletions src/Int256/USDPerQuantoInt256/Casting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pragma solidity >=0.8.19;

import {USDPerQuantoInt256} from "./ValueType.sol";
import {USDPerQuantoInt128} from "../../Int128/USDPerQuantoInt128/ValueType.sol";
import {USDPerQuantoUint256} from
"../../Uint256/USDPerQuantoUint256/ValueType.sol";
import {SafeCastI256} from "../../utils/SafeCast.sol";

using SafeCastI256 for int256;
Expand All @@ -23,11 +21,3 @@ function unwrap(USDPerQuantoInt256 x) pure returns (int256 result) {
function to128(USDPerQuantoInt256 x) pure returns (USDPerQuantoInt128 result) {
result = USDPerQuantoInt128.wrap(unwrap(x).to128());
}

/// @notice Converts a USDPerQuantoInt256 number into USDPerQuantoUint256.
function toUint(USDPerQuantoInt256 x)
pure
returns (USDPerQuantoUint256 result)
{
result = USDPerQuantoUint256.wrap(unwrap(x).toUint());
}
3 changes: 1 addition & 2 deletions src/Int256/USDPerQuantoInt256/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ type USDPerQuantoInt256 is int256;

using {
Casting.unwrap,
Casting.to128,
Casting.toUint
Casting.to128
} for USDPerQuantoInt256 global;

/*//////////////////////////////////////////////////////////////
Expand Down
20 changes: 0 additions & 20 deletions test/Int128/BaseInt128.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity >=0.8.19;
import {Test, console} from "forge-std/Test.sol";
import {
BaseInt128,
BaseUint128,
USDPerBaseInt128,
USDInt128
} from "../../src/UnitTypes.sol";
Expand Down Expand Up @@ -352,23 +351,4 @@ contract BaseInt128Test is Test {
assertEq(result.unwrap(), z);
}
}

function testBaseInt128ToUint() public {
int128 x = type(int128).min;
vm.expectRevert();
BaseInt128.wrap(x).toUint();
x = 1;
BaseUint128 result = BaseInt128.wrap(x).toUint();
assertEq(result.unwrap(), uint128(x));
}

function testBaseInt128ToUintFuzz(int128 x) public {
if (x < 0) {
vm.expectRevert();
BaseInt128.wrap(x).toUint();
} else {
BaseUint128 result = BaseInt128.wrap(x).toUint();
assertEq(result.unwrap(), uint128(x));
}
}
}
Loading

0 comments on commit 02aa1aa

Please sign in to comment.