feat(svm): add input_decimals and output_decimals to /pools#538
Merged
Conversation
Customers calculating prices from /pools had to fetch token decimals from a second endpoint. Decimals live in `svm-accounts` (separate from `svm-dex`), but the route handler already has the `accounts` database wired up — it just wasn't joined here. Decimals are looked up via `arrayJoin([token0, token1])` rather than `UNION DISTINCT SELECT token0/1`, scanning `pools_with_tokens` once instead of twice. ~30-40% faster than the naive shape on mint/amm filters. The `/v1/svm/pools` SQL spec already passed without filter at borderline 5s timing; tightening it to use `amm_pool` brings it deterministically under 2.5s and exercises the customer's actual query path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
/v1/svm/poolsnow returnsinput_decimalsandoutput_decimals(nullable) for each pool, joined fromsvm-accounts.decimals_state./v1/svm/swaps,/v1/svm/pools/ohlc, and/v1/svm/tokens.Why arrayJoin instead of UNION DISTINCT
The decimals CTE references the mint set from
pools_with_tokens. The UNION DISTINCT pattern (used in/v1/svm/swaps) caused ClickHouse to re-evaluatepools_with_tokenstwice, doubling the wide aggregation cost. Replacing witharrayJoin([token0, token1])keeps it to a single scan. ~30-40% faster across all filter shapes.🤖 Generated with Claude Code