Skip to content

Commit

Permalink
feat(pg): add hardhat task to explicitly fund deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Nov 16, 2022
1 parent ac04198 commit 3d1ca28
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-actors-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chugsplash/plugins': minor
---

Add Hardhat task to explicitly fund deployments
24 changes: 0 additions & 24 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,6 @@ export const getChugSplashManagerProxyAddress = (projectName: string) => {
)
}

// export const getChugSplashManagerAddress = (projectName: string) => {
// return utils.getCreate2Address(
// CHUGSPLASH_REGISTRY_ADDRESS,
// constants.HashZero,
// utils.solidityKeccak256(
// ['bytes', 'bytes'],
// [
// ChugSplashManagerArtifact.bytecode,
// utils.defaultAbiCoder.encode(
// ['address', 'string', 'address', 'uint256', 'uint256', 'uint256'],
// [
// CHUGSPLASH_REGISTRY_ADDRESS,
// projectName,
// PROXY_UPDATER_ADDRESS,
// EXECUTOR_BOND_AMOUNT,
// EXECUTION_LOCK_TIME,
// OWNER_BOND_AMOUNT,
// ]
// ),
// ]
// )
// )
// }

/**
* Registers a new ChugSplash project.
*
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/src/hardhat/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isProxyDeployed,
getChugSplashManagerProxyAddress,
chugsplashLog,
displayDeploymentTable,
} from '@chugsplash/core'
import { ChugSplashManagerABI, OWNER_BOND_AMOUNT } from '@chugsplash/contracts'
import { getChainId } from '@eth-optimism/core-utils'
Expand Down Expand Up @@ -167,6 +168,7 @@ export const deployChugSplashConfig = async (
deployer,
silent: true,
})
displayDeploymentTable(parsedConfig, false)
}
chugsplashLog(`Deployed ${parsedConfig.options.projectName}.`, silent)
}
Expand Down
110 changes: 51 additions & 59 deletions packages/plugins/src/hardhat/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getProjectOwnerAddress,
chugsplashLog,
displayDeploymentTable,
getChugSplashManagerProxyAddress,
} from '@chugsplash/core'
import {
ChugSplashManagerABI,
Expand Down Expand Up @@ -1119,65 +1120,56 @@ task(TASK_CHUGSPLASH_STATUS)
}
)

// task(TASK_FUND)
// .setDescription('Fund a ChugSplash deployment')
// .addParam('amount', 'Amount to send in wei')
// .addFlag('silent', "Hide all of ChugSplash's output")
// .addPositionalParam(
// 'configPath',
// 'Path to the ChugSplash config file'
// )
// .setAction(
// async (
// args: {
// amount: number
// silent: boolean
// configPath: string
// },
// hre: HardhatRuntimeEnvironment
// ) => {
// const { amount, silent, configPath } = args

// const signer = hre.ethers.provider.getSigner()

// const parsedConfig = loadParsedChugSplashConfig(configPath)

// const expectedAmountPlusBuffer = await getExecutionAmountPlusBuffer(
// hre,
// parsedConfig
// )

// const currSignerBalance = await signer.getBalance()
// if (currSignerBalance.lt(expectedAmountPlusBuffer)) {
// throw new Error(
// `Signer has insufficient funds. Please send at least ${ethers.utils.formatEther(
// amountPlusBuffer
// )} ETH to the signer's wallet: ${await signer.getAddress()}`
// )
// }

// const spinner = ora({ isSilent: silent })
// if (expectedAmount.gt(amount)) {
// throw new Error(`Insufficient amount supplied. The funds have not been sent.

// Expected amount: ${amountPlusBuffer} wei.
// Actual amount: ${amount} wei.

// Please attempt to deposit the funds again with the following command:
// npx hardhat fund --network ${hre.network.name} --amount ${amountPlusBuffer} ${configPath}`)
// } else if (expectedAmount.lte(0)) {
// spinner.fail(
// `Sufficient funds were previously deposited. No additional funds have been sent. You can proceed by approving the project to be executed:

// npx hardhat chugsplash-approve --network ${hre.network.name} ${configPath}`
// )
// } else {
// spinner.start(`Depositing ${ethers.utils.formatEther(amount)} ETH...`)
// // TODO: send tx
// spinner.succeed(`Deposited ${ethers.utils.formatEther(amount)} ETH.`)
// }
// }
// )
task(TASK_FUND)
.setDescription('Fund a ChugSplash deployment')
.addParam('amount', 'Amount to send in wei')
.addFlag('silent', "Hide all of ChugSplash's output")
.addPositionalParam('configPath', 'Path to the ChugSplash config file')
.setAction(
async (
args: {
amount: number
silent: boolean
configPath: string
},
hre: HardhatRuntimeEnvironment
) => {
const { amount, silent, configPath } = args

const spinner = ora({ isSilent: silent })

const signer = hre.ethers.provider.getSigner()
const parsedConfig = loadParsedChugSplashConfig(configPath)
const projectName = parsedConfig.options.projectName
const chugsplashManagerAddress =
getChugSplashManagerProxyAddress(projectName)
const signerBalance = await signer.getBalance()

if (signerBalance.lt(amount)) {
throw new Error(`Signer's balance is less than the specified amount.
Signer's balance: ${ethers.utils.formatEther(signerBalance)} ETH
Amount: ${ethers.utils.formatEther(amount)} ETH`)
}

spinner.start(
`Depositing ${ethers.utils.formatEther(
amount
)} ETH for the project: ${projectName}...`
)
await (
await signer.sendTransaction({
value: amount,
to: chugsplashManagerAddress,
})
).wait()
spinner.succeed(
`Deposited ${ethers.utils.formatEther(
amount
)} ETH for the project: ${projectName}.`
)
}
)

task(TASK_TEST_REMOTE_EXECUTION)
.setDescription(
Expand Down

0 comments on commit 3d1ca28

Please sign in to comment.