You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
osmosis-dex: cap pool tvl by sqs on-chain liquidity (#3267) - #3279
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.
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.
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
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.
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.
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
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.
Fixes the osmosis-dex half of #3267 (raydium-amm is in #3276).
Problem
tvlUsdwaspool.liquidityfromdata.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< 50e6guard.Fix
After the APR match, fetch the matched pool ids from
https://sqs.osmosis.zone/pools?IDs=...in batches of 100. Each row there carriesliquidity_cap, which Osmosis's router computes from the pool's on-chainbalances. Each pool now getstvlUsd = min(summary liquidity, sqs liquidity_cap). When sqs has no row or setsliquidity_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.Pools that changed in the replay:
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