refactor: stable slippage default#446
Conversation
📝 WalkthroughWalkthroughExtract slippage predicates into exported helpers, refactor useSlippage to consume them with an optional enabled gate and improved override expiry cleanup, update SlippageSettings to use a computed isSlippageAboveDefault, add tests, and gate/parametrize useSlippage in borrow/multiply/collateral forms. ChangesSlippage logic extraction and component integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
🚅 Deployed to the euler-lite-pr-446 environment in euler-lite
|
6e3d000 to
b35f8da
Compare
b35f8da to
57fe4ad
Compare
57fe4ad to
f834784
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/composables/useSlippage.test.ts (2)
21-29: ⚡ Quick winAssert numeric defaults explicitly in this suite.
These expectations reuse
DEFAULT_STABLECOIN_SLIPPAGE/DEFAULT_SLIPPAGE, so a constant regression can still pass here. Add at least one direct numeric assertion (e.g.,0.05/0.3) to pin product intent.🤖 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 `@tests/composables/useSlippage.test.ts` around lines 21 - 29, The test currently only asserts against the constants DEFAULT_STABLECOIN_SLIPPAGE and DEFAULT_SLIPPAGE which could hide regressions; update the cases in the it('uses 0.05% as the default for stablecoin swap pairs', ...) block (the const cases array) to include at least one explicit numeric expectation alongside the constants—e.g., replace or add an entry that expects 0.05 for stablecoin pairs and one that expects 0.3 for non-stablecoin pairs (referencing DEFAULT_STABLECOIN_SLIPPAGE and DEFAULT_SLIPPAGE for clarity), and update the assertion that iterates over cases to check the numeric literal as well as the constant.
36-50: ⚡ Quick winAdd an exact-expiry boundary test.
The suite checks
+1mspast expiry, but not the exactsetAt + SLIPPAGE_EXPIRY_MSboundary. Add one assertion to lock in intended>vs>=behavior.🤖 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 `@tests/composables/useSlippage.test.ts` around lines 36 - 50, Add an exact-expiry boundary assertion for isSlippageOverrideActive: after computing setAt and expiredNow in the test (using SLIPPAGE_EXPIRY_MS), call isSlippageOverrideActive(DEFAULT_SLIPPAGE, setAt, setAt + SLIPPAGE_EXPIRY_MS, DEFAULT_STABLECOIN_SLIPPAGE) and assert the expected boundary behavior (i.e., that the override is still active at exactly setAt + SLIPPAGE_EXPIRY_MS if your logic treats expiry as strictly greater than the window, or assert false if your logic treats it as >=); place this single assertion alongside the existing expiredNow check so the test documents the exact >= vs > behavior for SLIPPAGE_EXPIRY_MS and the isSlippageOverrideActive function.
🤖 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.
Nitpick comments:
In `@tests/composables/useSlippage.test.ts`:
- Around line 21-29: The test currently only asserts against the constants
DEFAULT_STABLECOIN_SLIPPAGE and DEFAULT_SLIPPAGE which could hide regressions;
update the cases in the it('uses 0.05% as the default for stablecoin swap
pairs', ...) block (the const cases array) to include at least one explicit
numeric expectation alongside the constants—e.g., replace or add an entry that
expects 0.05 for stablecoin pairs and one that expects 0.3 for non-stablecoin
pairs (referencing DEFAULT_STABLECOIN_SLIPPAGE and DEFAULT_SLIPPAGE for
clarity), and update the assertion that iterates over cases to check the numeric
literal as well as the constant.
- Around line 36-50: Add an exact-expiry boundary assertion for
isSlippageOverrideActive: after computing setAt and expiredNow in the test
(using SLIPPAGE_EXPIRY_MS), call isSlippageOverrideActive(DEFAULT_SLIPPAGE,
setAt, setAt + SLIPPAGE_EXPIRY_MS, DEFAULT_STABLECOIN_SLIPPAGE) and assert the
expected boundary behavior (i.e., that the override is still active at exactly
setAt + SLIPPAGE_EXPIRY_MS if your logic treats expiry as strictly greater than
the window, or assert false if your logic treats it as >=); place this single
assertion alongside the existing expiredNow check so the test documents the
exact >= vs > behavior for SLIPPAGE_EXPIRY_MS and the isSlippageOverrideActive
function.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: euler-xyz/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 67add0dd-255b-4be1-913b-45ef4bf1db26
📒 Files selected for processing (3)
components/entities/swap/SlippageSettings.vuecomposables/useSlippage.tstests/composables/useSlippage.test.ts
f834784 to
69bcf04
Compare
69bcf04 to
b9f3e6f
Compare
b9f3e6f to
bf2bff0
Compare
bf2bff0 to
af8a974
Compare
af8a974 to
4ddd8e4
Compare
4ddd8e4 to
aa3d699
Compare
Make slippage override expiry use the active pair default so stale generic overrides do not mask the stablecoin 0.05% default. Align the settings copy with the same pair-aware default and cover stable/non-stable pair cases.
aa3d699 to
8ba875a
Compare
Summary
0.05%default slippage in the settings modal and transaction slippage state.swap-slippage*storage keys hydrate into the explicit override shape for compatibility and are cleared after migration/reset so old values do not resurrect.Customand the value.Slippage Product Behavior
Swap slippage defaults follow the selected swap token pair:
USDC -> RLUSD) default to0.05%.wstETH -> WETH) default to0.3%.The slippage control is globally accessible from user settings and is also available inside swap flows. Custom slippage is stored as a user override with the pair-default bucket where it was set:
3%applies within the same default bucket where the user set it.3%override set from global settings or a normal0.3%pair applies to normal0.3%pairs, but does not carry into stable-to-stable0.05%pairs.3%override set from a stable-to-stable0.05%flow applies to stable-to-stable pairs, but does not carry into normal0.3%pairs.0.01%can carry across pair types and do not expire just because 24 hours passed.Existing persisted
swap-slippage*values hydrate into the current override model. Values with a stored stable0.05%bucket remain custom on stable pairs, while values without a stored bucket hydrate as normal0.3%overrides and fall back to the stable0.05%default on stable pairs.Changes
swap-slippage-overrideas the source of truth for persisted custom slippage.useSlippagecoverage for stable/non-stable pairs, override context changes, existing storage hydration, stale/future timestamps, invalid overrides, and clearing custom values equal to the active default.Test plan
npm run test:run -- tests/composables/useSlippage.test.ts tests/utils/swap-slippage-validation.test.ts(28 passing tests)npm run lintnpm run typecheckgit diff --check127.0.0.1:3082with deterministic injected swap contexts:0.05%0.3%3%override and showsresets to 0.05% default after 24h3%override and showsresets to 0.3% default after 24h3%override3%override0.01%lower-than-default overrides3%overrides fall back to0.05%swap-slippage*keys hydrate toCustom 3%swap-slippage*keys fall back to stable0.05%swap-slippage-overrideas JSONCustom 3%chip renders matching dark text for label and valueSummary by CodeRabbit
Bug Fixes
New Features
Refactor
Tests