forked from safe-global/safe-wallet-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Upgrade ethers to v6 and protocol-kit to v2 (safe-global#3087)
fixes safe-global#2901 (safe-global#2901) fixes safe-global#1984 (safe-global#1984) This PR upgrades ethers to version 6 and protocol kit to v2. We’ve followed the migration guide from v5 to perform the update: https://docs.ethers.org/v6/migrating/ # Ethers-v6 and protocol-kit v2 migration summary ## ethers-v6 The `tsc` target has been set to `es2020` to support the shorthand notation for BigNumber, such as `0n`. Generally, previously imports that were made either from `@ethersproject` or let’s say `ethers/lib/utiils` are now directly exported from `ethers`. e.g. ```jsx import { isAddress } from 'ethers/lib/utils’ ``` becomes ```jsx import { isAddress } from 'ethers’ ``` Imports from `@safe-global/safe-core-sdk` are now coming from `@safe-global/protocol-kit` Some packages rely on ethers v^6.7.1, others on v^6.9.2 . Yarn somehow fails to resolve those to the same ethers version, that’s why in package.json we force the resolution such packages to a specific version that we use. Otherwise we are getting weird typescript errors that types are incompatible, where in reality they should be compatible Some methods have been made `async` as in ethers-v6 there is no longer an `contract.address` prop, instead one needs to call `await contract.getAddress()` to get the address. Mainly because of this in a lot of places where `useEffect` was used, we now use the `useAsync` hook. `safe-ethers-lib` has been removed and replaced by `imports form @safe-global/protocol-kit`. `@safe-global/safe-core-sdk-utils` has been removed. Mapping functions from v5 → v6: `hexZeroPad` → `toBeHex` `hexZeroPad` → `zeroPadValue` (the difference to `toBeHex` is that the provided value needs to have even lengh, otherwise we get an error) `BigNumber.from(value)` → `BigInt(value)` or short notation `0n`, `1n`, `2n` etc *note: BigInt shouldn’t come in JSX, otherwise one gets an error. Stuff like this is no longer valid:* `{myBigNumber && <div>something</div>}` has to be ⇒ `{Number(myBigNumber) && <div> something</div>}` `Web3Provider` → `BrowserProvider` `arraify` → `getBytes` `hexDataLength` → `dataLength` `type PayableOverrides` → `type Overrides` `defaultAbiCoder` → `AbiCoder.defaultAbiCoder()` `_TypedDataEncoder` → `TypedDataEncoder` `ethers.utils.solidityPack` → `solidityPacked` `hexValue` → `toQuantity` `contract.callStatic.(execTransaction|whateverFunction)` → `contract.execTransaction.staticCall` ## protocol-kit `isL1SafeMasterCopy` → `isL1SafeSingleton` This mock: ```jsx jest.mock('@safe-global/protocol-kit', () => { const originalModule = jest.requireActual('@safe-global/protocol-kit') // Mock class class MockEthersAdapter extends originalModule.EthersAdapter { getChainId = jest.fn().mockImplementation(() => Promise.resolve(BigInt(4))) } return { ...originalModule, EthersAdapter: MockEthersAdapter, } }) ``` Is now needed in all tests that touch protocol-kit’s `EthersAdapter`. `EthersAdapter` automatically tries to get the chain id (in the past we were providing it to it), because of this we have to mock the `getChainId` function, otherwise we get a mysterous error “Range error” in the tests. --------------------------------------------- Co-authored-by: Daniel Dimitrov <daniel.d@safe-global> Co-authored-by: Usame Algan <usame@safe-global> Co-authored-by: Manuel Gellfart <manu@safe.global>
- Loading branch information
Showing
195 changed files
with
2,349 additions
and
1,889 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.