-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: use morpho utils #90
Conversation
src/Blue.sol
Outdated
@@ -243,7 +245,7 @@ contract Blue { | |||
if (marketTotalSupply != 0) { | |||
uint marketTotalBorrow = totalBorrow[id]; | |||
uint borrowRate = market.irm.borrowRate(market); | |||
uint accruedInterests = marketTotalBorrow.wMul(borrowRate).wMul(block.timestamp - lastUpdate[id]); | |||
uint accruedInterests = marketTotalBorrow.wadMulDown(borrowRate * (block.timestamp - lastUpdate[id])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Borrow rate would typically be 0.001% per second, in WAD. So we should simply multiply the borrow rate by the seconds elapsed, to get a WAD-based % of interests to accrue, that we WAD-multiply with the total borrow to get the quantity of interests accrued.
src/libraries/MathLib.sol
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm against using WadRayMath from morpho-utils, as is at least. We don't need Ray maths, and some other things from it. It would prefer to copy only the used functions (strict minimum) for this particular repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plus, I like the naming wDiv/wMul (rounding to add) as there is no ambiguity in this code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can rename function from a lib instead of copy pasting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -111,7 +111,7 @@ contract Blue { | |||
supplyShare[id][msg.sender] = WAD; | |||
totalSupplyShares[id] = WAD; | |||
} else { | |||
uint256 shares = amount.wMul(totalSupplyShares[id]).wDiv(totalSupply[id]); | |||
uint256 shares = amount.wadDivDown(totalSupply[id]).wadMulDown(totalSupplyShares[id]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering... isn't this basically equivalent to amount.mulDivDown(totalSupplyShares, totalSupply)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you change the order @Rubilmax ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MerlinEgalite discussed here: #90 (comment)
@@ -111,7 +111,7 @@ contract Blue { | |||
supplyShare[id][msg.sender] = WAD; | |||
totalSupplyShares[id] = WAD; | |||
} else { | |||
uint256 shares = amount.wMul(totalSupplyShares[id]).wDiv(totalSupply[id]); | |||
uint256 shares = amount.wadDivDown(totalSupply[id]).wadMulDown(totalSupplyShares[id]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you change the order @Rubilmax ?
src/libraries/MathLib.sol
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can rename function from a lib instead of copy pasting
WadRayMath
#71This PR is a draft because tests need to be updated with regard to rounding directions. I just want to make sure we're on the same page on this before.
@MathisGD @QGarchery please check rounding directions