ethereum-optimism / optimism

Optimism is Ethereum, scaled.
https://optimism.io
MIT License
5.67k stars 3.32k forks source link

sdk has an incompatible peer dependency with hardhat ethers@v5 vs ethers@v6 #6295

Closed 3esmit closed 5 months ago

3esmit commented 1 year ago

Is your feature request related to a problem? Please describe. I am trying to use hardhat and optimism sdk, however I fall under a dependency hell with Optimism requiring ethers^5 and hardhat requiring ethers^6. My project requires a custom L2 token, and I am using hardhat as the framework for compiling and deploying this token. So I want my project to be ran from hardhat framework, including the use of optimism sdk. Is there any reason why not updating to ethers^6?

Describe the solution you'd like Use ethers^6

Describe alternatives you've considered Stop using this sdk or hardhat. Create separate projects for sdk and hardhat.

3esmit commented 1 year ago

Are there any workarounds for this?

tynes commented 1 year ago

Thanks for being interested in optimism. Why do you need the sdk to deploy the token? There is a new typescript package here that may be useful. If not, what functionality do you need exactly?

3esmit commented 1 year ago

I need to deploy the token because I've written a custom token for L2, I need some extra functions and storage on my L2 Token that are not available on the default optimism L2 tokens. Therefore, I am using hardhat as development framework for building and deploying the contracts, and I would like to use also the optimism-sdk for interacting with the bridge.

tynes commented 1 year ago

I am guessing you would like to test deposits and withdrawals end to end? I don't think the contracts-ts package will give as nice of UX as the sdk for doing withdrawals.

3esmit commented 1 year ago

Yes, I would like to test that. I want to do exactly the bridge tutorial, using standard bridge, but with a custom token. And I would like to use hardhat as is a popular framework which I am used to work with.

3esmit commented 1 year ago

This issue is caused by dependencies of sdk: @eth-optimism/contracts

@eth-optimism/core-utils

These packages should be updated to use ethers^6.

tynes commented 1 year ago

I started work here but no guarantee this is complete or fully works: https://github.com/ethereum-optimism/optimism/tree/feat/sdk-ethersv6

tynes commented 1 year ago

This issue is caused by dependencies of sdk: @eth-optimism/contracts

@eth-optimism/core-utils

These packages should be updated to use ethers^6.

@eth-optimism/contracts is deprecated and we will want to remove as a dependency. Updating @eth-optimism/core-utils shouldn't be a ton of work to ethers v6

To be honest this isn't super high priority for the team, i did a little extra work attempting to port the sdk but I need to focus on my decentralization work. Happy to review any PRs if you would like to help

sbvegan commented 1 year ago

cc @roninjin10 @annieke I know y'all are busy, but I wanted to put this on your radar

annieke commented 1 year ago

@3esmit thank you for bringing this up! We're in the process of changing how we handle JS packages; sorry about the snag. The engineer leading that effort is off; we'll give you an update when he's back in a little over a week 🙏

roninjin10 commented 1 year ago

@3esmit I can help with this soon. Can you provide more information so I can help more?

3esmit commented 1 year ago

I am writing the code here https://github.com/logos-co/optimism-bridge-snt

I normally use npm, npm breaks when a project contains hardhat and optimism-sdk as dependencies. I also tried yarn - it installs but the project fails to run.

3esmit commented 1 year ago

In that repository, trying npm install @nomicfoundation/hardhat-toolbox gives npm ERR! Conflicting peer dependency: ethers@6.6.6

root@SURFACE-BOOK:/home/ricardo/optimism-bridge-snt# npm install @nomicfoundation/hardhat-toolbox
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: optimism-bridge-snt@1.0.0
npm ERR! Found: ethers@5.7.2
npm ERR! node_modules/ethers
npm ERR!   peer ethers@"^5" from @eth-optimism/contracts@0.6.0
npm ERR!   node_modules/@eth-optimism/contracts
npm ERR!     @eth-optimism/contracts@"0.6.0" from @eth-optimism/sdk@3.0.0
npm ERR!     node_modules/@eth-optimism/sdk
npm ERR!       dev @eth-optimism/sdk@"^3.0.0" from the root project
npm ERR!   ethers@"^5.7.0" from @eth-optimism/contracts-bedrock@0.15.0
npm ERR!   node_modules/@eth-optimism/contracts-bedrock
npm ERR!     @eth-optimism/contracts-bedrock@"0.15.0" from @eth-optimism/sdk@3.0.0
npm ERR!     node_modules/@eth-optimism/sdk
npm ERR!       dev @eth-optimism/sdk@"^3.0.0" from the root project
npm ERR!   3 more (@eth-optimism/sdk, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! @nomicfoundation/hardhat-toolbox@"*" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: ethers@6.6.6
npm ERR! node_modules/ethers
npm ERR!   peer ethers@"^6.4.0" from @nomicfoundation/hardhat-toolbox@3.0.0
npm ERR!   node_modules/@nomicfoundation/hardhat-toolbox
npm ERR!     @nomicfoundation/hardhat-toolbox@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /root/.npm/_logs/2023-07-28T14_43_36_463Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-07-28T14_43_36_463Z-debug-0.log
roninjin10 commented 1 year ago

Got it @3esmit. Here is how you can work around node resolution issues. This is easier to do with yarn than npm so I will demo with yarn if you are ok with using yarn.

  1. Add resolutions to your package.json Resolutions will tell yarn to install a different version of ethers for the optimism sdk
    {
    "resolutions": {
    "@eth-optimism/sdk/**/ethers": "^5.7.0"
    }
    }
  2. install ethers v5 you may find that interacting with the optimism sdk with ethers v6 works fine but I suspect you may need to pass in V5 providers to optimism. We can install ethers v5 under the namespace ethersv5
yarn add ethers@latest ethers5@npm:ethers@5 @nomicfoundation/hardhat-toolbox

Ethers v6 can be imported as normal

import * as ethers from 'ethers'

And then ethers v5 can be imported using ethers5


import * as ethers from 'ethers5`

I suspect you will have to initialize the optimism sdk via an ethers v5 provider but YMMV
roninjin10 commented 1 year ago

Thanks again for sharing the extra details and the link to repo. I tested the above instructions on your repo and the npm resolutions looked good. I haven't tested running hardhat so report back if you still run into any issues.

roninjin10 commented 1 year ago

For those reading this in future, we currently have no plans to update the sdk to v6 as this is a major breaking change and we don't want the SDK to be tightly coupled to a specific library like this. This library causes issues for viem users as well.

We instead we will be looking into building this functionality into libraries as extensions. E.g. viem's decorators or web3.js plugins or ethers.js plugins.

3esmit commented 1 year ago

This solution does not work for me. I tried that and it does not solve the issue.

root@SURFACE-BOOK:/home/ricardo/optimism-bridge-snt# yarn install
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "@nomicfoundation/hardhat-network-helpers@^1.0.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "@nomicfoundation/hardhat-chai-matchers@^2.0.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "@nomicfoundation/hardhat-ethers@^3.0.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "@nomicfoundation/hardhat-verify@^1.0.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "@types/chai@^4.2.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "@types/mocha@>=9.1.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "@types/node@>=12.0.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "@typechain/ethers-v6@^0.4.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "@typechain/hardhat@^8.0.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "chai@^4.2.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "hardhat-gas-reporter@^1.0.8".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "solidity-coverage@^0.8.1".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "ts-node@>=8.0.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "typechain@^8.2.0".
warning " > @nomicfoundation/hardhat-toolbox@3.0.0" has unmet peer dependency "typescript@>=4.5.0".
[4/4] Building fresh packages...
Done in 7.43s.
3esmit commented 1 year ago

we don't want the SDK to be tightly coupled to a specific library like this

Currently is coupled to ethers v5?

roninjin10 commented 1 year ago

we don't want the SDK to be tightly coupled to a specific library like this

Currently is coupled to ethers v5?

Correct this is something currently causing pain and we are actively moving away from. Some OP stack users are using viem. Some ethersv6. Most ethers v5.

Our strategy is to keep the sdk for ethersv5 users but work towards getting all functionality into the core libraries via extensions and decorators and I am chatting with all 3 major libraries to drive this effort. After this is done the sdk won't be necessary as these libraries will support OP functionality batteries included. Since our time is limited this unfortunately means neglecting old patterns like the sdk for the time being.

As for your issue, the error messages look related to hardhat and unrelated to this issue? I am no longer seeing ethersv5 as a missing peer dependency but instead other peer deps. Here is the complete list of peer deps this package depends on

clemsos commented 8 months ago

hello it seems the yarn resolutions approach mentioned @roninjin10 does not work as ethers is declared as a peerDependencies so there is no clear way to resolve that with yarn to my knowledge.

Any idea of another possible workaround?

Will love to integrate the sdk to our tooling as I am planning to bridge a token on several optimistic chains

tynes commented 5 months ago

The sdk has been deprecated

clemsos commented 5 months ago

The sdk has been deprecated

May I ask what replaced it ? @tynes

tynes commented 5 months ago

viem has OP Stack functionality, I recommend using viem