Skip to content

Commit

Permalink
fix(pg): improve deployment task error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Oct 30, 2022
1 parent 7dede33 commit dc88439
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 113 deletions.
7 changes: 7 additions & 0 deletions .changeset/mean-pumas-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@chugsplash/core': patch
'@chugsplash/demo': patch
'@chugsplash/plugins': patch
---

Improved error handling in deployment task
5 changes: 4 additions & 1 deletion packages/core/src/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,8 @@ export interface ChugSplashActionBundle {
export type ChugSplashBundleState = {
status: ChugSplashBundleStatus
executions: boolean[]
total: number
merkleRoot: string
actionsExecuted: number
timeClaimed: number
selectedExecutor: string
}
44 changes: 36 additions & 8 deletions packages/core/src/predeploys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers, Signer } from 'ethers'
import { Contract, ethers, Signer } from 'ethers'
import 'hardhat-deploy'
import {
OWNER_BOND_AMOUNT,
Expand All @@ -20,6 +20,8 @@ import {
DEFAULT_ADAPTER_ADDRESS,
} from '@chugsplash/contracts'

import { getChugSplashRegistry } from './utils'

export const deployChugSplashPredeploys = async (
hre,
deployer: ethers.Signer
Expand All @@ -44,6 +46,16 @@ export const deployChugSplashPredeploys = async (
if ((await isDefaultAdapterDeployed(deployer)) === false) {
await deployDefaultAdapter(hre, await deployer.getAddress())
}

const ChugSplashRegistry = getChugSplashRegistry(deployer)
if ((await isRegistryInitialized(ChugSplashRegistry)) === false) {
const tx = await ChugSplashRegistry.addProxyType(
ethers.constants.HashZero,
DEFAULT_ADAPTER_ADDRESS
)
await tx.wait()
}

// await deployProxyUpdater(hre, deployerAddress)
// await deployChugSplashRegistry(hre, deployerAddress)
// await deployDefaultAdapter(hre, deployerAddress)
Expand Down Expand Up @@ -177,23 +189,39 @@ export const deployDefaultAdapter = async (hre, deployerAddress: string) => {
await deploy()
}

export const chugsplashContractsAreDeployed = async (
export const chugsplashContractsAreDeployedAndInitialized = async (
signer: Signer
): Promise<boolean> => {
const deployed: boolean =
(await isBootloaderInitialized(signer)) &&
(await isDefaultAdapterDeployed(signer))
return deployed
const bootloaderInitialized = await isBootloaderInitialized(signer)
const defaultAdapterDeployed = await isDefaultAdapterDeployed(signer)
if (!bootloaderInitialized || !defaultAdapterDeployed) {
return false
}

const ChugSplashRegistry = getChugSplashRegistry(signer)
const registryInitialized = await isRegistryInitialized(ChugSplashRegistry)
return registryInitialized
}

export const isBootloaderInitialized = async (signer: Signer) => {
export const isBootloaderInitialized = async (
signer: Signer
): Promise<boolean> => {
const deployedBytecode = await signer.provider.getCode(PROXY_UPDATER_ADDRESS)
return deployedBytecode !== '0x'
}

export const isDefaultAdapterDeployed = async (signer: Signer) => {
export const isDefaultAdapterDeployed = async (
signer: Signer
): Promise<boolean> => {
const deployedBytecode = await signer.provider.getCode(
DEFAULT_ADAPTER_ADDRESS
)
return deployedBytecode !== '0x'
}

export const isRegistryInitialized = async (
registry: Contract
): Promise<boolean> => {
const adapter = await registry.adapters(ethers.constants.HashZero)
return adapter !== ethers.constants.AddressZero
}
4 changes: 1 addition & 3 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ export const registerChugSplashProject = async (
}
} else {
const existingProjectOwner = await getProjectOwner(projectName, signer)
if (existingProjectOwner === (await signer.getAddress())) {
throw new Error('You already registered this project.')
} else {
if (existingProjectOwner !== (await signer.getAddress())) {
throw new Error(`Project already registered by: ${existingProjectOwner}.`)
}
}
Expand Down
27 changes: 27 additions & 0 deletions packages/demo/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import '@chugsplash/plugins'
// Load environment variables from .env
dotenv.config()

const PRIVATE_KEY: any = process.env.PRIVATE_KEY

const config: HardhatUserConfig = {
solidity: {
version: '0.8.15',
Expand All @@ -23,6 +25,31 @@ const config: HardhatUserConfig = {
localhost: {
url: 'http://localhost:8545',
},
goerli: {
chainId: 5,
url: `https://goerli.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: [PRIVATE_KEY],
},
'optimism-goerli': {
chainId: 420,
url: `https://optimism-goerli.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: [PRIVATE_KEY],
},
optimism: {
chainId: 10,
url: `https://optimism-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: [PRIVATE_KEY],
},
arbitrum: {
chainId: 42161,
url: 'https://arb1.arbitrum.io/rpc',
accounts: [PRIVATE_KEY],
},
'arbitrum-goerli': {
chainId: 421613,
url: 'https://goerli-rollup.arbitrum.io/rpc',
accounts: [PRIVATE_KEY],
},
},
}

Expand Down
4 changes: 2 additions & 2 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"@eth-optimism/contracts": "^0.5.29",
"@eth-optimism/core-utils": "^0.9.0",
"@eth-optimism/core-utils": "^0.10.1",
"@nomiclabs/hardhat-ethers": "^2.0.6",
"@openzeppelin/contracts": "^4.6.0",
"@openzeppelin/contracts-upgradeable": "^4.6.0",
Expand All @@ -46,7 +46,7 @@
},
"dependencies": {
"@chugsplash/core": "^0.3.4",
"@chugsplash/plugins": "^0.5.1",
"@chugsplash/plugins": "link:packages/plugins",
"@types/node": "^18.0.0"
}
}
3 changes: 2 additions & 1 deletion packages/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import '@chugsplash/plugins'
```

Update the `outputSelection` setting in your `hardhat.config.ts` file:
```
```typescript
const config: HardhatUserConfig = {
...
solidity: {
Expand Down Expand Up @@ -180,6 +180,7 @@ ChugSplash uses deterministic proxies to deploy contracts and set their state va
* References to contracts in other config files are not supported (i.e. `{"!Ref: MyOtherProject.OtherContract "}`)
* You cannot use ChugSplash to upgrade existing contracts.
* Source code is not automatically verified on Etherscan or Sourcify.
* Deployment artifacts are not generated.
* Contract ABIs, source code, and deployment configs are not published to NPM.

All of these features will be supported in the near future. If you need any of these features before you can start using ChugSplash for your projects, please reach out to [@samgoldman0](https://t.me/samgoldman0) on Telegram and it will be prioritized.
2 changes: 1 addition & 1 deletion packages/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@chugsplash/contracts": "^0.3.5",
"@chugsplash/core": "^0.3.4",
"@chugsplash/core": "link:packages/core",
"@eth-optimism/core-utils": "^0.9.1",
"@ethereumjs/common": "^3.0.1",
"@ethereumjs/vm": "^6.2.0",
Expand Down
Loading

0 comments on commit dc88439

Please sign in to comment.