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

feat: Support opt-in use of viem for gas pricing #745

Merged
merged 14 commits into from
Nov 13, 2024
Merged

Conversation

pxrl
Copy link
Contributor

@pxrl pxrl commented Sep 30, 2024

This change updates the gasPriceOracle to support querying gas via viem's gas pricing strategies. This is beneficial because viem has an active community that are actively adding support for new chains and improving support for existing chains. An example of this is Linea, where linea_estimateGas is supported out of the box after a recent update.

In order to maintain some degree of compatibility with existing users of the gasPriceOracle, the external interface still accepts an ethers Provider instance. It then internally instantiates a viem PublicClient instance and uses that instead. There is still a residual issue of how to resolve the relevant provider URLs, since it's not necessarily reliable to pull from the provider due to the uncertain type (i.e. StaticJsonRpcProvider or one of the extended variants that wraps multiple providers).

Viem support can be enabled per-chain via the NEW_GAS_PRICE_ORACLE_<chainId> environment variable, which must be set explicitly to true. All other queries will revert to the existing ethers implementation.

This change updates the gasPriceOracle to leverage viem's gas pricing
strategies. This is beneficial because viem has an active community that
are actively adding support for new chains and improving support for
existing chains. An example of this is Linea, where linea_estimateGas is
supported out of the box after a recent update.

In order to maintain some degree of compatibility with existing users of
the gasPriceOracle, the external interface still accepts an ethers
Provider instance. It then internally instantiates a viem PublicClient
instance and uses that instead. There is still a residual issue of how
to resolve the relevant provider URLs, since it's not necessarily
reliable to pull from the provider due to the uncertain type (i.e.
StaticJsonRpcProvider or one of the extended variants that wraps
multiple providers).
Copy link
Contributor Author

@pxrl pxrl left a comment

Choose a reason for hiding this comment

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

Just dropping some initial breadcrumbs.

e2e/oracle.e2e.ts Outdated Show resolved Hide resolved
src/gasPriceOracle/adapters/polygon.ts Outdated Show resolved Hide resolved
src/gasPriceOracle/oracle.ts Outdated Show resolved Hide resolved
src/gasPriceOracle/oracle.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dohaki dohaki left a comment

Choose a reason for hiding this comment

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

This looks good 👍 I like the approach to gradually try viem in the SDK. Left some minor comments and there are still a bunch of linting errors. I think we should add https://eslint.org/docs/latest/rules/no-unused-vars#argsignorepattern to the eslint config EDIT: Ah sorry just saw #746 👍

src/gasPriceOracle/util.ts Show resolved Hide resolved
src/gasPriceOracle/oracle.ts Outdated Show resolved Hide resolved
src/gasPriceOracle/oracle.ts Outdated Show resolved Hide resolved
src/gasPriceOracle/adapters/ethereum.ts Outdated Show resolved Hide resolved
@dohaki dohaki marked this pull request as ready for review October 29, 2024 08:15
@dohaki dohaki self-requested a review October 29, 2024 08:15
@pxrl pxrl changed the title experimental: gasPriceOracle overhaul feat: Support opt-in use of viem for gas pricing Oct 31, 2024
Copy link
Contributor

@dohaki dohaki left a comment

Choose a reason for hiding this comment

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

Looking good 👍 Left one nit

src/gasPriceOracle/oracle.ts Show resolved Hide resolved
@pxrl pxrl merged commit 29af3e7 into master Nov 13, 2024
4 checks passed
@pxrl pxrl deleted the pxrl/experimentalGas branch November 13, 2024 19:41
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.

3 participants