Skip to content

Read per-pool AMM fees from the venue instead of assuming a constant - #462

Open
Naajih09 wants to merge 7 commits into
Divinity-Labs:mainfrom
Naajih09:fix/298-per-pool-fees
Open

Naajih09 wants to merge 7 commits into
Divinity-Labs:mainfrom
Naajih09:fix/298-per-pool-fees

Conversation

@Naajih09

Copy link
Copy Markdown

Closes #298

What this does

Pricing previously used a single fee constant for every AMM pool. Protocols set fees per pool, so pools with a different fee were priced wrongly with no error. This change reads each pool's fee from the venue, caches it, and uses it wherever a fee is needed.

  • Reads the fee for each AMM pool from the venue.
  • Caches the fee and tests the cache, including expiry and refresh.
  • Excludes any pool whose fee cannot be read from execution estimates, and reports it in the response so the exclusion is visible.
  • Removes the fee constant from the pricing path.
  • Echoes network in every response it touches and treats ?network= as required on any new behavior, per the issue's guidance.

Provenance

Responses that use a pool's fee include the pool ID, the fee in basis points, and when that fee was read. Excluded pools are listed with the reason.

Scope

SDEX order-book levels do not have a per-pool fee, so this PR covers AMM pools only. Any SDEX fee handling stays unchanged.

Known limits

  • Fee source. I have not yet confirmed the exact field the venue exposes for each pool's fee. This needs to be checked against the protocol's documentation before merge.
  • Cache lifetime. The cache duration is a judgment call. I'll state the value used and why in the PR review.
  • Not run against a live service. Tests run locally with fixtures. Verification against live pools is still needed.

How to verify

Added interfaces for excluded pools and depth outcomes, updated depth result structure, and modified getDepth function to handle excluded pools.
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@Naajih09 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Miracle656 added a commit that referenced this pull request Oct 22, 2026
  tsc --noEmit   clean
  vitest         93 files, 1068 passing (up from 91 / 1052)
  dropped-tests  none

  #433  from/to range args on getPriceHistory
  #456  make duplicate price points impossible at the database

#456 is the better of the two: a uniqueness constraint in the schema rather
than a check in the ingest path, so a duplicate cannot be written even by a
code path that forgets to look. It carries a migration and adds 14 tests.

Two others from this group were NOT merged -- both fail on their own, so this
is not a merge-order problem:

  #389 (preserve decimal precision in GraphQL prices)
       2 tsc errors, 31 test failures in isolation:
         src/aggregator/vwap.ts(250): Cannot find name 'isNonZeroDecimal'
       The function is called twice and never defined.

  #462 (read per-pool AMM fees from the venue)
       4 tsc errors, 2 failures in isolation:
         src/api/rest.ts(281): Expected 4 arguments, but got 3
         src/api/rest.ts(286): 'pairKey' is specified more than once
       The duplicate key is the shape a repeated base merge produces.

Claude-Session: https://claude.ai/code/session_01USgemLt4Rnz4SGB1Srf3GB

@Miracle656 Miracle656 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fails on its own branch, so this is not about merge order:

src/api/rest.ts(281,33): error TS2554: Expected 4 arguments, but got 3
src/api/rest.ts(286,9):  error TS2783: 'pairKey' is specified more than once, so this usage will be overwritten

4 type errors and 2 failing tests merged alone against current main.

The second one is worth looking at closely rather than just deleting the duplicate. 'pairKey' is specified more than once is the shape a repeated base merge produces — a key gets re-added alongside the one already there, the last wins, and whichever value was meant to apply silently does not. We have had the same thing happen in package.json on this project. Check which pairKey is the one you intend before removing either.

The arity error on line 281 suggests a helper gained a parameter underneath you, which a rebase will surface properly.

Reading per-pool AMM fees from the venue rather than assuming a flat rate is a real improvement and I want it — assumed fees are how a routing recommendation quietly becomes wrong. Fix the two errors and I will take it.

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.

Fees are assumed, not read

2 participants