Skip to content

fix: buidl#680 deposit preview and simulation error handling#58

Open
temptemp3 wants to merge 1 commit into
betafrom
fix/buidl-680-deposit-issues
Open

fix: buidl#680 deposit preview and simulation error handling#58
temptemp3 wants to merge 1 commit into
betafrom
fix/buidl-680-deposit-issues

Conversation

@temptemp3
Copy link
Copy Markdown
Contributor

@temptemp3 temptemp3 commented May 5, 2026

Summary

Addresses [buidl#680] Deposit issues in humble-interface (branch from beta).

Root cause

  1. Provider_deposit preview — The Reach/ABI shape is Provider_deposit(byte,(uint256,uint256),uint256). When the user’s first token is not pool token A (swapAForB === false), the code passed four numeric values in the tuple slot instead of two (two stray Math.round amounts). That corrupts the contract call used for expected LP / share preview whenever token order is B-first.
  2. Add liquidity simulation — On !swapR.success, the handler used return new Error(...) instead of throw, so execution continued into signing/sending despite a failed simulation (misleading failures or unsafe follow-on).
  3. Pool remove (related) — The same return new Error anti-pattern existed on remove-liquidity paths; replaced with throw so failures surface in the catch/toast and do not fall through.

Testing

  • npx tsc -b passes locally.

Notes

  • GitHub issue #680 was not visible on this repo via gh issue view; buidl reference kept in title/body per task tracking.

Made with Cursor

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved accuracy of expected outcome calculations in pool addition operations
    • Enhanced error messages to display detailed information when liquidity operations fail
    • Fixed error handling in pool removal operations to reliably prevent failed transactions from proceeding

- PoolAdd: Provider_deposit expects (uint256,uint256); remove two stray
  Math.round values when swapAForB is false so pool-side amounts match ABI.
- PoolAdd: throw when deposit group simulation fails instead of returning
  an Error (execution was continuing into sign/send).
- PoolRemove: throw on failed balance, withdraw preview, and custom group
  simulation instead of returning Error.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

📝 Walkthrough

Walkthrough

This PR improves error handling and contract interaction in two pool operation components. PoolAdd refines the Provider_deposit contract call to pass only required amounts and extracts detailed error messages from failures. PoolRemove converts error returns to throws in three validation points, ensuring failures properly abort execution and trigger error toasts.

Changes

Pool Operations Error Handling

Layer / File(s) Summary
Contract Argument Refinement
src/components/PoolAdd/index.tsx (lines 1083–1088)
Provider_deposit now passes only the two required uint256 amounts in the correct order based on swapAForB, removing previously appended rounded amount values.
Error Detail Extraction
src/components/PoolAdd/index.tsx (lines 1735–1752)
handleProviderDeposit error handling extracts failure details from swapR.error or swapR.message fields rather than throwing a generic message.
Error Control Flow
src/components/PoolRemove/index.tsx (lines 701, 720, 890)
Preview and group simulation failures now throw Error(...) instead of returning Error(...) objects, ensuring failures are caught and trigger toast.error(e.message).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through contract calls,
Fixing arguments that stumble and fall,
Errors now throw with details bright,
No more silent returns in the night!
Pool operations dance in the light. 🌙

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: buidl#680 deposit preview and simulation error handling' directly matches the main changes: fixing deposit preview argument passing and correcting error handling in both deposit and remove liquidity simulations.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/buidl-680-deposit-issues

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/components/PoolAdd/index.tsx (2)

1073-1092: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clear the preview when Provider_deposit fails.

expectedOutcome is only updated on success here, so a failed preview leaves the previous LP/share estimate on screen for the new inputs. Reset it in the failure path (and on rejection) to avoid showing stale numbers.

Suggested fix
-    ci.Provider_deposit(
+    ci.Provider_deposit(
       1,
       swapAForB
         ? [
             fromAmountBI,
             toAmountBI,
           ]
         : [toAmountBI, fromAmountBI],
       0
     ).then((Provider_depositR: any) => {
       if (Provider_depositR.success) {
         setExpectedOutcome(Provider_depositR.returnValue);
+      } else {
+        setExpectedOutcome(undefined);
       }
-    });
+    }).catch(() => {
+      setExpectedOutcome(undefined);
+    });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/PoolAdd/index.tsx` around lines 1073 - 1092, The preview isn't
cleared on failed Provider_deposit calls, so update the Promise chain for
ci.Provider_deposit (the call using swapAForB with fromAmountBI/toAmountBI) to
clear the displayed preview by calling setExpectedOutcome(undefined) (or null)
in both the failure branch (when Provider_depositR.success is false) and in the
.catch rejection handler; ensure setExpectedOutcome is referenced exactly as
used now and that the success branch still sets the returnValue as before.

1055-1086: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Normalize token IDs before deciding the deposit tuple order.

This branch still keys off token.tokenId === pool.tokA. For VOI/wVOI, the selected token can have tokenId === 0 while the pool side is stored as 390001, so swapAForB flips to false and the preview tuple is still reversed for those pools. That leaves the deposit preview incorrect on VOI pairs even after removing the extra tuple values.

Suggested fix
-    const swapAForB = token.tokenId === pool.tokA;
+    const swapAForB = tokenId(token) === pool.tokA;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/PoolAdd/index.tsx` around lines 1055 - 1086, The comparison
that sets swapAForB currently uses raw token.tokenId vs pool.tokA which fails
for VOI/wVOI (tokenId 0 vs pool side 390001); add a small normalization step
(e.g., normalizeTokenId) that maps the zero/placeholder ID to the pool's
canonical VOI ID (390001) and use it when computing swapAForB (replace
token.tokenId === pool.tokA with normalizeTokenId(token.tokenId) ===
normalizeTokenId(pool.tokA)); update any related comparisons that determine
tuple order (the swapAForB calculation used before Provider_deposit) so the
preview tuple order is correct for VOI pairs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/components/PoolAdd/index.tsx`:
- Around line 1073-1092: The preview isn't cleared on failed Provider_deposit
calls, so update the Promise chain for ci.Provider_deposit (the call using
swapAForB with fromAmountBI/toAmountBI) to clear the displayed preview by
calling setExpectedOutcome(undefined) (or null) in both the failure branch (when
Provider_depositR.success is false) and in the .catch rejection handler; ensure
setExpectedOutcome is referenced exactly as used now and that the success branch
still sets the returnValue as before.
- Around line 1055-1086: The comparison that sets swapAForB currently uses raw
token.tokenId vs pool.tokA which fails for VOI/wVOI (tokenId 0 vs pool side
390001); add a small normalization step (e.g., normalizeTokenId) that maps the
zero/placeholder ID to the pool's canonical VOI ID (390001) and use it when
computing swapAForB (replace token.tokenId === pool.tokA with
normalizeTokenId(token.tokenId) === normalizeTokenId(pool.tokA)); update any
related comparisons that determine tuple order (the swapAForB calculation used
before Provider_deposit) so the preview tuple order is correct for VOI pairs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 93d62579-619d-44bc-b2d1-7d2986d94eba

📥 Commits

Reviewing files that changed from the base of the PR and between 9cab6bb and dce20f5.

📒 Files selected for processing (2)
  • src/components/PoolAdd/index.tsx
  • src/components/PoolRemove/index.tsx

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