Skip to content
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 Vault integration (p3) #68

Merged
merged 63 commits into from
Sep 13, 2024
Merged

Conversation

cwang25
Copy link
Contributor

@cwang25 cwang25 commented Aug 30, 2024

  • Morpho Vault integration (earn flow)

@cwang25 cwang25 changed the base branch from main to hans/morpho-integration-2 August 30, 2024 11:46
@cwang25 cwang25 changed the title Morpho Vault integration (WIP) Morpho Vault integration (p3) (WIP) Aug 30, 2024
@cwang25 cwang25 changed the title Morpho Vault integration (p3) (WIP) Morpho Vault integration (p3) Aug 31, 2024
@cwang25 cwang25 marked this pull request as ready for review August 31, 2024 00:19
Hans Wang and others added 6 commits August 31, 2024 00:44
…o pass in complicated shares conversion amount, and also dropped risky changable receiver+owner address, so that client app can't forge iput of those fields to steal users' fund
… builder will only use repayAndwithdraw or supplyandBorrow, builder will never call inidividual supply/withdraw/repay...etc on its own, so trim those functions off to save cost. Also extend the ability to support repayMax and withdrawMax into function for both Morpho and MetaMorpho vault actions
@cwang25 cwang25 force-pushed the hans/morpho-integration-3-vault branch 2 times, most recently from 7da9452 to 2ab022c Compare September 2, 2024 23:03
Copy link
Contributor

@fluffywaffles fluffywaffles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks straightforward enough, and the test coverage looks pretty good. I don't see any missing revert cases, that kind of thing. 👍

However, I don't entirely understand what the XXX comments are about withdrawal checks that we don't implement. What are the "test that you have enough of the asset"-type comments about?

I brought up in a previous PR in this series that I think we should either (a) actually assert against the EIP712 data blobs or (b) drop the TODO that says we should. I admit to not seeing a lot of value in these tests, but (as far as I can tell) the only thing preventing us from testing the EIP712 data is the tedium of copy/pasting the expected hashes and whatnot into the test-case, so we should either go ahead and do that... or decide not do it. We should not leave behind a lingering TODO.

As I look over this code, having just looked at #67, I am struck by how much repetition there is. I wonder if there is not a way to abstract over some of the duplicated code here? Maybe there is not, but it puts an itch in my brain that there are some 100s of lines of code that differ only in the tiniest ways that are copy-pasted between methods of QuarkBuilder.sol. For example, there are code blocks in both PRs for // Validate generated actions for affordability, and these code blocks are really similar-looking at first blush, and sort of long-winded and ugly. I wonder if the logic could be refactored into a helper.

Accounts.ChainAccounts[] memory chainAccountsList,
PaymentInfo.Payment memory payment
) external pure returns (BuilderResult memory) {
// XXX confirm that you actually have the amount to withdraw
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still a to-do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is copied from the cometWithdraw builder, and since both are mostly the same, so I'm pretty sure if cometWithdraw still have this XXX morpho will have the same as well.

From my understanding this is an optional feature that it's left undecided from the beginning from cometWithdraw.
Which we make builder to verify the input and revert if client ever pass in a larger amount to withdraw while user position doesn't have that much of asset in chainAccountList.

But also we don't really need to check, as client won't likely to send in a request to withdraw larger amount than user has. Plus client also provide the ChainAccountList, so if something very wrong in client causing client thinks user has more to withdraw than user has, it's likely client may also mess up the ChainAccountList as well which builder won't be able to catch either.

src/builder/QuarkBuilder.sol Outdated Show resolved Hide resolved
test/builder/QuarkBuilderMorphoVaultSupply.t.sol Outdated Show resolved Hide resolved
test/builder/QuarkBuilderMorphoVaultSupply.t.sol Outdated Show resolved Hide resolved
test/builder/QuarkBuilderMorphoVaultSupply.t.sol Outdated Show resolved Hide resolved
test/builder/QuarkBuilderMorphoVaultSupply.t.sol Outdated Show resolved Hide resolved
test/builder/QuarkBuilderMorphoVaultWithdraw.t.sol Outdated Show resolved Hide resolved
@cwang25 cwang25 force-pushed the hans/morpho-integration-3-vault branch from 31b32f7 to 28c3092 Compare September 6, 2024 18:22
@cwang25
Copy link
Contributor Author

cwang25 commented Sep 6, 2024

Overall, this looks straightforward enough, and the test coverage looks pretty good. I don't see any missing revert cases, that kind of thing. 👍

However, I don't entirely understand what the XXX comments are about withdrawal checks that we don't implement. What are the "test that you have enough of the asset"-type comments about?

I brought up in a previous PR in this series that I think we should either (a) actually assert against the EIP712 data blobs or (b) drop the TODO that says we should. I admit to not seeing a lot of value in these tests, but (as far as I can tell) the only thing preventing us from testing the EIP712 data is the tedium of copy/pasting the expected hashes and whatnot into the test-case, so we should either go ahead and do that... or decide not do it. We should not leave behind a lingering TODO.

As I look over this code, having just looked at #67, I am struck by how much repetition there is. I wonder if there is not a way to abstract over some of the duplicated code here? Maybe there is not, but it puts an itch in my brain that there are some 100s of lines of code that differ only in the tiniest ways that are copy-pasted between methods of QuarkBuilder.sol. For example, there are code blocks in both PRs for // Validate generated actions for affordability, and these code blocks are really similar-looking at first blush, and sort of long-winded and ugly. I wonder if the logic could be refactored into a helper.

Yeah I figured repetition is a bit of pain, might need to major refactor and see if we can have a way to further modularize the builder. (Unfortunately solidity doesn't allow struct inheritances, so we have multiple structs with similar fields :( ). But I'm having some ideas of implementing some modularize functions to reduce those repetitions. Probably will be my next item after morpho integration if no one has picked that one up yet by then.

@kevincheng96
Copy link
Contributor

kevincheng96 commented Sep 9, 2024

Overall looks great. There does seem to be some weirdness with the action contexts that needs to be addressed.

I also agree with Jordan that we should think more about modularizing the code. It is becoming difficult to review these changes because a lot of the logic is copy-and-paste with some small changes. It'll definitely give me a bit more confidence if the copy-and-paste logic can be shared so I know that the same code path is running for the different supply/withdraw actions on different lending protocols.

src/builder/Actions.sol Outdated Show resolved Hide resolved
src/builder/Actions.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@fluffywaffles fluffywaffles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes are addressed, and we've decided to commit to some refactoring of QuarkBuilder as a follow-up while we integrate builder pack. So, Morpho should be unblocked! 👍

@cwang25 cwang25 changed the base branch from hans/morpho-integration-2 to main September 11, 2024 22:26
@cwang25 cwang25 changed the base branch from main to hans/morpho-integration-2 September 12, 2024 01:09
Base automatically changed from hans/morpho-integration-2 to main September 12, 2024 19:03
@cwang25 cwang25 merged commit 528477d into main Sep 13, 2024
4 checks passed
@cwang25 cwang25 deleted the hans/morpho-integration-3-vault branch September 13, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants