Giter Site home page Giter Site logo

sambacha / gas-reporting Goto Github PK

View Code? Open in Web Editor NEW
99.0 5.0 4.0 251 KB

Reference documentation on every gas price API and all the different formats

Home Page: https://doi.org/10.5281/zenodo.5702504

License: Other

JavaScript 77.77% Shell 22.23%
gwei gas ethereum transaction-pricing blockchain smart-contracts metamask nft erc20 eip1559

gas-reporting's Issues

Document off-chain calculation methods

Off chain calculations

Frontends like Uniswap do calculations off chain to compute gas cost, this should be documented to see how APIs are actually used in production

see https://github.com/Uniswap/smart-order-router/blob/c63deae67dcc2113efa0fe6348b2a2ddca3e6265/src/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.ts?rgh-link-date=2022-02-15T05%3A33%3A45Z#L30-L47

/**
 * Computes a gas estimate for a V3 swap using heuristics.
 * Considers number of hops in the route, number of ticks crossed
 * and the typical base cost for a swap.
 *
 * We get the number of ticks crossed in a swap from the QuoterV2
 * contract.
 *
 * We compute gas estimates off-chain because
 *  1/ Calling eth_estimateGas for a swaps requires the caller to have
 *     the full balance token being swapped, and approvals.
 *  2/ Tracking gas used using a wrapper contract is not accurate with Multicall
 *     due to EIP-2929. We would have to make a request for every swap we wanted to estimate.
 *  3/ For V2 we simulate all our swaps off-chain so have no way to track gas used.
 */

Layer2 Reporting

Add support for L2s

Arbitrum

Arbitrum gas units are different: opcodes are priced differently, so swaps as an example, cost different amounts.
Arbitrum has 2 separate gas meters- one for compute and one for storage
On Arb its not clear if we capture everything we need by querying eth_gasPrice (also unclear if we need to capture both when estimating gas)

Optimism

Optimism charges a fee based on the size of the calldata that would need to be sent to L1
On Optimism for example eth_gasPrice always return 1000000

Improve markup and code

Provide machine readable code and eliminate monolithic documentation style in favor of a module based document generation process

document eth_feeHistory option

see https://sourcegraph.com/github.com/MetaMask/core@80ff2fbb1fb38f577b4a5c7e3778550c4682202d/-/blob/packages/gas-fee-controller/src/fetchBlockFeeHistory.ts

/**

  • Uses eth_feeHistory (an EIP-1559 feature) to obtain information about gas fees from a range of
  • blocks that have occurred recently on a network.
  • To learn more, see these resources:
  • @param args - The arguments to this function.
  • @param args.ethQuery - An EthQuery instance that wraps a provider for the network in question.
  • @param args.endBlock - The desired end of the requested block range. Can be "latest" if you want
  • to start from the latest successful block or the number of a known past block.
  • @param args.numberOfBlocks - How many total blocks to fetch. Note that if this is more than 1024,
  • multiple calls to eth_feeHistory will be made.
  • @param args.percentiles - A set of numbers between 1 and 100 which will dictate how
  • priorityFeesByPercentile in each returned block will be formed. When Ethereum runs the
  • eth_feeHistory method, for each block it is considering, it will first sort all transactions by
  • the priority fee. It will then go through each transaction and add the total amount of gas paid
  • for that transaction to a bucket which maxes out at the total gas used for the whole block. As
  • the bucket fills, it will cross percentages which correspond to the percentiles specified here,
  • and the priority fees of the first transactions which cause it to reach those percentages will be
  • recorded. Hence, priorityFeesByPercentile represents the priority fees of transactions at key
  • gas used contribution levels, where earlier levels have smaller contributions and later levels
  • have higher contributions.
  • @param args.includeNextBlock - Whether to include an extra block that represents the next
  • block after the latest one. Only the baseFeePerGas will be filled in for this block (which is
  • estimated).
  • @returns The list of blocks and their fee data, sorted from oldest to newest.
    */

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.