Skip to content

Commit

Permalink
add if to skip if either borrow/repay is having 0 amount
Browse files Browse the repository at this point in the history
  • Loading branch information
cwang25 committed Nov 21, 2024
1 parent 5c3d0d7 commit 089cf26
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/DeFiScripts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 089cf26

Please sign in to comment.