From 7cc9579b6455574067dd08fa2ee60a82e4b3e4f4 Mon Sep 17 00:00:00 2001 From: barak manos <> Date: Mon, 29 Jan 2024 10:52:37 +0200 Subject: [PATCH] Replace internal implementation of `tryAdd` with OZ's implementation of it --- contracts/carbon/Strategies.sol | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/contracts/carbon/Strategies.sol b/contracts/carbon/Strategies.sol index 9740fe20..ec7c248b 100644 --- a/contracts/carbon/Strategies.sol +++ b/contracts/carbon/Strategies.sol @@ -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"; @@ -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(); @@ -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); } @@ -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;