Skip to content
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

feat: bridge controller #5276

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open

feat: bridge controller #5276

wants to merge 67 commits into from

Conversation

infiniteflower
Copy link
Contributor

@infiniteflower infiniteflower commented Feb 4, 2025

Explanation

This PR adds a new controller: BridgeController.

This controller handles the quote fetching and polling from the Bridge API.

References

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

@metamask/bridge-controller

  • : New BridgeController!

Checklist

  • 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
  • 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

@infiniteflower infiniteflower marked this pull request as ready for review February 5, 2025 20:48
Copy link

socket-security bot commented Feb 5, 2025

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

@infiniteflower
Copy link
Contributor Author

@SocketSecurity ignore npm/[email protected]

Was Introduced by @metamask/[email protected]

micaelae
micaelae previously approved these changes Feb 6, 2025
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Hi @infiniteflower! I've taken a good look at this PR. There are a number of items that would be great to fix to align with the rest of the controllers in this repo. However I recognize that the goal of this PR is probably just to port the controller from extension. So while I've made a lot of suggestions, I've marked the items I think we can could leave for another PR with ⏭️. Hope that helps.

.github/CODEOWNERS Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
* An object containing all of the chain ids for networks both built in and
* those that we have added custom code to support our feature set.
*/
export const CHAIN_IDS = {
Copy link
Contributor

Choose a reason for hiding this comment

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

⏭️ We have multiple instances of chain IDs in this repo (name-controller, preferences-controller, transaction-controller, etc.) and it'd be great if we could consolidate these.

We've been using controller-utils as a shared location for constants like this. It has a ChainId enum that I think could be a good candidate for copying this information to.

packages/bridge-controller/src/constants/chains.ts Outdated Show resolved Hide resolved
LINEA_MAINNET: 'linea-mainnet',
} as const;

export const MAINNET_DISPLAY_NAME = 'Ethereum Mainnet';
Copy link
Contributor

Choose a reason for hiding this comment

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

⏭️ controller-utils has a NetworkNickname enum, and I think these display names could be copied there.

partialRequest: Partial<QuoteRequest>,
requireAmount = true,
): partialRequest is QuoteRequest => {
const STRING_FIELDS = ['srcTokenAddress', 'destTokenAddress'];
Copy link
Contributor

Choose a reason for hiding this comment

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

⏭️ Maybe these should not be SCREAMING_SNAKE_CASE, since they are not globals.

Comment on lines +8 to +12
{ "path": "../base-controller" },
{ "path": "../controller-utils" },
{ "path": "../polling-controller" },
{ "path": "../network-controller" },
{ "path": "../transaction-controller" }
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this file is out of sync with dependencies:

Suggested change
{ "path": "../base-controller" },
{ "path": "../controller-utils" },
{ "path": "../polling-controller" },
{ "path": "../network-controller" },
{ "path": "../transaction-controller" }
{ "path": "../accounts-controller" },
{ "path": "../base-controller" },
{ "path": "../controller-utils" },
{ "path": "../network-controller" },
{ "path": "../polling-controller" },
{ "path": "../transaction-controller" }

Comment on lines +9 to +16
{ "path": "../accounts-controller/tsconfig.build.json" },
{ "path": "../approval-controller/tsconfig.build.json" },
{ "path": "../base-controller/tsconfig.build.json" },
{ "path": "../controller-utils/tsconfig.build.json" },
{ "path": "../keyring-controller/tsconfig.build.json" },
{ "path": "../network-controller/tsconfig.build.json" },
{ "path": "../preferences-controller/tsconfig.build.json" },
{ "path": "../polling-controller/tsconfig.build.json" }
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this is out of date with the dependencies:

Suggested change
{ "path": "../accounts-controller/tsconfig.build.json" },
{ "path": "../approval-controller/tsconfig.build.json" },
{ "path": "../base-controller/tsconfig.build.json" },
{ "path": "../controller-utils/tsconfig.build.json" },
{ "path": "../keyring-controller/tsconfig.build.json" },
{ "path": "../network-controller/tsconfig.build.json" },
{ "path": "../preferences-controller/tsconfig.build.json" },
{ "path": "../polling-controller/tsconfig.build.json" }
{ "path": "../accounts-controller/tsconfig.build.json" },
{ "path": "../base-controller/tsconfig.build.json" },
{ "path": "../controller-utils/tsconfig.build.json" },
{ "path": "../network-controller/tsconfig.build.json" },
{ "path": "../polling-controller/tsconfig.build.json" },
{ "path": "../transaction-controller/tsconfig.build.json" }

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 89,
Copy link
Contributor

Choose a reason for hiding this comment

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

⏭️ We should strive to hit 100% test coverage. Otherwise, if we are on a branch and we get errors from Jest saying that coverage has not been met, it is painful to figure out which lines have been added in that branch that we need to test.

packages/bridge-controller/package.json Outdated Show resolved Hide resolved
infiniteflower and others added 19 commits February 7, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants