Skip to content

feat: adds deeply liquid stablecoin slippage value of 0.5 #31744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2025

Conversation

ghgoodreau
Copy link
Contributor

@ghgoodreau ghgoodreau commented Apr 8, 2025

Description

Purpose:

To automatically apply a lower default slippage (0.5%) when fetching swap quotes for stablecoin pairs (like USDC/USDT), while using the user's custom setting for other pairs. This improves the swap experience for stablecoins and avoids unnecessary API calls with incorrect slippage.

Changes Made:

  • Address-Based Stablecoin Definition: Introduced a StablecoinsByChainId map in shared/constants/swaps.ts that lists known stablecoin contract addresses for each supported network, mirroring the mobile implementation.
  • Refactored Slippage Logic: Modified the fetchQuotesAndSetQuoteState function in ui/ducks/swaps/swaps.js to:
    --- Check the from and to token addresses against the StablecoinsByChainId map for the current network using a case-insensitive comparison.
    --- Determine the correct slippage (Slippage.stable or the user's maxSlippage) before dispatching the quote fetch action.
  • Updated Fetch & Analytics: Ensured the determined slippage value is passed to the API request and correctly logged in analytics events.

Open in GitHub Codespaces

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/MMS-2169

Manual testing steps

  1. Go to the swap page
  2. On any EVM chain, try to swap between USDT <-> USDC
  3. Observe a default slippage value of 0.5% instead of 2%

Screenshots/Recordings

Before

Screenshot 2025-04-08 at 11 06 50 PM Screenshot 2025-04-08 at 11 06 45 PM Screenshot 2025-04-08 at 11 06 59 PM

After

Screenshot 2025-04-08 at 11 07 26 PM Screenshot 2025-04-08 at 11 07 31 PM Screenshot 2025-04-08 at 11 07 42 PM

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

github-actions bot commented Apr 8, 2025

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-swaps-and-bridge For issues with Swaps or Bridging label Apr 8, 2025
@metamaskbot
Copy link
Collaborator

✨ Files requiring CODEOWNER review ✨

🔄 @MetaMask/swaps-engineers

  • ui/pages/swaps/prepare-swap-page/prepare-swap-page.js
  • ui/pages/swaps/transaction-settings/transaction-settings.js

return false;
}
const lowerAddressToCheck = addressToCheck.toLowerCase();
for (const addrInSet of addressSet) {
Copy link
Contributor

@infiniteflower infiniteflower Apr 9, 2025

Choose a reason for hiding this comment

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

Non-blocking comment: Set has O(1) lookups with set.has(...), if we're just iterating through it instead (O(n)), could just use a simple array.

Doesn't really matter because the list is so small though.

@ghgoodreau ghgoodreau marked this pull request as ready for review April 9, 2025 17:39
@ghgoodreau ghgoodreau requested a review from a team as a code owner April 9, 2025 17:39
@ghgoodreau ghgoodreau enabled auto-merge April 9, 2025 17:39
@metamaskbot
Copy link
Collaborator

Builds ready [4ac9dae]
UI Startup Metrics (1212 ± 59 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1212110914295912521319
load10649771249541139997
domContentLoaded10589701241541143994
domInteractive16134551627
firstPaint798811216402232985
backgroundConnect106273910
firstReactRender20145472040
getState12563979
initialActions001001
loadScripts81272898651840906
setupStore7414278
WebpackHomeuiStartup21451736259618622752409
load17021257218118117762056
domContentLoaded16961252217717917732034
domInteractive171291121450
firstPaint160643746124891
backgroundConnect3611354483556
firstReactRender154523521075986
getState2643936779
initialActions217134
loadScripts16851243217217117661970
setupStore15633669
FirefoxBrowserifyHomeuiStartup13781155170011614521621
load12381034153111412861490
domContentLoaded12371034153111412861490
domInteractive10537310408897
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect24169292443
firstReactRender22195042229
getState942142178
initialActions001001
loadScripts12151018149711212621472
setupStore841981967
WebpackHomeuiStartup15571391196111216051782
load13331180168610213811571
domContentLoaded13321180168610213811571
domInteractive9646189238997
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect27195382845
firstReactRender36306463946
getState1243313289
initialActions105111
loadScripts13091159166110113531539
setupStore8542489

@ghgoodreau ghgoodreau added this pull request to the merge queue Apr 9, 2025
Merged via the queue into main with commit 1f8d01a Apr 9, 2025
166 checks passed
@ghgoodreau ghgoodreau deleted the feat-MMS-2169-usdcusdt-slippage branch April 9, 2025 21:15
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2025
@metamaskbot metamaskbot added the release-12.17.0 Issue or pull request that will be included in release 12.17.0 label Apr 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.17.0 Issue or pull request that will be included in release 12.17.0 team-swaps-and-bridge For issues with Swaps or Bridging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants