morpho-org / morpho-utils

Repository gathering useful libraries and contracts.
GNU Affero General Public License v3.0
65 stars 1 forks source link

Fix weighted average double round up #43

Closed MathisGD closed 1 year ago

MathisGD commented 1 year ago

Fixes this issue found by @QGarchery. Unexpected, but it is saving gas ! Notice that the reverts for overflows are much more conservative with this solution, but I don't think that this is much of an issue.

github-actions[bot] commented 1 year ago

Changes to gas costs

๐Ÿงพ Summary

Contract Method Avg (+/-) %
PercentageMathFunctionsRef weightedAvg +105 โŒ -0.52%
PercentageMathFunctions weightedAvg -21 โœ… +0.10%

Full diff report ๐Ÿ‘‡
| Contract | Deployment Cost (+/-) | Method | Min (+/-) | % | Avg (+/-) | % | Median (+/-) | % | Max (+/-) | % | # Calls (+/-) | |:-|-:|:-|-:|-:|-:|-:|-:|-:|-:|-:|-:| | **PercentageMathFunctionsRef** | 140,583 (+19,418) | _weightedAvg_ | 764 (+105) | **-0.52%** | 764 (+105) | **-0.52%** | 764 (+105) | **-0.52%** | 764 (+105) | **-0.52%** | 2 (0) | | **PercentageMathFunctions** | 126,771 (-1,400) | _weightedAvg_ | 495 (-21) | **+0.10%** | 495 (-21) | **+0.10%** | 495 (-21) | **+0.10%** | 495 (-21) | **+0.10%** | 1 (0) |