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

SIP-25: RPC Routing Snaps #144

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

SIP-25: RPC Routing Snaps #144

wants to merge 8 commits into from

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Aug 11, 2024

Abstract

This SIP proposes a minimum standard interface for RPC routing Snaps, which will act as intermediaries between the MetaMask wallet and account Snaps (TODO: add account snaps SIP link here when complete). These routing Snaps will handle registration of account Snaps and interpret incoming CAIP-27 requests, determining whether they require signature and routing them to the appropriate account Snap for signature when applicable. They will broadcast signed transactions to the matching network and return results to MetaMask.

Motivation

The integration of MetaMask's MultiChain API and protocol Snaps necessitates a standardized approach for routing RPC requests across various blockchain networks. By establishing a standard interface for RPC routing Snaps, we aim to abstract the complexity of non-EVM protocol support away from the MetaMask engineering team, ensuring a seamless and scalable interaction model for decentralized applications (dApps). Because MetaMask is not equipped to interpret requests from non-EVM networks and, for instance, identify which of these requests require signatures or, for methods that do require signatures, which parameters correspond to the account that should sign a transaction, the RPC routing Snap will provide logic for interpreting and routing these requests accordingly.

This approach allows for greater flexibility and extensibility, enabling the MetaMask ecosystem to support a wide range of blockchain networks without requiring changes to the core wallet functionality.

This SIP outlines the key responsibilities and minimum interface requirements for RPC routing Snaps, enabling developers to build and deploy routing Snaps for specific blockchain networks.

@adonesky1 adonesky1 changed the title WIP: RPC Routing snaps SIP-25: RPC Routing Snaps Aug 12, 2024
@adonesky1 adonesky1 marked this pull request as ready for review August 12, 2024 21:40
@adonesky1 adonesky1 requested review from Montoya, ziad-saab and a team as code owners August 12, 2024 21:40
5. **Broadcast Transaction**: The RPC routing Snap broadcasts the signed transaction to the Bitcoin network.
6. **Return Result**: The RPC routing Snap returns the result to MetaMask, which forwards it to the dApp.

```json
Copy link
Member

Choose a reason for hiding this comment

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

This should remove the syntax error highlight from the comment:

Suggested change
```json
```json5

Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

@adonesky1 have you considered who displays the confirmation for requests requiring signatures? I imagine it must be the account snap.


## Motivation

The integration of MetaMask's MultiChain API and protocol Snaps necessitates a standardized approach for routing RPC requests across various blockchain networks. By establishing a standard interface for RPC routing Snaps, we aim to abstract the complexity of non-EVM protocol support away from the MetaMask engineering team, ensuring a seamless and scalable interaction model for decentralized applications (dApps). Because MetaMask is not equipped to interpret requests from non-EVM networks and, for instance, identify which of these requests require signatures or, for methods that do require signatures, which parameters correspond to the account that should sign a transaction, the RPC routing Snap will provide logic for interpreting and routing these requests accordingly.
Copy link

Choose a reason for hiding this comment

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

Part of the motivation is to to allow any team to add support for a protocol to MetaMask while maintaining consistent API patterns and avoiding tight code coupling with the whole wallet client codebase. It could still be MetaMask engineering OR external parties contributing code for protocols through Snaps, but they would be able to build, deploy, and maintain protocol support much more efficiently.


#### Handling Requests

- **Method**: `handleCaip27Request`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- **Method**: `handleCaip27Request`
- **Method**: `onCAIP27Request`

We should try to get this matching the existing exports as much as possible.


### Minimum Interface for Routing Snaps

#### Registration with MetaMask
Copy link
Member

@FrederikBolding FrederikBolding Aug 28, 2024

Choose a reason for hiding this comment

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

Is there a reason we couldn't do registration with a permission instead?

E.g.

{ 
  "initialPermissions": {
     "endowment:caip27-router": { "chains": ..., "methods": ..., "events": ... }
  } 
}

- `methods`: An array JSON-RPC methods the Snap supports.
- `events`: An array of events the Snap can handle.

#### Registering Account Snaps
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should be the responsibility of the account Snap to flag as part of its permissions as well.


2. **Account Snap Registration**:
- Account Snaps register with RPC routing Snaps using `accountSnap_register`, declaring their supported CAIP-2 identifiers, methods, and events.
- RPC routing Snaps maintain a registry of account Snaps and their capabilities.
Copy link
Member

Choose a reason for hiding this comment

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

Why would this not fall on MetaMask to maintain this, e.g. via the PermissionController?


3. **Handling CAIP-27 Requests**:
- RPC routing Snaps will interpret incoming CAIP-27 requests, identify the network-specific RPC request format, and route to the appropriate account Snap.
- If the request does not specify an account the routing Snap must provide UI for users to select from among the eligible signer Snaps for signing the request.
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason we would assume the Snap being the best facilitator of this over MetaMask itself?

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.

4 participants