Skip to content

osmosis-dex: cap pool tvl by sqs on-chain liquidity (#3267) - #3279

Open
mrstark25 wants to merge 1 commit into
DefiLlama:masterfrom
mrstark25:fix/osmosis-dex-sqs-tvl-cap
Open

mrstark25 wants to merge 1 commit into
DefiLlama:masterfrom
mrstark25:fix/osmosis-dex-sqs-tvl-cap

Conversation

@mrstark25

@mrstark25 mrstark25 commented Nov 27, 2026 •

Copy link
Copy Markdown

Fixes the osmosis-dex half of #3267 (raydium-amm is in #3276).

Problem

tvlUsd was pool.liquidity from data.osmosis.zone/pairs/v2/summary, taken as is. That feed published $45.9m for #2704 and $29.5m for #2791 while the pools held 40/41 and 414/422 base units on chain. #2704 also got past the < 50e6 guard.

Fix

After the APR match, fetch the matched pool ids from https://sqs.osmosis.zone/pools?IDs=... in batches of 100. Each row there carries liquidity_cap, which Osmosis's router computes from the pool's on-chain balances. Each pool now gets tvlUsd = min(summary liquidity, sqs liquidity_cap). When sqs has no row or sets liquidity_cap_error, the adapter keeps the summary figure as before.

The summary feed has already corrected these pools (#2704 now reads $0.00004), so the bad rows are gone for now. This change stops the next glitch from going out unchecked.

Testing

OSMOSIS_API_KEY (numia) is not available to me, so I ran old vs new code side by side. Numia was mocked with one APR row per summary pool above $10k; the summary feed and sqs were the live APIs.

run pools sum tvlUsd
today's summary, old 96 15,705,001
today's summary, new 96 15,667,930 (no pool moves >5% / $1k)
summary with the issue's figures put back, old 100 108,296,107
summary with the issue's figures put back, new 100 15,661,610

Pools that changed in the replay:

pool old tvlUsd new tvlUsd
osmosis-2704 45,855,522 2
osmosis-2791 29,545,584 2
osmosis-2803 9,170,000 2
osmosis-2705 8,020,000 2

sqs agrees with the summary on healthy pools: #1868 $3.31m vs $3.32m, #3497 $2.37m vs $2.37m.

The adapter now makes one extra request per 100 matched pools (about one request today). If sqs is down, the adapter throws, just as it does when data.osmosis.zone fails.

Summary by CodeRabbit

  • Improvements
    • Osmosis pool TVL now reflects the lower of reported liquidity and an available liquidity cap. When no cap is available, reported liquidity is used as before.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Osmosis DEX adaptor now retrieves SQS liquidity caps for pools included in both TVL and APR data. When a cap is available, the adaptor uses the lower of the cap and reported pool liquidity for tvlUsd.

Changes: Osmosis pool liquidity caps

Layer / File(s) Summary
Fetch SQS liquidity caps
src/adaptors/osmosis-dex/index.js
A helper fetches pool data in batches of 100. It skips records with liquidity_cap_error and returns finite caps keyed by pool ID.
Apply caps to pool TVL
src/adaptors/osmosis-dex/index.js
apy requests caps for unique pool IDs present in both TVL and APR data. tvlUsd uses the lower of reported liquidity and an available cap; otherwise, it retains reported liquidity.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • DefiLlama/yield-server#3267 — The cap applies to the issue’s Osmosis pool TVL figures. The Raydium part and proposed total_pool_liquidity check are not covered. The adaptor also retains the summary value when SQS returns no row or an error.

Suggested reviewers: slasher125

Merge Risk: Minimal · up to cc25c

The change caps Osmosis pool TVL at the on-chain liquidity cap. It has a narrow blast radius, and no concrete defect was found, so it looks ready to merge. One minor unknown is whether SQS can ever return a null cap without an error flag.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "osmosis-dex: cap pool tvl by sqs on-chain liquidity (#3267)" names the main change. The diff adds SQS liquidity-cap lookups for Osmosis pools and sets tvlUsd to the lower of reported liquid…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "osmosis-dex: cap pool tvl by sqs on-chain liquidity (#3267)" names the main change. The diff adds SQS liquidity-cap lookups for Osmosis pools and sets tvlUsd to the lower of reported liquidity and the SQS cap, which matches the title. The title uses the adaptor name, the action (cap), the metric (pool tvl), and the data source (SQS on-chain liquidity). It is specific and concise.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 84684e2b-58b3-42ff-baae-556562475563
Commits

Reviewing files that changed from the base of the PR and between ccd3bf6 and cc25c2b.

Files selected for processing: 1

  • src/adaptors/osmosis-dex/index.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@mrstark25

Copy link
Copy Markdown
Author

CI's 401 is the Numia APR call, which needs OSMOSIS_API_KEY and fork PRs don't get secrets. The added sqs call is public. Old vs new results with Numia mocked are in the description.

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.

1 participant