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: Use Viem in finalizer for some OpStack chains #1798

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

nicholaspai
Copy link
Member

@nicholaspai nicholaspai commented Aug 30, 2024

The eth-optimism NPM package is being deprecated

This package is built on ethers.js and it is scheduled for deprecation. The finalizer is one of the main packages in this repo that uses external SDK's so the finalizer eventually MUST migrate to the viem version of the optimism SDK. This PR adds OP-stack support for most chains we currently support minus a few that are non-standard.

Current limitations of Viem:

  • No easy way to convert ethers Provider to Viem transport, meaning that RPC calls won't go through our custom RetryProvider. The Viem transport does have retry and fallback logic natively but not caching built-in. I think we'll need a larger refactor to support this migration if we wanted to use Viem more widely throughout the codebase. We can probably get away with Viem in the finalizer if we restrict its use only for the few RPC calls required to support finalizer functions (e.g. building transaction args requires querying contracts).
  • This results in some unsightly casts to any to get types to match
  • getWithdrawalStatus only supports querying a transaction with a single withdrawal. This isn't very useful for us today since we usually multicall our withdrawals. We need something like this PR in order to use Viem to finalize This PR got merged!
  • Viem accounts don't seem to be obviously interoperable with ethers Signers

Suggested roadmap

  • Use Viem for optimism mainnet, and then a few op stack chains over time.
  • Build generalized Viem modules that could help us install viem into the broader codebase like:
    • converting between Ethers providers/signers and Viem transports/accounts

Resources

nicholaspai and others added 23 commits August 30, 2024 15:55
$$ Currently showing my WIP trying to use the Viem client to support limited finalizer functionality:
- check withdrawal status
- build proveWithdrawalTransaction and finalizeWithdrawal args

## Current limitations of Viem:
- No easy way to convert ethers Provider to [Viem transport](https://viem.sh/docs/clients/transports/custom), meaning that RPC calls won't go through our custom RetryProvider. The Viem transport does have retry and fallback logic natively but not caching built-in. I think we'll need a larger refactor to support this migration if we wanted to use Viem more widely throughout the codebase. We can probably get away with Viem in the finalizer if we restrict its use only for the few RPC calls required to support finalizer functions (e.g. building transaction args requires querying contracts)
- `getWithdrawalStatus` only supports querying a transaction with a single withdrawal. This isn't very useful for us today since we usually multicall our withdrawals.
- [Viem accounts](https://viem.sh/docs/clients/wallet#json-rpc-accounts) don't seem to be obviously interoperable with ethers Signers

## Suggested roadmap
- Use Viem for optimism mainnet, and then a few op stack chains over time.
- Build generalized Viem modules that could help us install viem into the broader codebase like:
    - converting between Ethers providers/signers and Viem transports/accounts
@nicholaspai nicholaspai changed the title [WIP]: Experimentally use Viem in OpStack finalizer feat: Use Viem in finalizer for some OpStack chains Oct 28, 2024
const publicClientL1 = viem
.createPublicClient({
chain: chainIsProd(chainId) ? viemChains.mainnet : viemChains.sepolia,
transport: viem.http(getCachedProvider(hubChainId, true).providers[0].connection.url),
Copy link
Member Author

Choose a reason for hiding this comment

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

this part is annoying: is there a better way to set up a viem.http() object without having to access the ethers.JSONRpcProvider's connection.url prop?

chain: chainIsProd(chainId) ? viemChains.mainnet : viemChains.sepolia,
transport: viem.http(getCachedProvider(hubChainId, true).providers[0].connection.url),
})
.extend(publicActionsL1() as any) as any;
Copy link
Member Author

Choose a reason for hiding this comment

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

Also really annoying and can't figure out how to get these typings to work, even the viem code itself has some weird castings so maybe its not that unexpected: https://github.com/wevm/viem/blob/80d0b61356f8a5acab2b9e622564e5b6fca53ccc/src/clients/createPublicClient.ts#L89

@nicholaspai nicholaspai marked this pull request as ready for review October 30, 2024 16:50
@nicholaspai nicholaspai requested a review from mrice32 as a code owner October 30, 2024 16:50
Copy link
Contributor

@james-a-morris james-a-morris left a comment

Choose a reason for hiding this comment

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

Is this still in flight? My only question is if we'd still look to use viem for this list of chains

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