Summary
The functions: getPrecision
, getAdditionalFeedPrecision
, getLiquidationThreshold
, getLiquidationBonus
, getMinHealthFactor
, getDsc
and getCollateralTokenPriceFeed
retrieve information that is already visible in the contract or can be shared with the users in other ways.
Tools Used
Visual Studio Code and Foundry.
Recommendations
I recommend removing those getters and declaring the functions in the library as internal to reduce deployment and execution gas costs as shown below.
Before changes:
| src/DSCEngine.sol:DSCEngine contract | | | | | |
|--------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 1015345 | 5500 | | | | |
| Function Name | min | avg | median | max |
| depositCollateralAndMintDsc | 93153 | 122997 | 122997 | 152841 | 2 |
| getHealthFactor | 9760 | 9760 | 9760 | 9760 | 3 |
| liquidate | 74676 | 74676 | 74676 | 74676 | 1 |
After changes:
| src/DSCEngine.sol:DSCEngine contract | | | | | |
|--------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 937652 | 5105 | | | | |
| Function Name | min | avg | median | max |
| depositCollateralAndMintDsc | 91614 | 120015 | 120015 | 148417 | 2 |
| getHealthFactor | 7836 | 7836 | 7836 | 7836 | 3 |
| liquidate | 69394 | 69394 | 69394 | 69394 | 1 |