Commit dc2d67d
feat: add gasSponsored flag to bridgeController (#6687)
## Explanation
### What is the current state of things and why does it need to change?
- Today, quotes can indicate when gas is embedded into the transaction
itself via `gasIncluded` and when EIP‑7702 delegated execution can be
used via `gasIncluded7702`, but there’s no explicit way to signal that a
third party will sponsor the gas cost.
- This prevents the UI/clients from differentiating between “quote
includes gas fees” and “quote is gasless to the user because gas is
sponsored,” which affects UX (badging, prioritization) and any
downstream decision logic.
### What is the solution your changes offer and how does it work?
- Added an optional boolean `quote.gasSponsored` to `QuoteSchema` in
`@validators.ts` to allow the bridge API to flag gas‑sponsored quotes.
- Ensured end‑to‑end preservation:
- Validation now accepts payloads with or without `gasSponsored`.
- `BridgeController.fetchQuotes` and the fee‑augmentation path preserve
the field unchanged so the UI and metrics layers can consume it.
- Tests:
- Added a test in `bridge-controller.test.ts` verifying that
`fetchQuotes` returns quotes where `quote.gasSponsored` is preserved
when present, and remains undefined when omitted.
- Backward compatibility:
- The field is optional; existing payloads and flows continue to work
unchanged.
- No sorting or fee calculations are altered by this addition.
### Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
- Distinction between flags:
- `gasIncluded`: Quote includes gas fees in the trade economics, but the
user still submits and pays gas.
- `gasIncluded7702`: Quote can use delegated execution under EIP‑7702.
- `gasSponsored`: A third party sponsors the gas so the user doesn’t pay
it; this is orthogonal to whether gas is “included” in pricing or
delegated via 7702.
## References
This PR is related to this BridgeAPI PR
consensys-vertical-apps/va-mmcx-bridge-api#527.
PR related for MM Extension:
MetaMask/metamask-extension#36227.
PR related for MM Mobile:
MetaMask/metamask-mobile#20878.
## Checklist
- [X] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [X] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [X] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds optional `quote.gasSponsored` to validation schema and ensures
`fetchQuotes` returns it unchanged; updates tests and changelog.
>
> - **Validation**:
> - Add optional `quote.gasSponsored` to `QuoteSchema` in
`utils/validators.ts`.
> - **Controller Tests**:
> - Add test verifying `fetchQuotes` preserves `quote.gasSponsored` when
present.
> - Introduce `makeQuoteRequest` helper for test requests.
> - **Changelog**:
> - Document new `gasSponsored` property in `fetchQuotes` results.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
c9872a7. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>1 parent f6d4f2e commit dc2d67d
File tree
3 files changed
+51
-0
lines changed- packages/bridge-controller
- src
- utils
3 files changed
+51
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
2615 | 2616 | | |
2616 | 2617 | | |
2617 | 2618 | | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
2618 | 2634 | | |
2619 | 2635 | | |
2620 | 2636 | | |
| |||
2845 | 2861 | | |
2846 | 2862 | | |
2847 | 2863 | | |
| 2864 | + | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
2848 | 2891 | | |
2849 | 2892 | | |
2850 | 2893 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
247 | 251 | | |
248 | 252 | | |
249 | 253 | | |
| |||
0 commit comments