Fix fast-path executed price to match the recorded bid and quote - #4981
Conversation
…the haircut at settle
…xecuted-price # Conflicts: # crates/driver/src/domain/competition/solution/mod.rs # crates/e2e/tests/e2e/fast_path_settle.rs
|
Claude finished @AryanGodara's task in 6m 34s —— View job PR Review: Fix fast-path executed priceI reviewed the fast-path fee-netting change against the quoting/validation flow. Overall the core logic is sound: I found one substantive gap, posted inline:
Non-blocking notes:
|
| fee: crate::fee::FeeParameters { | ||
| gas_amount: quote.gas_amount, | ||
| gas_price: data.metadata.gas_price, | ||
| sell_token_price: data.metadata.sell_token_price, | ||
| } | ||
| .fee(), |
There was a problem hiding this comment.
The staged fee uses FeeParameters::fee() (bare gas_amount * gas_price / sell_token_price), but the fee the user-facing quote and the orderbook fast-path validation net out is fee_with_additional_cost(additional_cost) — i.e. it also includes ERC-1271 signature-verification gas and, for unverified quotes, hook gas.
- User-facing quote:
to_final_quote→with_additional_cost(additional_cost)beforewith_scaled_sell_amount, soquote.buy_amountis scaled by the full fee. - Orderbook:
OrderQuoter::find_quoteapplieswith_additional_cost(...)(order_quoting.rs:738), andcheck_fast_path_limit_price_fitsvalidates against thatquote.buy_amount.
Because this only nets out the bare gas fee, apply_quote_fee in the autopilot subtracts less than the real fee, so the recorded bid ends up higher than the quoted buy for any order with non-zero additional_cost (ERC-1271 / Safe orders, or unverified quotes with hooks — see the comment at order_validation.rs:1056 "Quoted gas does not include gas for ERC1271 signatures"). That partially reintroduces the exact circuit-breaker mismatch this PR is fixing, just scaled down to the additional-cost portion.
For pure-EOA (EIP-712 / EthSign) quotes additional_cost is 0 so this path is unaffected — hence the unit/e2e tests (all EOA) don't catch it.
Consider persisting the final quote.fee_amount (with additional cost) instead of recomputing .fee() here, or threading the signing scheme / additional cost into the staged competition. Note the additional cost technically depends on the order's eventual signing scheme, so exact parity may require capturing it at placement — worth confirming the intended behaviour.
Description
Fast-path orders settled on-chain at a buy amount that matched didn't match the of chain signed price. PR attempting to fix the issue.
Changes
shared::fee::adjust_bid_for_gas_costsnets the quote's gas fee out of (sell, buy) the same way the user-facing quote does (sell orders scale buy down; buy orders raise sell), with unit tests.gas_cost_in_sell_tokenonStagedSolution(#[serde(default)]so already-staged rows keep prior behaviour).finalize_bid(account for gas cost and then apply volume fees), in both the pre-flight limit check and the recorded-bid computation.finalize_fast_path_solutionrebuilds the winning fulfillment withhaircut_fee = 0, so it settles the autopilot's bid exactly.How to test