Skip to content

Commit

Permalink
fix(pg): add --no-withdraw to the deploy task
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Jan 7, 2023
1 parent 242c7ca commit 89fd479
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-worms-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chugsplash/plugins': patch
---

Add a '--no-withdraw' flag to the deploy task
4 changes: 4 additions & 0 deletions packages/plugins/src/hardhat/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const deployAllChugSplashConfigs = async (
ipfsUrl,
noCompile,
confirm,
true,
await signer.getAddress(),
executor,
spinner
Expand All @@ -96,6 +97,7 @@ export const deployChugSplashConfig = async (
ipfsUrl: string,
noCompile: boolean,
confirm: boolean,
withdraw: boolean,
newOwner: string,
executor?: ChugSplashExecutor,
spinner: ora.Ora = ora({ isSilent: true })
Expand Down Expand Up @@ -220,6 +222,7 @@ export const deployChugSplashConfig = async (
await chugsplashApproveTask(
{
configPath,
noWithdraw: false, // This value doesn't matter because we're skipping monitoring deployment
silent: true,
skipMonitorStatus: true,
},
Expand Down Expand Up @@ -255,6 +258,7 @@ export const deployChugSplashConfig = async (
hre,
parsedConfig,
await getFinalDeploymentTxnHash(ChugSplashManager, bundleId),
withdraw,
newOwner,
spinner
)
Expand Down
45 changes: 30 additions & 15 deletions packages/plugins/src/hardhat/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,18 @@ export const getNumDeployedImplementations = (
* @param parsedConfig Parsed ParsedChugSplashConfig.
* @param finalDeploymentTxnHash Hash of the transaction that completed the deployment. This is the
* call to `completeChugSplashBundle` on the ChugSplashManager.
* @param withdraw Boolean that determines if remaining funds in the ChugSplashManager should be
* withdrawn to the project owner.
* @param newProjectOwner Optional address to receive ownership of the project.
*/
export const postExecutionActions = async (
hre: HardhatRuntimeEnvironment,
parsedConfig: ParsedChugSplashConfig,
finalDeploymentTxnHash: string,
withdraw: boolean,
newProjectOwner?: string,
spinner: ora.Ora = ora({ isSilent: true })
) => {
spinner.start(`Sending leftover funds to the project owner...`)

const provider = hre.ethers.provider
const signer = provider.getSigner()
const ChugSplashManager = getChugSplashManager(
Expand All @@ -171,32 +172,46 @@ export const postExecutionActions = async (
parsedConfig.options.projectName
)

spinner.start(`Retrieving leftover funds...`)

if ((await signer.getAddress()) === currProjectOwner) {
// Withdraw any of the current project owner's funds in the ChugSplashManager.
const ownerBalance = await getOwnerWithdrawableAmount(
provider,
parsedConfig.options.projectName
)
if (ownerBalance.gt(0)) {
await (
await ChugSplashManager.withdrawOwnerETH(
await getGasPriceOverrides(provider)
if (withdraw) {
// Withdraw any of the current project owner's funds in the ChugSplashManager.
if (ownerBalance.gt(0)) {
await (
await ChugSplashManager.withdrawOwnerETH(
await getGasPriceOverrides(provider)
)
).wait()
spinner.succeed(
`Sent leftover funds to the project owner. Amount: ${formatEther(
ownerBalance,
4
)} ETH. Recipient: ${currProjectOwner}`
)
).wait()
} else {
spinner.succeed(
`There were no leftover funds to send to the project owner.`
)
}
} else {
spinner.succeed(
`Sent leftover funds to the project owner. Amount: ${formatEther(
`Skipped withdrawing leftover funds. Amount remaining: ${formatEther(
ownerBalance,
4
)} ETH. Recipient: ${currProjectOwner}`
)
} else {
spinner.succeed(
`There were no leftover funds to send to the project owner.`
)} ETH.`
)
}

// Transfer ownership of the ChugSplashManager if a new project owner has been specified.
if (newProjectOwner !== undefined && newProjectOwner !== currProjectOwner) {
if (
ethers.utils.isAddress(newProjectOwner) &&
newProjectOwner !== currProjectOwner
) {
spinner.start(`Transferring project ownership to: ${newProjectOwner}`)
if (newProjectOwner === ethers.constants.AddressZero) {
// We must call a separate function if ownership is being transferred to address(0).
Expand Down
36 changes: 29 additions & 7 deletions packages/plugins/src/hardhat/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,19 @@ export const chugsplashDeployTask = async (
silent: boolean
noCompile: boolean
confirm: boolean
noWithdraw: boolean
},
hre: HardhatRuntimeEnvironment
) => {
const { configPath, newOwner, ipfsUrl, silent, noCompile } = args
const {
configPath,
newOwner,
ipfsUrl,
silent,
noCompile,
confirm,
noWithdraw,
} = args

const spinner = ora({ isSilent: silent })

Expand All @@ -213,7 +222,8 @@ export const chugsplashDeployTask = async (
remoteExecution,
ipfsUrl,
noCompile,
args.confirm,
confirm,
!noWithdraw,
newOwner ?? signerAddress,
executor,
spinner
Expand All @@ -233,6 +243,10 @@ task(TASK_CHUGSPLASH_DEPLOY)
)
.addFlag('silent', "Hide all of ChugSplash's output")
.addFlag('noCompile', "Don't compile when running this task")
.addFlag(
'noWithdraw',
'Skip withdrawing leftover funds to the project owner.'
)
.addFlag(
'confirm',
'Automatically confirm contract upgrades. Only applicable if upgrading on a live network.'
Expand Down Expand Up @@ -421,12 +435,13 @@ task(TASK_CHUGSPLASH_PROPOSE)
export const chugsplashApproveTask = async (
args: {
configPath: string
noWithdraw: boolean
silent: boolean
skipMonitorStatus: boolean
},
hre: HardhatRuntimeEnvironment
) => {
const { configPath, silent, skipMonitorStatus } = args
const { configPath, noWithdraw, silent, skipMonitorStatus } = args

const provider = hre.ethers.provider
const signer = provider.getSigner()
Expand Down Expand Up @@ -537,6 +552,7 @@ npx hardhat chugsplash-fund --network ${
hre,
parsedConfig,
finalDeploymentTxnHash,
!noWithdraw,
undefined,
spinner
)
Expand All @@ -550,9 +566,9 @@ npx hardhat chugsplash-fund --network ${

task(TASK_CHUGSPLASH_APPROVE)
.setDescription('Allows a manager to approve a bundle to be executed.')
.addParam(
'amount',
'Amount to send to fund the deployment, denominated in wei'
.addFlag(
'noWithdraw',
'Skip withdrawing leftover funds to the project owner.'
)
.addParam('configPath', 'Path to the ChugSplash config file to approve')
.addFlag('silent', "Hide all of ChugSplash's output")
Expand Down Expand Up @@ -886,12 +902,13 @@ subtask(TASK_CHUGSPLASH_VERIFY_BUNDLE)
export const monitorTask = async (
args: {
configPath: string
noWithdraw: boolean
silent: boolean
newOwner: string
},
hre: HardhatRuntimeEnvironment
) => {
const { configPath, silent, newOwner } = args
const { configPath, noWithdraw, silent, newOwner } = args

const spinner = ora({ isSilent: silent })
spinner.start(`Loading project information...`)
Expand Down Expand Up @@ -961,6 +978,7 @@ project with a name other than ${parsedConfig.options.projectName}`
hre,
parsedConfig,
finalDeploymentTxnHash,
!noWithdraw,
newOwner,
spinner
)
Expand All @@ -979,6 +997,10 @@ project with a name other than ${parsedConfig.options.projectName}`
task(TASK_CHUGSPLASH_MONITOR)
.setDescription('Displays the status of a ChugSplash bundle')
.addParam('configPath', 'Path to the ChugSplash config file to monitor')
.addFlag(
'noWithdraw',
'Skip withdrawing leftover funds to the project owner.'
)
.setAction(monitorTask)

export const chugsplashFundTask = async (
Expand Down

0 comments on commit 89fd479

Please sign in to comment.