feat(morpho vault adapter) : first draft vault adapter #85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adapter for morpho's VaultV2
Morpho's guidance was "Ok, very clear. Then in that case you should use vault v2 with a custom adapter that takes into account the asynchronicity. You can take inspiration from the Vaultv1 adapter "
TLDR
allocateanddeallocateneed to be synchronous. Our withdraw process is asyncrhonous.deallocateperforms the execute which claims.code
WildcatMarketV2Adapteris the main file - contains the logic for vault <-> wildcat market interactionsexplanation
Adapter deposits funds into wildcat markets on
allocate()calls and attempts to pull funds ondeallocate(). Since our withdrawals need to queue and mature, the adapter tracks pending batches to keep expiries. When attempting todeallocatewe try and realise any matured expiries and if there isnt enough liquidity for the deallocation request it fails.Contract maintains an indexed list of expiries with pending withdrawals and mutates as realised.
Tricky parts / confusions / please read dillon / laurence
deallocateis called with. This is only important for us since we can have scenarios where partial amounts are paid and the adapter/vault must revert or deallocate the exact amount.TODObecause nfi and dont want tim clancy on my backdeallocate-_realizeClaimable(8);this is just an arbitrary depth of batches to try and resolve on a deallocate call. if theres a better constant to use here LMK. can also be side-stepped with the function that allows you to input batch num though