Skip to content

fix: count initial collateral in CoW supply cap checks - #865

Merged
Seranged merged 3 commits into
developmentfrom
fix/lite-334
Sep 14, 2026
Merged

Seranged merged 3 commits into
developmentfrom
fix/lite-334

Conversation

@Seranged

@Seranged Seranged commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Issue

CoW multiply uses the same vault for the initial collateral deposit and the long side of the swap. Checking only totalAssets + quote.amountOut against its supply cap omits the initial deposit.

With 100 units of remaining capacity, an initial deposit of 60 and quoted swap output of 60 pass the output-only check despite requiring 120 units. This flow skips transaction simulation, so the missing check allows an order to proceed toward approvals and signing even though the combined deposits exceed the checked capacity.

Capturing the deposit before asynchronous preparation also requires using that captured value in review. If the user changes 60 to 1 during sub-account or allowance lookup, showing the live input would describe a different deposit from the execution parameters.

Resolution

Preflight compares totalAssets + initialDeposit + quotedSwapOutput with the supply cap. The initial deposit uses the collateral asset's actual decimals and bigint arithmetic. Exact-cap amounts are accepted, and existing unlimited-cap handling is preserved.

One captured deposit value supplies the cap check, execution parameters, approval amount/display, and Supply review row. The Swap output row is formatted directly from the captured quote using the long asset decimals. Edits during preparation therefore cannot replace the displayed deposit or swap output with live form values.

Validation

  • Cap regressions cover 6- and 18-decimal assets, combined deposits exceeding capacity, exact-cap and below-cap amounts, and unlimited-cap handling.
  • Deferred sub-account and allowance tests edit the input from 60 to 1 and verify that execution, approval display, and Supply review all retain 60. Clearing the live output during either lookup also preserves the captured quote output of 20 in the Swap row.
  • Node 24: lint (six existing warnings), typecheck, production build, and all 2,172 tests passed.
  • No wallet signing or fork settlement test. The check uses the current vault snapshot and quote; settlement-time capacity can still change.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected long-vault capacity checks to include both the initial collateral deposit and swap output.
    • Preserved submitted deposit and swap amounts in review details while account or allowance information is loading, even if inputs change.
    • Updated displayed swap output to accurately reflect the quoted amount.
  • Tests

    • Expanded coverage for pending submission states, allowance checks, review data, and vault capacity scenarios.

Check the combined deposit and quoted swap output before CoW preparation, using the collateral asset decimals.
@railway-app

railway-app Bot commented Sep 11, 2026

Copy link
Copy Markdown

🚅 Deployed to the euler-lite-pr-865 environment in euler-lite(dev,PR previews)

Service Status Web Updated
dev-build ✅ Success (View Logs) Web Sep 11, 2026 at 1:06 pm UTC

@railway-app
railway-app Bot temporarily deployed to euler-lite(dev,PR previews) / euler-lite-pr-865 September 11, 2026 12:05 Destroyed
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: euler-xyz/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: f1460315-3878-461b-bd9f-095253b2fb30

📥 Commits

Reviewing files that changed from the base of the PR and between 7aa1826 and a2a5c7d.

📒 Files selected for processing (2)
  • composables/borrow/useMultiplyCowSwap.ts
  • tests/composables/useMultiplyCowSwap.test.ts

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


📝 Walkthrough

Walkthrough

submitCowSwapMultiply captures the collateral amount before validation and reuses it for cap checks and review-step data. Tests cover cap boundaries and preserve submitted amounts while asynchronous lookups are pending.

Changes

CoW Swap multiply submission and cap validation

Layer / File(s) Summary
Submission data and cap validation
composables/borrow/useMultiplyCowSwap.ts
The long-vault cap check includes the initial collateral deposit and swap output. The flow derives the swap output from the quote and reuses the collateral amount for approval and supply-step display data.
Submission flow test coverage
tests/composables/useMultiplyCowSwap.test.ts
Tests cover cap rejection, boundary acceptance, decimal variations, unlimited caps, and preservation of submitted amounts while sub-account or allowance lookups are pending.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: leonardeulerxyz

Merge Risk: ⚪ Minimal · up to a2a5c

No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: including the initial collateral deposit in CoW supply-cap checks.
✨ 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/lite-334

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

Use the captured deposit amount for approval and Supply rows, with regressions for edits during sub-account and allowance reads.
@railway-app
railway-app Bot temporarily deployed to euler-lite(dev,PR previews) / euler-lite-pr-865 September 11, 2026 12:33 Destroyed

@LeonardEulerXYZ LeonardEulerXYZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review — cap arithmetic and preparation consistency

Reviewed exact head 7aa1826bda1dccfd89925942e48db76df8081c91 against development.

Approve the cap/deposit fix. No PR-introduced blocker found. This is not confirmation that every displayed amount is frozen.

Confirmed

  • The finite-cap preflight now compares totalAssets + initialDeposit + quote.amountOut with supplyCap, using bigint underlying-asset units. The form rejects CoW when margin and long vault addresses differ and excludes savings collateral, so adding both deposits against the same vault is appropriate.
  • With 900 supplied and a cap of 1,000, a 60 deposit plus 60 output is rejected before sub-account preparation. Exact-cap and below-cap cases pass; 6/18-decimal rejection and existing 0/maxUint256 unlimited handling are covered.
  • The deposit string and raw amount are captured before the first await and reused for execution collateralAmount, approval amount/display, and Supply review row. Both pending sub-account and allowance cases pass.
  • Inspected the installed Euler SDK 3.1.0 open-position planner: execution consumes captured collateralAmount and swapQuote. No dependency/config/API change in this PR.

Existing follow-up: Swap output still reads live state

At composables/borrow/useMultiplyCowSwap.ts:257, toAssetInfo.amount still reads options.multiplyLongAmount.value after the lookups. Supply/multiplier controls remain editable during preparation, and requesting a replacement quote clears/replaces this value. The original quote remains in executeParams, but the Swap row can display blank or the replacement quote's output.

I reproduced this with local throwaway tests at both deferred lookup stages: captured output 20; live output reset to blank; executeParams still contains the original quote, while the Swap row displays blank. The same tests fail against the base implementation, so this is a pre-existing follow-up rather than a regression blocking this narrow fix. To satisfy an all-amounts-frozen guarantee, derive the row from the captured quote (or capture its display amount before awaiting). The committed tests keep multiplyLongAmount constant, so they do not discriminate this case.

Validation

Node 24.21.0 / npm 11.10.0, isolated managed worktree; anchor and PR tracked source left unchanged.

  • vitest run tests/composables/useMultiplyCowSwap.test.ts: 8 passed.
  • npm run test:run: 2,168 passed, 1 skipped (221 test files passed, 1 skipped).
  • npm run typecheck: passed.
  • Targeted ESLint on both changed files: passed.
  • npm run build: passed.
  • git diff origin/development...HEAD --check: passed.
  • Additional Swap-row probes: 2 expected failures on head and 2 on base; scratch probes removed from the worktree.

Browser/wallet/fork settlement smoke: not run. Fixtures are synthetic composable inputs, not a funded live position. Cap validation is snapshot-based and cannot reserve settlement-time capacity.

Keep the Swap row aligned with the execution quote when live form output clears during asynchronous preparation.
@railway-app
railway-app Bot temporarily deployed to euler-lite(dev,PR previews) / euler-lite-pr-865 September 11, 2026 13:04 Destroyed

@LeonardEulerXYZ LeonardEulerXYZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed a2a5c7d0ecfff455b701c0fcd593dac762e71ad9: approved. The previous Swap-row follow-up is resolved.

swapOutputAmount is now formatted from the captured quote using long-asset decimals before the first await. Clearing/replacing live form output during sub-account or allowance preparation cannot replace the displayed Swap output. Deposit execution, approval display and Supply row remain captured, and both deposits remain included in finite-cap arithmetic.

Reviewed the incremental fix and full two-file base-to-head diff. The committed tests now exercise live output clearing at both await stages. Independently reran the original throwaway probes that failed on the previous head: all 10 tests pass, including both former failures. Scratch tests removed; worktree clean.

Node 24.21.0 / npm 11.10.0 validation:

  • Focused committed suite: 8 passed.
  • Original independent regression fixture: 10 passed.
  • Full repository suite: 2,168 passed, 1 skipped.
  • Typecheck, targeted ESLint, production build, diff whitespace check: passed.

No new blockers found. Browser/wallet/fork smoke not repeated; this is code and regression-test validation. Snapshot cap checking does not reserve settlement-time capacity.

@Seranged
Seranged merged commit 8b9b9f9 into development Sep 14, 2026
6 checks passed
@Seranged
Seranged deleted the fix/lite-334 branch September 14, 2026 10:12
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.

3 participants