Skip to content

Conversation

@kaze-cow
Copy link
Collaborator

@kaze-cow kaze-cow commented Oct 2, 2025

Do not review this PR unless you are looking to help validate the overall design direction of closing orders with euler

implements a test for closing a position after it is opened.

in general, the flow is:

  • a pre-hook is called with the order digest to require for a EVC batch to be executed after settlement. this is included in the initial signed batch from the user
  • settlement contract goes in reverse of the open leverage call (eSUSDS -> WETH). Updated milkswap contract to be a bit more general in how it handles leverage. Proceeds are sent to
  • the CowEvcWrapper is programmed to check all the executed settle order digests and automatically execute repays as necessary (through a helper function that is signed to be called)

known issues:

  • any remainder that hte user has after trade is returned to them in the form of the borrowed token (WETH in this case). this is going to be extremely difficult to work around since COW backends/solvers typically don't process exactOut orders (or if it does, it has deficiencies we have to look at)
  • only the required amount of collateral token is sold (this is probably intended but wierd pairing perhaps with problem 1)
  • if the user is attempting to simply shrink their position and the amount of collateral in their account is large enough, its technically possible that the solver could just execute the order without calling the wrapper at all, and thereby not actually repaying your debt. In this case, the funds would be sent to the wrapper contract and then anyone could take them, so we have to figure something out to resolve this. I have some ideas but they are... extreme.. perhaps

Kaze and others added 28 commits September 11, 2025 21:44
* check solver on internalSettle function
* check only callable through EVC
* prevent reentrancy
make settlement the gatekeeper

why did I not do this before
This reverts commit e56eac3.
best way to ensure the expected flow is followed exactly
* check solver on internalSettle function
* check only callable through EVC
* prevent reentrancy
they shouldn't have been in the repository
feat: use new wrapper from upstream
we use the settlement contract, so it shouldn't be needed anymore

also soljson.latest is still here
@kaze-cow kaze-cow self-assigned this Oct 2, 2025
@kaze-cow kaze-cow marked this pull request as draft October 2, 2025 10:25
Base automatically changed from feat/initial to master October 7, 2025 09:19
@kaze-cow kaze-cow closed this Oct 27, 2025
This was referenced Oct 31, 2025
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