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

🎢 Ethers v6 #1136

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bfe0c2b
Update to ethers v6 and make non-react stuff work
yivlad Aug 7, 2023
b761079
Fix Works when passed valid logs test
yivlad Aug 7, 2023
07f795d
useRawCall tests
yivlad Aug 9, 2023
d7179ed
useBlockNumber tests
yivlad Aug 10, 2023
f7427a1
useCall tests
yivlad Aug 10, 2023
fbf9c38
Gas price tests
yivlad Aug 16, 2023
de0427c
Remove .only
yivlad Aug 16, 2023
b4496f1
useLogs tests
yivlad Aug 16, 2023
30300e4
Remove .only
yivlad Aug 16, 2023
1be771b
token tests
yivlad Aug 16, 2023
f91b80b
Currency value tests
yivlad Aug 16, 2023
ede1ae0
useEthers tests
yivlad Aug 17, 2023
94f18ff
connectContractToSigner tests
yivlad Aug 17, 2023
66acb45
useSigner
yivlad Aug 17, 2023
54a53ac
useContractFunction
yivlad Aug 17, 2023
30278b4
Misc
yivlad Aug 17, 2023
d718d86
useSendTransaction tests
yivlad Aug 17, 2023
a5af374
All tests
yivlad Aug 17, 2023
72625fe
Lint
yivlad Aug 17, 2023
32b0edb
цшз
yivlad Aug 18, 2023
6b6b8eb
Add typechain types
yivlad Aug 18, 2023
88ff4e0
Update types
yivlad Aug 21, 2023
13958db
Update types again
yivlad Aug 21, 2023
3aac8af
Fix more types
yivlad Aug 21, 2023
9c842f4
Full build
yivlad Aug 23, 2023
78ef7de
Connectors
yivlad Aug 23, 2023
5fc45e0
Fix types
yivlad Aug 23, 2023
ad87aa3
Uniswap package
yivlad Aug 24, 2023
78cacbd
example app build
yivlad Aug 24, 2023
0d9fcd8
Example app tests
yivlad Aug 24, 2023
da72c4d
Example app lint
yivlad Aug 24, 2023
60a73a0
Siwe package
yivlad Aug 24, 2023
745ed02
extension package
yivlad Aug 25, 2023
6d53b5f
Lint
yivlad Aug 25, 2023
261a5a0
Add ganache provider patch
yivlad Aug 25, 2023
aeff5fd
Debug CI
yivlad Aug 25, 2023
f7e8c2c
Debug
yivlad Aug 25, 2023
f9dbf37
More debugging
yivlad Aug 25, 2023
0319d9c
Revert "Debug CI"
yivlad Aug 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
},
"dependencies": {
"@changesets/cli": "^2.14.1",
"ethers": "5.6.9",
"ethers": "6.7.0",
"prettier": "2.1.2"
},
"resolutions": {
"ethers": "5.6.9"
"ethers": "6.7.0"
},
"devDependencies": {
"eslint-plugin-no-only-tests": "^2.6.0"
},
"pnpm": {
"patchedDependencies": {
"@ethers-ext/[email protected]": "patches/@[email protected]"
}
}
}
2 changes: 1 addition & 1 deletion packages/coingecko/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"peerDependencies": {
"react": "*",
"ethers": "*"
"ethers": "6.7.0"
},
"scripts": {
"build": "pnpm run build:esm && pnpm run build:cjs",
Expand Down
6 changes: 3 additions & 3 deletions packages/connectors/portis/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Connector } from '@usedapp/core'
import { providers } from 'ethers'
import { ConnectorEvent, ConnectorUpdateData } from '@usedapp/core'
import Portis, { INetwork, IOptions } from '@portis/web3'
import { BrowserProvider } from 'ethers'

export class PortisConnector implements Connector {
public provider?: providers.Web3Provider
public provider?: BrowserProvider
public portis: Portis | undefined
public readonly name = 'Portis'

Expand All @@ -20,7 +20,7 @@ export class PortisConnector implements Connector {
if (this.provider) return
this.portis = new Portis(this.dappId, this.network, this.options)
await this.portis.provider.enable()
this.provider = new providers.Web3Provider(this.portis.provider)
this.provider = new BrowserProvider(this.portis.provider)
}

async connectEagerly(): Promise<void> {
Expand Down
8 changes: 4 additions & 4 deletions packages/connectors/wallet-connect-v2/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chain, Connector, ConnectorEvent, ConnectorUpdateData } from '@usedapp/core'
import EthereumProvider from "@walletconnect/ethereum-provider"
import { providers } from 'ethers'
import { BrowserProvider } from 'ethers'

interface WalletConnectV2ConnectorOptions {
projectId: string,
Expand All @@ -10,7 +10,7 @@ interface WalletConnectV2ConnectorOptions {
}

export class WalletConnectV2Connector implements Connector {
public provider?: providers.Web3Provider
public provider?: BrowserProvider
public readonly name = 'WalletConnectV2'

readonly update = new ConnectorEvent<ConnectorUpdateData>()
Expand Down Expand Up @@ -39,7 +39,7 @@ export class WalletConnectV2Connector implements Connector {
const accounts = await this.ethereumProvider.request({ method: "eth_accounts" }) as string[]

const chainId = await this.ethereumProvider.request({ method: "eth_chainId" }) as any
this.provider = new providers.Web3Provider(this.ethereumProvider)
this.provider = new BrowserProvider(this.ethereumProvider)
this.update.emit({ chainId: parseInt(chainId), accounts })
} catch (e) {
console.debug(e)
Expand All @@ -59,7 +59,7 @@ export class WalletConnectV2Connector implements Connector {
const accounts = await this.ethereumProvider.request({ method: "eth_accounts" }) as string[]

const chainId = await this.ethereumProvider.request({ method: "eth_chainId" }) as any
this.provider = new providers.Web3Provider(this.ethereumProvider)
this.provider = new BrowserProvider(this.ethereumProvider)
this.update.emit({ chainId: parseInt(chainId), accounts })
} catch (e: any) {
console.log(e)
Expand Down
6 changes: 3 additions & 3 deletions packages/connectors/wallet-connect/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Connector, ConnectorEvent, ConnectorUpdateData } from '@usedapp/core'
import { providers } from 'ethers'

import WalletConnectProvider from '@walletconnect/web3-provider'
import type { IWalletConnectProviderOptions } from '@walletconnect/types'
import { BrowserProvider } from 'ethers'

export class WalletConnectConnector implements Connector {
public provider?: providers.Web3Provider
public provider?: BrowserProvider
public readonly name = 'WalletConnect'

readonly update = new ConnectorEvent<ConnectorUpdateData>()
Expand All @@ -15,7 +15,7 @@ export class WalletConnectConnector implements Connector {

private async init() {
this.walletConnectProvider = new WalletConnectProvider(this.opts)
this.provider = new providers.Web3Provider(this.walletConnectProvider)
this.provider = new BrowserProvider(this.walletConnectProvider)
await this.walletConnectProvider.enable()
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/.mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"watchExtensions": "ts",
"extension": "ts",
"timeout": 10000,
"file": "./src/testing/test-setup.ts"
"file": "./src/testing/test-setup.ts",
"exit": "true"
}
34 changes: 18 additions & 16 deletions packages/core/generate-hooks/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ export async function generate() {
const factory = factories[factoryName]
const Interface = factory.createInterface()

const abi = factory.abi
Object.keys(Interface.functions).forEach((fn) => {
const functionName = fn.split('(')[0]
const fnABI = abi.find((a: any) => a.name === functionName)
if (['view', 'pure'].includes(fnABI?.stateMutability)) {
const functions = Interface.fragments.filter((f: any) => f.type === 'function')
functions.forEach((fn: any) => {
const functionName = fn.name
if (['view', 'pure'].includes(fn.stateMutability)) {
output += `
export const use${contractName}_${functionName} = (
contractAddress: Falsy | string,
Expand All @@ -36,7 +35,7 @@ export const use${contractName}_${functionName} = (
contractAddress
&& args
&& {
contract: new Contract(contractAddress, ${contractName}Interface) as ${contractName},
contract: new BaseContract(contractAddress, ${contractName}Interface) as ${contractName},
method: '${functionName}',
args
}, queryParams
Expand All @@ -51,7 +50,7 @@ export const use${contractName}_${functionName} = (
options?: TransactionOptions
) => {
return useContractFunction<${contractName}, '${functionName}'>(
contractAddress && new Contract(contractAddress, ${contractName}Interface) as ${contractName},
contractAddress && new BaseContract(contractAddress, ${contractName}Interface) as ${contractName},
'${functionName}',
options
)
Expand All @@ -61,9 +60,14 @@ export const use${contractName}_${functionName} = (
}
})

const events = Interface.fragments.filter((f: any) => f.type === 'event')
console.log({
event: Interface.fragments[2]
})

//write events
Object.keys(Interface.events).forEach((event) => {
const eventName = event.split('(')[0]
events.forEach((event: any) => {
const eventName = event.name
output += `
export const use${contractName}_event_${eventName} = (
contractAddress: Falsy | string,
Expand All @@ -73,7 +77,7 @@ export const use${contractName}_event_${eventName} = (
return useLogs(
contractAddress
&& {
contract: new Contract(contractAddress, ${contractName}Interface),
contract: new BaseContract(contractAddress, ${contractName}Interface),
event: '${eventName}',
args: args || [],
},
Expand All @@ -85,14 +89,12 @@ export const use${contractName}_event_${eventName} = (
})
output += `
export const use${contractName} = {
${Object.keys(Interface.functions)
.map(fn => fn.split('(')[0])
.map(fn => `${fn}: use${contractName}_${fn}`)
${functions
.map((fn: any) => `${fn.name}: use${contractName}_${fn.name}`)
.join(",\n ")},
events: {
${Object.keys(Interface.events)
.map(event => event.split('(')[0])
.map(event => ` ${event}: use${contractName}_event_${event}`)
${events
.map((event: any) => ` ${event.name}: use${contractName}_event_${event.name}`)
.join(",\n ")}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/generate-hooks/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path'

export const commonImports = `
import { Falsy, Params, QueryParams, TransactionOptions, TypedFilter, useCall, useContractFunction, useLogs } from '@usedapp/core'
import { Contract, utils } from 'ethers'
import { BaseContract, Interface } from 'ethers'
`

export interface ImportsOptions {
Expand All @@ -12,6 +12,6 @@ export interface ImportsOptions {
}
export const imports = ({typesDir, outDir, contractName}: ImportsOptions) => `
import { ${contractName}, ${contractName}__factory } from '${path.relative(outDir, typesDir)}'
const ${contractName}Interface = new utils.Interface(${contractName}__factory.abi)
const ${contractName}Interface = new Interface(${contractName}__factory.abi)

`
7 changes: 4 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
"nanoid": "3.3.4"
},
"peerDependencies": {
"ethers": "^5",
"ethers": "6.7.0",
"react": "*"
},
"devDependencies": {
"@ethers-ext/provider-ganache": "6.0.0-beta.2",
"@ethersproject/abi": "5.6.1",
"@ethersproject/abstract-provider": "^5.6.1",
"@ethersproject/providers": "5.6.2",
Expand All @@ -48,8 +49,8 @@
"chai-as-promised": "^7.1.1",
"eslint": "7.22.0",
"eslint-plugin-react-hooks": "^4.3.0",
"ethers": "5.6.9",
"ganache": "7.9.0",
"ethers": "6.7.0",
"ganache": "7.0.3",
"jsdom": "^16.4.0",
"jsdom-global": "^3.0.2",
"mocha": "^8.2.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/abi/multicall/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { utils } from 'ethers'
import { Interface } from 'ethers'
import MultiCall from '../../constants/abi/MultiCall.json'

export const ethersAbi = new utils.Interface(MultiCall.abi)
export const ethersAbi = new Interface(MultiCall.abi)
export const defaultMulticall1ErrorMessage =
'One of the calls reverted in Multicall v1. See https://usedapp-docs.netlify.app/docs/Guides/Troubleshooting for more details.'
2 changes: 1 addition & 1 deletion packages/core/src/abi/multicall/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { encodeUint } from '../common'
import { encodeCalls } from '../multicall2/encoder'
import { ethersAbi } from './constants'

const selector = ethersAbi.getSighash('aggregate')
const selector = ethersAbi.getFunction('aggregate')?.selector

export function encodeAggregate(calls: [string, string][]) {
// function aggregate(tuple(address target, bytes callData)[] calls) public returns (tuple(uint256 blockNumber, bytes returnData)[])
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/abi/multicall2/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { utils } from 'ethers'
import { Interface } from 'ethers'
import MultiCall2 from '../../constants/abi/MultiCall2.json'

export const ethersAbi = new utils.Interface(MultiCall2.abi)
export const ethersAbi = new Interface(MultiCall2.abi)

export const trueEncoded = '0'.repeat(63) + '1'
export const falseEncoded = '0'.repeat(63) + '0'
6 changes: 5 additions & 1 deletion packages/core/src/abi/multicall2/encoder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { encodeUint, bufPaddedLength, buffLength } from '../common'
import { ethersAbi, falseEncoded, trueEncoded } from './constants'

const selector = ethersAbi.getSighash('tryAggregate')
const selector = ethersAbi.getFunction('tryAggregate')?.selector

export function encodeCalls(start: string, calls: [string, string][]) {
let res = start
Expand Down Expand Up @@ -46,6 +46,10 @@ export function encodeTryAggregate(b: boolean, calls: [string, string][]) {
res += b ? trueEncoded : falseEncoded
res += encodeUint(dynamicOffset)

if (!res) {
throw new Error('Multicall2: failed to encode tryAggregate')
}

// encode dynamic array of calls
return encodeCalls(res, calls)
}
4 changes: 1 addition & 3 deletions packages/core/src/constants/abi/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { utils } from 'ethers'
import { Interface } from 'ethers'
import MultiCall from './MultiCall.json'
import MultiCall2 from './MultiCall2.json'
import ERC20 from './ERC20.json'
import ERC20Mock from './ERC20Mock.json'
import BlockNumberContract from './BlockNumber.json'

const Interface = utils.Interface

const MultiCallABI = new Interface(MultiCall.abi)

export { MultiCall, MultiCallABI }
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/constants/type/Config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AbstractProvider } from 'ethers'
import { Chain } from '../../constants'
import { Connector } from '../../providers/network/connectors/connector'
import { providers } from 'ethers'

export type BaseProviderFactory = () => providers.BaseProvider
export type BaseProviderFactory = () => AbstractProvider

export type NodeUrls = {
[chainId: number]: string | providers.BaseProvider | BaseProviderFactory
[chainId: number]: string | AbstractProvider | BaseProviderFactory
}

export type MulticallAddresses = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/constants/type/QueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockTag } from '@ethersproject/abstract-provider'
import { BlockTag } from 'ethers'
import { Config } from '..'
import { ChainId } from '../chainId'

Expand Down
15 changes: 7 additions & 8 deletions packages/core/src/helpers/address.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { utils } from 'ethers'
import { BigNumber } from 'ethers'
import { getAddress } from 'ethers'
import { Falsy } from '../model/types'
import { shortenString } from './common'

Expand All @@ -8,7 +7,7 @@ import { shortenString } from './common'
*/
export function shortenAddress(address: string): string {
try {
const formattedAddress = utils.getAddress(address)
const formattedAddress = getAddress(address)
return shortenString(formattedAddress)
} catch {
throw new TypeError("Invalid input, address can't be parsed")
Expand All @@ -30,14 +29,14 @@ export function shortenIfAddress(address: string | Falsy): string {
*/
export function compareAddress(firstAddress: string, secondAddress: string): number {
try {
const parsedFirstAddress = BigNumber.from(firstAddress)
const parsedSecondAddress = BigNumber.from(secondAddress)
const parsedFirstAddress = BigInt(firstAddress)
const parsedSecondAddress = BigInt(secondAddress)

if (parsedFirstAddress.gt(parsedSecondAddress)) {
if (parsedFirstAddress > parsedSecondAddress) {
return 1
}

if (parsedFirstAddress.lt(parsedSecondAddress)) {
if (parsedFirstAddress < parsedSecondAddress) {
return -1
}

Expand All @@ -52,7 +51,7 @@ export function compareAddress(firstAddress: string, secondAddress: string): num
*/
export function addressEqual(firstAddress: string, secondAddress: string): boolean {
try {
return utils.getAddress(firstAddress) === utils.getAddress(secondAddress)
return getAddress(firstAddress) === getAddress(secondAddress)
} catch {
throw new TypeError("Invalid input, address can't be parsed")
}
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/helpers/calls.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect } from 'chai'
import { Contract, utils } from 'ethers'
import { Interface } from 'ethers/lib/utils'
import { Contract, Interface } from 'ethers'
import { Call, RawCallResult } from '../../src'
import { decodeCallResult } from './calls'

Expand All @@ -22,7 +21,7 @@ describe('decodeCallResult', () => {
const errorMessage = 'Testing error message'
const errorResult: RawCallResult = {
success: false,
value: new utils.Interface(['function Error(string)']).encodeFunctionData('Error', [errorMessage]),
value: new Interface(['function Error(string)']).encodeFunctionData('Error', [errorMessage]),
}
const { value, error } = decodeCallResult(call, errorResult) || {}
expect(value).to.be.undefined
Expand All @@ -36,7 +35,7 @@ describe('decodeCallResult', () => {
}
const { value, error } = decodeCallResult(call, result) || {}
expect(value).to.be.undefined
expect(error?.message.startsWith('hex data is odd-length')).to.be.true
expect(error?.message.startsWith('invalid BytesLike value')).to.be.true
})

it('success', () => {
Expand Down
Loading
Loading