Skip to content

Commit

Permalink
fix: verify and deploy the chugsplash predeploys in the executor
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Nov 22, 2022
1 parent 03401c9 commit f217221
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 122 deletions.
7 changes: 7 additions & 0 deletions .changeset/small-ducks-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@chugsplash/core': patch
'@chugsplash/executor': patch
'@chugsplash/plugins': patch
---

Use the executor to deploy and verify the ChugSplash predeployed contracts
6 changes: 3 additions & 3 deletions packages/core/src/languages/solidity/predeploys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import {
import { getChugSplashRegistry, getProxyOwner } from '../../utils'

export const deployChugSplashPredeploys = async (
provider: ethers.providers.JsonRpcProvider
provider: ethers.providers.JsonRpcProvider,
deployer: ethers.Signer
): Promise<void> => {
const owner = '0x1A3DAA6F487A480c1aD312b90FD0244871940b66'
const deployer = provider.getSigner()

// Deploy the root ChugSplashManager.
const ChugSplashManager = await doDeterministicDeploy(provider, {
Expand Down Expand Up @@ -161,7 +161,7 @@ export const deployChugSplashPredeploys = async (
)

// Optionally initialize registry.
const ChugSplashRegistry = getChugSplashRegistry(provider.getSigner())
const ChugSplashRegistry = getChugSplashRegistry(deployer)
const adapter = await ChugSplashRegistry.adapters(ethers.constants.HashZero)
if (adapter === ethers.constants.AddressZero) {
await (
Expand Down
22 changes: 19 additions & 3 deletions packages/executor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ import {
hasSufficientFundsForExecution,
executeTask,
CanonicalChugSplashConfig,
deployChugSplashPredeploys,
} from '@chugsplash/core'
import { getChainId } from '@eth-optimism/core-utils'
import * as Amplitude from '@amplitude/node'

import { compileRemoteBundle, verifyChugSplashConfig } from './utils'
import {
compileRemoteBundle,
verifyChugSplashPredeploys,
verifyChugSplashConfig,
} from './utils'

export * from './utils'

Expand Down Expand Up @@ -121,14 +126,25 @@ export class ChugSplashExecutor extends BaseServiceV2<Options, Metrics, State> {
this.state.provider
)

// Deploy the ChugSplash predeploys.
await deployChugSplashPredeploys(this.state.provider, this.state.wallet)

// Verify the ChugSplash predeploys if the current network is live.
if ((await getChainId(this.state.provider)) !== 31337) {
await verifyChugSplashPredeploys(
this.state.provider,
this.options.network
)
}

this.logger = new Logger({
name: 'Logger',
level: options.logLevel,
})
}

async init() {
this.setup(this.options)
await this.setup(this.options)
}

async main(
Expand All @@ -139,7 +155,7 @@ export class ChugSplashExecutor extends BaseServiceV2<Options, Metrics, State> {
// Setup state if options were provided.
// Necessary to allow the user to pass in options when running the executor programmatically.
if (options) {
this.setup(options, provider)
await this.setup(options, provider)
}

const latestBlockNumber = await this.state.provider.getBlockNumber()
Expand Down
101 changes: 98 additions & 3 deletions packages/executor/src/utils/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ import { chainConfig } from '@nomiclabs/hardhat-etherscan/dist/src/ChainConfig'
import {
ChugSplashManagerABI,
CHUGSPLASH_MANAGER_ADDRESS,
ChugSplashManagerArtifact,
ChugSplashBootLoaderArtifact,
CHUGSPLASH_BOOTLOADER_ADDRESS,
ProxyUpdaterArtifact,
PROXY_UPDATER_ADDRESS,
ProxyArtifact,
CHUGSPLASH_REGISTRY_PROXY_ADDRESS,
ChugSplashManagerProxyArtifact,
ROOT_CHUGSPLASH_MANAGER_PROXY_ADDRESS,
ChugSplashRegistryArtifact,
CHUGSPLASH_REGISTRY_ADDRESS,
DefaultAdapterArtifact,
DEFAULT_ADAPTER_ADDRESS,
DeterministicProxyOwnerArtifact,
DETERMINISTIC_PROXY_OWNER_ADDRESS,
buildInfo,
CHUGSPLASH_CONSTRUCTOR_ARGS,
} from '@chugsplash/contracts'
import { request } from 'undici'

Expand All @@ -51,7 +68,7 @@ export const RESPONSE_OK = '1'

export const verifyChugSplashConfig = async (
configUri: string,
provider: ethers.providers.JsonRpcProvider,
provider: ethers.providers.Provider,
networkName: string
) => {
const { etherscanApiKey, etherscanApiEndpoints } = await getEtherscanInfo(
Expand Down Expand Up @@ -147,8 +164,86 @@ export const verifyChugSplashConfig = async (
}
}

export const verifyChugSplashPredeploys = async (
provider: ethers.providers.Provider,
networkName: string
) => {
const { etherscanApiKey, etherscanApiEndpoints } = await getEtherscanInfo(
provider,
networkName
)

const contracts = [
{
artifact: ChugSplashManagerArtifact,
address: CHUGSPLASH_MANAGER_ADDRESS,
},
{
artifact: ChugSplashBootLoaderArtifact,
address: CHUGSPLASH_BOOTLOADER_ADDRESS,
},
{ artifact: ProxyUpdaterArtifact, address: PROXY_UPDATER_ADDRESS },
{ artifact: ProxyArtifact, address: CHUGSPLASH_REGISTRY_PROXY_ADDRESS },
{
artifact: ChugSplashManagerProxyArtifact,
address: ROOT_CHUGSPLASH_MANAGER_PROXY_ADDRESS,
},
{
artifact: ChugSplashRegistryArtifact,
address: CHUGSPLASH_REGISTRY_ADDRESS,
},
{ artifact: DefaultAdapterArtifact, address: DEFAULT_ADAPTER_ADDRESS },
{
artifact: DeterministicProxyOwnerArtifact,
address: DETERMINISTIC_PROXY_OWNER_ADDRESS,
},
]

for (const { artifact, address } of contracts) {
const { sourceName, contractName, abi } = artifact

const minimumCompilerInput = getMinimumCompilerInput(
buildInfo.input,
buildInfo.output.sources,
sourceName
)

await attemptVerification(
provider,
networkName,
etherscanApiEndpoints,
address,
sourceName,
contractName,
abi,
etherscanApiKey,
minimumCompilerInput,
buildInfo.solcVersion,
CHUGSPLASH_CONSTRUCTOR_ARGS[sourceName]
)
}

// Link the ChugSplashRegistry's implementation with its proxy
await linkProxyWithImplementation(
etherscanApiEndpoints,
etherscanApiKey,
CHUGSPLASH_REGISTRY_PROXY_ADDRESS,
CHUGSPLASH_REGISTRY_ADDRESS,
'ChugSplashRegistry'
)

// Link the root ChugSplashManager's implementation with its proxy
await linkProxyWithImplementation(
etherscanApiEndpoints,
etherscanApiKey,
ROOT_CHUGSPLASH_MANAGER_PROXY_ADDRESS,
CHUGSPLASH_MANAGER_ADDRESS,
'ChugSplashManager'
)
}

export const attemptVerification = async (
provider: ethers.providers.JsonRpcProvider,
provider: ethers.providers.Provider,
networkName: string,
etherscanApiEndpoints: EtherscanURLs,
contractAddress: string,
Expand Down Expand Up @@ -259,7 +354,7 @@ export const attemptVerification = async (
}

export const getEtherscanInfo = async (
provider: ethers.providers.JsonRpcProvider,
provider: ethers.providers.Provider,
networkName: string
): Promise<{
etherscanApiKey: string
Expand Down
1 change: 0 additions & 1 deletion packages/executor/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from './compile'
export * from './constants'
export * from './helpers'
export * from './etherscan'
export * from './initialize'
102 changes: 0 additions & 102 deletions packages/executor/src/utils/initialize.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/plugins/src/hardhat/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ export const deployChugSplashConfig = async (
if (!remoteExecution) {
signer.sendTransaction({
to: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
value: ethers.utils.parseEther('10'),
value: ethers.utils.parseEther('1'),
})

const executor = new ChugSplashExecutor()
executor.main(
await executor.main(
{
privateKey:
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
Expand Down
Loading

0 comments on commit f217221

Please sign in to comment.