Skip to content

fix: swap quote slippage#5601

Merged
gleiser-oliveira merged 1 commit into
mainfrom
fix/trade-slippage
May 21, 2026
Merged

fix: swap quote slippage#5601
gleiser-oliveira merged 1 commit into
mainfrom
fix/trade-slippage

Conversation

@therealemjy
Copy link
Copy Markdown
Member

Changes

  • fix an issue where the slippage would be incorrectly applied to swap quotes coming from the API

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: b62eeca

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@venusprotocol/evm Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dapp-preview Ready Ready Preview May 21, 2026 2:58pm
dapp-testnet Ready Ready Preview May 21, 2026 2:58pm
venus.io Ready Ready Preview May 21, 2026 2:58pm

Request Review

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 21, 2026

Greptile Summary

This PR fixes a bug where slippagePercentage was being divided by 100 twice before being passed to formatSwapQuote: once when building the API request params (slippagePercentage / 100) and again when reading it back via Number(params.slippagePercentage). The fix replaces the read-back with the original slippagePercentage variable, so the correct percentage (e.g. 0.5) is used when computing minimum/maximum token amounts.

  • getSwapQuote/index.ts: One-line fix — slippagePercentage is now passed directly to formatSwapQuote instead of the already-divided params.slippagePercentage.
  • Test snapshots: Updated to reflect the correct 0.5% slippage values (995000000000000000n / 1005000n) replacing the erroneous 0.005% values.

Confidence Score: 5/5

Safe to merge — the fix is a straightforward one-line correction with updated tests that verify the correct slippage math.

The root cause is clear and well-understood: params.slippagePercentage was already slippagePercentage / 100, so reading it back via Number(params.slippagePercentage) applied the division twice. Using the original variable directly resolves this. The updated snapshots confirm the expected output now matches 0.5% slippage instead of 0.005%.

No files require special attention beyond the minor changeset versioning note.

Important Files Changed

Filename Overview
apps/evm/src/clients/api/queries/getSwapQuote/index.ts Fixes slippage being divided by 100 twice: replaces Number(params.slippagePercentage) (which was already slippagePercentage / 100) with the original slippagePercentage variable. Correct fix.
apps/evm/src/clients/api/queries/getSwapQuote/__ tests__/index.spec.ts Updates expected snapshot values to reflect the corrected 0.5% slippage (995000000000000000n / 1005000n) instead of the erroneous 0.005% slippage from before the fix. Math checks out.
.changeset/rotten-ways-love.md Changeset version type is minor for a pure bug fix; should be patch per semver convention.

Reviews (2): Last reviewed commit: "fix: fix an issue with swap quote slippa..." | Re-trigger Greptile

Comment thread apps/evm/src/clients/api/queries/getSwapQuote/formatSwapQuote/index.ts Outdated
Comment thread apps/evm/src/clients/api/queries/getSwapQuote/formatSwapQuote/index.ts Outdated
@therealemjy therealemjy force-pushed the fix/trade-slippage branch from b62eeca to 14a95bd Compare May 21, 2026 14:55
@therealemjy
Copy link
Copy Markdown
Member Author

@greptile

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for ./apps/evm

Status Category Percentage Covered / Total
🔵 Lines 81.18% 45343 / 55854
🔵 Statements 81.18% 45343 / 55854
🔵 Functions 62.36% 648 / 1039
🔵 Branches 72.3% 5106 / 7062
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
apps/evm/src/clients/api/queries/getSwapQuote/index.ts 98.59% 92.85% 100% 98.59% 1
Generated in workflow #13503 for commit 14a95bd by the Vitest Coverage Report Action

@gleiser-oliveira gleiser-oliveira merged commit c65102a into main May 21, 2026
5 checks passed
@gleiser-oliveira gleiser-oliveira deleted the fix/trade-slippage branch May 21, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants