-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify quote with pre interactions (#3160)
# Description Not too long ago #3081 changed the simulation logic to not do any set up steps on behalf of the user if the quote provided some pre-interactions. That was done to avoid reverts when a pre-interactions actually set up everything for the trade (e.g. get balances by unstaking). However, this caused issues with verifying quotes with `permit` pre-interactions. Because the quote provided the `permit` pre-interaction the simulation logic also did not try to fake balances although it could have. # Changes Now we again always call the code to setup approvals and such BUT we do it as the very last `pre-interaction`. That way this operation becomes a no-op if the user already sets up everything with their pre-interactions OR does the usual logic and reverts with helpful error messages if the pre-conditions can't be met. Since this function may now be a no-op I renamed it to `ensureSwapPreconditions()`. Additionally this moves code that was previously run before the settlement inside the settlement which increases the measured gas cost. To work around that I also introduced a wrapper function in `Solver.sol` that simply calls the `Trader` function and discounts the gas costs. Note that we can't simply do the necessary steps in the `Solver` because we need to be inside the context of the `Trader` to be able to set approvals and such. That way we can verify quotes which do no, partial or the entire swap setup in their pre-interactions while keeping good error messages and accurate gas estimates. Kudos to @nlordell for the idea. ## How to test I added an e2e test that fails without the PR.
- Loading branch information
1 parent
df9ca2b
commit a520f40
Showing
6 changed files
with
123 additions
and
61 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters