From c979bb01dddd166d159180045f31e74c17f8137f Mon Sep 17 00:00:00 2001 From: Hans Wang <2709448+cwang25@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:18:25 -0800 Subject: [PATCH] add if to skip if either borrow/repay is having 0 amount (#8) * add if to skip if either borrow/repay is having 0 amount * bump version to 0.3.1 --- src/DeFiScripts.sol | 24 ++++++++++++++++++------ src/builder/QuarkBuilderBase.sol | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/DeFiScripts.sol b/src/DeFiScripts.sol index b460b0d..6fa8cdc 100644 --- a/src/DeFiScripts.sol +++ b/src/DeFiScripts.sol @@ -252,13 +252,19 @@ contract CometSupplyMultipleAssetsAndBorrow { } for (uint256 i = 0; i < assets.length;) { - IERC20(assets[i]).forceApprove(comet, amounts[i]); - IComet(comet).supply(assets[i], amounts[i]); + if (amounts[i] > 0) { + IERC20(assets[i]).forceApprove(comet, amounts[i]); + IComet(comet).supply(assets[i], amounts[i]); + } + unchecked { ++i; } } - IComet(comet).withdraw(baseAsset, borrow); + + if (borrow > 0) { + IComet(comet).withdraw(baseAsset, borrow); + } } } @@ -273,10 +279,16 @@ contract CometRepayAndWithdrawMultipleAssets { revert DeFiScriptErrors.InvalidInput(); } - IERC20(baseAsset).forceApprove(comet, repay); - IComet(comet).supply(baseAsset, repay); + if (repay > 0) { + IERC20(baseAsset).forceApprove(comet, repay); + IComet(comet).supply(baseAsset, repay); + } + for (uint256 i = 0; i < assets.length;) { - IComet(comet).withdraw(assets[i], amounts[i]); + if (amounts[i] > 0) { + IComet(comet).withdraw(assets[i], amounts[i]); + } + unchecked { ++i; } diff --git a/src/builder/QuarkBuilderBase.sol b/src/builder/QuarkBuilderBase.sol index b2e5d95..3028168 100644 --- a/src/builder/QuarkBuilderBase.sol +++ b/src/builder/QuarkBuilderBase.sol @@ -18,7 +18,7 @@ import {QuarkOperationHelper} from "src/builder/QuarkOperationHelper.sol"; import {List} from "src/builder/List.sol"; import {HashMap} from "src/builder/HashMap.sol"; -string constant QUARK_BUILDER_VERSION = "0.3.0"; +string constant QUARK_BUILDER_VERSION = "0.3.1"; contract QuarkBuilderBase { /* ===== Output Types ===== */