Skip to content

Commit d931ffa

Browse files
feat: bridge controller (#5276)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> This PR adds a new controller: `BridgeController`. This controller handles the quote fetching and polling from the Bridge API. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> This is a port of the `BridgeController` from Extension: https://github.com/MetaMask/metamask-extension/tree/main/app/scripts/controllers/bridge Some minor changes were needed to fill in the missing functions and variables from Extension. This package will be consumed initially by the Metamask Mobile application first. Eventually, we wish to migrate the Extension to use this `core/bridge-controller` package. ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/bridge-controller` - **<ADDED>**: New `BridgeController`! ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've highlighted breaking changes using the "BREAKING" category above as appropriate - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes --------- Co-authored-by: Elliot Winkler <[email protected]>
1 parent d2d1800 commit d931ffa

33 files changed

+5183
-2
lines changed

.github/CODEOWNERS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
## Snaps Team
3838
/packages/rate-limit-controller @MetaMask/snaps-devs
3939

40+
## Swaps-Bridge Team
41+
/packages/bridge-controller @MetaMask/swaps-engineers
42+
4043
## Portfolio Team
4144
/packages/token-search-discovery-controller @MetaMask/portfolio
4245

@@ -112,4 +115,5 @@
112115
/packages/multichain-transactions-controller/CHANGELOG.md @MetaMask/accounts-engineers @MetaMask/wallet-framework-engineers
113116
/packages/token-search-discovery-controller/package.json @MetaMask/portfolio @MetaMask/wallet-framework-engineers
114117
/packages/token-search-discovery-controller/CHANGELOG.md @MetaMask/portfolio @MetaMask/wallet-framework-engineers
115-
118+
/packages/bridge-controller/package.json @MetaMask/swaps-engineers @MetaMask/wallet-framework-engineers
119+
/packages/bridge-controller/CHANGELOG.md @MetaMask/swaps-engineers @MetaMask/wallet-framework-engineers

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ scripts/coverage
3434
!.yarn/versions
3535

3636
# typescript
37-
packages/*/*.tsbuildinfo
37+
packages/*/*.tsbuildinfo

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Each package in this repository has its own README where you can find installati
2626
- [`@metamask/approval-controller`](packages/approval-controller)
2727
- [`@metamask/assets-controllers`](packages/assets-controllers)
2828
- [`@metamask/base-controller`](packages/base-controller)
29+
- [`@metamask/bridge-controller`](packages/bridge-controller)
2930
- [`@metamask/build-utils`](packages/build-utils)
3031
- [`@metamask/composable-controller`](packages/composable-controller)
3132
- [`@metamask/controller-utils`](packages/controller-utils)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Initial release
13+
14+
[Unreleased]: https://github.com/MetaMask/core/

packages/bridge-controller/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MIT License
2+
3+
Copyright (c) 2025 MetaMask
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

packages/bridge-controller/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# `@metamask/bridge-controller`
2+
3+
Manages bridge-related quote fetching functionality for MetaMask.
4+
5+
## Installation
6+
7+
`yarn add @metamask/bridge-controller`
8+
9+
or
10+
11+
`npm install @metamask/bridge-controller`
12+
13+
## Contributing
14+
15+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
const merge = require('deepmerge');
7+
const path = require('path');
8+
9+
const baseConfig = require('../../jest.config.packages');
10+
11+
const displayName = path.basename(__dirname);
12+
13+
module.exports = merge(baseConfig, {
14+
// The display name when running multiple projects
15+
displayName,
16+
17+
// An object that configures minimum threshold enforcement for coverage results
18+
coverageThreshold: {
19+
global: {
20+
branches: 93,
21+
functions: 98,
22+
lines: 99,
23+
statements: 99,
24+
},
25+
},
26+
});
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"name": "@metamask/bridge-controller",
3+
"version": "0.0.0",
4+
"description": "Manages bridge-related quote fetching functionality for MetaMask",
5+
"keywords": [
6+
"MetaMask",
7+
"Ethereum"
8+
],
9+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/bridge-controller#readme",
10+
"bugs": {
11+
"url": "https://github.com/MetaMask/core/issues"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/MetaMask/core.git"
16+
},
17+
"license": "MIT",
18+
"sideEffects": false,
19+
"exports": {
20+
".": {
21+
"import": {
22+
"types": "./dist/index.d.mts",
23+
"default": "./dist/index.mjs"
24+
},
25+
"require": {
26+
"types": "./dist/index.d.cts",
27+
"default": "./dist/index.cjs"
28+
}
29+
},
30+
"./package.json": "./package.json"
31+
},
32+
"main": "./dist/index.cjs",
33+
"types": "./dist/index.d.cts",
34+
"files": [
35+
"dist/"
36+
],
37+
"scripts": {
38+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
39+
"build:docs": "typedoc",
40+
"changelog:update": "../../scripts/update-changelog.sh @metamask/bridge-controller",
41+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/bridge-controller",
42+
"publish:preview": "yarn npm publish --tag preview",
43+
"since-latest-release": "../../scripts/since-latest-release.sh",
44+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
45+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
46+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
47+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
48+
},
49+
"dependencies": {
50+
"@metamask/base-controller": "^8.0.0",
51+
"@metamask/controller-utils": "^11.5.0",
52+
"@metamask/metamask-eth-abis": "^3.1.1",
53+
"@metamask/polling-controller": "^12.0.3",
54+
"@metamask/utils": "^11.1.0",
55+
"ethers": "^6.12.0"
56+
},
57+
"devDependencies": {
58+
"@metamask/accounts-controller": "^23.1.0",
59+
"@metamask/auto-changelog": "^3.4.4",
60+
"@metamask/eth-json-rpc-provider": "^4.1.8",
61+
"@metamask/json-rpc-engine": "^10.0.3",
62+
"@metamask/network-controller": "^22.2.1",
63+
"@metamask/transaction-controller": "^45.1.0",
64+
"@types/jest": "^27.4.1",
65+
"deepmerge": "^4.2.2",
66+
"jest": "^27.5.1",
67+
"jest-environment-jsdom": "^27.5.1",
68+
"lodash": "^4.17.21",
69+
"nock": "^13.3.1",
70+
"ts-jest": "^27.1.4",
71+
"typedoc": "^0.24.8",
72+
"typedoc-plugin-missing-exports": "^2.0.0",
73+
"typescript": "~5.2.2"
74+
},
75+
"peerDependencies": {
76+
"@metamask/accounts-controller": "^23.0.0",
77+
"@metamask/network-controller": "^22.0.0",
78+
"@metamask/transaction-controller": "^45.0.0"
79+
},
80+
"engines": {
81+
"node": "^18.18 || >=20"
82+
},
83+
"publishConfig": {
84+
"access": "public",
85+
"registry": "https://registry.npmjs.org/"
86+
}
87+
}

0 commit comments

Comments
 (0)