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

Design, Develop, Test CompoundV3 Adaptors #147

Conversation

0xEinCodes
Copy link
Contributor

@0xEinCodes 0xEinCodes commented Oct 11, 2023

Core changes:

This PR encompasses the integration of CompoundV3 into Sommelier. It revolves around the development and testing of an adaptor (or adaptors) that includes features such as:

  1. Supply BaseAssets to different Compound V3 lending markets.
  2. Adding Collateral to the calling Cellar's Compound V3 account.
  3. Borrowing and paying back BaseAssets to different Compound V3 lending markets.
  4. Claiming Rewards from Compound V3 lending positions.

The design may be split into two or more different adaptors. It is TBD as this PR develops.

Currently, this PR is in the discussion and design phase.

Current Design / TODOs

Currently doing (General):

  • Finish troubleshooting compilation errors. The main ones left are import bugs with CompoundV3ExtraLogic
  1. CompoundV3CollateralAdaptor.sol handles supplying 'Collateral` to a Cellar's lending market account / position.
  • Review CompoundV3 Docs and Codebase
  • Write out function architecture for smart contracts w/ pseudo code
  • PR Review concepts before writing implementation code
  • Write Implementation Code
  • Write tests
  • Peer Review
  • Resolve PR CRs
  • Final PR Review
  • Audit
  1. CompoundV3DebtAdaptor.sol handles borrowing BaseAsset (has to be coordinated with a CompoundV3CollateralAdaptor position with collateral provided.
  • Review CompoundV3 Docs and Codebase
  • Write out function architecture for smart contracts w/ pseudo code
  • PR Review concepts before writing implementation code
  • Write Implementation Code
  • Write tests
  • Peer Review
  • Resolve PR CRs
  • Final PR Review
  • Audit
  1. CompoundLendingAdaptor.sol handles lending BaseAsset to a respective CompoundMarket.
  • Review CompoundV3 Docs and Codebase
  • Write out function architecture for smart contracts w/ pseudo code
  • PR Review concepts before writing implementation code
  • Write Implementation Code
  • Write tests
  • Peer Review
  • Resolve PR CRs
  • Final PR Review
  • Audit
  1. There may be a HealthFactorLogic.sol type file providing helpers in calculating updated health factors.

References

  1. CompoundV3 Docs
  2. CompoundV3 Announcement

@0xEinCodes
Copy link
Contributor Author

@crispymangoes -CompoundV3CollateralAdaptor.sol is roughly written so far. It is ready for your first review though. The big questions right now are:

  1. Are we implementing a minimumHealthFactor that is 'safer' than the checks within the CompoundV3 contracts? If so, we'll need that logic within the contracts to make sure mutative functions don't cause unsafe positions.
  2. Are we combining the functionality of supplying Collateral and supplying BaseAssets into one Adaptor or separating that functionality?

@0xEinCodes
Copy link
Contributor Author

@crispymangoes - Roughly wrote the remaining adaptors (Supply and Debt adaptors). Next step is to go over the key complication areas such as the following (some discussed):

  1. Use of 'base' CompoundV3Adaptor contracts instead of having three standalone contracts since there could be repetitive functionality between some of them.
  2. The Health Factor logic, whether or not we can simply query it from the CompoundV3 lending market contracts or we have to carry out internal helper logic that mirrors CompoundV3 calculation methods.
    a. Once the second point here is sorted then we can clean up the Debt adaptor and other adaptors too. The DebtAdaptor won't need to validate both market and asset then, since the specific CollateralAsset could somehow not be affiliated to the health factor calcs. Not convinced on this theory though.
  3. Map out tests that are needed to hash out extraneous situations (whether or not CompoundV3 does full liquidations or only partial liquidations, etc.).
  4. Is it fair to have reward claiming possible on all adaptors (via inheritance of ExtraLogic adaptor)? I need to dig into it more but it seems that CompoundV3 could incentivize any actor within the protocol (Suppliers, Collateral Providers, Borrowers).
  5. Need to get to the bottom of how to calculate the truly liquid supplied baseAsset when Cellar may want to withdraw baseAsset that is supplies in a position. It could be partially used, and if so, then the remaining amount of liquid baseAsset would have to come from the rest of the protocol (other accounts' supply positions or the reserves).

@0xEinCodes
Copy link
Contributor Author

Worked through all major discussion points brought up through development so far. Now working through compilation troubleshooting. Once that is done, if there is time we will move on to writing unit tests for the supply adaptors, but this may be postponed as outlined in the CompoundV3AdaptorsREADME.md.

@0xEinCodes
Copy link
Contributor Author

I am closing this branch as it has been continued and completed in PR #176

@0xEinCodes 0xEinCodes closed this Jan 31, 2024
@0xEinCodes 0xEinCodes deleted the feat/Compound-v3-Supply-Adaptor branch January 31, 2024 22:09
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.

2 participants