From 2317096f772fd7687b29c85cfdef1d9f8e652643 Mon Sep 17 00:00:00 2001 From: MerlinEgalite Date: Wed, 5 Jul 2023 08:55:28 +0200 Subject: [PATCH 1/2] perf: != 0 instead of < --- src/Market.sol | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Market.sol b/src/Market.sol index 6f7cb8148..39b5ca60a 100644 --- a/src/Market.sol +++ b/src/Market.sol @@ -62,7 +62,7 @@ contract Blue { function supply(Market calldata market, uint amount) external { Id id = Id.wrap(keccak256(abi.encode(market))); require(lastUpdate[id] != 0, "unknown market"); - require(amount > 0, "zero amount"); + require(amount != 0, "zero amount"); accrueInterests(id); @@ -83,7 +83,7 @@ contract Blue { function withdraw(Market calldata market, uint amount) external { Id id = Id.wrap(keccak256(abi.encode(market))); require(lastUpdate[id] != 0, "unknown market"); - require(amount > 0, "zero amount"); + require(amount != 0, "zero amount"); accrueInterests(id); @@ -103,7 +103,7 @@ contract Blue { function borrow(Market calldata market, uint amount) external { Id id = Id.wrap(keccak256(abi.encode(market))); require(lastUpdate[id] != 0, "unknown market"); - require(amount > 0, "zero amount"); + require(amount != 0, "zero amount"); accrueInterests(id); @@ -127,7 +127,7 @@ contract Blue { function repay(Market calldata market, uint amount) external { Id id = Id.wrap(keccak256(abi.encode(market))); require(lastUpdate[id] != 0, "unknown market"); - require(amount > 0, "zero amount"); + require(amount != 0, "zero amount"); accrueInterests(id); @@ -145,7 +145,7 @@ contract Blue { function supplyCollateral(Market calldata market, uint amount) external { Id id = Id.wrap(keccak256(abi.encode(market))); require(lastUpdate[id] != 0, "unknown market"); - require(amount > 0, "zero amount"); + require(amount != 0, "zero amount"); accrueInterests(id); @@ -157,7 +157,7 @@ contract Blue { function withdrawCollateral(Market calldata market, uint amount) external { Id id = Id.wrap(keccak256(abi.encode(market))); require(lastUpdate[id] != 0, "unknown market"); - require(amount > 0, "zero amount"); + require(amount != 0, "zero amount"); accrueInterests(id); From 1ae8880036c1f0fa23fb839477c7eaa63c338e43 Mon Sep 17 00:00:00 2001 From: MerlinEgalite Date: Wed, 5 Jul 2023 11:11:10 +0200 Subject: [PATCH 2/2] perf: same for isHealthy and liquidate --- src/Market.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Market.sol b/src/Market.sol index 14a12d45a..fe1b2b1de 100644 --- a/src/Market.sol +++ b/src/Market.sol @@ -177,7 +177,7 @@ contract Blue { function liquidate(Market calldata market, address borrower, uint seized) external { Id id = Id.wrap(keccak256(abi.encode(market))); require(lastUpdate[id] != 0, "unknown market"); - require(seized > 0, "zero amount"); + require(seized != 0, "zero amount"); accrueInterests(id); @@ -227,7 +227,7 @@ contract Blue { function isHealthy(Market calldata market, Id id, address user) private view returns (bool) { uint borrowShares = borrowShare[id][user]; // totalBorrowShares[id] > 0 when borrowShares > 0. - uint borrowValue = borrowShares > 0 + uint borrowValue = borrowShares != 0 ? borrowShares.wMul(totalBorrow[id]).wDiv(totalBorrowShares[id]).wMul(market.borrowableOracle.price()) : 0; uint collateralValue = collateral[id][user].wMul(market.collateralOracle.price());