feat(ramps-controller): resolveFiatDepositRoute for buy-ETH-convert-to-mUSD#9428
Draft
saustrie-consensys wants to merge 3 commits into
Conversation
…o-mUSD Add a pure, provider-agnostic resolveFiatDepositRoute helper (and FiatDepositRoute type) that picks which on-ramp asset a region should buy for a fiat deposit: the preferred target asset (e.g. mUSD) when a provider serves it, otherwise the first convertible fallback asset (e.g. native ETH) with a serving provider, or undefined when none is purchasable. It reuses regionHasProviderForAsset so it obeys the same scope semantics (an aggregator-only fallback is unreachable under scope 'off'). This enables depositing to a mUSD Money Account in regions without a direct mUSD provider by buying ETH and letting a downstream step convert it. Pure and provider-agnostic; the conversion itself stays with the consumer.
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Headless Buy / Money Account follow-on to Phase 2, stacked on #9414 (base branch
saustrie/ramps-controller-phase2-selection, notmain).Today a Money Account (mUSD) fiat deposit can only be offered in a region that has an on-ramp provider serving mUSD directly. In regions that have no mUSD provider but do have a provider selling ETH (e.g. New York), the flow shows nothing, even though the existing "buy ETH on mainnet, then Relay to mUSD on Monad" pipeline can deliver mUSD. Deciding "buy mUSD directly, else buy a convertible asset like ETH" is a provider-availability decision that belongs in the controller, next to the other shared, provider-agnostic gates, so mobile stays a dumb consumer.
What changed:
resolveFiatDepositRoutehelper (andFiatDepositRoutetype) inproviderAvailability.ts. Given the region's providers, apreferredAssetId(the target deposit asset, e.g. mUSD), an ordered list offallbackAssetIds(convertible assets, e.g. native ETH), and the effectivescope, it returns{ assetId, isFallback }:isFallback: false),isFallback: true),undefined(caller shows no providers).regionHasProviderForAsset, so it obeys the same scope semantics: under scopeoffonly a native provider counts, so an aggregator-only fallback asset is unreachable until scope is widened toin-app/all.The conversion itself (ETH to mUSD via Relay + vault/CHOMP) stays entirely in the consumer (
@metamask/transaction-pay-controller+ mobile); this only picks the purchasable asset.getQuotesis unchanged (already asset-agnostic); the caller passes the resolvedassetId.Tests: new
resolveFiatDepositRoutecases inproviderAvailability.test.ts(prefer target, fall back in order, none, scope-offnative-only, native fallback underoff). PackageproviderAvailabilitysuite green (20 tests); changelog validates; lint clean.References
getSmartSelectedQuote/ scope-gated widening groundwork).Checklist
Made with Cursor