Skip to content

refactor(common-ts): scale max amount only on non-margin-bound withdraws - #389

Merged
ChesterSim merged 2 commits into
masterfrom
chester/improve-withdraws
Jul 27, 2026
Merged

refactor(common-ts): scale max amount only on non-margin-bound withdraws#389
ChesterSim merged 2 commits into
masterfrom
chester/improve-withdraws

Conversation

@ChesterSim

Copy link
Copy Markdown
Contributor

Summary

  • Only over-estimate (scale 2x) the withdraw amount when a max withdraw closes out the entire deposit, so the on-chain reduceOnly clamp (non-strict) can safely absorb accrued interest.
  • A margin-bound max (amount less than the full deposit) is now sent as-is, since the margin check gating the withdraw is strict and would reject an over-scaled amount.
  • Uses getTokenAmount with SpotBalanceType.DEPOSIT to compute the interest-adjusted deposit token amount instead of relying on raw scaledBalance.

Test plan

  • Added common-ts/tests/actions/spotWithdraw.test.ts covering margin-bound max (unscaled) and full-deposit max (scaled) withdraw scenarios.
  • yarn test in common-ts/

@ChesterSim
ChesterSim merged commit 393570d into master Jul 27, 2026
7 checks passed
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