Skip to content

Report Solana trade fees and return executedFee on /orders - #5302

Open
squadgazzz wants to merge 12 commits into
mainfrom
solana-autopilot/be-534-executed-fee
Open

squadgazzz wants to merge 12 commits into
mainfrom
solana-autopilot/be-534-executed-fee

Conversation

@squadgazzz

Copy link
Copy Markdown
Contributor

Description

A Solana order's executedFee on /orders should be everything taken from its fills, in the sell token, like on EVM. Solana's /orders does not return it.

The driver takes three amounts out of each fill before reporting it: the execution cost (rent and a share of the network fee), the solver fee and the protocol fee. They come out of the surplus token (the buy token of a sell order). /solve reported none of them, and without clearing prices the autopilot cannot recover them.

This PR reports their sum per trade on /solve as fee, and the autopilot stores it with the proposed solution. The sweep task from #5301 converts the winning solution's fee to the sell token, for a sell order at the fill's rate before the fee:

fee_sell = floor(fee_buy * executed_sell / (executed_buy + fee_buy))

Changes

  • V23 stores the reported fee on proposed_trade_executions, and the sweep task writes order_execution.executed_fee in the sell token
  • /orders returns executedFee, executedFeeToken and executedSellAmountBeforeFees, OpenAPI updated
EVM Solana Why
Fee source Surplus at uniform prices minus surplus at custom prices (autopilot/src/domain/settlement/trade/math.rs:126) What the driver reported cutting from the winning solution's fill No clearing prices
Sell-token conversion At uniform prices, rounded down (autopilot/src/domain/settlement/trade/math.rs:104) At the fill's rate before the fee, rounded down Same rate when the uniform price is the route's
Math error Total and protocol fees zeroed together (autopilot/src/domain/settlement/mod.rs:139) Same
Fee unknown Always computed NULL, summed as 0 on /orders like EVM's COALESCE (database/src/orders.rs:706) A trade that matches no winning solution, or a driver that does not report fee yet
executedFeeToken The recorded token, else the sell token (database/src/orders.rs:707) The sell token
executedSellAmountBeforeFees Executed sell minus the signed fee (orderbook/src/database/orders.rs:622) Executed sell Solana orders sign no fee

How to test

New unit, DB and API tests.

Related issues

BE-534

…a quote

The fresh quote of a placed order returns a typed error, so placement
follows the outcomes of the EVM `get_or_create_quote`:

- No driver has a route, or a token has no native price: the order is
  placed without a quote, like the EVM `PriceEstimationError::NoLiquidity`.
- The costs swallow the amount: the order is placed without a quote. The
  EVM orderbook stores such a quote and classes the order out of market,
  which an order without a quote is too.
- A driver failed, the verification dropped every quote, or the price
  lookup is rate limited: the order is rejected with the quote's 404
  `NoLiquidity`.

The quoter reports no liquidity only when every driver answered
`QuotingFailed`, and reads that from the body under any status, like the
EVM orderbook. The fresh quote asks for a verified one. The native payout
check of the quoted amount moves to the quote endpoint, since placement
checks the payout of the order's own limit.
@squadgazzz
squadgazzz added this pull request to stack #5300 November 17, 2026 19:39
@github-actions

Copy link
Copy Markdown

Reminder: Please consider backward compatibility when modifying the API specification.
If breaking changes are unavoidable, ensure:

  • You explicitly pointed out breaking changes.
  • You communicate the changes to affected teams (at least Frontend team and SAFE team).
  • You provide proper versioning and migration mechanisms.

Caused by:

@linear-code

linear-code Bot commented Nov 17, 2026

Copy link
Copy Markdown

BE-534

@squadgazzz
squadgazzz marked this pull request as ready for review November 17, 2026 19:41
@squadgazzz
squadgazzz requested a review from a team as a code owner November 17, 2026 19:41
@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @squadgazzz's task in 1m 19s —— View job


Review

I found one issue and left it as an inline comment: the executedFee description in the OpenAPI spec and in order/dto.rs leaves out the solver fee, which the reported fee includes.

I checked the rest and found no problems:

  • Sweep amounts: the proposed amounts match the indexed on-chain amounts, so the sweep finds the right proposal. For a buy order, the protocol fee pull counts toward the sell amount.
  • Timing: the competition is saved before settlement starts, so the sweep can't run before the proposal it needs is stored.
  • Conversion math: the u128 arithmetic for the sell-token conversion can't overflow.

Comment thread crates/solana-orderbook/openapi.yml Resolved
@github-actions

Copy link
Copy Markdown

🤖 Claude reviewed this PR. Any issues are posted as inline comments on the relevant lines.

  • Runs automatically when a PR is opened or marked ready for review.
  • Re-run it: comment @claude on this PR (requires write access; bots and drafts are skipped).
  • Skip it: add the skip-claude-review label.

Won't run when: the PR is a draft, the author is a bot or lacks write access, or the skip-claude-review label is set.

@squadgazzz
squadgazzz requested a review from tilacog November 18, 2026 12:12
Base automatically changed from solana-autopilot/be-497-executed-protocol-fees to main November 20, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant