Skip to content

Commit

Permalink
fix(pg): update the chugsplash-execute hardhat task
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Nov 16, 2022
1 parent 457b19a commit 7c367b4
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 121 deletions.
6 changes: 6 additions & 0 deletions .changeset/small-falcons-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@chugsplash/executor': patch
'@chugsplash/plugins': patch
---

Updates the chugsplash-execute task
10 changes: 2 additions & 8 deletions packages/executor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ChugSplashRegistryABI,
CHUGSPLASH_REGISTRY_PROXY_ADDRESS,
} from '@chugsplash/contracts'
import { ChugSplashBundleState } from '@chugsplash/core'
import { getChainId } from '@eth-optimism/core-utils'
import * as Amplitude from '@amplitude/node'

Expand Down Expand Up @@ -112,11 +111,6 @@ export class ChugSplashExecutor extends BaseServiceV2<Options, Metrics, State> {
continue
}

// fetch bundle state
const bundleState: ChugSplashBundleState = await manager.bundles(
activeBundleId
)

// get proposal event and compile
const proposalEvents = await manager.queryFilter(
manager.filters.ChugSplashBundleProposed(activeBundleId)
Expand All @@ -141,10 +135,10 @@ export class ChugSplashExecutor extends BaseServiceV2<Options, Metrics, State> {
try {
await hre.run('chugsplash-execute', {
chugSplashManager: manager,
bundleState,
bundleId: activeBundleId,
bundle,
parsedConfig: canonicalConfig,
deployer: signer,
executor: signer,
hide: false,
})
this.logger.info('Successfully executed')
Expand Down
19 changes: 8 additions & 11 deletions packages/plugins/src/hardhat/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path'
import * as fs from 'fs'

import '@nomiclabs/hardhat-ethers'
import { Contract, ethers, Signer } from 'ethers'
import { ethers } from 'ethers'
import {
ChugSplashConfig,
getProxyAddress,
Expand All @@ -11,14 +11,12 @@ import {
ChugSplashBundleState,
ChugSplashBundleStatus,
isProxyDeployed,
getChugSplashManagerProxyAddress,
chugsplashLog,
displayDeploymentTable,
ChugSplashActionBundle,
computeBundleId,
getChugSplashManager,
} from '@chugsplash/core'
import { ChugSplashManagerABI, OWNER_BOND_AMOUNT } from '@chugsplash/contracts'
import { getChainId } from '@eth-optimism/core-utils'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

Expand All @@ -27,13 +25,12 @@ import { loadParsedChugSplashConfig, writeHardhatSnapshotId } from './utils'
import {
chugsplashApproveTask,
chugsplashCommitSubtask,
chugsplashProposeTask,
fundTask,
statusTask,
TASK_CHUGSPLASH_VERIFY_BUNDLE,
} from './tasks'
import { deployChugSplashPredeploys } from './predeploys'
import { getExecutionAmountPlusBuffer } from './fund'
import { postExecutionActions } from './execution'

/**
* TODO
Expand Down Expand Up @@ -74,8 +71,7 @@ export const deployChugSplashConfig = async (
) => {
const provider = hre.ethers.provider
const signer = provider.getSigner()
const deployer = provider.getSigner()
const deployerAddress = await deployer.getAddress()
const signerAddress = await signer.getAddress()

const parsedConfig = loadParsedChugSplashConfig(configPath)

Expand All @@ -86,7 +82,7 @@ export const deployChugSplashConfig = async (
await registerChugSplashProject(
provider,
parsedConfig.options.projectName,
deployerAddress
signerAddress
)

// Get the bundle ID without publishing anything to IPFS.
Expand Down Expand Up @@ -174,12 +170,13 @@ export const deployChugSplashConfig = async (
if (!remoteExecution) {
await hre.run('chugsplash-execute', {
chugSplashManager: ChugSplashManager,
bundleState,
bundleId,
bundle,
parsedConfig,
deployer,
executor: signer,
silent: true,
})
await postExecutionActions(provider, parsedConfig)
}

displayDeploymentTable(parsedConfig, silent)
Expand Down Expand Up @@ -284,7 +281,7 @@ export const checkValidDeployment = async (
}

export const getFinalDeploymentTxnHash = async (
ChugSplashManager: Contract,
ChugSplashManager: ethers.Contract,
bundleId: string
): Promise<string> => {
const [finalDeploymentEvent] = await ChugSplashManager.queryFilter(
Expand Down
50 changes: 49 additions & 1 deletion packages/plugins/src/hardhat/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {
ChugSplashConfig,
chugsplashLog,
getChugSplashRegistry,
getChugSplashManager,
} from '@chugsplash/core'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { SingleBar, Presets } from 'cli-progress'
import { Contract, ethers } from 'ethers'
import { ethers } from 'ethers'
import { ChugSplashManagerABI } from '@chugsplash/contracts'
import { sleep } from '@eth-optimism/core-utils'

Expand Down Expand Up @@ -115,3 +116,50 @@ export const monitorRemoteExecution = async (
throw new Error(`${projectName} was cancelled.`)
}
}

/**
* Performs actions on behalf of the project owner after the successful execution of a bundle.
*
* @param provider JSON RPC provider corresponding to the current project owner.
* @param parsedConfig Parsed ChugSplashConfig.
*/
export const postExecutionActions = async (
provider: ethers.providers.JsonRpcProvider,
parsedConfig: ChugSplashConfig
) => {
const signer = provider.getSigner()
const ChugSplashManager = getChugSplashManager(
signer,
parsedConfig.options.projectName
)
const currChugSplashManagerOwner = await ChugSplashManager.owner()

// Exit early if the calling address is not the current owner of the ChugSplashManager.
if (signer.getAddress() !== currChugSplashManagerOwner) {
return
}

// Withdraw any of the current project owner's funds in the ChugSplashManager.
const totalDebt = await ChugSplashManager.totalDebt()
const chugsplashManagerBalance = await provider.getBalance(
ChugSplashManager.address
)
if (chugsplashManagerBalance.sub(totalDebt).gt(0)) {
await (await ChugSplashManager.withdrawOwnerETH()).wait()
}

// Transfer ownership of the ChugSplashManager to the project owner specified in the
// ChugSplashConfig if their address isn't already the owner.
if (parsedConfig.options.projectOwner !== currChugSplashManagerOwner) {
if (parsedConfig.options.projectOwner === ethers.constants.AddressZero) {
// We must call a separate function if ownership is being transferred to address(0).
await (await ChugSplashManager.renounceOwnership()).wait()
} else {
await (
await ChugSplashManager.transferOwnership(
parsedConfig.options.projectOwner
)
).wait()
}
}
}
Loading

0 comments on commit 7c367b4

Please sign in to comment.