scroll-tech / contribute-to-scroll

This repository guides developers wanting to contribute to the Scroll ecosystem.
https://scroll.io
994 stars 621 forks source link

Bridge Fee Aware Metamask Snap #12

Open pajicf opened 1 year ago

pajicf commented 1 year ago

Name of the project

Bridge Fee Aware Metamask Snap

Project abstract

Currently, when sending TXs on Scroll L2, the rollup fees are not accounted for. Sometimes this can result in failed transactions.

Idea is to create a snap (plugin) for Metamask to include them and show a breakdown of transaction fees

Specification

L2 Gas Price

Fee charged to an User using an L2 can be broken down to:

  1. L2 gas fee

    • This is calculated pretty much the same as on the L1, formula being gas_price * gas_used
  2. L1 data fee

    • This is an additional fee that covers the cost of sending data to L1 for data availability.
    • It's calculated based on the size of tx calldata

Problem

Since most regular wallets aren't aware of L1 data fee happening on the rollup, they are unable to display it in their UI. If the wallet has enough assets to pay for the gas fee, the transaction will pass but the user will be deducted more funds than what they were expecting since the UI didn't display the additional fee. If the wallet doesn't have enough funds to pay for gas, the transaction will simply fail or the wallet will simulate it and conclude it will fail, not allowing user to emit it to the network. This leaves the user confused on why he can't interact with some DApp.

Solution

Extend Metamask wallet using Snaps to be aware of complete L2 gas fees. Goal is to:

Useful links

0x4r45h commented 10 months ago

I have created a snap for this issue! please take a look L2Insights.
You can install the latest version here
l2insights-example1