From 1ba5166b84e4d2ef3f9dce92abee11d27fea4441 Mon Sep 17 00:00:00 2001 From: Terry Pawn Date: Tue, 23 Apr 2024 15:38:06 +0800 Subject: [PATCH 1/2] Add precision in FlashSwapRouterV3Helper --- contracts/swap/FlashSwapRouterV3Helper.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/swap/FlashSwapRouterV3Helper.sol b/contracts/swap/FlashSwapRouterV3Helper.sol index 10497cb8..e421d17e 100644 --- a/contracts/swap/FlashSwapRouterV3Helper.sol +++ b/contracts/swap/FlashSwapRouterV3Helper.sol @@ -24,9 +24,10 @@ contract FlashSwapRouterV3Helper { address tokenQuote, uint256 minOutR, uint256 maxOutR, + uint256 precision, uint256 inQuote ) external returns (uint256 outR) { - while (minOutR < maxOutR - 1) { + while (minOutR + precision < maxOutR) { uint256 midOutR = minOutR / 2 + maxOutR / 2; (bool success, bytes memory data) = address(flashSwapRouter).call( abi.encodeWithSelector( From e334b4f42012d9d877ae7f7739e00b68cc71789c Mon Sep 17 00:00:00 2001 From: Terry Pawn Date: Thu, 25 Apr 2024 09:29:55 +0800 Subject: [PATCH 2/2] Use SafeMath in FlashSwapRouterV3Helper --- contracts/swap/FlashSwapRouterV3Helper.sol | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contracts/swap/FlashSwapRouterV3Helper.sol b/contracts/swap/FlashSwapRouterV3Helper.sol index e421d17e..a77da291 100644 --- a/contracts/swap/FlashSwapRouterV3Helper.sol +++ b/contracts/swap/FlashSwapRouterV3Helper.sol @@ -1,9 +1,13 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity >=0.6.10 <0.8.0; +import "@openzeppelin/contracts/math/SafeMath.sol"; + import "./FlashSwapRouterV3.sol"; contract FlashSwapRouterV3Helper { + using SafeMath for uint256; + FlashSwapRouterV3 public immutable flashSwapRouter; constructor(address flashSwapRouter_) public { @@ -27,7 +31,7 @@ contract FlashSwapRouterV3Helper { uint256 precision, uint256 inQuote ) external returns (uint256 outR) { - while (minOutR + precision < maxOutR) { + while (minOutR.add(precision) < maxOutR) { uint256 midOutR = minOutR / 2 + maxOutR / 2; (bool success, bytes memory data) = address(flashSwapRouter).call( abi.encodeWithSelector(