Fix: AMM fee rates must include the pool's LP fee - #7
Merged
Merged
Conversation
An AMM swap pays the platform fee AND the pool's LP fee; the pool reports them as separate lines, so the all-in rate is their sum. `venue_fees` took `platformBuy`/ `platformSell` alone, understating every AMM figure by the LP fee — for our pools a buy read 3% instead of 5%, making an "acquired via AMM" break-even identical to the order-book one and quoting a recovery ask ~2% too low. Verified against live quotes rather than inferred: buy fees.total 3.096917 / usdcAmount 61.938345 = 5.00% (platform 3 + lp 2) sell fees.total 3.406609 / usdcAmount 61.672950 = 5.52% (platform 3.5 + lp 2) The order book keeps its own rates: the LP fee compensates AMM liquidity providers and has no order-book analogue. Found by dogfooding — the output showed both acquisition scenarios with an identical 3.00% buy fee, which is exactly the tell. A pool with no `lp` line falls back to the platform rate; a pool with no platform rate is still genuinely unknown and yields no scenario. Claude-Session: https://claude.ai/code/session_01J7bz8aijn2Uwv1yF5rUenW
piekstra-dev
left a comment
Collaborator
There was a problem hiding this comment.
Automated PR Review
Reviewed commit: bb82811de2d0
Profile: reviewer - Posting as: piekstra-dev
Summary
| Reviewer | Findings |
|---|---|
| documentation:docs | 0 |
| policies:conventions | 0 |
Reviewer Coverage
| Reviewer | Status | Inspected | Skipped | Constraints |
|---|---|---|---|---|
| documentation:docs | complete_broad | README.md | unavailable | unavailable |
| policies:conventions | complete_broad | README.md | unavailable | No sibling cli-common/.github convention docs were present in the review context, so this check relied only on repo-local docs (README.md, AGENTS.md, CONTRIBUTING.md) visible in the workbench. |
| unassigned | incomplete_unassigned | unavailable | src/commands/account.rs | changed files were not assigned to a selected reviewer |
0 PR discussion threads considered. 0 summarized; 0 resolved.
Completed in 1m 28s | $1.11 | claude-sonnet-5 | cr 0.10.268
| Field | Value |
|---|---|
| Model | claude-sonnet-5 |
| Reviewers | documentation:docs, policies:conventions |
| Engine | claude_cli · claude-sonnet-5 |
| Reviewed by | cr · piekstra-dev |
| Duration | 1m 28s wall · 2m 15s compute |
| Cost | $1.11 |
| Tokens | 60 in / 9.4k out |
Per-workstream usage
| Workstream | Model | In | Out | Cache read | Cache create | Cost | Duration |
|---|---|---|---|---|---|---|---|
| orchestrator-selection | claude-sonnet-5 | 6 | 1.8k | 32.8k | 31.4k | $0.23 | 25s |
| documentation:docs | claude-sonnet-5 | 24 | 3.4k | 378.5k | 37.4k | $0.39 | 49s |
| policies:conventions | claude-sonnet-5 | 24 | 3.7k | 353.3k | 35.5k | $0.38 | 49s |
| orchestrator-rollup | claude-sonnet-5 | 6 | 478 | 59.7k | 16.1k | $0.12 | 10s |
piekstra
added a commit
that referenced
this pull request
Jul 28, 2026
Three read-only commands for the questions the raw API can't answer directly, plus one fee correctness fix: - `account coverage` — USDC reserved backing bids vs free to spend (#4) - `account breakeven` — fee-inclusive sell price; costBasis hides the buy fee (#5) - `rewards eligibility`— are my orders earning right now, and if not why (#6) - fix: AMM rates are platform + the pool's LP fee (#7) All three verified against a live account before release. Claude-Session: https://claude.ai/code/session_01J7bz8aijn2Uwv1yF5rUenW
piekstra
added a commit
that referenced
this pull request
Jul 30, 2026
An AMM swap pays the platform fee AND the pool's LP fee; the pool reports them as separate lines, so the all-in rate is their sum. `venue_fees` took `platformBuy`/ `platformSell` alone, understating every AMM figure by the LP fee — for our pools a buy read 3% instead of 5%, making an "acquired via AMM" break-even identical to the order-book one and quoting a recovery ask ~2% too low. Verified against live quotes rather than inferred: buy fees.total 3.096917 / usdcAmount 61.938345 = 5.00% (platform 3 + lp 2) sell fees.total 3.406609 / usdcAmount 61.672950 = 5.52% (platform 3.5 + lp 2) The order book keeps its own rates: the LP fee compensates AMM liquidity providers and has no order-book analogue. Found by dogfooding — the output showed both acquisition scenarios with an identical 3.00% buy fee, which is exactly the tell. A pool with no `lp` line falls back to the platform rate; a pool with no platform rate is still genuinely unknown and yields no scenario.
piekstra
added a commit
that referenced
this pull request
Jul 30, 2026
Three read-only commands for the questions the raw API can't answer directly, plus one fee correctness fix: - `account coverage` — USDC reserved backing bids vs free to spend (#4) - `account breakeven` — fee-inclusive sell price; costBasis hides the buy fee (#5) - `rewards eligibility`— are my orders earning right now, and if not why (#6) - fix: AMM rates are platform + the pool's LP fee (#7) All three verified against a live account before release.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
An AMM swap pays the platform fee and the pool's LP fee. The pool reports them as separate lines, so the all-in rate is their sum — but
venue_feestookplatformBuy/platformSellalone, understating every AMM figure by the LP fee.For our pools that's 3% instead of 5% on a buy. Consequences:
How it was found
Dogfooding. Running
lofty account breakeven --margin 5against a real account printed:Two identical rows with a 3.00% "AMM" fee is the tell — no unit test would have caught it, because the test fixture asserted whatever the code already did.
Verification — measured, not inferred
Live AMM quotes for the same pool:
fees.totalusdcAmountThis also matches the independent evidence already on record: a 1-token buy with
totalSpent$11.90 debited $12.50 — exactly ×1.05.After the fix, the same command reproduces the hand-derived numbers:
Scope
mtBuyFeePct/mtSellFeePctstand alone.lpline falls back to the platform rate (not a missing rate).Testing
New
amm_rates_include_the_pools_lp_feepins all three cases. The existing pool fixture was also corrected to the real observed shape ({lp: 2, platformBuy: 3, platformSell: 3.5}) instead of invented values — which flipped one assertion honestly: swapping out now costs more than resting an ask, so it needs a higher break-even, not a lower one.All 60 tests,
fmt, andclippy -D warningsclean; re-verified live after installing.