-
Notifications
You must be signed in to change notification settings - Fork 95
Add callbacks #121
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
Add callbacks #121
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.
I like the idea but need to reflect a bit more on it.
I don't think there's any problem with this PR either. If it does then the problem was already there for any ERC777 tokens.
I just made some suggestions!
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 thought one main usecase would be single-tx leverage, which involves borrowing and making the promise to supply enough collateral by the end of the callback. It seems callbacks are not implemented for withdraw/borrow. Is this intended?
I don't think callbacks would be useful in those cases, especially before the token transfers. It is likely that whoever is calling the funds wants the funds actually transferred from Blue to the receiver so that they can do something with it. If it is a contract calling Blue, they can simply continue with their logic as normal. As such, I saw it as intended design to not implement callbacks in these functions. Maybe I'm mistaken though. |
Totally makes sense, sorry! |
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.
Contango is extremely bullish on this feature. They suggest to have separate callbacks. In any case, I'm ok to include this feature.
I think I'm in favor of introducing callbacks to Blue it would ease a lot some usecases on top of Blue(position migration, liquidations, etc.) |
I thought about it and changed my mind about callbacks. I now also think callbacks should be implemented. |
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.
Can you do a gas diff comparison @makcandrov please?
It seems to me that defining a specific function for each callback is a better design (suggested by Contango):
|
If everyone agrees (or is not opposed, at least), I'll implement that |
47a0311
Let's rebase on main and handle this question. |
I think that callbacks are important for advanced users to perform complex operations. To provide maximum flexibility, we should add one before transferring an asset from the user to Blue (ie in supply, supply collateral, repay, liquidate, and flashloan), and allow reentrancies on purpose. It can seem scary, but it can be done safely if the last two things in the concerned function are the callback and then the
transferFrom
, with all the checks and storage updates being done before. In fact, it remains safe as long as we never use the contract's balance in the logic.I made some choices that may be discussed (in addition to the need for callbacks ofc):
amount
, representing the amount to supply or repay, depending on the case