Skip to content

surplus and fee calculations into reusable methods#4405

Open
ashleychandy wants to merge 1 commit into
cowprotocol:mainfrom
ashleychandy:perf/trade-surplus-reuse
Open

surplus and fee calculations into reusable methods#4405
ashleychandy wants to merge 1 commit into
cowprotocol:mainfrom
ashleychandy:perf/trade-surplus-reuse

Conversation

@ashleychandy
Copy link
Copy Markdown
Contributor

Description

Optimizes trade metric calculations by computing surplus once and reusing it, eliminating redundant calculations when surplus, fees, and breakdown are needed together.

Changes

  • Added calculate_all_metrics() for single-pass calculation of surplus, fee, and breakdown
  • Refactored surplus/fee methods to accept pre-computed values (surplus_to_ether(), fee_to_ether(), protocol_fees_from_surplus(), fee_breakdown_from_surplus())
  • Introduced TradeMetrics struct to hold all metrics together

@ashleychandy ashleychandy requested a review from a team as a code owner May 12, 2026 09:58
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors trade metric calculations to support single-pass computation using pre-computed surplus values. It introduces the calculate_all_metrics method and several helper functions in the math module to derive ETH-denominated surplus and fees. No critical issues found; I have no feedback to provide.

@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed.

@github-actions github-actions Bot added the stale label May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant