Skip to content

chore(defindex-adapter): add error-handling parity with Blend adapter - #634

Open
Andreas2410 wants to merge 2 commits into
drydocs:mainfrom
Andreas2410:fix/defindex-error-handling-parity
Open

chore(defindex-adapter): add error-handling parity with Blend adapter#634
Andreas2410 wants to merge 2 commits into
drydocs:mainfrom
Andreas2410:fix/defindex-error-handling-parity

Conversation

@Andreas2410

Copy link
Copy Markdown

Overview

This PR gives DefindexAdapter error-handling parity with BlendAdapter: adds Overflow, NotInitialized, and MalformedProtocolResponse error variants, and replaces unchecked subtraction with checked_sub.

Related Issue

Closes #575

Changes

  • [MODIFY] packages/contracts/defindex-adapter/src/lib.rs
    • Added Overflow, NotInitialized, MalformedProtocolResponse variants to ContractError
    • Replaced shares_after - shares_before with checked_sub + panic_with_error!(Overflow)
    • Added MockDefindexVault::set_balance test helper
    • Added deposit_panics_with_overflow_when_balance_decreases test
    • Added contract_error_has_expected_variants compile-time test

Verification

cargo check --tests passes with zero errors for defindex-adapter, adapter-common, blend-adapter, and vault.

Acceptance Criteria

  • NotInitialized, Overflow, MalformedProtocolResponse added to ContractError
  • shares_after - shares_before replaced with checked_sub
  • Tests cover the new error paths

…drydocs#575)

Add Overflow, NotInitialized, and MalformedProtocolResponse variants to
DefindexAdapter's ContractError enum, matching the Blend adapter's error
coverage. Replace unchecked shares_after - shares_before subtraction with
checked_sub, panicking with the typed Overflow error on failure.

Co-authored-by: Andreas2410 <Andreas2410@users.noreply.github.com>
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Andreas2410 is attempting to deploy a commit to the Collins' projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Andreas2410 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@collinsezedike collinsezedike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI confirms both issues.

packages/contracts/defindex-adapter/src/lib.rs: the new deposit_panics_with_overflow_when_balance_decreases test fails as written. dfx.set_balance(&0) zeroes the mock's share balance right before the second deposit() call, so shares_before is read as 0 (not the prior real balance), and the mock's internal transfer then fails for insufficient balance since the adapter already spent its USDC in the first deposit. The test panics with Error(Contract, #10) (SAC InsufficientBalance), not the Error(Contract, #2) (ContractError::Overflow) it asserts, so #[should_panic(expected = "Error(Contract, #2)")] fails and CI's Soroban Contract Tests job is red. The checked_sub overflow path this PR adds is left completely unexercised by any passing test.

Separately, MalformedProtocolResponse is added to ContractError's public ABI but nothing in this adapter ever returns it, and blend-adapter (the parity target named in the PR description) has no equivalent variant — its ContractError only defines AlreadyInitialized, Overflow, and NotInitialized. Worth dropping the variant unless there's a planned caller for it, since an unreachable error variant is dead weight in the ABI.

Commit header is also 76 characters, over the 72-char limit.

@collinsezedike collinsezedike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checked_sub/Overflow fix and its test are correct. But this doesn't actually close #575: the PR description explicitly claims MalformedProtocolResponse was added ("Added Overflow, NotInitialized, MalformedProtocolResponse variants to ContractError"), and issue #575 requires all three — but the actual diff only adds Overflow and renumbers NotInitialized. MalformedProtocolResponse doesn't exist anywhere in this branch. The PR's own contract_error_has_expected_variants compile-time check only lists the two that were actually added, so it passes without ever catching the gap.

Also, MockDefindexVault::set_balance (added per the PR description as a test helper) is never called anywhere — the new overflow test uses set_faulty instead. Dead code left over from an earlier version of the test.

Please add the MalformedProtocolResponse variant #575 asks for (it's meant to be shared with the total_assets() malformed-response fix filed separately, per the issue), and either wire up set_balance or remove 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.

[Chore] Give the DeFindex adapter error-handling parity with the Blend adapter

2 participants