Skip to content

Commit

Permalink
Replace internal implementation of tryAdd with OZ's implementation …
Browse files Browse the repository at this point in the history
…of it
  • Loading branch information
barak manos committed Jan 29, 2024
1 parent 7bb6e3b commit 7cc9579
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions contracts/carbon/Strategies.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.19;
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { EnumerableSetUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import { MathUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
import { SafeMathUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
import { SafeCastUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { MathEx } from "../utility/MathEx.sol";
Expand Down Expand Up @@ -127,6 +128,7 @@ abstract contract Strategies is Initializable {
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet;
using Address for address payable;
using MathUpgradeable for uint256;
using SafeMathUpgradeable for uint256;
using SafeCastUpgradeable for uint256;

error NativeAmountMismatch();
Expand Down Expand Up @@ -779,7 +781,7 @@ abstract contract Strategies is Initializable {
uint256 temp4 = MathEx.mulDivC(temp1, temp1, factor);
uint256 temp5 = MathEx.mulDivC(temp3, A, factor);

(bool safe, uint256 sum) = tryAdd(temp4, temp5);
(bool safe, uint256 sum) = SafeMathUpgradeable.tryAdd(temp4, temp5);
if (safe) {
return MathEx.mulDivF(temp2, temp3 / factor, sum);
}
Expand Down Expand Up @@ -977,13 +979,6 @@ abstract contract Strategies is Initializable {
}
}

function tryAdd(uint256 x, uint256 y) private pure returns (bool safe, uint256 sum) {
unchecked {
sum = x + y;
safe = sum >= x;
}
}

function uncheckedInc(uint256 i) private pure returns (uint256 j) {
unchecked {
j = i + 1;
Expand Down

0 comments on commit 7cc9579

Please sign in to comment.