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

[WIP] Extend GasFeeController to poll for network status #609

Closed
wants to merge 10 commits into from

Commits on Oct 25, 2021

  1. Refactor and backfill GasFeeController tests

    The tests for GasFeeController are currently lacking in a few ways:
    
    * `nock` is being used to test that requests are being used to obtain
      data; however, GasFeeController takes functions as arguments which can
      be used to stub out those requests, thereby removing the need for
      `nock`.
    * The logic within `getGasFeeEstimatesAndStartPolling` is not being
      fully exercised, specifically the polling code.
    * There are no tests for `disconnectPoller`.
    * There are no explicit tests for `stopPolling`.
    * The logic within `_fetchGasFeeEstimateData` is not being fully
      exercised, specifically with regard to  how the result of `getChainId`
      changes the URL that ends up being hit for both EIP-1559 and
      non-EIP-1559 flows.
    * There are tests categorized under a `getChainId` describe block which
      are actually for `_fetchGasFeeEstimateData`.
    
    This commit attempts to address these issues so that future changes to
    GasFeeController do not break existing behavior.
    mcmire committed Oct 25, 2021
    Configuration menu
    Copy the full SHA
    f174f93 View commit details
    Browse the repository at this point in the history

Commits on Oct 28, 2021

  1. Extract determineGasFeeSuggestions

    We would like to introduce another fallback to how we estimate gas fees
    in a future commit — namely, we want to use `eth_feeHistory` for
    EIP-1559 networks if the usual API is down. To do this, the existing
    code around gas fee estimates needs to be refactored. This is the first
    in a two-part refactor, extracting the majority of the code in
    `GasFeeController._fetchGasFeeEstimateData` to `gas-util`. In addition
    to making room for more changes, this also allows us to test this code
    in isolation from the polling code that already exists in
    GasFeeController.
    
    Note that I am using the term "suggestions" to encompass the data that
    `_fetchGasFeeEstimateData` returns. This is because `gasFeeEstimates` is
    an intermediate value that can also be packaged with
    `estimatedGasFeeTimeBounds`, so "estimates" could be confusing. Also, I
    replaced "fetch" with "determine" as in the future we may be performing
    calculations that APIs have done for us in the past ("fetch" seems like
    a more low-level action).
    mcmire committed Oct 28, 2021
    Configuration menu
    Copy the full SHA
    ecac47e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4fa9bc4 View commit details
    Browse the repository at this point in the history

Commits on Oct 29, 2021

  1. another small change

    mcmire committed Oct 29, 2021
    Configuration menu
    Copy the full SHA
    ae5b0dd View commit details
    Browse the repository at this point in the history

Commits on Nov 1, 2021

  1. Refactor and backfill GasFeeController tests

    The tests for GasFeeController are currently lacking in a few ways:
    
    * `nock` is being used to test that requests are being used to obtain
      data; however, GasFeeController takes functions as arguments which can
      be used to stub out those requests, thereby removing the need for
      `nock`.
    * The logic within `getGasFeeEstimatesAndStartPolling` is not being
      fully exercised, specifically the polling code.
    * There are no tests for `disconnectPoller`.
    * There are no explicit tests for `stopPolling`.
    * The logic within `_fetchGasFeeEstimateData` is not being fully
      exercised, specifically with regard to  how the result of `getChainId`
      changes the URL that ends up being hit for both EIP-1559 and
      non-EIP-1559 flows.
    * There are tests categorized under a `getChainId` describe block which
      are actually for `_fetchGasFeeEstimateData`.
    
    This commit attempts to address these issues so that future changes to
    GasFeeController do not break existing behavior.
    mcmire committed Nov 1, 2021
    Configuration menu
    Copy the full SHA
    d87b8c4 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f103867 View commit details
    Browse the repository at this point in the history
  3. Refactor and backfill GasFeeController tests

    The tests for GasFeeController are currently lacking in a few ways:
    
    * `nock` is being used to test that requests are being used to obtain
      data; however, GasFeeController takes functions as arguments which can
      be used to stub out those requests, thereby removing the need for
      `nock`.
    * The logic within `getGasFeeEstimatesAndStartPolling` is not being
      fully exercised, specifically the polling code.
    * There are no tests for `disconnectPoller`.
    * There are no explicit tests for `stopPolling`.
    * The logic within `_fetchGasFeeEstimateData` is not being fully
      exercised, specifically with regard to  how the result of `getChainId`
      changes the URL that ends up being hit for both EIP-1559 and
      non-EIP-1559 flows.
    * There are tests categorized under a `getChainId` describe block which
      are actually for `_fetchGasFeeEstimateData`.
    
    This commit attempts to address these issues so that future changes to
    GasFeeController do not break existing behavior.
    mcmire committed Nov 1, 2021
    Configuration menu
    Copy the full SHA
    7e20e7b View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    b16cb47 View commit details
    Browse the repository at this point in the history
  5. Use eth_feeHistory as a fallback for gas estimates

    If we are on an EIP-1559-supported network and the Metaswap API fails
    for some reason, fall back to using `eth_feeHistory` to calculate gas
    estimates (which the API uses anyway). This code is more or less taken
    from the code for the API ([1]).
    
    [1]: https://gitlab.com/ConsenSys/codefi/products/metaswap/gas-api/-/blob/eae6927b1a0c445e02cb3cba9e9e6b0f35857a12/src/eip1559/feeHistory.ts
    mcmire committed Nov 1, 2021
    Configuration menu
    Copy the full SHA
    b4f23df View commit details
    Browse the repository at this point in the history
  6. Extend GasFeeController to poll for network status

    When a user is about to send a transaction or is looking at a swap
    quote, we would like to inform them if the network is busy so that we
    can push them to use a lower fee setting. GasFeeController already
    provides a way to poll for fee estimates, which we employ on transaction
    preview screens. This commit updates the polling code so that we also
    gauge network status as we pull estimates. This is done by hitting
    another endpoint in the MetaSwap API which specifically gives us a base
    fee threshold we can use to determine whether the network is busy
    (falling back to using `eth_feeHistory` if the API is not available).
    mcmire committed Nov 1, 2021
    Configuration menu
    Copy the full SHA
    888b63d View commit details
    Browse the repository at this point in the history