-
Notifications
You must be signed in to change notification settings - Fork 61
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
feat: add fee #63
feat: add fee #63
Conversation
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.
approving the idea!
@pakim249CAL can you continue this PR? |
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.
Cool implementation, it's nice that we only have to change that one place and that it's done at each interaction ❤️
Can we make it a per market fee @pakim249CAL ? |
@@ -78,6 +79,11 @@ contract Blue { | |||
owner = newOwner; | |||
} | |||
|
|||
function setFee(MarketParams calldata marketParams, uint fee) external onlyOwner { | |||
require(fee <= WAD, "fee must be <= 1"); | |||
_marketStorage[marketParams.toId()].market.fee = fee; |
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.
It does not cost much to check that the market where we change the fee exists (since this is an admin function)
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.
May have been enforced via a private
or internal
getter :D
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.
Agreed, this is what I proposed here. It has been closed because input validation is pretty minimal right now, only 2 things to check that are not related: the id corresponds to an existing market, the amount is non zero. I'm ok with either solution
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.
The fee should be capped, just created an issue for that #110
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.
Could you move the base to main
, I think we agree on the fee mechanism but it's not obvious that we all agree on the storage refactoring
@@ -78,6 +79,11 @@ contract Blue { | |||
owner = newOwner; | |||
} | |||
|
|||
function setFee(MarketParams calldata marketParams, uint fee) external onlyOwner { | |||
require(fee <= WAD, "fee must be <= 1"); | |||
_marketStorage[marketParams.toId()].market.fee = fee; |
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.
The fee should be capped, just created an issue for that #110
@@ -296,6 +302,12 @@ contract Blue { | |||
uint256 accruedInterests = marketTotalBorrow.wMul(borrowRate).wMul(block.timestamp - m.lastUpdate); | |||
m.totalSupply = marketTotalSupply + accruedInterests; | |||
m.totalBorrow = marketTotalBorrow + accruedInterests; | |||
if (m.fee != 0) { |
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.
if (m.fee != 0) { | |
if (m.fee != 0) { |
Let's make the code breath a bit
@@ -296,6 +302,12 @@ contract Blue { | |||
uint256 accruedInterests = marketTotalBorrow.wMul(borrowRate).wMul(block.timestamp - m.lastUpdate); | |||
m.totalSupply = marketTotalSupply + accruedInterests; | |||
m.totalBorrow = marketTotalBorrow + accruedInterests; | |||
if (m.fee != 0) { | |||
uint256 fee = accruedInterests.wMul(m.fee); | |||
uint256 feeShares = fee.wMul(m.totalSupplyShares).wDiv(m.totalSupply - fee); |
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.
should we explain the reasoning of the "-"?
The base branch was changed.
Redone here on main #116 |
Fixes #62
Just contains minimal fee logic for a global fee with a global fee recipient. We can expand on this in future PRs.