-
Notifications
You must be signed in to change notification settings - Fork 43
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
Develop Functionality to Supply Collateral and Borrow w/ CompoundV2 #167
Conversation
* Work on strategist functions * Finish setup for test * Get crvUSD Pool working * Test adaptor functions for working with ERC20s and native ETH * Get a good test contract going, and add comments about handling rate tokens * Get as many pools working as possible before handling rate pools * Add support for rate assets with CurveEMAExtension * Get all pools working with liquidity add and removes * Add in test for staking and unstaking curve LP in gauge * update test * Finish vast majority of curve adaptor tests * Update comments in CurveAdaptor * Try to fix CI failing * Add missing 2Pool extension tests * Add in natspec to CurveAdaptor * Add in extra TODOs * Add in a ton of tests, and natsepc to curve helper * remove intentional revert test * Add in last missing test * Try to fix weird fuzz test failure * Add in TODOs from initial talk with auditor
* Write pseudo-code strat fns w/ ConvexAdaptor * Develop deposit & withdraw fns w/ convex adaptor * Develop draft-version remaining adaptor fns w/ convex * Outline testing concepts in comments in ConvexAdaptor.t.sol * Update nat spec w/ ConvexAdaptor.sol * Begin writing setup() for convex adaptor tests * Debug ConvexAdaptor.sol so it compiles * Begin working on ConvexFraxAdaptor.sol * Replace immutable booster w/ immutable voterProxy * Write withdrawLockedAndUnwrap() implementation * Write comments outlining next steps for getReward() * Reconfig setup() in ConvexCurveAdaptor.t.sol * Finish rough setup() for ConvexCurveAdaptor.t.sol * Write majority rough tests w/ ConvexCurveAdaptor * Begin working through compilation errors for convex-curve * Reduce storage reads via adding lpt param to adaptorData * Reformat & remove TODOs that are resolved * Write comparison logic btw adaptorData & queried PoolInfo * Resolve PR#155 CRs & async CRs w/ re-entrancy checks * Write base fns tests w/ CurveConvexAdaptor & minor fixes * Debug more compilation errors in test & adaptor * Resolve main bugs w/ testManagingVanillaCurveLPTs1 * Continue troubleshooting ConvexCurveAdaptor.t.sol tests * Resolve non-managingCurveLPT unit tests * Resolve last bugs w/ ConvexCurveAdaptor.t.sol for PR * PR#155 CRs - Write CVX reward tests & extra validate code * Resolve extra CRs w/ PR#155 * Reformat & remove unused test code * Add CurveHelper to ConvexCurveAdaptor test suite * Remove lingering TODOs w/ ConvexCurveAdaptor * Fix & & remove convex-frax files * Fix lingering period in code * Resolve warnings about unused params w/ getRewards()
* Rough out implementation * Add simple gas test * Rework withdraw queue * plan out user set fee * Update queue with simpler logic * Add comment about front run attack vector * Add share to events * Hash out more tests * Add in potential TODO * Add in solver helper function * Add natspec to WithdrawQueue * Plan out simple Solver * Update comments, and add important bug fix * Add missing natspec, and TODO that is an auditor Q * Add in extra safety checks to simple solver * Add extra TODO note
* Finish 1 TODO and add missing test TODO * Add reentrancy guard with unstructured storage * Fully implement unstructured storage reentrancy lock * Add in missing test where we repeat native eth in input array * Add checks to validate curve addresses Cellar is trying to work with * Add in TODOs from audit check in * Merge changes from dev but remove changes to Curve code * Add proof of concept attack vector * Add helper function to get the underlying token array. * Fix attack vector where strateagist passes in the wrong token array * Implement delta balance transfers for proxy functions * Add informational to Curve2PoolExtension about additional protections not seen in the extension. * Remove unsued code, and update comments. * Update 2 pool extension to use safer pricing method, and add new tests (#163) * Update 2 pool extension to use safer pricing method, and add new tests * Add missing natspec * Remove old TODO
* Write rough deposit() logic * Write rough withdraw() logic * Write rough mint() logic * Write rough redeem() logic * Reformat natspec * Optimize deposit() w/ previewDeposit() * Write pseudo-code for happy-path tests * Write test basic setup() & testDeposit() * Finish rough happy path tests * Start reversion tests * Finish rough test code w/ TODOs * Resolve CRs from PR #161 * Debug tests up to underflow/overlow * Resolve remaining failing tests * Add _revokeExternalApproval() helper fn * Resolve PR #161 CRs from Crispy * Remove TODOs after chat w/ Crispy
* Add in TODOs * Add in bounds checks, just need to refactor tests, and add tests checking for bounds reverts * Draft up MockCurvePricingSource.sol for tests * Resolve compilation errors due to _enforceBounds * Write remaining _enforeBounds() tests * Remove TODO & outdated comments --------- Co-authored-by: 0xEinCodes <[email protected]>
* Add isLiquid bool to ERC20 Adaptor * Add ERC20 Adaptor tests
#166) * Add initiator value to finishSolve and greatly simplify SimpleSolver logic * Finish remaining TODOs
Questions for Compound:
|
This PR is being shelved until sometime in January 2024 when it will be picked up to be audited again. Here are the important notes when picking it up again: What was done so far:Contracts developed: Contracts being troubleshot: Main Aspects that Need Further Work (where a dev will pick up from):*See TODOs outlined in code files.
Detailed Notes to Assist when Picking this Up Again:Decimals for HF:
Equation 1: The difference between the two versions is the scaling factors used throughout each version. Version A gives up precision throughout calculating HF (when compared to what CompoundV2 does behind the scenes), and Version B mimics the precision of CompoundV2 but has to deal with more vars and more gas consumption.
Extra Extra Notes
Handling Native Assets (like ETH):
Below are screenshots from the CompoundV2 docs regarding the scalingFactors used for variables within the calculation of health factor. The links below were useful for dissecting the CompoundV2 codebase alongside their github and docs. https://etherscan.deth.net/address/0x39aa39c021dfbae8fac545936693ac917d5e7563 |
* Feat/curve position support (#156) * Work on strategist functions * Finish setup for test * Get crvUSD Pool working * Test adaptor functions for working with ERC20s and native ETH * Get a good test contract going, and add comments about handling rate tokens * Get as many pools working as possible before handling rate pools * Add support for rate assets with CurveEMAExtension * Get all pools working with liquidity add and removes * Add in test for staking and unstaking curve LP in gauge * update test * Finish vast majority of curve adaptor tests * Update comments in CurveAdaptor * Try to fix CI failing * Add missing 2Pool extension tests * Add in natspec to CurveAdaptor * Add in extra TODOs * Add in a ton of tests, and natsepc to curve helper * remove intentional revert test * Add in last missing test * Try to fix weird fuzz test failure * Add in TODOs from initial talk with auditor * Design, Develop, and Test Convex Adaptors (#155) * Write pseudo-code strat fns w/ ConvexAdaptor * Develop deposit & withdraw fns w/ convex adaptor * Develop draft-version remaining adaptor fns w/ convex * Outline testing concepts in comments in ConvexAdaptor.t.sol * Update nat spec w/ ConvexAdaptor.sol * Begin writing setup() for convex adaptor tests * Debug ConvexAdaptor.sol so it compiles * Begin working on ConvexFraxAdaptor.sol * Replace immutable booster w/ immutable voterProxy * Write withdrawLockedAndUnwrap() implementation * Write comments outlining next steps for getReward() * Reconfig setup() in ConvexCurveAdaptor.t.sol * Finish rough setup() for ConvexCurveAdaptor.t.sol * Write majority rough tests w/ ConvexCurveAdaptor * Begin working through compilation errors for convex-curve * Reduce storage reads via adding lpt param to adaptorData * Reformat & remove TODOs that are resolved * Write comparison logic btw adaptorData & queried PoolInfo * Resolve PR#155 CRs & async CRs w/ re-entrancy checks * Write base fns tests w/ CurveConvexAdaptor & minor fixes * Debug more compilation errors in test & adaptor * Resolve main bugs w/ testManagingVanillaCurveLPTs1 * Continue troubleshooting ConvexCurveAdaptor.t.sol tests * Resolve non-managingCurveLPT unit tests * Resolve last bugs w/ ConvexCurveAdaptor.t.sol for PR * PR#155 CRs - Write CVX reward tests & extra validate code * Resolve extra CRs w/ PR#155 * Reformat & remove unused test code * Add CurveHelper to ConvexCurveAdaptor test suite * Remove lingering TODOs w/ ConvexCurveAdaptor * Fix & & remove convex-frax files * Fix lingering period in code * Resolve warnings about unused params w/ getRewards() * Add lpt transferrance w/ withdraw() * Remove unnecessary LoCs in withdraw() * Feat/withdraw queue (#158) * Rough out implementation * Add simple gas test * Rework withdraw queue * plan out user set fee * Update queue with simpler logic * Add comment about front run attack vector * Add share to events * Hash out more tests * Add in potential TODO * Add in solver helper function * Add natspec to WithdrawQueue * Plan out simple Solver * Update comments, and add important bug fix * Add missing natspec, and TODO that is an auditor Q * Add in extra safety checks to simple solver * Add extra TODO note * Resolve minor fixes from Macro Audit w/ ConvexCurveAdaptor * Fix/macro audit 14 (#157) * Finish 1 TODO and add missing test TODO * Add reentrancy guard with unstructured storage * Fully implement unstructured storage reentrancy lock * Add in missing test where we repeat native eth in input array * Add checks to validate curve addresses Cellar is trying to work with * Add in TODOs from audit check in * Merge changes from dev but remove changes to Curve code * Add proof of concept attack vector * Add helper function to get the underlying token array. * Fix attack vector where strateagist passes in the wrong token array * Implement delta balance transfers for proxy functions * Add informational to Curve2PoolExtension about additional protections not seen in the extension. * Remove unsued code, and update comments. * Update 2 pool extension to use safer pricing method, and add new tests (#163) * Update 2 pool extension to use safer pricing method, and add new tests * Add missing natspec * Remove old TODO * Make a small simplification refactor * Move variable declaration up so all values sit in the same slot * Add evm version to toml, and remove console import from ConvexCurveAdaptor * Feat/simple slippage router (#161) * Write rough deposit() logic * Write rough withdraw() logic * Write rough mint() logic * Write rough redeem() logic * Reformat natspec * Optimize deposit() w/ previewDeposit() * Write pseudo-code for happy-path tests * Write test basic setup() & testDeposit() * Finish rough happy path tests * Start reversion tests * Finish rough test code w/ TODOs * Resolve CRs from PR #161 * Debug tests up to underflow/overlow * Resolve remaining failing tests * Add _revokeExternalApproval() helper fn * Resolve PR #161 CRs from Crispy * Remove TODOs after chat w/ Crispy * Fix/bounding curve pricing (#165) * Add in TODOs * Add in bounds checks, just need to refactor tests, and add tests checking for bounds reverts * Draft up MockCurvePricingSource.sol for tests * Resolve compilation errors due to _enforceBounds * Write remaining _enforeBounds() tests * Remove TODO & outdated comments --------- Co-authored-by: 0xEinCodes <[email protected]> * Feat/illiquid erc20 (#164) * Add isLiquid bool to ERC20 Adaptor * Add ERC20 Adaptor tests * Add initiator value to finishSolve and greatly simplify SimpleSolver … (#166) * Add initiator value to finishSolve and greatly simplify SimpleSolver logic * Finish remaining TODOs * Plan out multi asset support * Rework math to account for share appreciation * Update mullti asset deposit math * Add natspec and add revert tests * Add advanced cellar permutations, and reduce cellar contract size * Update Cellar so deposit event emits asset deposited, and beforeDeposit now knows the asset deposited * Fix PR comments --------- Co-authored-by: 0xEinCodes <[email protected]> Co-authored-by: 0xEinCodes <[email protected]>
* Write rough MorphoBlueSupplyAdaptor.sol * Write rough MorphoBlueCollateralAdaptor.sol * Write very rough debt adaptor w/ morpho blue * Finish rough implementation w/ MBSupplyAdaptor * Write rough implementation of HF calcs * Write MBCollateralAdaptor rough implementation * Write MBDebtAdaptor rough implementation * Work on implementation of repayment fn * Finish basic repayMBDebt implementation * Update natspec for MB adaptors * Start debugging compilation errors * Continue debugging up to Id UserDefined Syntax errors * Finish debugging compilation errors * Begin writing tests & write strat fns for supplyAdaptor * Debug supplyAdaptor strat fns & continue tests * Write basic fuzz tests for collateralAdaptor * Finish rough separate tests for collateral & debt adaptors * Write rough implementation of combo collat/debt tests * Write remaining rough tests for collat/debt adaptors * Write rough tests for supplyAdaptor * Clean up setup() & begin debugging tests * Continue to debug MorphoBlue adaptors & hf calcs * Resolve hf calcs by fixing mockMBPriceFeed * Debug repayment & multiple position tests * Resolve remaining collat & debt adaptor tests except 1 fuzz * Debug most MorphoBlueSupplyAdaptor tests * Delete resolved TODOs in morphoBlue tests * Remove resolved TODOs within morphoBlue adaptors * Resolve more TODOs tests * Resolve supplyAdaptor withdraw bug w/ receiver * Add IrmMock in supply tests to try resolving testAccrueInterest() * Resolve accrueInterest() test w/ Crispy * Resolve testMultipleMorphoBluePositions fuzzing * Resolve some CRs from PR #154 Review * Resolve remaining CRs for PR #154 * Finish balanceOf test for supplyAdaptor * Clean up small formatting fixes in tests * Rename MBHealthFactor logic file to MBHelperLogic * Make most CRs as per Morpho team PR #154 review * Use MorphoLib for _userBorrowBalance() in helper logic * Reformat MBSupplyAdaptor code & tests * Reformat MBCollateral adaptorData input * Reformat MBDebt adaptorData w/ MarketParams * Add isLiquid config to supplyAdaptor * Make final PR #154 CRs w/ crispy * Fix failing tests --------- Co-authored-by: crispymangoes <[email protected]>
* Separate normal deposits and multi asset deposits, and add preview function. * Add missing test and remove old commented code * Copy over code to more advanced cellar permutations * Add natspec clarifying who can call multi asset only owner functions. * Add missing natspec * Address warning * Implement missing advanced permutations * Separate deposit events into 2 separate events * Add better natspec to the multi asset deposit event
* Copy over multichain share files * Fix submodules * Try to debug dependency bug * forge install: ccip v2.6.0 * Still debugging * forge install: ccip ccip-develop * update gitignore * Write additional natspec for CCIP share-bridging contracts * Correct small natspec spelling error * Fix PR comments * Address hidden PR comments --------- Co-authored-by: 0xEinCodes <[email protected]>
…r-contracts into feat/compound-v2-borrows
Important Auto Review SkippedDraft detected. Please check the settings in the CodeRabbit UI or the To trigger a single review, invoke the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
// Check for errors. | ||
if (errorCode != 0) revert CTokenAdaptor__NonZeroCompoundErrorCode(errorCode); | ||
|
||
uint256 hf = _getHealthFactor(address(this), comptroller); |
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.
This is left here currently as I am troubleshooting tests testBorrowInSameCollateralMarket
and testStrategistWithdrawTooLowHF
in CompoundV2AdditionalTests.t.sol
.
I was comparing the HF calculated here vs the methods I created within the test file itself. It all shows that the HF is calculated the same way. The problem is the amountToWithdraw
calculated using the helper. That seems to be incorrect but I keep looking at it and can't seem to get atop of what is incorrect.
); | ||
|
||
uint256 lowerThanMinHF = 1.05e18; | ||
uint256 amountToWithdraw = _generateAmountBasedOnHFOptionA( |
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.
@crispymangoes, this is what my comment is referring to in regards to calculating the proper amountToWithdraw
that will make this test pass.
// uint256 borrowAmountNeeded = (sumCollateral.mulDivDown(1e18, _hfRequested) - sumBorrow); | ||
// return borrowAmountNeeded; | ||
} else { | ||
uint256 withdrawAmountNeeded = (sumCollateral - (sumBorrow.mulDivDown(_hfRequested, 1e18)) / (10 ** (18 - _borrowDecimals))); |
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.
@crispymangoes this is the helper function that is giving me issues for the two failing tests, specifically the lines of code within this else statement.
TODOs that I'd like some help with:Checking over Health Factor calculations and helpers / tests
|
This is paused due to other priorities right now. Notes on where things are left off for future reference:
|
Core changes:
This PR encompasses the integration of CompoundV2 into Sommelier. It revolves around the development and testing of an adaptor (or adaptors) that includes features such as:
BaseAssets
to different Compound V2 lending markets (already done w/CTokenAdaptor.sol
enterMarkets()
on theComptroller
BaseAssets
to different Compound V2 lending markets.Current Design / TODOs
CTokenAdaptorV2.sol
handles supplying 'Collateral` to a Cellar's lending market account / position.CompoundV2DebtAdaptor.sol
handles borrowingBaseAsset
(has to be coordinated with aCompoundV3CollateralAdaptor
position withcollateral
provided.CompoundLendingAdaptor.sol
handles lendingBaseAsset
to a respectiveCompoundMarket
.CTokenAdaptor.sol
previously madeHealthFactorLogic.sol
type file providing helpers in calculating updated health factors.References