-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat(ctb): put dictator behind Proxy #4206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/contracts-bedrock/deploy/009-SystemDictatorProxy.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { DeployFunction } from 'hardhat-deploy/dist/types' | ||
|
|
||
| import { | ||
| assertContractVariable, | ||
| deployAndVerifyAndThen, | ||
| } from '../src/deploy-utils' | ||
|
|
||
| const deployFn: DeployFunction = async (hre) => { | ||
| const { deployer } = await hre.getNamedAccounts() | ||
| await deployAndVerifyAndThen({ | ||
| hre, | ||
| name: 'SystemDictatorProxy', | ||
| contract: 'Proxy', | ||
| args: [deployer], | ||
| postDeployAction: async (contract) => { | ||
| await assertContractVariable(contract, 'admin', deployer) | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| deployFn.tags = ['SystemDictatorProxy'] | ||
|
|
||
| export default deployFn |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
packages/contracts-bedrock/deploy/018-SystemDictatorImpl.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { DeployFunction } from 'hardhat-deploy/dist/types' | ||
| import '@eth-optimism/hardhat-deploy-config' | ||
| import 'hardhat-deploy' | ||
|
|
||
| import { deployAndVerifyAndThen } from '../src/deploy-utils' | ||
|
|
||
| const deployFn: DeployFunction = async (hre) => { | ||
| await deployAndVerifyAndThen({ | ||
| hre, | ||
| name: 'SystemDictator', | ||
| args: [], | ||
| }) | ||
| } | ||
|
|
||
| deployFn.tags = ['SystemDictatorImpl'] | ||
|
|
||
| export default deployFn |
137 changes: 137 additions & 0 deletions
137
packages/contracts-bedrock/deploy/019-SystemDictatorInit.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import { ethers } from 'ethers' | ||
| import { DeployFunction } from 'hardhat-deploy/dist/types' | ||
| import { awaitCondition } from '@eth-optimism/core-utils' | ||
| import '@eth-optimism/hardhat-deploy-config' | ||
| import 'hardhat-deploy' | ||
|
|
||
| import { | ||
| assertDictatorConfig, | ||
| makeDictatorConfig, | ||
| getContractsFromArtifacts, | ||
| } from '../src/deploy-utils' | ||
|
|
||
| const deployFn: DeployFunction = async (hre) => { | ||
| const { deployer } = await hre.getNamedAccounts() | ||
|
|
||
| let controller = hre.deployConfig.controller | ||
| if (controller === ethers.constants.AddressZero) { | ||
| if (hre.network.config.live === false) { | ||
| console.log(`WARNING!!!`) | ||
| console.log(`WARNING!!!`) | ||
| console.log(`WARNING!!!`) | ||
| console.log(`WARNING!!! A controller address was not provided.`) | ||
| console.log( | ||
| `WARNING!!! Make sure you are ONLY doing this on a test network.` | ||
| ) | ||
| controller = deployer | ||
| } else { | ||
| throw new Error( | ||
| `controller address MUST NOT be the deployer on live networks` | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| let finalOwner = hre.deployConfig.finalSystemOwner | ||
| if (finalOwner === ethers.constants.AddressZero) { | ||
| if (hre.network.config.live === false) { | ||
| console.log(`WARNING!!!`) | ||
| console.log(`WARNING!!!`) | ||
| console.log(`WARNING!!!`) | ||
| console.log(`WARNING!!! A proxy admin owner address was not provided.`) | ||
| console.log( | ||
| `WARNING!!! Make sure you are ONLY doing this on a test network.` | ||
| ) | ||
| finalOwner = deployer | ||
| } else { | ||
| throw new Error(`must specify the finalSystemOwner on live networks`) | ||
| } | ||
| } | ||
|
|
||
| // Load the contracts we need to interact with. | ||
| const [ | ||
| SystemDictator, | ||
| SystemDictatorProxy, | ||
| SystemDictatorProxyWithSigner, | ||
| SystemDictatorImpl, | ||
| ] = await getContractsFromArtifacts(hre, [ | ||
| { | ||
| name: 'SystemDictatorProxy', | ||
| iface: 'SystemDictator', | ||
| signerOrProvider: deployer, | ||
| }, | ||
| { | ||
| name: 'SystemDictatorProxy', | ||
| }, | ||
| { | ||
| name: 'SystemDictatorProxy', | ||
| signerOrProvider: deployer, | ||
| }, | ||
| { | ||
| name: 'SystemDictator', | ||
| signerOrProvider: deployer, | ||
| }, | ||
| ]) | ||
|
|
||
| // Load the dictator configuration. | ||
| const config = await makeDictatorConfig(hre, controller, finalOwner, false) | ||
|
|
||
| // Update the implementation if necessary. | ||
| if ( | ||
| (await SystemDictatorProxy.callStatic.implementation({ | ||
| from: ethers.constants.AddressZero, | ||
| })) !== SystemDictatorImpl.address | ||
| ) { | ||
| console.log('Upgrading the SystemDictator proxy...') | ||
|
|
||
| // Upgrade and initialize the proxy. | ||
| await SystemDictatorProxyWithSigner.upgradeToAndCall( | ||
| SystemDictatorImpl.address, | ||
| SystemDictatorImpl.interface.encodeFunctionData('initialize', [config]) | ||
| ) | ||
|
|
||
| // Wait for the transaction to execute properly. | ||
| await awaitCondition( | ||
| async () => { | ||
| return ( | ||
| (await SystemDictatorProxy.callStatic.implementation({ | ||
| from: ethers.constants.AddressZero, | ||
| })) === SystemDictatorImpl.address | ||
| ) | ||
| }, | ||
| 30000, | ||
| 1000 | ||
| ) | ||
|
|
||
| // Verify that the contract was initialized correctly. | ||
| await assertDictatorConfig(SystemDictator, config) | ||
| } | ||
|
|
||
| // Update the owner if necessary. | ||
| if ( | ||
| (await SystemDictatorProxy.callStatic.admin({ | ||
| from: ethers.constants.AddressZero, | ||
| })) !== controller | ||
| ) { | ||
| console.log('Transferring ownership of the SystemDictator proxy...') | ||
|
|
||
| // Transfer ownership to the controller address. | ||
smartcontracts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await SystemDictatorProxyWithSigner.transferOwnership(controller) | ||
|
|
||
| // Wait for the transaction to execute properly. | ||
| await awaitCondition( | ||
| async () => { | ||
| return ( | ||
| (await SystemDictatorProxy.callStatic.admin({ | ||
| from: ethers.constants.AddressZero, | ||
| })) === controller | ||
| ) | ||
| }, | ||
| 30000, | ||
| 1000 | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| deployFn.tags = ['SystemDictatorImpl'] | ||
|
|
||
| export default deployFn | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.