Skip to content

Commit

Permalink
feat: migrate to ethers v6
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Aug 21, 2023
1 parent 7d2ae57 commit 2b80792
Show file tree
Hide file tree
Showing 74 changed files with 1,480 additions and 1,468 deletions.
9 changes: 9 additions & 0 deletions .changeset/new-ducks-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@sphinx-labs/contracts': minor
'@sphinx-labs/executor': minor
'@sphinx-labs/plugins': minor
'@sphinx-labs/core': minor
'@sphinx-labs/demo': minor
---

Upgrade to EthersV6
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"packages": [
"packages/contracts",
"packages/core",
"packages/executor",
"packages/plugins",
"packages/executor",
"packages/demo"
],
"nohoist": [
Expand All @@ -25,7 +25,6 @@
"@sphinx-labs/{plugins,demo}/forge-std",
"@sphinx-labs/{plugins,demo}/ds-test",
"@sphinx-labs/plugins/solidity-stringutils",
"@sphinx-labs/plugins/@prb/math",
"@sphinx-labs/plugins/@layerzerolabs/solidity-examples"
]
},
Expand All @@ -42,7 +41,7 @@
"@changesets/cli": "^2.16.0",
"@types/chai": "^4.2.18",
"@types/mocha": "^8.2.2",
"@types/node": "^18.0.0",
"@types/node": "18.15.13",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^4.26.0",
"chai": "^4.2.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,19 @@
},
"devDependencies": {
"@connext/interfaces": "^2.0.5",
"@eth-optimism/core-utils": "^0.9.0",
"@openzeppelin/contracts": "^4.8.1",
"@openzeppelin/contracts-upgradeable": "^4.6.0",
"dotenv": "^16.0.1",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"forge-std": "https://github.com/foundry-rs/forge-std.git#v1.6.0",
"hardhat": "^2.9.9",
"hardhat": "^2.17.1",
"solhint": "^3.4.1",
"solhint-plugin-prettier": "^0.0.5",
"solmate": "^6.7.0"
},
"dependencies": {
"@eth-optimism/contracts": "^0.5.40",
"@eth-optimism/contracts-bedrock": "^0.0.0-20230522161230",
"ethers": "^5.6.9"
"ethers": "^6.7.0"
}
}
38 changes: 18 additions & 20 deletions packages/contracts/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from 'ethers'
import { ethers, toBeHex } from 'ethers'

export const OWNER_MULTISIG_ADDRESS =
'0x226F14C3e19788934Ff37C653Cf5e24caD198341'
Expand All @@ -9,38 +9,36 @@ export const getOwnerAddress = () => {
}
export const EXECUTOR = '0x42761facf5e6091fca0e38f450adfb1e22bd8c3c'

export const PROPOSER_ROLE = ethers.utils.solidityKeccak256(
export const PROPOSER_ROLE = ethers.solidityPackedKeccak256(
['string'],
['ProposerRole']
)

export const DEFAULT_ADMIN_ROLE = ethers.constants.HashZero
export const DEFAULT_ADMIN_ROLE = ethers.ZeroHash

export const SPHINX_PROXY_ADMIN_ADDRESS_SLOT_KEY = ethers.BigNumber.from(
ethers.utils.keccak256(ethers.utils.toUtf8Bytes('sphinx.proxy.admin'))
export const SPHINX_PROXY_ADMIN_ADDRESS_SLOT_KEY = toBeHex(
BigInt(ethers.keccak256(ethers.toUtf8Bytes('sphinx.proxy.admin'))) - 1n
)
.sub(1)
.toHexString()

export const EXTERNAL_TRANSPARENT_PROXY_TYPE_HASH = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes('external-transparent')
export const EXTERNAL_TRANSPARENT_PROXY_TYPE_HASH = ethers.keccak256(
ethers.toUtf8Bytes('external-transparent')
)
export const OZ_TRANSPARENT_PROXY_TYPE_HASH = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes('oz-transparent')
export const OZ_TRANSPARENT_PROXY_TYPE_HASH = ethers.keccak256(
ethers.toUtf8Bytes('oz-transparent')
)
export const OZ_UUPS_OWNABLE_PROXY_TYPE_HASH = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes('oz-ownable-uups')
export const OZ_UUPS_OWNABLE_PROXY_TYPE_HASH = ethers.keccak256(
ethers.toUtf8Bytes('oz-ownable-uups')
)
export const OZ_UUPS_ACCESS_CONTROL_PROXY_TYPE_HASH = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes('oz-access-control-uups')
export const OZ_UUPS_ACCESS_CONTROL_PROXY_TYPE_HASH = ethers.keccak256(
ethers.toUtf8Bytes('oz-access-control-uups')
)
export const IMMUTABLE_TYPE_HASH = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes('immutable')
export const IMMUTABLE_TYPE_HASH = ethers.keccak256(
ethers.toUtf8Bytes('immutable')
)
export const IMPLEMENTATION_TYPE_HASH = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes('implementation')
export const IMPLEMENTATION_TYPE_HASH = ethers.keccak256(
ethers.toUtf8Bytes('implementation')
)
export const DEFAULT_PROXY_TYPE_HASH = ethers.constants.HashZero
export const DEFAULT_PROXY_TYPE_HASH = ethers.ZeroHash

export const DETERMINISTIC_DEPLOYMENT_PROXY_ADDRESS =
'0x4e59b44847b379578588920ca78fbf26c0b4956c'
Expand Down
20 changes: 14 additions & 6 deletions packages/core/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { HardhatRuntimeEnvironment, HardhatUserConfig } from 'hardhat/types'
import { task } from 'hardhat/config'
import * as dotenv from 'dotenv'

// Hardhat plugins
import '@nomiclabs/hardhat-ethers'
import { task } from 'hardhat/config'
import { HardhatRuntimeEnvironment, HardhatUserConfig } from 'hardhat/types'
import '@nomicfoundation/hardhat-ethers'
import '@openzeppelin/hardhat-upgrades'

import { initializeAndVerifySphinx } from './src/languages/solidity/predeploys'
import { isHttpNetworkConfig } from './src/utils'
import { SphinxJsonRpcProvider } from './src/provider'

// Load environment variables from .env
dotenv.config()
Expand Down Expand Up @@ -155,7 +155,15 @@ task('deploy-system')
},
hre: HardhatRuntimeEnvironment
) => {
await initializeAndVerifySphinx(args.systemConfig, hre.ethers.provider)
// Throw an error if we're on the Hardhat network. This ensures that the `url` field is
// defined for this network.
if (!isHttpNetworkConfig(hre.network.config)) {
throw new Error(
`Cannot deploy Sphinx on the Hardhat network using this task.`
)
}
const provider = new SphinxJsonRpcProvider(hre.network.config.url)
await initializeAndVerifySphinx(args.systemConfig, provider)
}
)

Expand Down
13 changes: 4 additions & 9 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"@amplitude/node": "^1.10.2",
"@eth-optimism/common-ts": "^0.7.1",
"@eth-optimism/contracts-bedrock": "^0.0.0-20230522161230",
"@eth-optimism/core-utils": "^0.9.1",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@nomicfoundation/hardhat-ethers": "^3.0.4",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@openzeppelin/hardhat-upgrades": "^1.22.1",
"@openzeppelin/merkle-tree": "^1.0.5",
Expand All @@ -44,11 +44,10 @@
"chalk": "^4.1.2",
"core-js": "^3.27.1",
"dotenv": "^16.0.3",
"ethers": "^5.6.9",
"ethers": "^6.7.0",
"fs": "^0.0.1-security",
"handlebars": "^4.7.7",
"hardhat": "^2.10.0",
"hardhat-deploy": "^0.11.18",
"hardhat": "^2.17.1",
"insight": "^0.11.1",
"ipfs-http-client": "56.0.3",
"ipfs-only-hash": "^4.0.0",
Expand All @@ -58,9 +57,5 @@
"solidity-ast": "^0.4.45",
"undici": "^5.21.1",
"yesno": "^0.4.0"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.2.1",
"hardhat": "^2.10.0"
}
}
19 changes: 10 additions & 9 deletions packages/core/src/actions/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
writeDeploymentArtifact,
} from '../utils'
import 'core-js/features/array/at'
import { SphinxJsonRpcProvider } from '../provider'

/**
* Gets the storage layout for a contract.
Expand All @@ -41,17 +42,17 @@ export const getStorageLayout = (
}

export const getDeployedBytecode = async (
provider: ethers.providers.JsonRpcProvider,
provider: SphinxJsonRpcProvider,
address: string
): Promise<string> => {
const deployedBytecode = await provider.getCode(address)
return deployedBytecode
}

export const writeDeploymentArtifacts = async (
provider: ethers.providers.Provider,
provider: ethers.Provider,
parsedConfig: ParsedConfig,
deploymentEvents: ethers.Event[],
deploymentEvents: ethers.EventLog[],
networkDirName: string,
deploymentFolderPath: string,
configArtifacts: ConfigArtifacts
Expand Down Expand Up @@ -88,9 +89,9 @@ export const writeDeploymentArtifacts = async (
...receipt,
gasUsed: receipt.gasUsed.toString(),
cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
// Exclude the `effectiveGasPrice` if it's undefined, which is the case on Optimism.
...(receipt.effectiveGasPrice && {
effectiveGasPrice: receipt.effectiveGasPrice.toString(),
// Exclude the `gasPrice` if it's undefined
...(receipt.gasPrice && {
gasPrice: receipt.gasPrice.toString(),
}),
},
numDeployments: 1,
Expand Down Expand Up @@ -143,9 +144,9 @@ export const writeDeploymentArtifacts = async (
...receipt,
gasUsed: receipt.gasUsed.toString(),
cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
// Exclude the `effectiveGasPrice` if it's undefined, which is the case on Optimism.
...(receipt.effectiveGasPrice && {
effectiveGasPrice: receipt.effectiveGasPrice.toString(),
// Exclude the `gasPrice` if it's undefined
...(receipt.gasPrice && {
gasPrice: receipt.gasPrice.toString(),
}),
},
numDeployments: 1,
Expand Down
Loading

0 comments on commit 2b80792

Please sign in to comment.