gas

Replace OZ's library with Solmate to save gas

Reward

Total

24.49 USDC

Selected
24.49 USDC
Selected Submission

Replace OZ's library with Solmate to save gas

Severity

Gas Optimization

Relevant GitHub Links

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DecentralizedStableCoin.sol#L26-L27

Summary

Solmate's ERC20 and Ownable implementations are more optimized than OZ's version. In order to save gas is recommended to switch such implementations from OZ to Solmate in DecentralizedStableCoin.sol

Impact

testRevertsIfMintFails() (gas: -60 (-0.003%)) testRevertsIfTransferFromFails() (gas: -60 (-0.003%)) testHealthFactorCanGoBelowOne() (gas: -19 (-0.007%)) testRevertsWithUnapprovedCollateral() (gas: -60 (-0.008%)) testProperlyReportsHealthFactor() (gas: -19 (-0.009%)) testRevertsIfRedeemAmountIsZero() (gas: -19 (-0.009%)) testCanDepositCollateralWithoutMinting() (gas: -17 (-0.019%)) testCanMintDsc() (gas: -40 (-0.020%)) testCanMintWithDepositedCollateral() (gas: -40 (-0.020%)) testRevertsIfTokenLengthDoesntMatchPriceFeeds() (gas: -54 (-0.030%)) testRevertsIfBurnAmountIsZero() (gas: -79 (-0.039%)) testRevertsIfMintAmountIsZero() (gas: -79 (-0.039%)) testCantLiquidateGoodHealthFactor() (gas: -144 (-0.041%)) testCantBurnMoreThanYouHave() (gas: -32 (-0.053%)) testMustBurnMoreThanZero() (gas: -32 (-0.053%)) testCantMintToZeroAddress() (gas: -7 (-0.056%)) testMustMintMoreThanZero() (gas: -7 (-0.058%)) testRevertsIfCollateralZero() (gas: -60 (-0.138%)) testRevertsIfMintedDscBreaksHealthFactor() (gas: -490 (-0.295%)) testRevertsIfMintAmountBreaksHealthFactor() (gas: -496 (-0.298%)) testUserStillHasSomeEthAfterLiquidation() (gas: -1821 (-0.365%)) testLiquidationPayoutIsCorrect() (gas: -1821 (-0.376%)) testLiquidatorTakesOnUsersDebt() (gas: -1821 (-0.377%)) testUserHasNoMoreDebt() (gas: -1821 (-0.377%)) testCanRedeemDepositedCollateral() (gas: -1823 (-0.724%)) testMustRedeemMoreThanZero() (gas: -1806 (-0.762%)) testCanBurnDsc() (gas: -1823 (-0.768%)) Overall gas change: -14550 (-0.096%)

Tools Used

Manual Review

Recommendations

Switch ERC20Burnable.sol to ERC20 from solmate. Switch Ownable.sol to Owned.sol from solmate