Skip to content

fix(web): use fresh vault state for slippage floors #817 - #843

Open
Xhaka00 wants to merge 2 commits into
drydocs:mainfrom
Xhaka00:fix/fresh-vault-state-slippage-817
Open

Xhaka00 wants to merge 2 commits into
drydocs:mainfrom
Xhaka00:fix/fresh-vault-state-slippage-817

Conversation

@Xhaka00

@Xhaka00 Xhaka00 commented Sep 24, 2026

Copy link
Copy Markdown

Overview

Deposit/withdraw slippage floors were derived from cached position.deposited / position.shares (30s staleTime). After yield accrual that share price lags on-chain vault state, so min_shares_out / min_usdc_out could be set too high and revert with SlippageExceeded / MinAmountOutNotMet. This change prices floors from a fresh vault-state read (totalAssets / totalShares) at transaction build time in useVaultActions.

Related Issue

Closes #817

Changes

  • [MODIFY] apps/web/src/hooks/useVaultState.ts

    • Export fetchFreshVaultState() for an uncached vault-state API read.
    • Add computeMinSharesOut / computeMinUsdcOut helpers using live totals + DEFAULT_SLIPPAGE_BPS.
  • [MODIFY] apps/web/src/hooks/useVaultActions.ts

    • Before buildDeposit / buildWithdraw, when no explicit floor is passed, fetch fresh vault state and compute the slippage floor from totalAssets / totalShares.
    • If the vault-state fetch fails, omit the floor rather than falling back to stale position data.
  • [MODIFY] apps/web/src/components/dashboard/VaultPanel.tsx

    • Stop deriving slippage floors from cached position share price; defer to useVaultActions.
  • [MODIFY/ADD] tests for panel deferral, action-hook fresh-state flooring, and helper math.

Verification Results

Static review of changed modules + updated unit test expectations
✅ Slippage math: amount * (totalShares/totalAssets) * (1 - 50bps) matches prior fixtures (e.g. 25 → 12.4375000)
✅ VaultPanel no longer passes position-derived floors
✅ useVaultActions fetches getVaultState when floors omitted; explicit overrides still honored
⚠️ Full vitest suite not executed in this environment (GitHub REST-only fix path; no local clone/CI run)
Acceptance Criteria Status
Slippage uses fresh on-chain vault totals at tx build time ✅ fetchFreshVaultState in deposit/withdraw path
Stale position cache cannot drive floors ✅ VaultPanel passes undefined; actions ignore position cache
First-time / failed vault-state still safe ✅ Omit floor when totals missing or fetch fails
Closes #817 ✅

Closes #817

@vercel

vercel Bot commented Sep 24, 2026

Copy link
Copy Markdown

@Xhaka00 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 Sep 24, 2026

Copy link
Copy Markdown

@Xhaka00 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.

@Xhaka00 thank you for the contribution. Pricing the slippage floor from a fresh on-chain vault-state read at build time, with a safe fallback to an omitted floor when the read fails, correctly addresses the stale-share-price reverts in #817. Two CI items and the template need attention.

Commit Messages fails on two headers over the 72-character limit (75 and 73). The six commits are also split one-per-file (fix(web): refresh vault state for slippage floors (<filename>)); please squash them into a single logical commit with a header within the limit.

Lint & Typecheck fails on prettier --check; run npx prettier --write on VaultPanel.tsx and useVaultState.ts.

The PR body needs the required template. Please read CONTRIBUTING.md, specifically the Submitting Changes section, and fill out the ## Summary and ## Test plan sections.

@Xhaka00

Xhaka00 commented Sep 25, 2026

Copy link
Copy Markdown
Author

Merge conflict with main resolved

Pushed merge commit f6870c883c into this branch (main @ a27675d8df). This is a merge commit, not a force-push, so the commit history is intact.

Conflicting file(s) resolved:

  • apps/web/src/components/dashboard/VaultPanel.tsx

The pull request is mergeable again — CI will re-run on the new head. @collinsezedike ready for review and merge when you have a moment.

@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.

Thank you @Xhaka00 for the update. The slippage-floor computation itself is correct: the input guards, the formula, and the vault-state source all check out.

Two things need addressing. VaultPanel.tsx reverts the risk-disclosure deduplication from #814 (main commit a27675d), reintroducing the local useState and hand-rolled accept logic that the merged useRiskDisclosure hook replaced. That is unrelated to #817 and looks like it came from an out-of-date base. Please rebase on the latest main and drop that change so the deduplication stays in place.

In useVaultActions.ts, a failed vault-state fetch leaves the floor undefined, which the contract treats as zero, so a transient failure of the rate-limited endpoint submits the deposit or withdraw with no slippage protection at all. Since preventing that exposure is the point of #817, please handle the fetch failure rather than proceeding without a floor.

Commit Messages also fails on two headers over 72 characters (75 and 73), and Lint & Typecheck fails on prettier --check for two files. Please reword those commit headers and run npx prettier --write.

@Xhaka00
Xhaka00 force-pushed the fix/fresh-vault-state-slippage-817 branch 2 times, most recently from 1419a6a to ebe1442 Compare October 1, 2026 16:41
@collinsezedike
collinsezedike force-pushed the fix/fresh-vault-state-slippage-817 branch from 4c48205 to 794c7fe Compare October 3, 2026 15:04

This branch has not been deployed

No deployments
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.

[Fix] Stale position data causes unnecessary slippage reverts

2 participants