Skip to content

Commit

Permalink
add if to skip if either borrow/repay is having 0 amount (#8)
Browse files Browse the repository at this point in the history
* add if to skip if either borrow/repay is having 0 amount

* bump version to 0.3.1
  • Loading branch information
cwang25 authored Nov 22, 2024
1 parent 21ea11a commit c979bb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 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
2 changes: 1 addition & 1 deletion src/builder/QuarkBuilderBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===== */
Expand Down

0 comments on commit c979bb0

Please sign in to comment.