Skip to content

fix: await floating balance promises (valence, sierra-money)#20040

Merged
RohanNero merged 1 commit into
DefiLlama:mainfrom
Himess:fix/await-floating-balance-promises
Jul 16, 2026
Merged

fix: await floating balance promises (valence, sierra-money)#20040
RohanNero merged 1 commit into
DefiLlama:mainfrom
Himess:fix/await-floating-balance-promises

Conversation

@Himess

@Himess Himess commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Two adapters kick off an async balance-adding call but return before it settles. The framework reads api.getBalances() right after await tvl(api), and pending promises are not tracked — so the balance is silently missing. Neither shows up as a spike (the value is just persistently low/flickery), which is why it slips past review.

valence (neutron) — deterministic undercount

getLpTvl converts astroport LP shares into their underlying value:

possibleLpTokens.forEach(async (lpToken) => {
  const shareValues = await dexConfig.queryShareValue({ ... }); // network
  shareValues.forEach(sv => api.add(sv.denom, sv.amount));
})
// no await after the loop -> getLpTvl returns here

forEach discards the returned promises and there is no await after the loop, so getLpTvl returns before any api.add runs. Since it's the last call in the neutron tvl, the entire astroport-LP underlying value is dropped on every run. Fixed by awaiting Promise.all(map(...)).

sierra-money (avax) — race

api.sumTokens({ owners, tokens: [ADDRESSES.avax.USDC] }); // not awaited
const openTradeBalances = await api.multiCall({ abi, calls });

The reserve-USDC sumTokens is a floating promise racing the awaited OpenTrade multiCall. When the multiCall wins, the reserve USDC (part of the adapter's stated methodology) is dropped before getBalances() is read. Fixed by awaiting the call.

Both changes are minimal and leave behavior otherwise unchanged; the try/catch handling in valence is preserved.

Summary by CodeRabbit

  • Bug Fixes
    • Improved TVL reporting accuracy by ensuring token and liquidity-pool calculations finish before results are returned.
    • Reduced the risk of incomplete or inconsistent values appearing in dashboard metrics.

Both adapters start an async balance-adding call but return before it
settles, so the balance is absent when the framework reads
api.getBalances() (pending promises are not tracked).

- valence (neutron): getLpTvl unwraps astroport LP shares inside
  possibleLpTokens.forEach(async ...) and has no await after the loop,
  so the api.add() calls never run before the function returns. Use
  await Promise.all(map(...)) instead.
- sierra-money (avax): tvl calls api.sumTokens({ USDC }) without await,
  racing the OpenTrade multiCall; the reserve USDC is dropped when the
  multiCall wins. Await the call.
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6f3b0bab-cce5-4c9f-a6e5-d9ebe94d5e5d

📥 Commits

Reviewing files that changed from the base of the PR and between 01a4389 and 6f01aa2.

📒 Files selected for processing (2)
  • projects/sierra-money/index.js
  • projects/valence/index.js

📝 Walkthrough

Walkthrough

Two adapter TVL calculations were updated to await asynchronous token summation and LP token processing before continuing.

Changes

Async calculation completion

Layer / File(s) Summary
Await USDC summation
projects/sierra-money/index.js
The tvl function awaits api.sumTokens before subsequent vault balance computations.
Await LP token processing
projects/valence/index.js
getLpTvl replaces async forEach processing with Promise.all so LP share value queries and additions complete before continuing.

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

Suggested reviewers: sierraismoney

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: awaiting async balance operations in valence and sierra-money.
Description check ✅ Passed The description clearly explains the bug, impacted adapters, and the minimal fix, matching the PR's purpose.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

The adapter at projects/sierra-money exports TVL:

avax                      40.95 M

total                    40.95 M 

@github-actions

Copy link
Copy Markdown

The adapter at projects/valence exports TVL:

neutron                   1.22 k
terra2                    0.00

total                    1.22 k 

@RohanNero
RohanNero merged commit 0765029 into DefiLlama:main Jul 16, 2026
2 checks passed
@RohanNero

Copy link
Copy Markdown
Contributor

Thanks for the PR

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.

2 participants