@@ -244,6 +244,65 @@ const sendProposal = async (proposalArgs, description, opts = {}) => {
244244 log ( "Done" ) ;
245245} ;
246246
247+ /**
248+ * Shortcut to create a deployment for hardhat to use
249+ * @param {Object } options for deployment
250+ * @param {Promise<Object> } fn to deploy contracts and return needed proposals
251+ * @returns {Object } main object used by hardhat
252+ */
253+ function deploymentWithProposal ( opts , fn ) {
254+ const { deployName, dependencies } = opts ;
255+ const runDeployment = async ( hre ) => {
256+ const tools = {
257+ ethers,
258+ deployWithConfirmation,
259+ } ;
260+ const proposal = await fn ( tools ) ;
261+
262+ const propDescription = proposal . name ;
263+ const propArgs = await proposeArgs ( proposal . actions ) ;
264+
265+ if ( isMainnet ) {
266+ // On Mainnet, only propose. The enqueue and execution are handled manually via multi-sig.
267+ log ( "Sending proposal to governor..." ) ;
268+ await sendProposal ( propArgs , propDescription ) ;
269+ log ( "Proposal sent." ) ;
270+ } else if ( isFork ) {
271+ // On Fork we can send the proposal then impersonate the guardian to execute it.
272+ log ( "Sending and executing proposal..." ) ;
273+ await executeProposal ( propArgs , propDescription ) ;
274+ log ( "Proposal executed." ) ;
275+ } else {
276+ // Hardcoding gas estimate on Rinkeby since it fails for an undetermined reason...
277+ const gasLimit = isRinkeby ? 1000000 : null ;
278+ for ( const proposal of proposals ) {
279+ const { contract, signature, args } = proposal ;
280+ log ( `Sending goverance action ${ signature } to ${ address } ` ) ;
281+ await withConfirmation (
282+ contract
283+ . connect ( sGovernor )
284+ [ signature ] ( ...args , await getTxOpts ( gasLimit ) )
285+ ) ;
286+ console . log ( `... ${ signature } completed` ) ;
287+ }
288+ }
289+ } ;
290+
291+ const main = async ( hre ) => {
292+ console . log ( `Running ${ deployName } deployment...` ) ;
293+ if ( ! hre ) {
294+ hre = require ( "hardhat" ) ;
295+ }
296+ await runDeployment ( hre ) ;
297+ console . log ( `${ deployName } deploy done.` ) ;
298+ return true ;
299+ } ;
300+ main . id = deployName ;
301+ main . dependencies = dependencies ;
302+ main . skip = ( ) => ! ( isMainnet || isRinkeby || isFork ) || isSmokeTest ;
303+ return main ;
304+ }
305+
247306module . exports = {
248307 log,
249308 sleep,
@@ -253,4 +312,5 @@ module.exports = {
253312 executeProposal,
254313 executeProposalOnFork,
255314 sendProposal,
315+ deploymentWithProposal,
256316} ;
0 commit comments