fix(token-prices): price a token from the median of its deepest paths - #398
Closed
tamaralipows wants to merge 1 commit into
Closed
fix(token-prices): price a token from the median of its deepest paths#398tamaralipows wants to merge 1 commit into
tamaralipows wants to merge 1 commit into
Conversation
tamaralipows
force-pushed
the
tnl/token-price-depth-floor
branch
from
August 3, 2026 18:08
f32296c to
cc447d8
Compare
tamaralipows
force-pushed
the
tnl/token-price-depth-floor
branch
from
August 3, 2026 20:52
4a7bd89 to
81112f1
Compare
tamaralipows
force-pushed
the
tnl/token-price-depth-floor
branch
from
August 3, 2026 21:30
9453f54 to
fd7c708
Compare
Token prices came from the candidate path with the tightest round-trip spread. Spread only measures whether a probe-sized round trip returns symmetric; it says nothing about whether the rate is right. A pool holding one side and almost none of the other quotes a wrong rate with a tight spread and deep liquidity, and on BSC such a WBNB-USDT pool priced USDT 12191x too low. No threshold on that pool alone can catch it, because its reserves are internally consistent. What catches it is that no other path agrees. Candidates are now ranked by the depth of their thinnest hop and the deepest PRICED_PATHS_PER_TOKEN are simulated. From three quotes up the token's price is their median, so a lone disagreeing pool is outvoted; below three it is the deepest path's, since two quotes cannot outvote each other. Depth replaces spread as the ranking key because the wrong pool wins on spread, so ranking by spread would fill the sample with it. Depth ranks paths rather than admitting them. A hop with no depth recorded reads as zero and sorts last instead of being dropped, so a token whose pools are all thin keeps a rough price rather than losing it. Token prices now require pool_depths, which reorders the derived schedule to spot prices, then depths, then token prices. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
tamaralipows
force-pushed
the
tnl/token-price-depth-floor
branch
from
August 3, 2026 21:37
fd7c708 to
28e8c3d
Compare
Contributor
Author
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.
Bug
Token prices come from the candidate path with the tightest round-trip spread. Spread only measures whether a probe-sized round trip returns symmetric. It says nothing about whether the rate is right, and a pool holding one side and almost none of the other quotes a wrong rate with a tight spread and deep liquidity.
On BSC such a WBNB-USDT pool priced USDT 12191x too low. No threshold on that pool alone can catch it: its reserves are internally consistent, so it looks like a legitimate pool for a token that really trades at that rate. What catches it is that no other path agrees.
The price feeds solving, not just reporting.
water_fill.rsconverts gas through it, which setsamount_out_net_gas— the router's ranking key.most_liquid.rsnormalizes edge depth through it. hindsight'svalue_usddivides by it.Fix
Rank candidate paths by the depth of their thinnest hop and simulate deepest first, until
PRICED_PATHS_PER_TOKEN(5) have quoted.From three quotes up, the token's price is their median, so a lone disagreeing pool is outvoted. Below three it is the deepest path's, since two quotes cannot outvote each other.
Depth replaces spread as the ranking key because the wrong pool wins on spread, so ranking by spread would fill the sample with it.
Depth ranks paths rather than admitting them. A hop with no depth recorded reads as zero and sorts last instead of being dropped, so a token whose pools are all thin keeps a rough price rather than losing it.
Token prices now require
pool_depths, which reorders the derived schedule to spot prices → depths → token prices.Cost
The cap counts quotes, not attempts, so a path that fails to simulate does not use up a token's budget. Worst case matches today — a token whose paths all fail tries them all, as the round-robin already did — and the common case is lower, since a token stops at five successes.
None of this is on the solve path. It runs per block in
ComputationManager, and all three algorithms declareallow_stale("token_prices"), so no worker blocks on it. The one real cost is scheduling: prices now run after depths instead of alongside, so per-block freshness lags by the depth computation.Worth a look
🤖 Generated with Claude Code