Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista committed Feb 14, 2024
1 parent 4f759df commit c7bc6aa
Show file tree
Hide file tree
Showing 70 changed files with 297 additions and 783 deletions.
2 changes: 1 addition & 1 deletion examples/oapp/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dotenv/config'

import 'hardhat-deploy'
import 'hardhat-contract-sizer'
import '@nomiclabs/hardhat-ethers'
import '@nomicfoundation/hardhat-ethers'
import '@layerzerolabs/toolbox-hardhat'
import { HardhatUserConfig, HttpNetworkAccountsUserConfig } from 'hardhat/types'

Expand Down
2 changes: 1 addition & 1 deletion examples/oapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@types/mocha": "^10.0.6",
"chai": "^4.4.1",
"dotenv": "^16.4.1",
"ethers": "^5.7.2",
"ethers": "~6.11.0",
"hardhat": "^2.19.5",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-deploy": "^0.11.45",
Expand Down
2 changes: 1 addition & 1 deletion examples/oft/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dotenv/config'

import 'hardhat-deploy'
import 'hardhat-contract-sizer'
import '@nomiclabs/hardhat-ethers'
import '@nomicfoundation/hardhat-ethers'
import '@layerzerolabs/toolbox-hardhat'
import { HardhatUserConfig, HttpNetworkAccountsUserConfig } from 'hardhat/types'

Expand Down
2 changes: 1 addition & 1 deletion examples/oft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@types/mocha": "^10.0.6",
"chai": "^4.4.1",
"dotenv": "^16.4.1",
"ethers": "^5.7.2",
"ethers": "~6.11.0",
"hardhat": "^2.19.5",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-deploy": "^0.11.45",
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@
"packageManager": "[email protected]",
"engines": {
"node": ">=18.16.0"
},
"pnpm": {
"overrides": {
"ethers": "~6.11.0",
"zksync-web3": "npm:[email protected]"
}
}
}
2 changes: 1 addition & 1 deletion packages/build-lz-options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"yoga-layout-prebuilt": "^1.10.0"
},
"devDependencies": {
"@ethersproject/address": "~5.7.0",
"@layerzerolabs/devtools": "~0.2.2",
"@layerzerolabs/devtools-evm": "~0.2.2",
"@layerzerolabs/io-devtools": "~0.1.3",
Expand All @@ -43,6 +42,7 @@
"commander": "^11.1.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"ethers": "~6.11.0",
"ink": "^3.2.0",
"ink-gradient": "^2.0.0",
"prompts": "^2.4.2",
Expand Down
13 changes: 4 additions & 9 deletions packages/devtools-evm-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,19 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@ethersproject/wallet": "^5.7.0",
"@layerzerolabs/devtools": "~0.2.2",
"@layerzerolabs/devtools-evm": "~0.2.2",
"@layerzerolabs/io-devtools": "~0.1.3",
"@layerzerolabs/lz-definitions": "~2.1.7",
"@layerzerolabs/lz-evm-sdk-v1": "~2.1.7",
"@layerzerolabs/test-devtools": "~0.1.5",
"@layerzerolabs/test-devtools-evm-hardhat": "~0.1.5",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@swc/core": "^1.4.0",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
"ethers": "~6.11.0",
"fast-check": "^3.15.1",
"hardhat": "^2.19.5",
"hardhat-deploy": "^0.11.45",
Expand All @@ -76,15 +73,13 @@
"typescript": "^5.3.3"
},
"peerDependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@layerzerolabs/devtools": "~0.2.2",
"@layerzerolabs/devtools-evm": "~0.2.2",
"@layerzerolabs/io-devtools": "~0.1.2",
"@layerzerolabs/lz-definitions": "~2.1.3",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"ethers": "~6.11.0",
"hardhat": "^2.19.4",
"hardhat-deploy": "^0.11.45"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools-evm-hardhat/src/errors/parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAllArtifacts, isErrorFragment } from '@/artifacts'
import { Contract } from '@ethersproject/contracts'
import { Contract } from 'ethers'
import { OmniContract, createContractErrorParser } from '@layerzerolabs/devtools-evm'
import { makeZeroAddress } from '@layerzerolabs/devtools-evm'
import { EndpointId } from '@layerzerolabs/lz-definitions'
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools-evm-hardhat/src/omnigraph/coordinates.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { OmniPoint } from '@layerzerolabs/devtools'
import pMemoize from 'p-memoize'
import { OmniContract } from '@layerzerolabs/devtools-evm'
import { Contract } from '@ethersproject/contracts'
import { Contract } from 'ethers'
import assert from 'assert'
import { OmniContractFactoryHardhat, OmniDeployment } from './types'
import { createGetHreByEid } from '@/runtime'
Expand Down
6 changes: 3 additions & 3 deletions packages/devtools-evm-hardhat/src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { JsonRpcProvider } from '@ethersproject/providers'
import type { ProviderFactory } from '@layerzerolabs/devtools-evm'
import pMemoize from 'p-memoize'
import { createGetHreByEid, wrapEIP1193Provider } from './runtime'
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'

export const createProviderFactory = (
networkEnvironmentFactory = createGetHreByEid()
): ProviderFactory<JsonRpcProvider> => {
): ProviderFactory<HardhatEthersProvider> => {
return pMemoize(async (eid) => {
const env = await networkEnvironmentFactory(eid)

return wrapEIP1193Provider(env.network.provider)
return wrapEIP1193Provider(env.network.provider, env.network.name)
})
}
8 changes: 5 additions & 3 deletions packages/devtools-evm-hardhat/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { HardhatRuntimeEnvironment, EthereumProvider } from 'hardhat/types'

import pMemoize from 'p-memoize'
import type { JsonRpcProvider } from '@ethersproject/providers'
import { ConfigurationError } from './errors'
import { HardhatContext } from 'hardhat/internal/context'
import { Environment as HardhatRuntimeEnvironmentImplementation } from 'hardhat/internal/core/runtime-environment'
import { EndpointId } from '@layerzerolabs/lz-definitions'
import { EndpointBasedFactory, Factory, formatEid } from '@layerzerolabs/devtools'
import { EthersProviderWrapper } from '@nomiclabs/hardhat-ethers/internal/ethers-provider-wrapper'
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'
import assert from 'assert'
import memoize from 'micro-memoize'

Expand Down Expand Up @@ -130,7 +129,10 @@ export const createGetHreByEid = (
* @param {EIP1193Provider} provider
* @returns {JsonRpcProvider}
*/
export const wrapEIP1193Provider = (provider: EthereumProvider): JsonRpcProvider => new EthersProviderWrapper(provider)
export const wrapEIP1193Provider = (
provider: EthereumProvider,
networkName: string = 'unnamed network'
): HardhatEthersProvider => new HardhatEthersProvider(provider, networkName)

/**
* Gets an EndpointId defined in the hardhat config
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools-evm-hardhat/src/transactions/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const createSignerFactory = (
): OmniSignerFactory<OmniSignerEVM> => {
return pMemoize(async (eid) => {
const provider = await providerFactory(eid)
const signer = provider.getSigner(addressOrIndex)
const signer = await provider.getSigner(addressOrIndex)

return new OmniSignerEVM(eid, signer)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fc from 'fast-check'
import 'hardhat'
import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'
import { JsonRpcProvider, Web3Provider } from 'ethers'
import { createConnectedContractFactory } from '@/omnigraph'
import { pointArbitrary } from '@layerzerolabs/test-devtools'
import { Contract } from '@ethersproject/contracts'
import { Contract } from 'ethers'
import { makeZeroAddress } from '@layerzerolabs/devtools-evm'

// Ethers calls the eth_chainId RPC method when initializing a provider so we mock the result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Deployment } from 'hardhat-deploy/dist/types'
import { endpointArbitrary, evmAddressArbitrary } from '@layerzerolabs/test-devtools'
import { OmniDeployment, createContractFactory, omniDeploymentToContract, omniDeploymentToPoint } from '@/omnigraph'
import { EndpointId } from '@layerzerolabs/lz-definitions'
import { Contract } from '@ethersproject/contracts'
import { Contract } from 'ethers'
import { makeZeroAddress } from '@layerzerolabs/devtools-evm'
import { createGetHreByEid } from '@/runtime'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
createOmniNodeHardhatTransformer,
createOmniPointHardhatTransformer,
} from '@/omnigraph/transformations'
import { Contract } from '@ethersproject/contracts'
import { Contract } from 'ethers'
import { endpointArbitrary, evmAddressArbitrary, nullableArbitrary, pointArbitrary } from '@layerzerolabs/test-devtools'
import { isOmniPoint, parallel, sequence } from '@layerzerolabs/devtools'

Expand Down
2 changes: 1 addition & 1 deletion packages/devtools-evm-hardhat/test/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'hardhat'
import { createGetHreByEid } from '@/runtime'
import { EndpointId } from '@layerzerolabs/lz-definitions'
import { createProviderFactory } from '@/provider'
import { JsonRpcProvider } from '@ethersproject/providers'
import { JsonRpcProvider } from 'ethers'

// Ethers calls the eth_chainId RPC method when initializing a provider so we mock the result
jest.spyOn(JsonRpcProvider.prototype, 'detectNetwork').mockResolvedValue({ chainId: 1, name: 'mock' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'hardhat'
import { EndpointId } from '@layerzerolabs/lz-definitions'
import { createSignerFactory } from '@/transactions/signer'
import { JsonRpcProvider, JsonRpcSigner } from '@ethersproject/providers'
import { JsonRpcProvider, JsonRpcSigner } from 'ethers'
import { OmniSignerEVM } from '@layerzerolabs/devtools-evm'

// Ethers calls the eth_chainId RPC method when initializing a provider so we mock the result
Expand Down
18 changes: 2 additions & 16 deletions packages/devtools-evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,14 @@
"p-memoize": "~4.0.4"
},
"devDependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "~5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@layerzerolabs/devtools": "~0.2.2",
"@layerzerolabs/io-devtools": "~0.1.3",
"@layerzerolabs/lz-definitions": "~2.1.7",
"@layerzerolabs/test-devtools": "~0.1.5",
"@swc/core": "^1.4.0",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
"ethers": "~6.11.0",
"fast-check": "^3.15.1",
"jest": "^29.7.0",
"jest-extended": "^4.0.2",
Expand All @@ -64,17 +57,10 @@
"zod": "^3.22.4"
},
"peerDependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "~5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@layerzerolabs/devtools": "~0.2.2",
"@layerzerolabs/io-devtools": "~0.1.2",
"@layerzerolabs/lz-definitions": "~2.1.3",
"ethers": "~6.11.0",
"zod": "^3.22.4"
},
"publishConfig": {
Expand Down
5 changes: 2 additions & 3 deletions packages/devtools-evm/src/address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { OmniAddress } from '@layerzerolabs/devtools'
import { getAddress } from '@ethersproject/address'
import { AddressZero } from '@ethersproject/constants'
import { getAddress, ZeroAddress } from 'ethers'

/**
* Turns a nullish value (`null` or `undefined`) into a zero address
Expand All @@ -9,7 +8,7 @@ import { AddressZero } from '@ethersproject/constants'
*
* @returns {string}
*/
export const makeZeroAddress = (address?: OmniAddress | null | undefined): string => address ?? AddressZero
export const makeZeroAddress = (address?: OmniAddress | null | undefined): string => address ?? ZeroAddress

/**
* Applies checksum to a given address, lower/uppercasing
Expand Down
11 changes: 7 additions & 4 deletions packages/devtools-evm/src/errors/parser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { defaultAbiCoder } from '@ethersproject/abi'
import { AbiCoder } from 'ethers'
import { ContractError, CustomError, UnknownError, PanicError, RevertError } from './errors'
import { BigNumberishBigIntSchema } from '@/schema'
import type { Contract } from '@ethersproject/contracts'
import type { Contract } from 'ethers'
import type { OmniContractErrorParserFactory } from './types'
import { UIntBigIntSchema } from '@layerzerolabs/devtools'

const defaultAbiCoder = AbiCoder.defaultAbiCoder()

/**
* Creates an error parser based on a specific `OmniContract`
Expand Down Expand Up @@ -76,7 +78,7 @@ const basicDecoder = (data: string): ContractError[] => {
try {
// The codes should follow the docs here https://docs.soliditylang.org/en/latest/control-structures.html#error-handling-assert-require-revert-and-exceptions
const [decodedRawReason] = defaultAbiCoder.decode(['uint256'], `0x${reason}`)
const decodedReason = BigNumberishBigIntSchema.parse(decodedRawReason)
const decodedReason = UIntBigIntSchema.parse(decodedRawReason)

return [new PanicError(decodedReason)]
} catch {
Expand Down Expand Up @@ -112,6 +114,7 @@ const createContractDecoder =
(data: string): ContractError[] => {
try {
const errorDescription = contract.interface.parseError(data)
if (errorDescription == null) return []

return [new CustomError(errorDescription.name, [...errorDescription.args])]
} catch {
Expand Down
14 changes: 5 additions & 9 deletions packages/devtools-evm/src/events/parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { LogDescription } from '@ethersproject/abi'
import { Contract } from '@ethersproject/contracts'
import { TransactionReceipt } from '@ethersproject/providers'
import type { Contract, LogDescription, TransactionReceipt } from 'ethers'

/**
* Parse event logs.
Expand All @@ -10,12 +8,10 @@ import { TransactionReceipt } from '@ethersproject/providers'
*/
export const parseLogs = (receipt: TransactionReceipt, contract: Contract): LogDescription[] =>
receipt.logs?.flatMap((log) => {
// ensure the log address matches the contract address
if (log.address !== contract.address) {
return []
}
try {
return [contract.interface.parseLog(log)]
const parsed = contract.interface.parseLog(log)

return parsed == null ? [] : [parsed]
} catch {
return []
}
Expand All @@ -29,4 +25,4 @@ export const parseLogs = (receipt: TransactionReceipt, contract: Contract): LogD
* @returns {LogDescription[]}
*/
export const parseLogsWithName = (receipt: TransactionReceipt, contract: Contract, name: string): LogDescription[] =>
parseLogs(receipt, contract).filter((log) => log.eventFragment.name === name)
parseLogs(receipt, contract).filter((log) => log.fragment.name === name)
1 change: 0 additions & 1 deletion packages/devtools-evm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export * from './errors'
export * from './events'
export * from './omnigraph'
export * from './provider'
export * from './schema'
export * from './signer'
10 changes: 8 additions & 2 deletions packages/devtools-evm/src/omnigraph/coordinates.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import type { OmniPoint } from '@layerzerolabs/devtools'
import type { OmniContract } from './types'
import { Provider } from '@/provider/types'
import type { Addressable, Contract } from 'ethers'
import assert from 'assert'

function assertContractTarget(value: string | Addressable): asserts value is string {
assert(typeof value === 'string', 'Contracts using Addressable contract.target are not yet supported')
}

export const omniContractToPoint = ({ eid, contract }: OmniContract): OmniPoint => ({
eid,
address: contract.address,
address: (assertContractTarget(contract.target), contract.target),
})

export const connectOmniContract = ({ eid, contract }: OmniContract, provider: Provider): OmniContract => ({
eid,
contract: contract.connect(provider),
contract: contract.connect(provider) as Contract,
})
2 changes: 1 addition & 1 deletion packages/devtools-evm/src/omnigraph/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Contract } from '@ethersproject/contracts'
import type { Contract } from 'ethers'
import type { Factory, IOmniSDK as IOmniSDKAbstract, OmniPoint, WithEid } from '@layerzerolabs/devtools'

export type OmniContract<TContract extends Contract = Contract> = WithEid<{
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools-evm/src/provider/factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pMemoize from 'p-memoize'
import { ProviderFactory, RpcUrlFactory } from './types'
import { JsonRpcProvider } from '@ethersproject/providers'
import { JsonRpcProvider } from 'ethers'

export const createProviderFactory = (urlFactory: RpcUrlFactory): ProviderFactory<JsonRpcProvider> =>
pMemoize(async (eid) => new JsonRpcProvider(await urlFactory(eid)))
2 changes: 1 addition & 1 deletion packages/devtools-evm/src/provider/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { EndpointBasedFactory } from '@layerzerolabs/devtools'
import type { BaseProvider } from '@ethersproject/providers'
import type { Provider as BaseProvider } from 'ethers'

export type Provider = BaseProvider

Expand Down
Loading

0 comments on commit c7bc6aa

Please sign in to comment.