Validate order limit prices#75
Open
fedgiac wants to merge 1 commit into
Open
Conversation
fedgiac
force-pushed
the
limit-price-check
branch
from
July 17, 2026 21:09
99a169c to
b535496
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Make a user intent more meaningful by disallowing the contract to pull funds from the user if the price is worse than what the intent specifies.
Until now the program moved an order's sell tokens (pulls) and paid its buy tokens (pushes) without checking that the amounts respected the order. This adds the per-order checks that back DESIGN.md's user guarantee that the user receives at least the specified buy amount, proportional to how much of the sell amount was used.
This is the first of two PRs: it does the limit price only. The per-order sell/buy caps, fill-or-kill, and cumulative cross-settlement accounting follow separately.
Parsing the push amounts
BeginSettlenow also parses the push amounts through introspection, similarly to what was done for the accounts before.Consistency with parsing is validated by sharing helpers and a proptest.
The check
Note that it doesn't matter for this check whether an order is sell or buy.
I run the check after the pulls rather than before to make the code simpler.
I'm a bit concerned for security once token2022 is introduced and CPI on transfer becomes a thing, but for now this code should be safe.
Tests
Added
settle_limit_prices.rswith integration tests.Some of the edge cases are only covered by unit tests, but by the way the code is structured I think it should be enough.