Settle fast-path quote solutions via the existing /settle - #4710
Conversation
|
Reminder: Please consider backward compatibility when modifying the API specification.
Resolved |
ad645bf to
1b8d082
Compare
|
Claude finished @AryanGodara's task in 5m 23s —— View job PR Review — Settle fast-path quote solutions
The design is sound and, importantly, fail-safe: Two minor points posted inline (silent dropping of invalid native prices → missing slippage buffer; and all fast-path failures collapsing into One item not inline-able (file not in diff):
Nothing here blocks merge — the amount-mismatch guard makes the risky part safe. LGTM once the openapi doc is updated. |
MartinquaXD
left a comment
There was a problem hiding this comment.
I'm positively surprised. A few things seem more complicated than they need to and some edge cases are not handled but overall the approach seems relatively non invasive. 👍
MartinquaXD
left a comment
There was a problem hiding this comment.
Things are more complicated than I thought. Will have to think more about it and do another pass tomorrow.
…stpath-quote # Conflicts: # crates/driver/openapi.yml # crates/driver/src/domain/competition/mod.rs # crates/driver/src/domain/quote.rs # crates/driver/src/infra/api/routes/quote/dto/quote.rs # crates/driver/src/infra/api/routes/quote/mod.rs # crates/driver/src/tests/cases/quote.rs # crates/driver/src/tests/setup/mod.rs
|
Reminder: Please consider backward compatibility when modifying the API specification.
Caused by: |
| order::Side::Sell => user.buy_amount(&clearing)?.0 >= limit_prices.buy, | ||
| order::Side::Buy => user.sell_amount(&clearing)?.0 <= limit_prices.sell, |
There was a problem hiding this comment.
it's not enough to ensure that the original solution is at least as good as the required limit prices.
The driver also has to make sure the order gets executed EXACTLY at that limit price otherwise the circuit breaker will complain that the order did not get filled as it was intended.
There was a problem hiding this comment.
I see. Now >= is only a feasibility gate (can the cached route cover the limit?),
so after the check I pin the order's two clearing prices to the signed limit, so it fills at exactly that.
also added a small test for this
| #[error("invalid fast-path trade: {0:?}")] | ||
| FastPathTrade(#[from] Trade), |
There was a problem hiding this comment.
Can we get a reason as to why it was invalid?
| Kind::InvalidFastPathOrder => { | ||
| "the settle order does not match the quoted fast-path solution" |
There was a problem hiding this comment.
If this is the respective error message, the error should be called "FastPathOrderQuoteMismatch" or similar, it's much closer and less general than just "invalid order"
| } | ||
|
|
||
| impl Order { | ||
| #[expect(deprecated)] |
There was a problem hiding this comment.
why add a new function if its already deprecated?
There was a problem hiding this comment.
it's not deprecated, that attribute is only there because it still maps the old Balancer Internal/External balance variants which are marked deprecated but not removed yet. i pulled it out into its own function so /settle can reuse the same conversion /solve does. (so when those are removed, expect will error out, reminding to remove this attirbute as well)
| #[error("fast-path order does not match the quoted solution: {0:?}")] | ||
| FastPathInvalidOrder(solution::Error), |
There was a problem hiding this comment.
again specific message vs generic error
| impl DataAggregator { | ||
| /// Resolves the order's app-data hash to the underlying JSON if it isn't | ||
| /// already resolved. | ||
| pub async fn resolve_app_data(&self, order: &mut Order) { |
There was a problem hiding this comment.
not the biggest fan of the mut reference mutation, personally i'd rather take ownership for mutation and returning it afterwards
leaving this to your judgement
There was a problem hiding this comment.
keeping &mut for now, as it just updates one field and does nothing when there's nothing to fetch, so passing the whole order in and out didn't seem worth it
Description
Completes the driver half of BE-58. A fast-path quote already caches its
Solution(in #4678). This works on the/settlepart. At settle time the driver re-encodes the cached solution against the real signed order and submits via the unchanged mempool path.Changes
orderand its nativepricesto/settle. When the order is present, the driver re-encodes the cached quote solution against it before the (unchanged) settle path submits.(auction_id, solution_id), so the existing/settlelookup + mempool submission consume it unchanged.How to test