Skip to content

fix(contracts): error on malformed DeFindex valuation, add vault zero-assets backstop - #590

Open
laurentketterle-hub wants to merge 1 commit into
drydocs:mainfrom
laurentketterle-hub:fix/defindex-total-assets-zero-backstop
Open

fix(contracts): error on malformed DeFindex valuation, add vault zero-assets backstop#590
laurentketterle-hub wants to merge 1 commit into
drydocs:mainfrom
laurentketterle-hub:fix/defindex-total-assets-zero-backstop

Conversation

@laurentketterle-hub

Copy link
Copy Markdown

Summary

  • DefindexAdapter::total_assets() is the denominator of the vault's share-pricing formula. On a malformed get_asset_amounts_per_shares response, amounts.get(0).unwrap_or(0) manufactured a valid-looking zero price, collapsing the denominator to OFFSET and letting any meaningful deposit mint a share count that dilutes every prior depositor.
  • defindex-adapter: total_assets() now fails with a new MalformedProtocolResponse error when a held position cannot be valued, instead of silently returning zero. A genuinely empty position (shares <= 0) still returns zero, which is the truth.
  • vault: deposit() now rejects with a new AdapterReportedNoAssets error when shares are outstanding but the adapter reports zero/negative total assets — a vault-side backstop that holds regardless of which adapter is active.
  • Added regression tests for both changes (adapter panics on malformed response; vault rejects a deposit against a broken adapter's zero valuation).

Test plan

  • cargo fmt --all -- --check passes
  • cargo clippy --all-targets -- -D warnings passes
  • cargo test passes (all 14 blend, 13 defindex, 44 vault tests green)
  • cargo build --target wasm32-unknown-unknown --release succeeds

Closes #555

…-assets backstop

DefindexAdapter::total_assets() is the denominator of the vault's
share-pricing formula. On a malformed get_asset_amounts_per_shares
response, amounts.get(0).unwrap_or(0) manufactured a valid-looking zero
price, collapsing the denominator to OFFSET and letting any meaningful
deposit mint a share count that dilutes every prior depositor.

- defindex-adapter: total_assets() now panics with
  MalformedProtocolResponse when a held position cannot be valued, instead
  of returning zero.
- vault: deposit() rejects with AdapterReportedNoAssets when shares are
  outstanding but the adapter reports zero/negative total assets, so no
  present or future adapter can drive the pricing denominator to zero.

Closes drydocs#555

Signed-off-by: laurentketterle-hub <laurentketterle-hub@users.noreply.github.com>
@vercel

vercel Bot commented Aug 24, 2026

Copy link
Copy Markdown

@laurentketterle-hub is attempting to deploy a commit to the Collins' projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Bug] DefindexAdapter::total_assets() silently returns zero on a malformed response

1 participant