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

More limit order E2E tests #780

Merged
merged 5 commits into from
Nov 15, 2022
Merged

More limit order E2E tests #780

merged 5 commits into from
Nov 15, 2022

Conversation

sistemd
Copy link
Contributor

@sistemd sistemd commented Nov 15, 2022

Fixes #769.

Adds a test for settling two limit orders and a mix of 1 limit order and 1 market order.

@MartinquaXD figured out that our tests were failing due to this, in particular:

Notice that this required the E2E tests to change to have order provide some fee amount so there are sufficient buffers for this rounding error.

All credit for the detective work goes to him. I fixed the issue in our test setup by funding the settlement contract and also making it so that surplus fees for limit orders are always 1 when testing.

@sistemd sistemd requested a review from a team as a code owner November 15, 2022 12:49
/// quote.
/// quote. The fee is denoted in the sell token.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making sure I'm not missing anything: is this comment correct in all cases?

Comment on lines 641 to 645
// Fund settlement contract
tx!(
solver_account,
token_a.mint(contracts.gp_settlement.address(), to_wei(1010))
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only want to avoid the rounding issue mentioned in the PR description we would only ever have to fund the settlement contract with a single wei per order with 0 fees. Using 1010 ETH seems a bit excessive. 😅
Note that we only still run into this issue because the single wei of surplus_fee hardcoded at the moment is so small that it still causes numerical issues (adjusting the buy_token price for such a small fee doesn't change the buy_token price at all leaving again no fee to cover the NaiveSolver rounding issue). For this specific test it be enough to not fund the settlement contract and instead hard code a fee of 2 wei (big enough to change the adjusted price).
However, to be on safe side and never have to worry about this thing it's probably best to be a bit more generous with the hardcoded surplus_fee (maybe 1_000?). This value is already unrealistically small but at least it should be big enough to never cause numerical issues, making it unnecessary to ever fund the settlement contract for an e2e test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7b0b0c7

I don't know the details of this calculation, so I only updated the tests to match the values that I got when they failed. If you can verify this in some meaningful way, please do.

Comment on lines +311 to +314
quoter: Arc::new(FixedFeeQuoter {
quoter,
fee: 1_000.into(),
}),
Copy link
Contributor

@nlordell nlordell Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually like to see this quote fees using the baseline quoter.

Its still not 100% clear to me exactly where the rounding issue is coming from.

One concern that I have is that it actually comes from the clearing price calculation related to the limit prices and not the Naive solver. And, if we use this fixed fee, it might be harder to catch regressions over there.

Copy link
Contributor

@MartinquaXD MartinquaXD Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its still not 100% clear to me exactly where the rounding issue is coming from.

What part of the explanation do you not find convincing?
Note that when the test still set a surplus_fee of 0 the settlement contract was short of exactly 1 wei of the token swapped on uniswap. That's the exact behavior explained in the linked PR.
I went a bit more into the details for the 0 surplus_fee case here in case you missed that.

I guess technically it's still possible that there is an error in the price adjustment for limit orders but I'm fairly certain the issues we experienced before were caused by the NaiveSolver.

And, if we use this fixed fee, it might be harder to catch regressions over there.

Not sure how a variable fee would help with that case.

Copy link
Contributor

@nlordell nlordell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E2E test looks good. Happy to merge as is!

Would be nice to circle back to this and make a follow up where we deal with the rounding issues that are causing the settlements to fail.

@sistemd sistemd merged commit fd7231d into main Nov 15, 2022
@sistemd sistemd deleted the limit_orders_e2e_two branch November 15, 2022 17:17
@github-actions github-actions bot locked and limited conversation to collaborators Nov 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend the E2E test to cover the full flow and fix bugs
3 participants