Commit 37de01d
Volume fees in the orderbook (cowprotocol#3900)
# Description
Adds protocol volume fee support to the orderbook quote API in order to
reflect the auction fees after submitting an order using the same quote.
The quote response now includes `protocolFeeBps` ~~and
`protocolFeeSellAmount`~~ field~~s~~ when volume fees are configured,
allowing users to see the fee before placing orders.
Volume fees are applied to the surplus token (buy token for sell orders,
sell token for buy orders) following the same logic as the driver. The
orderbook adjusts quote amounts so that orders can be signed with
amounts that will be fillable after the driver applies fees during
auction competition.
The PriceImprovement and Surplus fees are based on the quotes, so it
doesn't make any sense to support them in the quote API.
# Changes
- Added `--volume-fee` CLI argument to orderbook (e.g.,
`--volume-fee=0.0002` for 0.02% or 2 basis points)
- Accepts decimal values in range `[0, 1)` representing the fee factor
- Added optional `protocolFeeBps` (string) ~~and `protocolFeeSellAmount`
(U256)~~ field~~s~~ to `OrderQuoteResponse`
- The field~~s~~ are only present when `--volume-fee` is configured in
the orderbook
# Implementation details
- Volume fee calculation follows driver logic:
https://github.com/cowprotocol/services/blob/31ea719f35072bc6155fdeb990bbc27c9b8833b3/crates/driver/src/domain/competition/solution/fee.rs#L185-L202
- **Sell orders**: Fee calculated on `buy_amount`, reduces the buy
amount returned in quote
- **Buy orders**: Fee calculated on `sell_amount` + network fee,
increases the sell amount returned in quote
- ~~Fee amounts are always converted to sell token for the
`protocolFeeSellAmount` field~~
- ~~Uses `quote.sell_amount/buy_amount` (final computed amounts after
network fees) rather than
`quote.data.quoted_sell_amount/quoted_buy_amount` (original exchange
rate amounts)~~
## How to test
New unit and e2e tests.
## Further configuration
This feature needs to be enabled only on a specific block. This logic
will be implemented in a follow-up PR.
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>1 parent e952516 commit 37de01d
File tree
7 files changed
+399
-8
lines changed- crates
- e2e/tests/e2e
- model/src
- orderbook
- src
- api
7 files changed
+399
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
| |||
403 | 409 | | |
404 | 410 | | |
405 | 411 | | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
| 327 | + | |
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
| |||
332 | 333 | | |
333 | 334 | | |
334 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
335 | 339 | | |
336 | 340 | | |
337 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1682 | 1682 | | |
1683 | 1683 | | |
1684 | 1684 | | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
1685 | 1699 | | |
1686 | 1700 | | |
1687 | 1701 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| 321 | + | |
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
144 | 187 | | |
145 | 188 | | |
146 | 189 | | |
| |||
172 | 215 | | |
173 | 216 | | |
174 | 217 | | |
| 218 | + | |
175 | 219 | | |
176 | 220 | | |
177 | 221 | | |
| |||
225 | 269 | | |
226 | 270 | | |
227 | 271 | | |
| 272 | + | |
228 | 273 | | |
229 | 274 | | |
230 | 275 | | |
| |||
0 commit comments