Skip to content

bbayazit16/l2savings

Repository files navigation

L2Savings

How much fees have you saved by using Ethereum L2's?

See how much fees Ξ$ you've saved on l2savings.org!

Motivation

Ethereum Layer 2 solutions offer near-instant confirmations, Ethereum-level security and decentralization, and near-infinite scalability. They are one of the most convenient ways of solving the blockchain trilemma, along with sharding. However Ethereum Layer 2's often lack marketing and incentives to push developers to deploy their applications on them. L2Savings aims to show how much anyone has saved by using Ethereum L2s compared to if their transactions were sent on Ethereum Mainnet.

Data Provided

Following data is provided for every supported chain:

  • Transaction Count On L2
  • Gas Spent on L2 (Converted To Mainnet Gas If Applicable)
  • Chain-Native Gas Spent (eg. arbgas)
  • L2 Fees Paid in Ether
  • L2 Fees Paid in USD (according to Ether's current value)
  • L1 Fees Paid in Ether (If L2 transactions were sent on L1)
  • L1 Fees Paid in USD
  • Fees Saved in Ether and USD
  • Times cheaper (Fee If On L1 / L2 Fee paid)

How Savings Are Calculated

Simply put,

Fees if the transaction was sent on L1 at the same day with exactly the same gas - Actual fees paid for transaction on L2

Optimism

For EVM equivalent L2's such as Optimism, it is easy to calculate the equivalent L1 cost, because the concept of gas is same on the L2. (L2 Gas * Mainnet gas price at the time of transaction).

The formula for Optimism Transaction fee is (Gas Price * Gas) + (L1 Gas Used * L1 Fee Scalar * L1 Gas Price). Optimistic Etherscan doesn't provide the transaction fee in their API, let alone the L1 Fee Scalar, L1 Gas Price and L1 Gas used. Due to this reason the L1 gas price and overhead is extracted from eth_getTransactionReceipt calls to an Optimism RPC.

For more info, see the FAQ

Arbitrum

Arbitrum is not EVM equivalent, but EVM compatible. Due to it's design, the Arbitrum Virtual Machine (AVM) require(d) a different approach to gas. Each unit used to be referred to as "arbgas". However, with the Nitro upgrade, L2 instruction costs are now equivalavent to L1 instruction costs. L2Savings only supports transactions after the Arbitrum Nitro upgrade.

L2Gas includes both the L2 computation cost and the L1 calldata gas cost. So:

L1Gas = L2Gas - gasUsedForL1

Similar to Optimism, all values can be found in the eth_getTransactionReceipt method. L1 Gas price during the time of the transaction is found by querying eth_feeHistory with a median reward value using eth_getTransactionReceipt.l1BlockNumber value.

ZkSync Lite

ZkSync Lite is a ZK (Zero Knowledge) Rollup which is an L2 much cheaper than Optimistic Rollups.

Two rollups walk into a bar. The barman asks: "Can I see your ids?". ZK Rollup says: "I can prove to you I'm over 18, but I won't show you my id". Optimistic Rollup says: "If nobody can prove I'm underage in 7 days that means I'm over 18" Source

However ZkSync Lite is not EVM equivalent, unlike ZkSync ERA, making it harder to predict equivalent L1 gas cost of operations. ZkSync has "types" of transactions, which are ChangePubKey, Transfer, Swap, Withdraw, ForcedExit, MintNFT and WithdrawNFT. The L2 <--> L1 gas is estimate is thus done by using the average costs for each operation on Ethereum L1. Which means Ether transfers are considered as 21000 gas, token transfers 65000, swaps 160000 and NFT Mints 150000. ZkSync also allows users to pay with different tokens, such as stablecoins, which requires the conversion of fees paid into ether with the price rate during the time of transaction. For a diagram of how the calculation process goes, see this diagram.

Linea

Linea is a ZK Rollup which is EVM equivalent. This means that the gas cost of operations on Linea is the same as Ethereum L1. However Linea RPC does not return l1BlockNumber, so we have to use the average daily gas price during the day of the transaction.

Base

Base is an EVM-equivalent rollup based on Optimism's OP stack. The calculations for Base are exactly the same as Optimism; in fact, the code for calculating Base savings is a copy-paste of Optimism with the only difference being the RPC and explorer endpoints.

Building and Running

yarn install # install dependencies
yarn dev # run development server
yarn build # build for production
yarn start # run production server

Make sure to create a .env.local file based on .env.example with your own API keys.

License

AGPL-3.0-only

About

How much in fees have you saved by using L2s?

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages