-
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
Morpho leverage extension #185
Conversation
* Collateral balance * (net borrow limit - existing borrow balance) / net borrow limit | ||
* | ||
* Net borrow limit is calculated as: | ||
* Collateral Balance * Collateral Price in Borrow units * morpho LLTV * (1 - unutilized leverage %) |
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 don't understand why the borrow limit increases when there is more capacity to borrow ie the unutilized leverage percentage increases. This sounds counter intuitive to me.
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.
When we delever we:
- Withdraw collateral
- Trade collateral for borrow tokens
- Repay borrow tokens
In this case the, the borrow limit is a bit of a misnomer actually as it describes the maximum amount of collateral tokens that can be withdrawn in step 1 without resulting in an "unhealthy" position. (and triggering a revertion here).
The more unutilized leverage the higher that "maximum withdrawal amount" (as it should be called in the delver case) is.
In the case of levering we:
- Borrow
- Swap From Borrow To Collateral
- Deposit Collateral
In this scenario the max borrow limit is aptly named as it describes the maximum amount of tokens that can be borrowed in step 1.
@MerlinEgalite Let me know if:
- That makes it more intuitive
- Our math here seems wrong to you when calculating said limit
- There is any way to defer the position health check maybe to the end of the whole levering / delevering process (i.e. after repaying the loan / depositing collateral) in which case we could increase this limit.
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.
Note that the resulting value is used as a an upper limit here for the rebalance "chunk" size.
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.
Clear to me thx
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.
Looks great to me. I wasn't able to spot any issues. Excellent work 🔥
// Issue 1 SetToken | ||
issueQuantity = ether(1); | ||
|
||
await morphoLeverageModule.sync(setToken.address, { gasLimit: 10000000 }); |
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 curious why you have to call sync
here? I thought there would be no deposit or borrow positions in Morpho before calling engage.
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.
Good call. I didn't need to actually.
Removed it here: 3104684
🎉 This PR is included in version 0.30.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
No description provided.