Skip to content

Commit 089cf26

Browse files
committed
add if to skip if either borrow/repay is having 0 amount
1 parent 5c3d0d7 commit 089cf26

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/DeFiScripts.sol

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,19 @@ contract CometSupplyMultipleAssetsAndBorrow {
252252
}
253253

254254
for (uint256 i = 0; i < assets.length;) {
255-
IERC20(assets[i]).forceApprove(comet, amounts[i]);
256-
IComet(comet).supply(assets[i], amounts[i]);
255+
if (amounts[i] > 0) {
256+
IERC20(assets[i]).forceApprove(comet, amounts[i]);
257+
IComet(comet).supply(assets[i], amounts[i]);
258+
}
259+
257260
unchecked {
258261
++i;
259262
}
260263
}
261-
IComet(comet).withdraw(baseAsset, borrow);
264+
265+
if (borrow > 0) {
266+
IComet(comet).withdraw(baseAsset, borrow);
267+
}
262268
}
263269
}
264270

@@ -273,10 +279,16 @@ contract CometRepayAndWithdrawMultipleAssets {
273279
revert DeFiScriptErrors.InvalidInput();
274280
}
275281

276-
IERC20(baseAsset).forceApprove(comet, repay);
277-
IComet(comet).supply(baseAsset, repay);
282+
if (repay > 0) {
283+
IERC20(baseAsset).forceApprove(comet, repay);
284+
IComet(comet).supply(baseAsset, repay);
285+
}
286+
278287
for (uint256 i = 0; i < assets.length;) {
279-
IComet(comet).withdraw(assets[i], amounts[i]);
288+
if (amounts[i] > 0) {
289+
IComet(comet).withdraw(assets[i], amounts[i]);
290+
}
291+
280292
unchecked {
281293
++i;
282294
}

0 commit comments

Comments
 (0)